diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 02:58:21 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 02:58:21 +0000 |
commit | 84ff1e9c512b93641613927257a39e4d2def3987 (patch) | |
tree | d26b63435a2d60475b29106006e0ba35648f7b9f /ui | |
parent | b4919b407c59c92c32bbf06af22acf64ce816488 (diff) | |
download | chromium_src-84ff1e9c512b93641613927257a39e4d2def3987.zip chromium_src-84ff1e9c512b93641613927257a39e4d2def3987.tar.gz chromium_src-84ff1e9c512b93641613927257a39e4d2def3987.tar.bz2 |
Fixes content scaling when resizing
Repro steps
1) Run chrome with --default-device-scale-factor=2
2) Maximize window
3) Web content gets scaled to twice the size it was before the window was maximized.
Bug=131806
Test=Manual
Review URL: https://chromiumcodereview.appspot.com/10533074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141842 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/window.cc | 4 | ||||
-rw-r--r-- | ui/aura/window.h | 1 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 37 | ||||
-rw-r--r-- | ui/compositor/layer.h | 3 | ||||
-rw-r--r-- | ui/views/view.cc | 4 | ||||
-rw-r--r-- | ui/views/view.h | 1 | ||||
-rw-r--r-- | ui/views/view_unittest.cc | 22 |
7 files changed, 68 insertions, 4 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc index b6097b5..1c25547 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -153,10 +153,14 @@ void Window::Init(ui::LayerType layer_type) { ui::Layer* Window::RecreateLayer() { // Disconnect the old layer, but don't delete it. ui::Layer* old_layer = AcquireLayer(); + if (!old_layer) + return NULL; + old_layer->set_delegate(NULL); layer_ = new ui::Layer(old_layer->type()); layer_owner_.reset(layer_); layer_->SetVisible(old_layer->visible()); + layer_->set_scale_content(old_layer->scale_content()); layer_->set_delegate(this); UpdateLayerName(name_); layer_->SetFillsBoundsOpaquely(!transparent_); diff --git a/ui/aura/window.h b/ui/aura/window.h index 7133f5a..a516730 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -81,6 +81,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate, // caller may wish to set new bounds and other state on the window/layer. // Returns the old layer, which can be used for animations. Caller owns the // memory for the returned layer and must delete it when animation completes. + // Returns NULL and does not recreate layer if window does not own its layer. ui::Layer* RecreateLayer() WARN_UNUSED_RESULT; void set_owned_by_parent(bool owned_by_parent) { diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index ab150fe..5932a4c 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -1596,6 +1596,43 @@ TEST_F(WindowTest, AcquireLayer) { EXPECT_EQ(1U, parent->children().size()); } +// Make sure that properties which should persist from the old layer to the new +// layer actually do. +TEST_F(WindowTest, RecreateLayer) { + // Set properties to non default values. + Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); + w.set_id(1); + w.Init(ui::LAYER_SOLID_COLOR); + w.SetBounds(gfx::Rect(0, 0, 100, 100)); + + ui::Layer* layer = w.layer(); + layer->set_scale_content(false); + layer->SetVisible(false); + + ui::Layer child_layer; + layer->Add(&child_layer); + + scoped_ptr<ui::Layer> old_layer(w.RecreateLayer()); + layer = w.layer(); + EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); + EXPECT_EQ(false, layer->scale_content()); + EXPECT_EQ(false, layer->visible()); + EXPECT_EQ(1u, layer->children().size()); +} + +// Ensure that acquiring a layer then recreating a layer does not crash +// and that RecreateLayer returns null. +TEST_F(WindowTest, AcquireThenRecreateLayer) { + scoped_ptr<Window> w( + CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), NULL)); + scoped_ptr<ui::Layer>acquired_layer(w->AcquireLayer()); + scoped_ptr<ui::Layer>doubly_acquired_layer(w->RecreateLayer()); + EXPECT_EQ(NULL, doubly_acquired_layer.get()); + + // Destroy window before layer gets destroyed. + w.reset(); +} + TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) { scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); diff --git a/ui/compositor/layer.h b/ui/compositor/layer.h index 40661a3..c05b759 100644 --- a/ui/compositor/layer.h +++ b/ui/compositor/layer.h @@ -219,6 +219,9 @@ class COMPOSITOR_EXPORT Layer : // the correct pixel size. void set_scale_content(bool scale_content) { scale_content_ = scale_content; } + // Returns true if the layer scales its content. + bool scale_content() const { return scale_content_; } + // Sometimes the Layer is being updated by something other than SetCanvas // (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT). bool layer_updated_externally() const { return layer_updated_externally_; } diff --git a/ui/views/view.cc b/ui/views/view.cc index 7da3a3b..322a3ba 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -458,7 +458,11 @@ void View::SetPaintToLayer(bool paint_to_layer) { ui::Layer* View::RecreateLayer() { ui::Layer* layer = AcquireLayer(); + if (!layer) + return NULL; + CreateLayer(); + layer_->set_scale_content(layer->scale_content()); return layer; } diff --git a/ui/views/view.h b/ui/views/view.h index 2a097a6..28a5b19 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -284,6 +284,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // the View no longer has a pointer to the old layer (so it won't be able to // update the old layer or destroy it). The caller must free the returned // layer. + // Returns NULL and does not recreate layer if view does not own its layer. ui::Layer* RecreateLayer() WARN_UNUSED_RESULT; // RTL positioning ----------------------------------------------------------- diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc index 3b6099d..1ccd2dc 100644 --- a/ui/views/view_unittest.cc +++ b/ui/views/view_unittest.cc @@ -3212,16 +3212,30 @@ TEST_F(ViewLayerTest, ReorderUnderWidget) { TEST_F(ViewLayerTest, AcquireLayer) { View* content = new View; widget()->SetContentsView(content); - View* c1 = new View; + scoped_ptr<View> c1(new View); c1->SetPaintToLayer(true); EXPECT_TRUE(c1->layer()); - content->AddChildView(c1); + content->AddChildView(c1.get()); scoped_ptr<ui::Layer> layer(c1->AcquireLayer()); EXPECT_EQ(layer.get(), c1->layer()); - layer.reset(c1->RecreateLayer()); - EXPECT_NE(c1->layer(), layer.get()); + scoped_ptr<ui::Layer> layer2(c1->RecreateLayer()); + EXPECT_NE(c1->layer(), layer2.get()); + + // Destroy view before destroying layer. + c1.reset(); +} + +// Verify that new layer scales content only if the old layer does. +TEST_F(ViewLayerTest, RecreateLayer) { + scoped_ptr<View> v(new View()); + v->SetPaintToLayer(true); + // Set to non default value. + v->layer()->set_scale_content(false); + scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); + ui::Layer* new_layer = v->layer(); + EXPECT_EQ(false, new_layer->scale_content()); } #endif // USE_AURA |