summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoralicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 18:39:38 +0000
committeralicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 18:39:38 +0000
commit05af5c36662cfbc64767b8ec35ed06bc07c6a39f (patch)
treede556aec13e5d33b7f0bf0a33343116e6aca9e15 /ash
parent38136ddc6e077ff48fc8f4435e310a2c9afcb53c (diff)
downloadchromium_src-05af5c36662cfbc64767b8ec35ed06bc07c6a39f.zip
chromium_src-05af5c36662cfbc64767b8ec35ed06bc07c6a39f.tar.gz
chromium_src-05af5c36662cfbc64767b8ec35ed06bc07c6a39f.tar.bz2
Do not allow window to drop below work area in aura during resize.
After this change: - when a window is resized (by pulling at the bottom or lower corners), bottom resizing will stop at the top of the status area. - a window can be dragged beyond the work area (well into status bar). - left and right edge resizing is not affected by this change. - top edge resizing is already not allowed to go beyond top work area and not affected by this change. BUG=107807 TEST=tested on aura browser window drag and resizing. Review URL: http://codereview.chromium.org/9085026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116515 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/toplevel_window_event_filter.cc12
-rw-r--r--ash/wm/toplevel_window_event_filter_unittest.cc45
2 files changed, 55 insertions, 2 deletions
diff --git a/ash/wm/toplevel_window_event_filter.cc b/ash/wm/toplevel_window_event_filter.cc
index c173ce7..1ff6edc 100644
--- a/ash/wm/toplevel_window_event_filter.cc
+++ b/ash/wm/toplevel_window_event_filter.cc
@@ -290,7 +290,17 @@ bool ToplevelWindowEventFilter::HandleDrag(aura::Window* target,
gfx::Size size = GetSizeForDrag(bounds_change, target, &delta_x, &delta_y);
gfx::Point origin = GetOriginForDrag(bounds_change, delta_x, delta_y);
- target->SetBounds(gfx::Rect(origin, size));
+ gfx::Rect new_bounds(origin, size);
+ // Update bottom edge to stay in the work area when we are resizing
+ // by dragging the bottome edge or corners.
+ if (bounds_change & kBoundsChange_Resizes &&
+ origin.y() == target->bounds().y()) {
+ gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow(target);
+ if (new_bounds.bottom() > work_area.bottom())
+ new_bounds.Inset(0, 0, 0,
+ new_bounds.bottom() - work_area.bottom());
+ }
+ target->SetBounds(new_bounds);
return true;
}
diff --git a/ash/wm/toplevel_window_event_filter_unittest.cc b/ash/wm/toplevel_window_event_filter_unittest.cc
index fb86a15..2ab742c 100644
--- a/ash/wm/toplevel_window_event_filter_unittest.cc
+++ b/ash/wm/toplevel_window_event_filter_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -320,5 +320,48 @@ TEST_F(ToplevelWindowEventFilterTest, DoubleClickCaptionTogglesMaximize) {
EXPECT_FALSE(IsWindowMaximized(w1.get()));
}
+TEST_F(ToplevelWindowEventFilterTest, BottomRightWorkArea) {
+ scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT));
+ gfx::Rect work_area =
+ gfx::Screen::GetMonitorWorkAreaNearestWindow(target.get());
+ gfx::Point position = target->bounds().origin();
+ // Drag further than work_area bottom.
+ DragFromCenterBy(target.get(), 100, work_area.height());
+ // Position should not have changed.
+ EXPECT_EQ(position, target->bounds().origin());
+ // Size should have increased by 100, work_area.height() - target->bounds.y()
+ EXPECT_EQ(gfx::Size(200, work_area.height() - target->bounds().y()),
+ target->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, BottomLeftWorkArea) {
+ scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT));
+ gfx::Rect work_area =
+ gfx::Screen::GetMonitorWorkAreaNearestWindow(target.get());
+ gfx::Point position = target->bounds().origin();
+ // Drag further than work_area bottom.
+ DragFromCenterBy(target.get(), -30, work_area.height());
+ // origin is now at 70, 100.
+ EXPECT_EQ(position.x() - 30, target->bounds().x());
+ EXPECT_EQ(position.y(), target->bounds().y());
+ // Size should have increased by 30, work_area.height() - target->bounds.y()
+ EXPECT_EQ(gfx::Size(130, work_area.height() - target->bounds().y()),
+ target->bounds().size());
+}
+
+TEST_F(ToplevelWindowEventFilterTest, BottomWorkArea) {
+ scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOM));
+ gfx::Rect work_area =
+ gfx::Screen::GetMonitorWorkAreaNearestWindow(target.get());
+ gfx::Point position = target->bounds().origin();
+ // Drag further than work_area bottom.
+ DragFromCenterBy(target.get(), 0, work_area.height());
+ // Position should not have changed.
+ EXPECT_EQ(position, target->bounds().origin());
+ // Size should have increased by 0, work_area.height() - target->bounds.y()
+ EXPECT_EQ(gfx::Size(100, work_area.height() - target->bounds().y()),
+ target->bounds().size());
+}
+
} // namespace test
} // namespace aura