summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-10 16:51:37 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-10 16:51:37 +0000
commitaa4769f96d89c16a4c04bf2237d3094878e7830b (patch)
tree834390a6c4733f95d58bc8cb1c24fefab1abbddf /ui
parent77783d7d72ccad6477fead96cb1def8423752478 (diff)
downloadchromium_src-aa4769f96d89c16a4c04bf2237d3094878e7830b.zip
chromium_src-aa4769f96d89c16a4c04bf2237d3094878e7830b.tar.gz
chromium_src-aa4769f96d89c16a4c04bf2237d3094878e7830b.tar.bz2
Basic window resizing.http://crbug.com/93937TEST=see unit tests
Review URL: http://codereview.chromium.org/8202025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104730 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp3
-rw-r--r--ui/aura/demo/demo_main.cc2
-rw-r--r--ui/aura/hit_test.h4
-rw-r--r--ui/aura/test_window_delegate.cc67
-rw-r--r--ui/aura/test_window_delegate.h44
-rw-r--r--ui/aura/toplevel_window_event_filter.cc192
-rw-r--r--ui/aura/toplevel_window_event_filter.h28
-rw-r--r--ui/aura/toplevel_window_event_filter_unittest.cc189
-rw-r--r--ui/aura/window_unittest.cc77
9 files changed, 532 insertions, 74 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 977d15ab..8da3aa6 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -101,6 +101,9 @@
'test_desktop_delegate.h',
'test_suite.cc',
'test_suite.h',
+ 'test_window_delegate.cc',
+ 'test_window_delegate.h',
+ 'toplevel_window_event_filter_unittest.cc',
'window_unittest.cc',
'../gfx/compositor/test_compositor.cc',
'../gfx/compositor/test_compositor.h',
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc
index e539a0b..4dae809 100644
--- a/ui/aura/demo/demo_main.cc
+++ b/ui/aura/demo/demo_main.cc
@@ -10,6 +10,7 @@
#include "third_party/skia/include/core/SkXfermode.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
+#include "ui/aura/hit_test.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/resource/resource_bundle.h"
@@ -18,7 +19,6 @@
#include "ui/gfx/rect.h"
#if defined(USE_X11)
-#include "ui/aura/hit_test.h"
#include "base/message_pump_x.h"
#endif
diff --git a/ui/aura/hit_test.h b/ui/aura/hit_test.h
index 4ea50e8..fab418d 100644
--- a/ui/aura/hit_test.h
+++ b/ui/aura/hit_test.h
@@ -6,6 +6,8 @@
#define UI_AURA_HIT_TEST_H_
#pragma once
+#if !defined(OS_WIN)
+
// Defines the same symbolic names used by the WM_NCHITTEST Notification under
// win32 (the integer values are not guaranteed to be equivalent). We do this
// because we have a whole bunch of code that deals with window resizing and
@@ -39,4 +41,6 @@ enum HitTestCompat {
HTZOOM
};
+#endif // !defined(OS_WIN)
+
#endif // UI_AURA_HIT_TEST_H_
diff --git a/ui/aura/test_window_delegate.cc b/ui/aura/test_window_delegate.cc
new file mode 100644
index 0000000..e812439
--- /dev/null
+++ b/ui/aura/test_window_delegate.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/aura/test_window_delegate.h"
+
+#include "ui/aura/hit_test.h"
+
+namespace aura {
+namespace internal {
+
+TestWindowDelegate::TestWindowDelegate() {
+}
+
+TestWindowDelegate::~TestWindowDelegate() {
+}
+
+void TestWindowDelegate::OnBoundsChanged(const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) {
+}
+
+void TestWindowDelegate::OnFocus() {
+}
+
+void TestWindowDelegate::OnBlur() {
+}
+
+bool TestWindowDelegate::OnKeyEvent(KeyEvent* event) {
+ return false;
+}
+
+gfx::NativeCursor TestWindowDelegate::GetCursor(const gfx::Point& point) {
+ return NULL;
+}
+
+int TestWindowDelegate::GetNonClientComponent(const gfx::Point& point) const {
+ return HTCLIENT;
+}
+
+bool TestWindowDelegate::OnMouseEvent(MouseEvent* event) {
+ return false;
+}
+
+bool TestWindowDelegate::ShouldActivate(MouseEvent* event) {
+ return true;
+}
+
+void TestWindowDelegate::OnActivated() {
+}
+
+void TestWindowDelegate::OnLostActive() {
+}
+
+void TestWindowDelegate::OnCaptureLost() {
+}
+
+void TestWindowDelegate::OnPaint(gfx::Canvas* canvas) {
+}
+
+void TestWindowDelegate::OnWindowDestroying() {
+}
+
+void TestWindowDelegate::OnWindowDestroyed() {
+}
+
+} // namespace internal
+} // namespace aura
diff --git a/ui/aura/test_window_delegate.h b/ui/aura/test_window_delegate.h
new file mode 100644
index 0000000..0e00e73
--- /dev/null
+++ b/ui/aura/test_window_delegate.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_AURA_TEST_WINDOW_DELEGATE_H_
+#define UI_AURA_TEST_WINDOW_DELEGATE_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "ui/aura/window_delegate.h"
+
+namespace aura {
+namespace internal {
+
+// WindowDelegate implementation with all methods stubbed out.
+class TestWindowDelegate : public WindowDelegate {
+ public:
+ TestWindowDelegate();
+ virtual ~TestWindowDelegate();
+
+ // Overridden from WindowDelegate:
+ virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds);
+ virtual void OnFocus() OVERRIDE;
+ virtual void OnBlur() OVERRIDE;
+ virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE;
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
+ virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
+ virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE;
+ virtual bool ShouldActivate(MouseEvent* event) OVERRIDE;
+ virtual void OnActivated() OVERRIDE;
+ virtual void OnLostActive() OVERRIDE;
+ virtual void OnCaptureLost() OVERRIDE;
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+ virtual void OnWindowDestroying() OVERRIDE;
+ virtual void OnWindowDestroyed() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
+};
+
+} // namespace internal
+} // namespace aura
+#endif // UI_AURA_TEST_WINDOW_DELEGATE_H_
diff --git a/ui/aura/toplevel_window_event_filter.cc b/ui/aura/toplevel_window_event_filter.cc
index bb27126..e867f80 100644
--- a/ui/aura/toplevel_window_event_filter.cc
+++ b/ui/aura/toplevel_window_event_filter.cc
@@ -7,15 +7,113 @@
#include "ui/aura/cursor.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
+#include "ui/aura/hit_test.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
-#if !defined(OS_WIN)
-#include "ui/aura/hit_test.h"
-#endif
-
namespace aura {
+namespace {
+
+// Identifies the types of bounds change operations performed by a drag to a
+// particular window component.
+const int kBoundsChange_None = 0;
+const int kBoundsChange_Repositions = 1;
+const int kBoundsChange_Resizes = 2;
+
+int GetBoundsChangeForWindowComponent(int window_component) {
+ int bounds_change = kBoundsChange_None;
+ switch (window_component) {
+ case HTTOPLEFT:
+ case HTTOP:
+ case HTTOPRIGHT:
+ case HTLEFT:
+ case HTBOTTOMLEFT:
+ bounds_change |= kBoundsChange_Repositions | kBoundsChange_Resizes;
+ break;
+ case HTCAPTION:
+ bounds_change |= kBoundsChange_Repositions;
+ break;
+ case HTRIGHT:
+ case HTBOTTOMRIGHT:
+ case HTBOTTOM:
+ case HTGROWBOX:
+ bounds_change |= kBoundsChange_Resizes;
+ break;
+ default:
+ break;
+ }
+ return bounds_change;
+}
+
+// Possible directions for changing bounds.
+
+const int kBoundsChangeDirection_None = 0;
+const int kBoundsChangeDirection_Horizontal = 1;
+const int kBoundsChangeDirection_Vertical = 2;
+
+int GetPositionChangeDirectionForWindowComponent(int window_component) {
+ int pos_change_direction = kBoundsChangeDirection_None;
+ switch (window_component) {
+ case HTTOPLEFT:
+ case HTBOTTOMRIGHT:
+ case HTGROWBOX:
+ case HTCAPTION:
+ pos_change_direction |=
+ kBoundsChangeDirection_Horizontal | kBoundsChangeDirection_Vertical;
+ break;
+ case HTTOP:
+ case HTTOPRIGHT:
+ case HTBOTTOM:
+ pos_change_direction |= kBoundsChangeDirection_Vertical;
+ break;
+ case HTBOTTOMLEFT:
+ case HTRIGHT:
+ case HTLEFT:
+ pos_change_direction |= kBoundsChangeDirection_Horizontal;
+ break;
+ default:
+ break;
+ }
+ return pos_change_direction;
+}
+
+int GetSizeChangeDirectionForWindowComponent(int window_component) {
+ int size_change_direction = kBoundsChangeDirection_None;
+ switch (window_component) {
+ case HTTOPLEFT:
+ case HTTOPRIGHT:
+ case HTBOTTOMLEFT:
+ case HTBOTTOMRIGHT:
+ case HTGROWBOX:
+ case HTCAPTION:
+ size_change_direction |=
+ kBoundsChangeDirection_Horizontal | kBoundsChangeDirection_Vertical;
+ break;
+ case HTTOP:
+ case HTBOTTOM:
+ size_change_direction |= kBoundsChangeDirection_Vertical;
+ break;
+ case HTRIGHT:
+ case HTLEFT:
+ size_change_direction |= kBoundsChangeDirection_Horizontal;
+ break;
+ default:
+ break;
+ }
+ return size_change_direction;
+}
+
+int GetXMultiplierForWindowComponent(int window_component) {
+ return window_component == HTTOPRIGHT ? -1 : 1;
+}
+
+int GetYMultiplierForWindowComponent(int window_component) {
+ return window_component == HTBOTTOMLEFT ? -1 : 1;
+}
+
+}
+
ToplevelWindowEventFilter::ToplevelWindowEventFilter(Window* owner)
: EventFilter(owner),
window_component_(HTNOWHERE) {
@@ -36,19 +134,15 @@ bool ToplevelWindowEventFilter::OnMouseEvent(Window* target,
target->delegate()->GetNonClientComponent(event->location());
break;
case ui::ET_MOUSE_PRESSED:
- mouse_down_offset_ = event->location();
- if (window_component_ == HTCAPTION)
- return true;
- break;
+ mouse_down_bounds_ = target->bounds();
+ mouse_down_offset_in_target_ = event->location();
+ mouse_down_offset_in_parent_ = mouse_down_offset_in_target_;
+ Window::ConvertPointToWindow(target, target->parent(),
+ &mouse_down_offset_in_parent_);
+ return GetBoundsChangeForWindowComponent(window_component_) !=
+ kBoundsChange_None;
case ui::ET_MOUSE_DRAGGED:
- if (window_component_ == HTCAPTION) {
- gfx::Point new_origin(event->location());
- new_origin.Offset(-mouse_down_offset_.x(), -mouse_down_offset_.y());
- new_origin.Offset(target->bounds().x(), target->bounds().y());
- target->SetBounds(gfx::Rect(new_origin, target->bounds().size()));
- return true;
- }
- break;
+ return HandleDrag(target, event);
case ui::ET_MOUSE_RELEASED:
if (window_component_ == HTMAXBUTTON) {
if (target->show_state() == ui::SHOW_STATE_MAXIMIZED)
@@ -76,4 +170,70 @@ void ToplevelWindowEventFilter::MoveWindowToFront(Window* target) {
}
}
+bool ToplevelWindowEventFilter::HandleDrag(Window* target, MouseEvent* event) {
+ int bounds_change = GetBoundsChangeForWindowComponent(window_component_);
+ if (bounds_change == kBoundsChange_None)
+ return false;
+
+ target->SetBounds(gfx::Rect(GetOriginForDrag(bounds_change, target, event),
+ GetSizeForDrag(bounds_change, target, event)));
+ return true;
+}
+
+gfx::Point ToplevelWindowEventFilter::GetOriginForDrag(
+ int bounds_change,
+ Window* target,
+ MouseEvent* event) const {
+ gfx::Point origin = mouse_down_bounds_.origin();
+ if (bounds_change & kBoundsChange_Repositions) {
+ int pos_change_direction =
+ GetPositionChangeDirectionForWindowComponent(window_component_);
+
+ if (pos_change_direction & kBoundsChangeDirection_Horizontal) {
+ origin.set_x(event->location().x());
+ origin.Offset(-mouse_down_offset_in_target_.x(), 0);
+ origin.Offset(target->bounds().x(), 0);
+ }
+ if (pos_change_direction & kBoundsChangeDirection_Vertical) {
+ origin.set_y(event->location().y());
+ origin.Offset(0, -mouse_down_offset_in_target_.y());
+ origin.Offset(0, target->bounds().y());
+ }
+ }
+ return origin;
+}
+
+gfx::Size ToplevelWindowEventFilter::GetSizeForDrag(int bounds_change,
+ Window* target,
+ MouseEvent* event) const {
+ gfx::Size size = mouse_down_bounds_.size();
+ if (bounds_change & kBoundsChange_Resizes) {
+ int size_change_direction =
+ GetSizeChangeDirectionForWindowComponent(window_component_);
+
+ gfx::Point event_location_in_parent(event->location());
+ Window::ConvertPointToWindow(target, target->parent(),
+ &event_location_in_parent);
+
+ // The math changes depending on whether the window is being resized, or
+ // repositioned in addition to being resized.
+ int first_x = bounds_change & kBoundsChange_Repositions ?
+ mouse_down_offset_in_parent_.x() : event_location_in_parent.x();
+ int first_y = bounds_change & kBoundsChange_Repositions ?
+ mouse_down_offset_in_parent_.y() : event_location_in_parent.y();
+ int second_x = bounds_change & kBoundsChange_Repositions ?
+ event_location_in_parent.x() : mouse_down_offset_in_parent_.x();
+ int second_y = bounds_change & kBoundsChange_Repositions ?
+ event_location_in_parent.y() : mouse_down_offset_in_parent_.y();
+
+ int x_multiplier = GetXMultiplierForWindowComponent(window_component_);
+ int y_multiplier = GetYMultiplierForWindowComponent(window_component_);
+ size.Enlarge(size_change_direction & kBoundsChangeDirection_Horizontal ?
+ x_multiplier * (first_x - second_x) : 0,
+ size_change_direction & kBoundsChangeDirection_Vertical ?
+ y_multiplier * (first_y - second_y) : 0);
+ }
+ return size;
+}
+
} // namespace aura
diff --git a/ui/aura/toplevel_window_event_filter.h b/ui/aura/toplevel_window_event_filter.h
index e5281d3..812be92 100644
--- a/ui/aura/toplevel_window_event_filter.h
+++ b/ui/aura/toplevel_window_event_filter.h
@@ -9,6 +9,7 @@
#include "base/compiler_specific.h"
#include "ui/aura/event_filter.h"
#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
namespace aura {
@@ -29,9 +30,32 @@ class ToplevelWindowEventFilter : public EventFilter {
// NOTE: this does NOT activate the window.
void MoveWindowToFront(Window* target);
- void UpdateCursorForWindowComponent();
+ // Called during a drag to resize/position the window.
+ // The return value is returned by OnMouseEvent() above.
+ bool HandleDrag(Window* target, MouseEvent* event);
- gfx::Point mouse_down_offset_;
+ // Calculates the new origin of the window during a drag.
+ gfx::Point GetOriginForDrag(int bounds_change,
+ Window* target,
+ MouseEvent* event) const;
+
+ // Calculates the new size of the window during a drag.
+ gfx::Size GetSizeForDrag(int bounds_change,
+ Window* target,
+ MouseEvent* event) const;
+
+ // The mouse position in the target window when the mouse was pressed, in
+ // target window coordinates.
+ gfx::Point mouse_down_offset_in_target_;
+
+ // The mouse position in the target window when the mouse was pressed, in
+ // the target window's parent's coordinates.
+ gfx::Point mouse_down_offset_in_parent_;
+
+ // The bounds of the target window when the mouse was pressed.
+ gfx::Rect mouse_down_bounds_;
+
+ // The window component (hit-test code) the mouse is currently over.
int window_component_;
DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventFilter);
diff --git a/ui/aura/toplevel_window_event_filter_unittest.cc b/ui/aura/toplevel_window_event_filter_unittest.cc
new file mode 100644
index 0000000..c77ba9f
--- /dev/null
+++ b/ui/aura/toplevel_window_event_filter_unittest.cc
@@ -0,0 +1,189 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/aura/aura_test_base.h"
+#include "ui/aura/desktop.h"
+#include "ui/aura/event.h"
+#include "ui/aura/hit_test.h"
+#include "ui/aura/test_desktop_delegate.h"
+#include "ui/aura/test_window_delegate.h"
+
+#if defined(OS_WIN)
+// Windows headers define macros for these function names which screw with us.
+#if defined(CreateWindow)
+#undef CreateWindow
+#endif
+#endif
+
+
+namespace aura {
+namespace internal {
+
+namespace {
+
+// A simple window delegate that returns the specified hit-test code when
+// requested.
+class HitTestWindowDelegate : public TestWindowDelegate {
+ public:
+ explicit HitTestWindowDelegate(int hittest_code)
+ : hittest_code_(hittest_code) {
+ }
+ virtual ~HitTestWindowDelegate() {}
+
+ private:
+ // Overridden from TestWindowDelegate:
+ virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
+ return hittest_code_;
+ }
+ virtual void OnWindowDestroyed() OVERRIDE {
+ delete this;
+ }
+
+ int hittest_code_;
+
+ DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate);
+};
+
+class ToplevelWindowEventFilterTest : public AuraTestBase {
+ public:
+ ToplevelWindowEventFilterTest() {}
+ virtual ~ToplevelWindowEventFilterTest() {}
+
+ protected:
+ Window* CreateWindow(int hittest_code) {
+ HitTestWindowDelegate* d1 = new HitTestWindowDelegate(hittest_code);
+ Window* w1 = new Window(d1);
+ w1->set_id(1);
+ w1->Init();
+ w1->SetParent(NULL);
+ w1->SetBounds(gfx::Rect(0, 0, 100, 100));
+ w1->Show();
+ return w1;
+ }
+
+ void DragFromCenterBy(Window* window, int x, int y) {
+ gfx::Point click = window->bounds().CenterPoint();
+ Desktop* desktop= Desktop::GetInstance();
+ Window::ConvertPointToWindow(window->parent(), desktop->window(), &click);
+ desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_MOVED, click, 0));
+ desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, click, 0));
+ click.Offset(x, y);
+ desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_DRAGGED, click, 0));
+ desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, click, 0));
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventFilterTest);
+};
+
+}
+
+TEST_F(ToplevelWindowEventFilterTest, Caption) {
+ scoped_ptr<Window> w1(CreateWindow(HTCAPTION));
+ gfx::Size size = w1->bounds().size();
+ DragFromCenterBy(w1.get(), 100, 100);
+ // Position should have been offset by 100,100.
+ EXPECT_EQ(gfx::Point(100, 100), w1->bounds().origin());
+ // Size should not have.
+ EXPECT_EQ(size, w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, BottomRight) {
+ scoped_ptr<Window> w1(CreateWindow(HTBOTTOMRIGHT));
+ gfx::Point position = w1->bounds().origin();
+ DragFromCenterBy(w1.get(), 100, 100);
+ // Position should not have changed.
+ EXPECT_EQ(position, w1->bounds().origin());
+ // Size should have increased by 100,100.
+ EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, GrowBox) {
+ scoped_ptr<Window> w1(CreateWindow(HTGROWBOX));
+ gfx::Point position = w1->bounds().origin();
+ DragFromCenterBy(w1.get(), 100, 100);
+ // Position should not have changed.
+ EXPECT_EQ(position, w1->bounds().origin());
+ // Size should have increased by 100,100.
+ EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, Right) {
+ scoped_ptr<Window> w1(CreateWindow(HTRIGHT));
+ gfx::Point position = w1->bounds().origin();
+ DragFromCenterBy(w1.get(), 100, 100);
+ // Position should not have changed.
+ EXPECT_EQ(position, w1->bounds().origin());
+ // Size should have increased by 100,0.
+ EXPECT_EQ(gfx::Size(200, 100), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, Bottom) {
+ scoped_ptr<Window> w1(CreateWindow(HTBOTTOM));
+ gfx::Point position = w1->bounds().origin();
+ DragFromCenterBy(w1.get(), 100, 100);
+ // Position should not have changed.
+ EXPECT_EQ(position, w1->bounds().origin());
+ // Size should have increased by 0,100.
+ EXPECT_EQ(gfx::Size(100, 200), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, TopRight) {
+ scoped_ptr<Window> w1(CreateWindow(HTTOPRIGHT));
+ DragFromCenterBy(w1.get(), -50, 50);
+ // Position should have been offset by 0,50.
+ EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin());
+ // Size should have decreased by 50,50.
+ EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, Top) {
+ scoped_ptr<Window> w1(CreateWindow(HTTOP));
+ DragFromCenterBy(w1.get(), 50, 50);
+ // Position should have been offset by 0,50.
+ EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin());
+ // Size should have decreased by 0,50.
+ EXPECT_EQ(gfx::Size(100, 50), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, Left) {
+ scoped_ptr<Window> w1(CreateWindow(HTLEFT));
+ DragFromCenterBy(w1.get(), 50, 50);
+ // Position should have been offset by 50,0.
+ EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin());
+ // Size should have decreased by 50,0.
+ EXPECT_EQ(gfx::Size(50, 100), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, BottomLeft) {
+ scoped_ptr<Window> w1(CreateWindow(HTBOTTOMLEFT));
+ DragFromCenterBy(w1.get(), 50, -50);
+ // Position should have been offset by 50,0.
+ EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin());
+ // Size should have decreased by 50,50.
+ EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, TopLeft) {
+ scoped_ptr<Window> w1(CreateWindow(HTTOPLEFT));
+ DragFromCenterBy(w1.get(), 50, 50);
+ // Position should have been offset by 50,50.
+ EXPECT_EQ(gfx::Point(50, 50), w1->bounds().origin());
+ // Size should have decreased by 50,50.
+ EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, Client) {
+ scoped_ptr<Window> w1(CreateWindow(HTCLIENT));
+ gfx::Rect bounds = w1->bounds();
+ DragFromCenterBy(w1.get(), 100, 100);
+ // Neither position nor size should have changed.
+ EXPECT_EQ(bounds, w1->bounds());
+}
+
+} // namespace internal
+} // namespace aura
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index fbb83c4..3cca1da 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -9,57 +9,22 @@
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
#include "ui/aura/focus_manager.h"
+#include "ui/aura/hit_test.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test_desktop_delegate.h"
+#include "ui/aura/test_window_delegate.h"
#include "ui/aura/window_delegate.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/base/keycodes/keyboard_codes.h"
-#if !defined(OS_WIN)
-#include "ui/aura/hit_test.h"
-#endif
-
namespace aura {
namespace internal {
namespace {
-// WindowDelegate implementation with all methods stubbed out.
-class WindowDelegateImpl : public WindowDelegate {
- public:
- WindowDelegateImpl() {}
- virtual ~WindowDelegateImpl() {}
-
- // Overridden from WindowDelegate:
- virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) OVERRIDE {}
- virtual void OnFocus() OVERRIDE {}
- virtual void OnBlur() OVERRIDE {}
- virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE {
- return false;
- }
- virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
- return NULL;
- }
- virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
- return HTCLIENT;
- }
- virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { return false; }
- virtual bool ShouldActivate(MouseEvent* event) OVERRIDE { return true; }
- virtual void OnActivated() OVERRIDE {}
- virtual void OnLostActive() OVERRIDE {}
- virtual void OnCaptureLost() OVERRIDE {}
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {}
- virtual void OnWindowDestroying() OVERRIDE {}
- virtual void OnWindowDestroyed() OVERRIDE {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(WindowDelegateImpl);
-};
-
// Used for verifying destruction methods are invoked.
-class DestroyTrackingDelegateImpl : public WindowDelegateImpl {
+class DestroyTrackingDelegateImpl : public TestWindowDelegate {
public:
DestroyTrackingDelegateImpl()
: destroying_count_(0),
@@ -115,7 +80,7 @@ class ChildWindowDelegateImpl : public DestroyTrackingDelegateImpl {
};
// Used in verifying mouse capture.
-class CaptureWindowDelegateImpl : public WindowDelegateImpl {
+class CaptureWindowDelegateImpl : public TestWindowDelegate {
public:
explicit CaptureWindowDelegateImpl()
: capture_lost_count_(0),
@@ -144,17 +109,17 @@ class CaptureWindowDelegateImpl : public WindowDelegateImpl {
// A simple WindowDelegate implementation for these tests. It owns itself
// (deletes itself when the Window it is attached to is destroyed).
-class TestWindowDelegate : public WindowDelegateImpl {
+class ColorTestWindowDelegate : public TestWindowDelegate {
public:
- TestWindowDelegate(SkColor color)
+ ColorTestWindowDelegate(SkColor color)
: color_(color),
last_key_code_(ui::VKEY_UNKNOWN) {
}
- virtual ~TestWindowDelegate() {}
+ virtual ~ColorTestWindowDelegate() {}
ui::KeyboardCode last_key_code() const { return last_key_code_; }
- // Overridden from WindowDelegateImpl:
+ // Overridden from TestWindowDelegate:
virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE {
last_key_code_ = event->key_code();
return true;
@@ -170,7 +135,7 @@ class TestWindowDelegate : public WindowDelegateImpl {
SkColor color_;
ui::KeyboardCode last_key_code_;
- DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
+ DISALLOW_COPY_AND_ASSIGN(ColorTestWindowDelegate);
};
class WindowTest : public AuraTestBase {
@@ -186,7 +151,7 @@ class WindowTest : public AuraTestBase {
int id,
const gfx::Rect& bounds,
Window* parent) {
- return CreateTestWindowWithDelegate(new TestWindowDelegate(color),
+ return CreateTestWindowWithDelegate(new ColorTestWindowDelegate(color),
id, bounds, parent);
}
@@ -221,7 +186,7 @@ TEST_F(WindowTest, GetChildById) {
}
TEST_F(WindowTest, HitTest) {
- Window w1(new TestWindowDelegate(SK_ColorWHITE));
+ Window w1(new ColorTestWindowDelegate(SK_ColorWHITE));
w1.set_id(1);
w1.Init();
w1.SetBounds(gfx::Rect(10, 10, 50, 50));
@@ -253,6 +218,7 @@ TEST_F(WindowTest, GetEventHandlerForPoint) {
CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get()));
Window* desktop = Desktop::GetInstance()->window();
+ w1->parent()->SetBounds(gfx::Rect(500, 500));
EXPECT_EQ(NULL, desktop->GetEventHandlerForPoint(gfx::Point(5, 5)));
EXPECT_EQ(w1.get(), desktop->GetEventHandlerForPoint(gfx::Point(11, 11)));
EXPECT_EQ(w11.get(), desktop->GetEventHandlerForPoint(gfx::Point(16, 16)));
@@ -275,7 +241,8 @@ TEST_F(WindowTest, Focus) {
scoped_ptr<Window> w12(
CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25),
w1.get()));
- TestWindowDelegate* w121delegate = new TestWindowDelegate(SK_ColorYELLOW);
+ ColorTestWindowDelegate* w121delegate =
+ new ColorTestWindowDelegate(SK_ColorYELLOW);
scoped_ptr<Window> w121(
CreateTestWindowWithDelegate(w121delegate, 121, gfx::Rect(5, 5, 5, 5),
w12.get()));
@@ -390,7 +357,7 @@ TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
EXPECT_EQ(NULL, root->capture_window());
}
-class MouseEnterExitWindowDelegate : public WindowDelegateImpl {
+class MouseEnterExitWindowDelegate : public TestWindowDelegate {
public:
MouseEnterExitWindowDelegate() : entered_(false), exited_(false) {}
@@ -450,7 +417,7 @@ TEST_F(WindowTest, MouseEnterExit) {
EXPECT_FALSE(d2.exited());
}
-class ActivateWindowDelegate : public WindowDelegateImpl {
+class ActivateWindowDelegate : public TestWindowDelegate {
public:
ActivateWindowDelegate()
: activate_(true),
@@ -561,7 +528,7 @@ TEST_F(WindowTest, ActivateOnMouse) {
// because it has no children that can handle the event and it has no delegate
// allowing it to handle the event itself.
TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) {
- WindowDelegateImpl d111;
+ TestWindowDelegate d111;
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
gfx::Rect(0, 0, 500, 500), NULL));
scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11,
@@ -616,9 +583,9 @@ TEST_F(WindowTest, Visibility) {
// should make sure that none behind it in the z-order see events if it has
// children. If it does not have children, event targeting works as usual.
TEST_F(WindowTest, StopsEventPropagation) {
- WindowDelegateImpl d11;
- WindowDelegateImpl d111;
- WindowDelegateImpl d121;
+ TestWindowDelegate d11;
+ TestWindowDelegate d111;
+ TestWindowDelegate d121;
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
gfx::Rect(0, 0, 500, 500), NULL));
scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11,
@@ -727,8 +694,8 @@ TEST_F(WindowTest, Maximized) {
// Various assertions for activating/deactivating.
TEST_F(WindowTest, Deactivate) {
- WindowDelegateImpl d1;
- WindowDelegateImpl d2;
+ TestWindowDelegate d1;
+ TestWindowDelegate d2;
scoped_ptr<Window> w1(
CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL));
scoped_ptr<Window> w2(