summaryrefslogtreecommitdiffstats
path: root/ash/wm/workspace
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-26 02:07:32 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-26 02:07:32 +0000
commit12423509133aaf33fdb8e651558487f9820ba6e6 (patch)
tree9054358ba635d06dc7ad2073ec23d6e281a6455f /ash/wm/workspace
parent5b88f7ce7ef49daae377b0405186d064344d4102 (diff)
downloadchromium_src-12423509133aaf33fdb8e651558487f9820ba6e6.zip
chromium_src-12423509133aaf33fdb8e651558487f9820ba6e6.tar.gz
chromium_src-12423509133aaf33fdb8e651558487f9820ba6e6.tar.bz2
Fixes bug in window resizing code that could lead to window snapping
above the top of the screen. BUG=120036 TEST=covered by unit test R=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/9853004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/workspace')
-rw-r--r--ash/wm/workspace/workspace_window_resizer.cc16
-rw-r--r--ash/wm/workspace/workspace_window_resizer_unittest.cc14
2 files changed, 25 insertions, 5 deletions
diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc
index 274cb5c..feed24e 100644
--- a/ash/wm/workspace/workspace_window_resizer.cc
+++ b/ash/wm/workspace/workspace_window_resizer.cc
@@ -315,15 +315,21 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges(
int top_edge = AlignToGridRoundUp(work_area.y(), details_.grid_size);
int bottom_edge = AlignToGridRoundDown(work_area.bottom(),
details_.grid_size);
- if (ShouldSnapToEdge(bounds->x() - left_edge, details_.grid_size))
+ if (ShouldSnapToEdge(bounds->x() - left_edge, details_.grid_size)) {
bounds->set_x(left_edge);
- else if (ShouldSnapToEdge(right_edge - bounds->right(), details_.grid_size))
+ } else if (ShouldSnapToEdge(right_edge - bounds->right(),
+ details_.grid_size)) {
bounds->set_x(right_edge - bounds->width());
- if (ShouldSnapToEdge(bounds->y() - top_edge, details_.grid_size))
+ } if (ShouldSnapToEdge(bounds->y() - top_edge, details_.grid_size)) {
bounds->set_y(top_edge);
- else if (ShouldSnapToEdge(bottom_edge - bounds->bottom(),
- details_.grid_size))
+ } else if (ShouldSnapToEdge(bottom_edge - bounds->bottom(),
+ details_.grid_size) &&
+ bounds->height() < (bottom_edge - top_edge)) {
+ // Only snap to the bottom if the window is smaller than the work area.
+ // Doing otherwise can lead to window snapping in weird ways as it bounces
+ // between snapping to top then bottom.
bounds->set_y(bottom_edge - bounds->height());
+ }
}
bool WorkspaceWindowResizer::TouchesBottomOfScreen() const {
diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc
index 72fea98..160ba43 100644
--- a/ash/wm/workspace/workspace_window_resizer_unittest.cc
+++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc
@@ -567,6 +567,20 @@ TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
EXPECT_EQ("96,0 320x160", window_->bounds().ToString());
// No need to test dragging < 0 as we force that to 0.
}
+
+// Verifies a window taller than work area height doesn't snap above the top of
+// the work area.
+TEST_F(WorkspaceWindowResizerTest, TallWindow) {
+ aura::RootWindow* root = Shell::GetInstance()->GetRootWindow();
+ Shell::GetInstance()->SetMonitorWorkAreaInsets(
+ root, gfx::Insets(0, 0, 50, 0));
+ window_->SetBounds(gfx::Rect(0, 0, 320, 560));
+ scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
+ window_.get(), gfx::Point(), HTCAPTION, 16, empty_windows()));
+ resizer->Drag(CalculateDragPoint(*resizer, 0, 9));
+ EXPECT_EQ("0,9 320x560", window_->bounds().ToString());
+}
+
#endif
} // namespace