diff options
Diffstat (limited to 'ui')
-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 { |