diff options
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/window.cc | 13 | ||||
-rw-r--r-- | ui/aura/window.h | 7 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 22 |
3 files changed, 38 insertions, 4 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 67fbdba..f41edf5 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -110,6 +110,15 @@ void Window::Restore() { } } +gfx::Rect Window::GetScreenBounds() const { + const gfx::Rect local_bounds = bounds(); + gfx::Point origin = local_bounds.origin(); + Window::ConvertPointToWindow(parent_, + aura::Desktop::GetInstance(), + &origin); + return gfx::Rect(origin, local_bounds.size()); +} + void Window::Activate() { // If we support minimization need to ensure this restores the window first. aura::Desktop::GetInstance()->SetActiveWindow(this, this); @@ -239,8 +248,8 @@ const Window* Window::GetChildById(int id) const { } // static -void Window::ConvertPointToWindow(Window* source, - Window* target, +void Window::ConvertPointToWindow(const Window* source, + const Window* target, gfx::Point* point) { ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); } diff --git a/ui/aura/window.h b/ui/aura/window.h index 5084169..57ea1ea 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -97,6 +97,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate { // Restore the window to its original bounds. void Restore(); + // Returns the window's bounds in screen coordinates. + gfx::Rect GetScreenBounds() const; + // Returns the window's show state. ui::WindowShowState show_state() const { return show_state_; } @@ -167,8 +170,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate { Window* GetChildById(int id); const Window* GetChildById(int id) const; - static void ConvertPointToWindow(Window* source, - Window* target, + static void ConvertPointToWindow(const Window* source, + const Window* target, gfx::Point* point); // Returns the cursor for the specified point, in window coordinates. diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 94233bb..ceacf65 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -161,6 +161,10 @@ class WindowTest : public AuraTestBase { return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent); } + Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent) { + return CreateTestWindowWithDelegate(NULL, 0, bounds, parent); + } + Window* CreateTestWindow(SkColor color, int id, const gfx::Rect& bounds, @@ -432,6 +436,24 @@ TEST_F(WindowTest, ReleaseCaptureOnDestroy) { EXPECT_EQ(NULL, desktop->capture_window()); } +TEST_F(WindowTest, GetScreenBounds) { + scoped_ptr<Window> viewport(CreateTestWindowWithBounds( + gfx::Rect(0, 0, 300, 300), NULL)); + scoped_ptr<Window> child(CreateTestWindowWithBounds( + gfx::Rect(0, 0, 100, 100), viewport.get())); + // Sanity check. + EXPECT_EQ("0,0 100x100", child->GetScreenBounds().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->GetScreenBounds().ToString()); + + // The |child| window is moved to the 0,0 in screen coordinates. + // |GetScreenBounds()| should return 0,0. + child->SetBounds(gfx::Rect(100, 100, 100, 100)); + EXPECT_EQ("0,0 100x100", child->GetScreenBounds().ToString()); +} + class MouseEnterExitWindowDelegate : public TestWindowDelegate { public: MouseEnterExitWindowDelegate() : entered_(false), exited_(false) {} |