diff --git a/viewer/document_view.cc b/viewer/document_view.cc index 0c5f9a2a0cf..80ae7db9e62 100644 --- a/viewer/document_view.cc +++ b/viewer/document_view.cc @@ -118,10 +118,7 @@ void DocumentView::OnEmbed( Load(response_.Pass()); - auto& bounds = root_->bounds(); - float device_pixel_ratio = GetDevicePixelRatio(); - web_view_->resize(blink::WebSize(bounds.width / device_pixel_ratio, - bounds.height / device_pixel_ratio)); + UpdateRootSizeAndViewportMetrics(root_->bounds()); // TODO(abarth): We should ask the view whether it is focused instead of // assuming that we're focused. @@ -270,6 +267,20 @@ void DocumentView::OnViewBoundsChanged(mojo::View* view, const mojo::Rect& old_bounds, const mojo::Rect& new_bounds) { DCHECK_EQ(view, root_); + UpdateRootSizeAndViewportMetrics(new_bounds); +} + +void DocumentView::OnViewViewportMetricsChanged( + mojo::View* view, + const mojo::ViewportMetrics& old_metrics, + const mojo::ViewportMetrics& new_metrics) { + DCHECK_EQ(view, root_); + web_view_->setDeviceScaleFactor(GetDevicePixelRatio()); + UpdateRootSizeAndViewportMetrics(root_->bounds()); +} + +void DocumentView::UpdateRootSizeAndViewportMetrics( + const mojo::Rect& new_bounds) { float device_pixel_ratio = GetDevicePixelRatio(); web_view_->resize(blink::WebSize(new_bounds.width / device_pixel_ratio, new_bounds.height / device_pixel_ratio)); diff --git a/viewer/document_view.h b/viewer/document_view.h index 58e526d3040..3c57354cfa5 100644 --- a/viewer/document_view.h +++ b/viewer/document_view.h @@ -112,6 +112,10 @@ class DocumentView : public blink::ServiceProvider, void OnViewBoundsChanged(mojo::View* view, const mojo::Rect& old_bounds, const mojo::Rect& new_bounds) override; + void OnViewViewportMetricsChanged( + mojo::View* view, + const mojo::ViewportMetrics& old_metrics, + const mojo::ViewportMetrics& new_metrics) override; void OnViewFocusChanged(mojo::View* gained_focus, mojo::View* lost_focus) override; void OnViewDestroyed(mojo::View* view) override; @@ -121,6 +125,8 @@ class DocumentView : public blink::ServiceProvider, float GetDevicePixelRatio() const; scoped_ptr CreateRasterizer(); + void UpdateRootSizeAndViewportMetrics(const mojo::Rect& new_bounds); + mojo::URLResponsePtr response_; mojo::ServiceProviderImpl exported_services_; mojo::ServiceProviderPtr imported_services_;