Chromium Code Reviews| 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 5451535598fc95e5e85e2c835d0c580fe797b1ba..5334ef79ae147e50e5561ccdbef03bbcd79163d6 100644 |
| --- a/ash/wm/workspace/workspace_window_resizer.cc |
| +++ b/ash/wm/workspace/workspace_window_resizer.cc |
| @@ -9,6 +9,7 @@ |
| #include <utility> |
| #include <vector> |
| +#include "ash/ash_switches.h" |
| #include "ash/display/display_controller.h" |
| #include "ash/screen_ash.h" |
| #include "ash/shell.h" |
| @@ -22,6 +23,7 @@ |
| #include "ash/wm/window_util.h" |
| #include "ash/wm/workspace/phantom_window_controller.h" |
| #include "ash/wm/workspace/snap_sizer.h" |
| +#include "base/command_line.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/window_types.h" |
| #include "ui/aura/root_window.h" |
| @@ -74,16 +76,21 @@ namespace internal { |
| namespace { |
| -// Duration of the animation when snapping the window into place. |
| -const int kSnapDurationMS = 100; |
| +const int kStickySize = 64; |
|
sky
2013/04/22 17:20:00
Comment.
stevenjb
2013/04/22 18:09:41
Done.
|
| -// 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 true if the window should stick to the edge. |
| +bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { |
| + if (CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kAshEnableStickyEdges)) { |
| + return distance_from_edge < 0 && |
| + distance_from_edge > -sticky_size; |
| + } else { |
|
sky
2013/04/22 17:20:00
no else.
stevenjb
2013/04/22 18:09:41
Done.
|
| + return distance_from_edge < sticky_size && |
| + distance_from_edge > -sticky_size * 2; |
| + } |
| } |
| -// Returns the coordinate along the secondary axis to snap to. |
| +// Returns the coordinate along the secondary axis to stick to. |
|
sky
2013/04/22 17:20:00
This isn't used in what you are calling sticking.
stevenjb
2013/04/22 18:09:41
Done.
|
| int CoordinateAlongSecondaryAxis(SecondaryMagnetismEdge edge, |
| int leading, |
| int trailing, |
| @@ -187,7 +194,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 component edge to the magnetic edge to snap to. |
| uint32 WindowComponentToMagneticEdge(int window_component) { |
| switch (window_component) { |
| case HTTOPLEFT: |
| @@ -312,8 +319,15 @@ 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; |
| + int snap_size; |
|
sky
2013/04/22 17:20:00
sticky_size
stevenjb
2013/04/22 18:09:41
Done.
|
| + if (event_flags & ui::EF_CONTROL_DOWN) { |
| + snap_size = 0; |
| + } else if (CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kAshEnableStickyEdges)) { |
| + snap_size = kStickySize; |
| + } else { |
| + snap_size = kScreenEdgeInset; |
| + } |
| // |bounds| is in |window()->parent()|'s coordinates. |
| gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); |
| @@ -666,13 +680,13 @@ void WorkspaceWindowResizer::AdjustBoundsForMainWindow( |
| } |
| if (snap_size > 0) { |
| - SnapToWorkAreaEdges(work_area, snap_size, bounds); |
| + StickToWorkAreaEdges(work_area, snap_size, bounds); |
| MagneticallySnapToOtherWindows(bounds); |
| } |
| } else if (snap_size > 0) { |
| MagneticallySnapResizeToOtherWindows(bounds); |
| if (!magnetism_window_ && snap_size > 0) |
| - SnapResizeToWorkAreaBounds(work_area, snap_size, bounds); |
| + StickyResizeToWorkAreaBounds(work_area, snap_size, bounds); |
| } |
| if (attached_windows_.empty()) |
| @@ -688,23 +702,22 @@ void WorkspaceWindowResizer::AdjustBoundsForMainWindow( |
| } |
| } |
| -void WorkspaceWindowResizer::SnapToWorkAreaEdges( |
| +void WorkspaceWindowResizer::StickToWorkAreaEdges( |
| const gfx::Rect& work_area, |
| - int snap_size, |
| + int sticky_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 (ShouldStickToEdge(bounds->x() - left_edge, sticky_size)) { |
| bounds->set_x(left_edge); |
| - } else if (ShouldSnapToEdge(right_edge - bounds->right(), |
| - snap_size)) { |
| + } else if (ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { |
| bounds->set_x(right_edge - bounds->width()); |
| } |
| - if (ShouldSnapToEdge(bounds->y() - top_edge, snap_size)) { |
| + if (ShouldStickToEdge(bounds->y() - top_edge, sticky_size)) { |
| bounds->set_y(top_edge); |
| - } else if (ShouldSnapToEdge(bottom_edge - bounds->bottom(), snap_size) && |
| + } else if (ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_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 |
| @@ -713,9 +726,9 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges( |
| } |
| } |
| -void WorkspaceWindowResizer::SnapResizeToWorkAreaBounds( |
| +void WorkspaceWindowResizer::StickyResizeToWorkAreaBounds( |
| const gfx::Rect& work_area, |
| - int snap_size, |
| + int sticky_size, |
| gfx::Rect* bounds) const { |
| const uint32 edges = WindowComponentToMagneticEdge(details_.window_component); |
| const int left_edge = work_area.x(); |
| @@ -723,21 +736,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)) { |
| + ShouldStickToEdge(bounds->y() - top_edge, sticky_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)) { |
| + ShouldStickToEdge(bounds->x() - left_edge, sticky_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)) { |
| + ShouldStickToEdge(bottom_edge - bounds->bottom(), sticky_size)) { |
| bounds->set_height(bottom_edge - bounds->y()); |
| } |
| if (edges & MAGNETISM_EDGE_RIGHT && |
| - ShouldSnapToEdge(right_edge - bounds->right(), snap_size)) { |
| + ShouldStickToEdge(right_edge - bounds->right(), sticky_size)) { |
| bounds->set_width(right_edge - bounds->x()); |
| } |
| } |