diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 00:09:04 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 00:09:04 +0000 |
commit | d3f5bbc1736289a4f2d44a971acdb2dd0ffa1504 (patch) | |
tree | 9b76581261e298180ea3fa2e94c06e0198cd3a82 /ui | |
parent | 3bd858679bb3fdeb04224179099b5bc059433bec (diff) | |
download | chromium_src-d3f5bbc1736289a4f2d44a971acdb2dd0ffa1504.zip chromium_src-d3f5bbc1736289a4f2d44a971acdb2dd0ffa1504.tar.gz chromium_src-d3f5bbc1736289a4f2d44a971acdb2dd0ffa1504.tar.bz2 |
Notification for device scale factor change
BUG=105165
TEST=updated compositor test to cover OnDeviceScaleFactorChagned.
Review URL: https://chromiumcodereview.appspot.com/10391165
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137571 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/demo/demo_main.cc | 1 | ||||
-rw-r--r-- | ui/aura/test/test_window_delegate.cc | 4 | ||||
-rw-r--r-- | ui/aura/test/test_window_delegate.h | 1 | ||||
-rw-r--r-- | ui/aura/window.cc | 5 | ||||
-rw-r--r-- | ui/aura/window.h | 1 | ||||
-rw-r--r-- | ui/aura/window_delegate.h | 3 | ||||
-rw-r--r-- | ui/compositor/layer.cc | 2 | ||||
-rw-r--r-- | ui/compositor/layer_delegate.h | 3 | ||||
-rw-r--r-- | ui/compositor/layer_unittest.cc | 42 | ||||
-rw-r--r-- | ui/views/view.cc | 4 | ||||
-rw-r--r-- | ui/views/view.h | 1 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 4 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.h | 1 |
13 files changed, 70 insertions, 2 deletions
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc index 98b6f84..fb8e683 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -64,6 +64,7 @@ class DemoWindowDelegate : public aura::WindowDelegate { virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { canvas->DrawColor(color_, SkXfermode::kSrc_Mode); } + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} virtual void OnWindowDestroying() OVERRIDE {} virtual void OnWindowDestroyed() OVERRIDE {} virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE {} diff --git a/ui/aura/test/test_window_delegate.cc b/ui/aura/test/test_window_delegate.cc index 0865079..52b50d7 100644 --- a/ui/aura/test/test_window_delegate.cc +++ b/ui/aura/test/test_window_delegate.cc @@ -69,6 +69,10 @@ void TestWindowDelegate::OnCaptureLost() { void TestWindowDelegate::OnPaint(gfx::Canvas* canvas) { } +void TestWindowDelegate::OnDeviceScaleFactorChanged( + float device_scale_factor) { +} + void TestWindowDelegate::OnWindowDestroying() { } diff --git a/ui/aura/test/test_window_delegate.h b/ui/aura/test/test_window_delegate.h index 57a5ba1..294709d 100644 --- a/ui/aura/test/test_window_delegate.h +++ b/ui/aura/test/test_window_delegate.h @@ -38,6 +38,7 @@ class TestWindowDelegate : public WindowDelegate { virtual bool CanFocus() OVERRIDE; virtual void OnCaptureLost() OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void OnWindowDestroying() OVERRIDE; virtual void OnWindowDestroyed() OVERRIDE; virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE; diff --git a/ui/aura/window.cc b/ui/aura/window.cc index d18937b..4128d90 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -794,6 +794,11 @@ void Window::OnPaintLayer(gfx::Canvas* canvas) { delegate_->OnPaint(canvas); } +void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { + if (delegate_) + delegate_->OnDeviceScaleFactorChanged(device_scale_factor); +} + void Window::UpdateLayerName(const std::string& name) { #if !defined(NDEBUG) DCHECK(layer()); diff --git a/ui/aura/window.h b/ui/aura/window.h index 7917fba..382d582 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -395,6 +395,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate, // Overridden from ui::LayerDelegate: virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; // Updates the layer name with a name based on the window's name and id. void UpdateLayerName(const std::string& name); diff --git a/ui/aura/window_delegate.h b/ui/aura/window_delegate.h index c3b79e2..34521c8 100644 --- a/ui/aura/window_delegate.h +++ b/ui/aura/window_delegate.h @@ -64,6 +64,9 @@ class AURA_EXPORT WindowDelegate { // Asks the delegate to paint window contents into the supplied canvas. virtual void OnPaint(gfx::Canvas* canvas) = 0; + // Called when the window's device scale factor has changed. + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) = 0; + // Called from Window's destructor before OnWindowDestroyed and before the // children have been destroyed and the window has been removed from its // parent. diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc index ae2085f..620ec58 100644 --- a/ui/compositor/layer.cc +++ b/ui/compositor/layer.cc @@ -377,6 +377,8 @@ void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) { RecomputeTransform(); RecomputeDrawsContentAndUVRect(); SchedulePaint(gfx::Rect(bounds_.size())); + if (delegate_) + delegate_->OnDeviceScaleFactorChanged(device_scale_factor); for (size_t i = 0; i < children_.size(); ++i) children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); } diff --git a/ui/compositor/layer_delegate.h b/ui/compositor/layer_delegate.h index 292e399..cb00366 100644 --- a/ui/compositor/layer_delegate.h +++ b/ui/compositor/layer_delegate.h @@ -21,6 +21,9 @@ class COMPOSITOR_EXPORT LayerDelegate { // clipped to the Layer's invalid rect. virtual void OnPaintLayer(gfx::Canvas* canvas) = 0; + // Called when the layer's device scale factor has changed. + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) = 0; + protected: virtual ~LayerDelegate() {} }; diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc index 3af502d..581e1db 100644 --- a/ui/compositor/layer_unittest.cc +++ b/ui/compositor/layer_unittest.cc @@ -132,6 +132,9 @@ class ColoredLayer : public Layer, public LayerDelegate { canvas->DrawColor(color_); } + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { + } + private: SkColor color_; }; @@ -212,7 +215,7 @@ class LayerWithRealCompositorTest : public testing::Test { // LayerDelegate that paints colors to the layer. class TestLayerDelegate : public LayerDelegate { public: - explicit TestLayerDelegate() : color_index_(0) {} + explicit TestLayerDelegate() { reset(); } virtual ~TestLayerDelegate() {} void AddColor(SkColor color) { @@ -226,6 +229,10 @@ class TestLayerDelegate : public LayerDelegate { return StringPrintf("%.1f %.1f", scale_x_, scale_y_); } + float device_scale_factor() const { + return device_scale_factor_; + } + // Overridden from LayerDelegate: virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { SkBitmap contents = canvas->ExtractBitmap(); @@ -237,10 +244,15 @@ class TestLayerDelegate : public LayerDelegate { scale_y_ = matrix.getScaleY(); } + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { + device_scale_factor_ = device_scale_factor; + } + void reset() { color_index_ = 0; paint_size_.SetSize(0, 0); scale_x_ = scale_y_ = 0.0f; + device_scale_factor_ = 0.0f; } private: @@ -249,6 +261,7 @@ class TestLayerDelegate : public LayerDelegate { gfx::Size paint_size_; float scale_x_; float scale_y_; + float device_scale_factor_; DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); }; @@ -270,6 +283,8 @@ class DrawTreeLayerDelegate : public LayerDelegate { virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { painted_ = true; } + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { + } bool painted_; @@ -286,6 +301,8 @@ class NullLayerDelegate : public LayerDelegate { // Overridden from LayerDelegate: virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { } + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { + } DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); }; @@ -1000,6 +1017,9 @@ class SchedulePaintLayerDelegate : public LayerDelegate { last_clip_rect_ = gfx::SkRectToRect(sk_clip_rect); } + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { + } + int paint_count_; Layer* layer_; gfx::Rect schedule_paint_rect_; @@ -1071,6 +1091,9 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) { EXPECT_EQ("200x220", size_in_pixel.ToString()); size_in_pixel = l1->web_layer().bounds(); EXPECT_EQ("140x180", size_in_pixel.ToString()); + // No scale change, so no scale notification. + EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); + EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); RunPendingMessages(); EXPECT_EQ("200x220", root_delegate.paint_size().ToString()); @@ -1085,6 +1108,9 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) { EXPECT_EQ("400x440", size_in_pixel.ToString()); size_in_pixel = l1->web_layer().bounds(); EXPECT_EQ("280x360", size_in_pixel.ToString()); + // New scale factor must have been notified. + EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); + EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); // Canvas size must have been scaled down up. RunPendingMessages(); @@ -1102,6 +1128,9 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) { EXPECT_EQ("200x220", size_in_pixel.ToString()); size_in_pixel = l1->web_layer().bounds(); EXPECT_EQ("140x180", size_in_pixel.ToString()); + // New scale factor must have been notified. + EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); + EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); // Canvas size must have been scaled down too. RunPendingMessages(); @@ -1112,8 +1141,12 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) { root_delegate.reset(); l1_delegate.reset(); - // Just changing the size shouldn't trigger repaint. + // Just changing the size shouldn't notify the scale change nor + // trigger repaint. GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); + // No scale change, so no scale notification. + EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); + EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); RunPendingMessages(); EXPECT_EQ("0x0", root_delegate.paint_size().ToString()); EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString()); @@ -1139,6 +1172,7 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) { EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); gfx::Size size_in_pixel = l1->web_layer().bounds(); EXPECT_EQ("140x180", size_in_pixel.ToString()); + EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); RunPendingMessages(); EXPECT_EQ("140x180", l1_delegate.paint_size().ToString()); @@ -1159,6 +1193,7 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) { EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); size_in_pixel = l1->web_layer().bounds(); EXPECT_EQ("280x360", size_in_pixel.ToString()); + EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); RunPendingMessages(); EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString()); @@ -1179,6 +1214,9 @@ TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) { GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); GetCompositor()->SetRootLayer(root.get()); + // Scale factor change is notified regardless of scale_canvas flag. + EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); + RunPendingMessages(); EXPECT_EQ("280x360", l1_delegate.paint_size().ToString()); EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString()); diff --git a/ui/views/view.cc b/ui/views/view.cc index f5dd39b..cbcb45c 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -1230,6 +1230,10 @@ void View::OnPaintLayer(gfx::Canvas* canvas) { PaintCommon(canvas); } +void View::OnDeviceScaleFactorChanged(float device_scale_factor) { + // Repainting with new scale factor will paint the content at the right scale. +} + void View::ReorderLayers() { View* v = this; while (v && !v->layer()) diff --git a/ui/views/view.h b/ui/views/view.h index fc4a27f..8492d95 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -996,6 +996,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Overridden from ui::LayerDelegate: virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; // Finds the layer that this view paints to (it may belong to an ancestor // view), then reorders the immediate children of that layer to match the diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index b63e8fd..a71b3d7 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -784,6 +784,10 @@ void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { delegate_->OnNativeWidgetPaint(canvas); } +void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) { + // Repainting with new scale factor will paint the content at the right scale. +} + void NativeWidgetAura::OnWindowDestroying() { delegate_->OnNativeWidgetDestroying(); diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h index c9a1480..7d89a77 100644 --- a/ui/views/widget/native_widget_aura.h +++ b/ui/views/widget/native_widget_aura.h @@ -144,6 +144,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, virtual bool CanFocus() OVERRIDE; virtual void OnCaptureLost() OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void OnWindowDestroying() OVERRIDE; virtual void OnWindowDestroyed() OVERRIDE; virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE; |