diff options
author | lxas <lxas@yandex-team.ru> | 2014-12-29 07:37:40 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-29 15:38:29 +0000 |
commit | 5a78d5058e122d9a989dc681ea445220b0101ecf (patch) | |
tree | 9ed996aeea452d5bd7ac3e3b96b511ba9e533066 | |
parent | 2c10dab1015566a726cc890e026f7c0dbb2f1949 (diff) | |
download | chromium_src-5a78d5058e122d9a989dc681ea445220b0101ecf.zip chromium_src-5a78d5058e122d9a989dc681ea445220b0101ecf.tar.gz chromium_src-5a78d5058e122d9a989dc681ea445220b0101ecf.tar.bz2 |
GetBoundsInRootWindow() gives wrong coordinates with translations
Window::GetBoundsInRootWindow() calculates wrong coordinates
when the child window has transformation layer assigned
with non-zero translation parameters
R=sky@chromium.org,sadrul@chromium.org
TEST=WindowTest.GetBoundsInRootWindowWithLayersAndTranslations passes
Review URL: https://codereview.chromium.org/762253002
Cr-Commit-Position: refs/heads/master@{#309706}
-rw-r--r-- | ui/aura/window.cc | 6 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 74 |
2 files changed, 77 insertions, 3 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 3c6dcc8..91df99e 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -384,9 +384,9 @@ gfx::Rect Window::GetBoundsInRootWindow() const { // do for now. if (!GetRootWindow()) return bounds(); - gfx::Point origin = bounds().origin(); - ConvertPointToTarget(parent_, GetRootWindow(), &origin); - return gfx::Rect(origin, bounds().size()); + gfx::Rect bounds_in_root(bounds().size()); + ConvertRectToTarget(this, GetRootWindow(), &bounds_in_root); + return bounds_in_root; } gfx::Rect Window::GetBoundsInScreen() const { diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 7276113..4f53320 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -246,6 +246,12 @@ class DestroyWindowDelegate : public TestWindowDelegate { DISALLOW_COPY_AND_ASSIGN(DestroyWindowDelegate); }; +void OffsetBounds(Window* window, int horizontal, int vertical) { + gfx::Rect bounds = window->bounds(); + bounds.Offset(horizontal, vertical); + window->SetBounds(bounds); +} + } // namespace TEST_F(WindowTest, GetChildById) { @@ -1083,6 +1089,74 @@ TEST_F(WindowTest, GetBoundsInRootWindow) { EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); } +TEST_F(WindowTest, GetBoundsInRootWindowWithLayers) { + scoped_ptr<Window> viewport( + CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); + + scoped_ptr<Window> widget( + CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); + + scoped_ptr<Window> child( + CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); + + // Sanity check. + EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); + + // The |child| window's screen bounds should move along with the |viewport|. + OffsetBounds(viewport.get(), -100, -100); + EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); + + OffsetBounds(widget.get(), 50, 50); + EXPECT_EQ("-50,-50 100x100", child->GetBoundsInRootWindow().ToString()); + + // The |child| window is moved to the 0,0 in screen coordinates. + // |GetBoundsInRootWindow()| should return 0,0. + OffsetBounds(child.get(), 50, 50); + EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); +} + +TEST_F(WindowTest, GetBoundsInRootWindowWithLayersAndTranslations) { + scoped_ptr<Window> viewport( + CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); + + scoped_ptr<Window> widget( + CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); + + scoped_ptr<Window> child( + CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); + + // Sanity check. + EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); + + // The |child| window's screen bounds should move along with the |viewport|. + viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); + EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); + + widget->SetBounds(gfx::Rect(50, 50, 200, 200)); + EXPECT_EQ("-50,-50 100x100", child->GetBoundsInRootWindow().ToString()); + + // The |child| window is moved to the 0,0 in screen coordinates. + // |GetBoundsInRootWindow()| should return 0,0. + child->SetBounds(gfx::Rect(50, 50, 100, 100)); + EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); + + gfx::Transform transform1; + transform1.Translate(-10, 20); + viewport->SetTransform(transform1); + EXPECT_EQ("-10,20 100x100", child->GetBoundsInRootWindow().ToString()); + + gfx::Transform transform2; + transform2.Translate(40, 100); + widget->SetTransform(transform2); + EXPECT_EQ("30,120 100x100", child->GetBoundsInRootWindow().ToString()); + + // Testing potentially buggy place + gfx::Transform transform3; + transform3.Translate(-30, -120); + child->SetTransform(transform3); + EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); +} + // TODO(tdanderson): Remove this class and use // test::EventCountDelegate in its place. class MouseEnterExitWindowDelegate : public TestWindowDelegate { |