summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-22 01:31:25 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-22 01:31:25 +0000
commita4c5814a1e4863f2a0d690f7cd3f264285bb51cf (patch)
treedcf2509bf5dc14c3837b70572b9e34a4b71e5891
parent45e6041ea5bc692576bffce6a95c3d03d27faa0b (diff)
downloadchromium_src-a4c5814a1e4863f2a0d690f7cd3f264285bb51cf.zip
chromium_src-a4c5814a1e4863f2a0d690f7cd3f264285bb51cf.tar.gz
chromium_src-a4c5814a1e4863f2a0d690f7cd3f264285bb51cf.tar.bz2
Implement NativeWidgetAura::GetScreenBounds
BUG=none TEST=added new tests to window_unittests. Review URL: http://codereview.chromium.org/8372008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106829 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/window.cc13
-rw-r--r--ui/aura/window.h7
-rw-r--r--ui/aura/window_unittest.cc22
-rw-r--r--views/widget/native_widget_aura.cc7
4 files changed, 42 insertions, 7 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) {}
diff --git a/views/widget/native_widget_aura.cc b/views/widget/native_widget_aura.cc
index cc1baa1..4388d64 100644
--- a/views/widget/native_widget_aura.cc
+++ b/views/widget/native_widget_aura.cc
@@ -259,17 +259,18 @@ void NativeWidgetAura::BecomeModal() {
}
gfx::Rect NativeWidgetAura::GetWindowScreenBounds() const {
- // TODO(beng): ensure screen bounds
- return window_->bounds();
+ return window_->GetScreenBounds();
}
gfx::Rect NativeWidgetAura::GetClientAreaScreenBounds() const {
// TODO(beng):
- return window_->bounds();
+ NOTIMPLEMENTED();
+ return window_->GetScreenBounds();
}
gfx::Rect NativeWidgetAura::GetRestoredBounds() const {
// TODO(beng):
+ NOTIMPLEMENTED();
return window_->bounds();
}