mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Plumb ViewportMetrics change notifications around the world and back.
This fixes the race which is seen where mojo_shell will sometimes launch with the wrong viewport metrics since the DisplayManager will happily respond to GetViewportMetrics with default values before the NativeViewport has fully booted and told it what the actual values are. I considered making DisplayManager hang until the NativeViewport was ready, but I decided that it does make sense for the ViewportMetrics (device pixel ratio, mostly) to change for a view if it were to move between displays (as exists on desktop OSes today). R=abarth@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/880743002
This commit is contained in:
parent
722daacffb
commit
09c29db6b0
@ -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));
|
||||
|
||||
@ -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<Rasterizer> CreateRasterizer();
|
||||
|
||||
void UpdateRootSizeAndViewportMetrics(const mojo::Rect& new_bounds);
|
||||
|
||||
mojo::URLResponsePtr response_;
|
||||
mojo::ServiceProviderImpl exported_services_;
|
||||
mojo::ServiceProviderPtr imported_services_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user