summaryrefslogtreecommitdiffstats
path: root/ash/wm
diff options
context:
space:
mode:
authorjeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-21 07:48:40 +0000
committerjeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-21 07:48:40 +0000
commit5a09ec16a047304b128736fa640a024ee12f1bdb (patch)
treee0f098667c55609569f76b3ed389ca7429996613 /ash/wm
parent54131da48bccbe9266fe80eba8fdc3faa67b3507 (diff)
downloadchromium_src-5a09ec16a047304b128736fa640a024ee12f1bdb.zip
chromium_src-5a09ec16a047304b128736fa640a024ee12f1bdb.tar.gz
chromium_src-5a09ec16a047304b128736fa640a024ee12f1bdb.tar.bz2
[ash] Don't fling-snap windows that aren't maximizable.
BUG=157965 R=sadrul@chromium.org Review URL: https://chromiumcodereview.appspot.com/11276046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174357 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm')
-rw-r--r--ash/wm/gestures/two_finger_drag_handler.cc5
-rw-r--r--ash/wm/system_gesture_event_filter_unittest.cc109
2 files changed, 112 insertions, 2 deletions
diff --git a/ash/wm/gestures/two_finger_drag_handler.cc b/ash/wm/gestures/two_finger_drag_handler.cc
index acab05e..d042a2f 100644
--- a/ash/wm/gestures/two_finger_drag_handler.cc
+++ b/ash/wm/gestures/two_finger_drag_handler.cc
@@ -132,10 +132,11 @@ bool TwoFingerDragHandler::ProcessGestureEvent(aura::Window* target,
Reset();
if (event.details().swipe_up()) {
- wm::MaximizeWindow(target);
+ if (wm::CanMaximizeWindow(target))
+ wm::MaximizeWindow(target);
} else if (event.details().swipe_down()) {
wm::MinimizeWindow(target);
- } else {
+ } else if (wm::CanSnapWindow(target)) {
ui::ScopedLayerAnimationSettings scoped_setter(
target->layer()->GetAnimator());
scoped_setter.SetPreemptionStrategy(
diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc
index d6afd42..fa93f8f 100644
--- a/ash/wm/system_gesture_event_filter_unittest.cc
+++ b/ash/wm/system_gesture_event_filter_unittest.cc
@@ -28,6 +28,7 @@
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/screen.h"
+#include "ui/gfx/size.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
@@ -122,11 +123,62 @@ class ResizableWidgetDelegate : public views::WidgetDelegateView {
private:
virtual bool CanResize() const OVERRIDE { return true; }
+ virtual bool CanMaximize() const OVERRIDE { return true; }
virtual void DeleteDelegate() OVERRIDE { delete this; }
DISALLOW_COPY_AND_ASSIGN(ResizableWidgetDelegate);
};
+// Support class for testing windows with a maximum size.
+class MaxSizeNCFV : public views::NonClientFrameView {
+ public:
+ MaxSizeNCFV() {}
+ private:
+ virtual gfx::Size GetMaximumSize() OVERRIDE {
+ return gfx::Size(200, 200);
+ }
+ virtual gfx::Rect GetBoundsForClientView() const OVERRIDE {
+ return gfx::Rect();
+ };
+
+ virtual gfx::Rect GetWindowBoundsForClientBounds(
+ const gfx::Rect& client_bounds) const OVERRIDE {
+ return gfx::Rect();
+ };
+
+ // This function must ask the ClientView to do a hittest. We don't do this in
+ // the parent NonClientView because that makes it more difficult to calculate
+ // hittests for regions that are partially obscured by the ClientView, e.g.
+ // HTSYSMENU.
+ virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE {
+ return HTNOWHERE;
+ }
+ virtual void GetWindowMask(const gfx::Size& size,
+ gfx::Path* window_mask) OVERRIDE {}
+ virtual void ResetWindowControls() OVERRIDE {}
+ virtual void UpdateWindowIcon() OVERRIDE {}
+ virtual void UpdateWindowTitle() OVERRIDE {}
+
+ DISALLOW_COPY_AND_ASSIGN(MaxSizeNCFV);
+};
+
+class MaxSizeWidgetDelegate : public views::WidgetDelegateView {
+ public:
+ MaxSizeWidgetDelegate() {}
+ virtual ~MaxSizeWidgetDelegate() {}
+
+ private:
+ virtual bool CanResize() const OVERRIDE { return true; }
+ virtual bool CanMaximize() const OVERRIDE { return false; }
+ virtual void DeleteDelegate() OVERRIDE { delete this; }
+ virtual views::NonClientFrameView* CreateNonClientFrameView(
+ views::Widget* widget) OVERRIDE {
+ return new MaxSizeNCFV;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(MaxSizeWidgetDelegate);
+};
+
} // namespace
class SystemGestureEventFilterTest : public AshTestBase {
@@ -641,6 +693,63 @@ TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) {
EXPECT_EQ(current_bounds.ToString(), right_tile_bounds.ToString());
}
+TEST_F(SystemGestureEventFilterTest, WindowsWithMaxSizeDontSnap) {
+ gfx::Rect bounds(150, 150, 100, 100);
+ aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
+ views::Widget* toplevel = views::Widget::CreateWindowWithBounds(
+ new MaxSizeWidgetDelegate, bounds);
+ toplevel->Show();
+
+ const int kSteps = 15;
+ const int kTouchPoints = 2;
+ gfx::Point points[kTouchPoints] = {
+ gfx::Point(150+10, 150+30),
+ gfx::Point(150+30, 150+20),
+ };
+
+ aura::test::EventGenerator generator(root_window,
+ toplevel->GetNativeWindow());
+
+ // Swipe down to minimize.
+ generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 0, 150);
+ EXPECT_TRUE(wm::IsWindowMinimized(toplevel->GetNativeWindow()));
+
+ toplevel->Restore();
+ toplevel->GetNativeWindow()->SetBounds(bounds);
+
+ // Check that swiping up doesn't maximize.
+ generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 0, -150);
+ EXPECT_FALSE(wm::IsWindowMaximized(toplevel->GetNativeWindow()));
+
+ toplevel->Restore();
+ toplevel->GetNativeWindow()->SetBounds(bounds);
+
+ // Check that swiping right doesn't snap.
+ gfx::Rect normal_bounds = toplevel->GetWindowBoundsInScreen();
+ generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 150, 0);
+ normal_bounds.set_x(normal_bounds.x() + 150);
+ EXPECT_EQ(normal_bounds.ToString(),
+ toplevel->GetWindowBoundsInScreen().ToString());
+
+ toplevel->GetNativeWindow()->SetBounds(bounds);
+
+ // Check that swiping left doesn't snap.
+ normal_bounds = toplevel->GetWindowBoundsInScreen();
+ generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, -150, 0);
+ normal_bounds.set_x(normal_bounds.x() - 150);
+ EXPECT_EQ(normal_bounds.ToString(),
+ toplevel->GetWindowBoundsInScreen().ToString());
+
+ toplevel->GetNativeWindow()->SetBounds(bounds);
+
+ // Swipe right again, make sure the window still doesn't snap.
+ normal_bounds = toplevel->GetWindowBoundsInScreen();
+ normal_bounds.set_x(normal_bounds.x() + 150);
+ generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 150, 0);
+ EXPECT_EQ(normal_bounds.ToString(),
+ toplevel->GetWindowBoundsInScreen().ToString());
+}
+
TEST_F(SystemGestureEventFilterTest, TwoFingerDragEdge) {
gfx::Rect bounds(0, 0, 100, 100);
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();