summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-12 22:40:44 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-12 22:40:44 +0000
commitbf70ff744afe295bc48c5407ea1a3832d5050917 (patch)
tree136c7ad7fdc2595c9233535d51f0c0676fbce2b2
parentcf8102524fdc24fc7765a45001eda182667bd40c (diff)
downloadchromium_src-bf70ff744afe295bc48c5407ea1a3832d5050917.zip
chromium_src-bf70ff744afe295bc48c5407ea1a3832d5050917.tar.gz
chromium_src-bf70ff744afe295bc48c5407ea1a3832d5050917.tar.bz2
Two tweaks to ToplevelWindowEventFilter:
. don't let windows resize bigger than screen area. . don't let windows be dragged to a -y location. We currently restrict this in ToplevelLayoutManager, which lead to not letting the y location go negative but having the window resize from the bottom when dragging from the top. BUG=106762 TEST=covered by tests. R=ben@chromium.org Review URL: http://codereview.chromium.org/9186048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117538 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/wm/toplevel_window_event_filter.cc34
-rw-r--r--ash/wm/toplevel_window_event_filter.h6
-rw-r--r--ash/wm/toplevel_window_event_filter_unittest.cc22
3 files changed, 56 insertions, 6 deletions
diff --git a/ash/wm/toplevel_window_event_filter.cc b/ash/wm/toplevel_window_event_filter.cc
index 1ff6edc..44c0e68 100644
--- a/ash/wm/toplevel_window_event_filter.cc
+++ b/ash/wm/toplevel_window_event_filter.cc
@@ -300,6 +300,12 @@ bool ToplevelWindowEventFilter::HandleDrag(aura::Window* target,
new_bounds.Inset(0, 0, 0,
new_bounds.bottom() - work_area.bottom());
}
+ if (bounds_change & kBoundsChange_Resizes &&
+ bounds_change & kBoundsChange_Repositions && new_bounds.y() < 0) {
+ int delta = new_bounds.y();
+ new_bounds.set_y(0);
+ new_bounds.set_height(new_bounds.height() + delta);
+ }
target->SetBounds(new_bounds);
return true;
}
@@ -347,13 +353,16 @@ gfx::Size ToplevelWindowEventFilter::GetSizeForDrag(
int size_change_direction =
GetSizeChangeDirectionForWindowComponent(window_component_);
size.SetSize(
- GetWidthForDrag(size_change_direction, min_size.width(), delta_x),
- GetHeightForDrag(size_change_direction, min_size.height(), delta_y));
+ GetWidthForDrag(target, size_change_direction, min_size.width(),
+ delta_x),
+ GetHeightForDrag(target, size_change_direction, min_size.height(),
+ delta_y));
}
return size;
}
-int ToplevelWindowEventFilter::GetWidthForDrag(int size_change_direction,
+int ToplevelWindowEventFilter::GetWidthForDrag(aura::Window* target,
+ int size_change_direction,
int min_width,
int* delta_x) const {
int width = mouse_down_bounds_.width();
@@ -368,11 +377,20 @@ int ToplevelWindowEventFilter::GetWidthForDrag(int size_change_direction,
width = min_width;
*delta_x = -x_multiplier * (mouse_down_bounds_.width() - min_width);
}
+
+ // And don't let the window go bigger than the monitor.
+ int max_width =
+ gfx::Screen::GetMonitorAreaNearestWindow(target).width();
+ if (width > max_width) {
+ width = max_width;
+ *delta_x = -x_multiplier * (mouse_down_bounds_.width() - max_width);
+ }
}
return width;
}
-int ToplevelWindowEventFilter::GetHeightForDrag(int size_change_direction,
+int ToplevelWindowEventFilter::GetHeightForDrag(aura::Window* target,
+ int size_change_direction,
int min_height,
int* delta_y) const {
int height = mouse_down_bounds_.height();
@@ -387,6 +405,14 @@ int ToplevelWindowEventFilter::GetHeightForDrag(int size_change_direction,
height = min_height;
*delta_y = -y_multiplier * (mouse_down_bounds_.height() - min_height);
}
+
+ // And don't let the window go bigger than the monitor.
+ int max_height =
+ gfx::Screen::GetMonitorAreaNearestWindow(target).height();
+ if (height > max_height) {
+ height = max_height;
+ *delta_y = -y_multiplier * (mouse_down_bounds_.height() - max_height);
+ }
}
return height;
}
diff --git a/ash/wm/toplevel_window_event_filter.h b/ash/wm/toplevel_window_event_filter.h
index 4da26d8..a08e973 100644
--- a/ash/wm/toplevel_window_event_filter.h
+++ b/ash/wm/toplevel_window_event_filter.h
@@ -82,14 +82,16 @@ class ASH_EXPORT ToplevelWindowEventFilter :
// Calculates new width of a window during a drag where the mouse
// position changed by |delta_x|. |delta_x| may be clamped if the window
// size is constrained by |min_width|.
- int GetWidthForDrag(int size_change_direction,
+ int GetWidthForDrag(aura::Window* target,
+ int size_change_direction,
int min_width,
int* delta_x) const;
// Calculates new height of a window during a drag where the mouse
// position changed by |delta_y|. |delta_y| may be clamped if the window
// size is constrained by |min_height|.
- int GetHeightForDrag(int size_change_direction,
+ int GetHeightForDrag(aura::Window* target,
+ int size_change_direction,
int min_height,
int* delta_y) const;
diff --git a/ash/wm/toplevel_window_event_filter_unittest.cc b/ash/wm/toplevel_window_event_filter_unittest.cc
index 2ab742c..0fef59d 100644
--- a/ash/wm/toplevel_window_event_filter_unittest.cc
+++ b/ash/wm/toplevel_window_event_filter_unittest.cc
@@ -363,5 +363,27 @@ TEST_F(ToplevelWindowEventFilterTest, BottomWorkArea) {
target->bounds().size());
}
+// Verifies we don't let windows drag to a -y location.
+TEST_F(ToplevelWindowEventFilterTest, DontDragToNegativeY) {
+ scoped_ptr<aura::Window> target(CreateWindow(HTTOP));
+ gfx::Rect work_area =
+ gfx::Screen::GetMonitorWorkAreaNearestWindow(target.get());
+ aura::test::EventGenerator generator(target.get());
+ generator.MoveMouseTo(0, 5);
+ generator.DragMouseBy(0, -5);
+ // The y location and height should not have changed.
+ EXPECT_EQ(0, target->bounds().y());
+ EXPECT_EQ(100, target->bounds().height());
+}
+
+// Verifies we don't let windows go bigger than the monitor width.
+TEST_F(ToplevelWindowEventFilterTest, DontGotWiderThanScreen) {
+ scoped_ptr<aura::Window> target(CreateWindow(HTRIGHT));
+ gfx::Rect work_area = gfx::Screen::GetMonitorAreaNearestWindow(target.get());
+ DragFromCenterBy(target.get(), work_area.width() * 2, 0);
+ // The y location and height should not have changed.
+ EXPECT_EQ(work_area.width(), target->bounds().width());
+}
+
} // namespace test
} // namespace aura