Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2912)

Unified Diff: ash/wm/workspace/workspace_window_resizer.cc

Issue 14273008: Add ash-enable-sticky-edges for 'sticky' instead of 'snap' behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wm/workspace/workspace_window_resizer.cc
diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc
index 347954ce75063d3e8abc826ed1206d85178d50d1..1a1e20997f84c266b9ce8922a240f1c04aaf0bb5 100644
--- a/ash/wm/workspace/workspace_window_resizer.cc
+++ b/ash/wm/workspace/workspace_window_resizer.cc
@@ -74,16 +74,7 @@ namespace internal {
namespace {
-// Duration of the animation when snapping the window into place.
-const int kSnapDurationMS = 100;
-
-// Returns true if should snap to the edge.
-bool ShouldSnapToEdge(int distance_from_edge, int grid_size) {
- return distance_from_edge < grid_size &&
- distance_from_edge > -grid_size * 2;
-}
-
-// Returns the coordinate along the secondary axis to snap to.
+// Returns the coordinate along the secondary axis to stick to.
int CoordinateAlongSecondaryAxis(SecondaryMagnetismEdge edge,
int leading,
int trailing,
@@ -187,7 +178,7 @@ gfx::Rect BoundsForMagneticResizeAttach(const gfx::Rect& src,
return gfx::Rect(x, y, w, h);
}
-// Converts a window comopnent edge to the magnetic edge to snap to.
+// Converts a window comopnent edge to the magnetic edge to stick to.
flackr 2013/04/16 00:32:14 nit: s/comopnent/component
stevenjb 2013/04/16 20:08:20 Done.
uint32 WindowComponentToMagneticEdge(int window_component) {
switch (window_component) {
case HTTOPLEFT:
@@ -312,13 +303,13 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent,
int event_flags) {
last_mouse_location_ = location_in_parent;
- const int snap_size =
- event_flags & ui::EF_CONTROL_DOWN ? 0 : kScreenEdgeInset;
+ const bool is_sticky = !(event_flags & ui::EF_CONTROL_DOWN);
+
// |bounds| is in |window()->parent()|'s coordinates.
gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent);
if (wm::IsWindowNormal(window()))
- AdjustBoundsForMainWindow(snap_size, &bounds);
+ AdjustBoundsForMainWindow(is_sticky, &bounds);
if (bounds != window()->bounds()) {
if (!did_move_or_resize_) {
@@ -596,7 +587,8 @@ void WorkspaceWindowResizer::CreateBucketsForAttached(
}
}
-void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) {
+void WorkspaceWindowResizer::MagneticallyStickToOtherWindows(
+ gfx::Rect* bounds) {
if (UpdateMagnetismWindow(*bounds, kAllMagnetismEdges)) {
bounds->set_origin(
OriginForMagneticAttach(*bounds, magnetism_window_->bounds(),
@@ -604,7 +596,7 @@ void WorkspaceWindowResizer::MagneticallySnapToOtherWindows(gfx::Rect* bounds) {
}
}
-void WorkspaceWindowResizer::MagneticallySnapResizeToOtherWindows(
+void WorkspaceWindowResizer::MagneticallyStickResizeToOtherWindows(
gfx::Rect* bounds) {
const uint32 edges = WindowComponentToMagneticEdge(details_.window_component);
if (UpdateMagnetismWindow(*bounds, edges)) {
@@ -617,7 +609,7 @@ bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds,
uint32 edges) {
MagnetismMatcher matcher(bounds, edges);
- // If we snapped to a window then check it first. That way we don't bounce
+ // If we stuck to a window then check it first. That way we don't bounce
// around when close to multiple edges.
if (magnetism_window_) {
if (window_tracker_.Contains(magnetism_window_) &&
@@ -644,9 +636,8 @@ bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds,
return false;
}
-void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
- int snap_size,
- gfx::Rect* bounds) {
+void WorkspaceWindowResizer::AdjustBoundsForMainWindow(bool is_sticky,
+ gfx::Rect* bounds) {
gfx::Point last_mouse_location_in_screen = last_mouse_location_;
wm::ConvertPointToScreen(window()->parent(), &last_mouse_location_in_screen);
gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(
@@ -665,14 +656,14 @@ void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
bounds->set_y(work_area.y());
}
- if (snap_size > 0) {
- SnapToWorkAreaEdges(work_area, snap_size, bounds);
- MagneticallySnapToOtherWindows(bounds);
+ if (is_sticky) {
+ StickToWorkAreaEdges(work_area, bounds);
+ MagneticallyStickToOtherWindows(bounds);
}
- } else if (snap_size > 0) {
- MagneticallySnapResizeToOtherWindows(bounds);
- if (!magnetism_window_ && snap_size > 0)
- SnapResizeToWorkAreaBounds(work_area, snap_size, bounds);
+ } else if (is_sticky) {
+ MagneticallyStickResizeToOtherWindows(bounds);
+ if (!magnetism_window_)
+ StickyResizeToWorkAreaBounds(work_area, bounds);
}
if (attached_windows_.empty())
@@ -688,23 +679,21 @@ void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
}
}
-void WorkspaceWindowResizer::SnapToWorkAreaEdges(
+void WorkspaceWindowResizer::StickToWorkAreaEdges(
const gfx::Rect& work_area,
- int snap_size,
gfx::Rect* bounds) const {
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)) {
+ if (wm::ShouldStickToEdge(bounds->x() - left_edge)) {
bounds->set_x(left_edge);
- } else if (ShouldSnapToEdge(right_edge - bounds->right(),
- snap_size)) {
+ } else if (wm::ShouldStickToEdge(right_edge - bounds->right())) {
bounds->set_x(right_edge - bounds->width());
}
- if (ShouldSnapToEdge(bounds->y() - top_edge, snap_size)) {
+ if (wm::ShouldStickToEdge(bounds->y() - top_edge)) {
bounds->set_y(top_edge);
- } else if (ShouldSnapToEdge(bottom_edge - bounds->bottom(), snap_size) &&
+ } else if (wm::ShouldStickToEdge(bottom_edge - bounds->bottom()) &&
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
@@ -713,9 +702,8 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges(
}
}
-void WorkspaceWindowResizer::SnapResizeToWorkAreaBounds(
+void WorkspaceWindowResizer::StickyResizeToWorkAreaBounds(
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();
@@ -723,21 +711,21 @@ void WorkspaceWindowResizer::SnapResizeToWorkAreaBounds(
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)) {
+ wm::ShouldStickToEdge(bounds->y() - top_edge)) {
bounds->set_height(bounds->bottom() - top_edge);
bounds->set_y(top_edge);
}
if (edges & MAGNETISM_EDGE_LEFT &&
- ShouldSnapToEdge(bounds->x() - left_edge, snap_size)) {
+ wm::ShouldStickToEdge(bounds->x() - left_edge)) {
bounds->set_width(bounds->right() - left_edge);
bounds->set_x(left_edge);
}
if (edges & MAGNETISM_EDGE_BOTTOM &&
- ShouldSnapToEdge(bottom_edge - bounds->bottom(), snap_size)) {
+ wm::ShouldStickToEdge(bottom_edge - bounds->bottom())) {
bounds->set_height(bottom_edge - bounds->y());
}
if (edges & MAGNETISM_EDGE_RIGHT &&
- ShouldSnapToEdge(right_edge - bounds->right(), snap_size)) {
+ wm::ShouldStickToEdge(right_edge - bounds->right())) {
bounds->set_width(right_edge - bounds->x());
}
}
« ash/wm/workspace/workspace_window_resizer.h ('K') | « ash/wm/workspace/workspace_window_resizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698