summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-19 20:55:17 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-19 20:55:17 +0000
commitfb7ffba75e81a79436434bab0715be0d6e67bc07 (patch)
tree95e4c8e795849e3bde646fbc04748a9cc5533e33
parentefd7e47fbeb0f2ce01c0d8ef7910c0359fd587fa (diff)
downloadchromium_src-fb7ffba75e81a79436434bab0715be0d6e67bc07.zip
chromium_src-fb7ffba75e81a79436434bab0715be0d6e67bc07.tar.gz
chromium_src-fb7ffba75e81a79436434bab0715be0d6e67bc07.tar.bz2
Makes resizing a window snap to other windows.
BUG=152295 TEST=covered by tests R=ben@chromium.org Review URL: https://codereview.chromium.org/11232005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163051 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/wm/workspace/workspace_window_resizer.cc44
-rw-r--r--ash/wm/workspace/workspace_window_resizer.h6
-rw-r--r--ash/wm/workspace/workspace_window_resizer_unittest.cc59
3 files changed, 96 insertions, 13 deletions
diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc
index 5f5973a..26309d1 100644
--- a/ash/wm/workspace/workspace_window_resizer.cc
+++ b/ash/wm/workspace/workspace_window_resizer.cc
@@ -571,6 +571,8 @@ void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
}
} else if (snap_size > 0) {
MagneticallySnapResizeToOtherWindows(bounds);
+ if (!magnetism_window_ && snap_size > 0)
+ SnapResizeToWorkAreaBounds(work_area, snap_size, bounds);
}
if (attached_windows_.empty())
@@ -590,10 +592,10 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges(
const gfx::Rect& work_area,
int snap_size,
gfx::Rect* bounds) const {
- int left_edge = work_area.x();
- int right_edge = work_area.right();
- int top_edge = work_area.y();
- int bottom_edge = work_area.bottom();
+ const int left_edge = work_area.x();
+ const int right_edge = work_area.right();
+ const int top_edge = work_area.y();
+ const int bottom_edge = work_area.bottom();
if (ShouldSnapToEdge(bounds->x() - left_edge, snap_size)) {
bounds->set_x(left_edge);
} else if (ShouldSnapToEdge(right_edge - bounds->right(),
@@ -611,13 +613,33 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges(
}
}
-bool WorkspaceWindowResizer::TouchesBottomOfScreen() const {
- gfx::Rect work_area(
- ScreenAsh::GetDisplayWorkAreaBoundsInParent(window()));
- return (attached_windows_.empty() &&
- window()->bounds().bottom() == work_area.bottom()) ||
- (!attached_windows_.empty() &&
- attached_windows_.back()->bounds().bottom() == work_area.bottom());
+void WorkspaceWindowResizer::SnapResizeToWorkAreaBounds(
+ const gfx::Rect& work_area,
+ int snap_size,
+ gfx::Rect* bounds) const {
+ const uint32 edges = WindowComponentToMagneticEdge(details_.window_component);
+ const int left_edge = work_area.x();
+ const int right_edge = work_area.right();
+ const int top_edge = work_area.y();
+ const int bottom_edge = work_area.bottom();
+ if (edges & MAGNETISM_EDGE_TOP &&
+ ShouldSnapToEdge(bounds->y() - top_edge, snap_size)) {
+ bounds->set_height(bounds->bottom() - top_edge);
+ bounds->set_y(top_edge);
+ }
+ if (edges & MAGNETISM_EDGE_LEFT &&
+ ShouldSnapToEdge(bounds->x() - left_edge, snap_size)) {
+ bounds->set_width(bounds->right() - left_edge);
+ bounds->set_x(left_edge);
+ }
+ if (edges & MAGNETISM_EDGE_BOTTOM &&
+ ShouldSnapToEdge(bottom_edge - bounds->bottom(), snap_size)) {
+ bounds->set_height(bottom_edge - bounds->y());
+ }
+ if (edges & MAGNETISM_EDGE_RIGHT &&
+ ShouldSnapToEdge(right_edge - bounds->right(), snap_size)) {
+ bounds->set_width(right_edge - bounds->x());
+ }
}
int WorkspaceWindowResizer::PrimaryAxisSize(const gfx::Size& size) const {
diff --git a/ash/wm/workspace/workspace_window_resizer.h b/ash/wm/workspace/workspace_window_resizer.h
index 4f139b2..26065b13 100644
--- a/ash/wm/workspace/workspace_window_resizer.h
+++ b/ash/wm/workspace/workspace_window_resizer.h
@@ -131,8 +131,10 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
int snap_size,
gfx::Rect* bounds) const;
- // Returns true if the window touches the bottom edge of the work area.
- bool TouchesBottomOfScreen() const;
+ // Snaps the window bounds to the work area during a resize.
+ void SnapResizeToWorkAreaBounds(const gfx::Rect& work_area,
+ int snap_size,
+ gfx::Rect* bounds) const;
// Returns a coordinate along the primary axis. Used to share code for
// left/right multi window resize and top/bottom resize.
diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc
index 10233d5..75aad47 100644
--- a/ash/wm/workspace/workspace_window_resizer_unittest.cc
+++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc
@@ -967,6 +967,65 @@ TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
// No need to test dragging < 0 as we force that to 0.
}
+// Verifies a resize snap when dragging TOPLEFT.
+TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) {
+ window_->SetBounds(gfx::Rect(100, 200, 20, 30));
+ scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
+ window_.get(), gfx::Point(), HTTOPLEFT, empty_windows()));
+ ASSERT_TRUE(resizer.get());
+ resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0);
+ EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
+}
+
+// Verifies a resize snap when dragging TOPRIGHT.
+TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) {
+ window_->SetBounds(gfx::Rect(100, 200, 20, 30));
+ gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
+ window_.get()));
+ scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
+ window_.get(), gfx::Point(), HTTOPRIGHT, empty_windows()));
+ ASSERT_TRUE(resizer.get());
+ resizer->Drag(
+ CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0);
+ EXPECT_EQ(100, window_->bounds().x());
+ EXPECT_EQ(work_area.y(), window_->bounds().y());
+ EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
+ EXPECT_EQ(230, window_->bounds().height());
+}
+
+// Verifies a resize snap when dragging BOTTOMRIGHT.
+TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) {
+ window_->SetBounds(gfx::Rect(100, 200, 20, 30));
+ gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
+ window_.get()));
+ scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
+ window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows()));
+ ASSERT_TRUE(resizer.get());
+ resizer->Drag(
+ CalculateDragPoint(*resizer, work_area.right() - 120 - 1,
+ work_area.bottom() - 220 - 2), 0);
+ EXPECT_EQ(100, window_->bounds().x());
+ EXPECT_EQ(200, window_->bounds().y());
+ EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
+ EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
+}
+
+// Verifies a resize snap when dragging BOTTOMLEFT.
+TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) {
+ window_->SetBounds(gfx::Rect(100, 200, 20, 30));
+ gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
+ window_.get()));
+ scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
+ window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows()));
+ ASSERT_TRUE(resizer.get());
+ resizer->Drag(
+ CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
+ EXPECT_EQ(0, window_->bounds().x());
+ EXPECT_EQ(200, window_->bounds().y());
+ EXPECT_EQ(120, window_->bounds().width());
+ EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
+}
+
// Verifies a window taller than work area height doesn't snap above the top of
// the work area.
TEST_F(WorkspaceWindowResizerTest, TallWindow) {