| 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..25430933827c63762fb0e9b7dcc1cc1d348f5370 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,13 +76,19 @@ namespace internal {
|
|
|
| namespace {
|
|
|
| -// Duration of the animation when snapping the window into place.
|
| -const int kSnapDurationMS = 100;
|
| +// Distance in pixels that the cursor must move past an edge for a window
|
| +// to move or resize beyond that edge.
|
| +const int kStickyDistancePixels = 64;
|
|
|
| -// 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;
|
| + }
|
| + return distance_from_edge < sticky_size &&
|
| + distance_from_edge > -sticky_size * 2;
|
| }
|
|
|
| // Returns the coordinate along the secondary axis to snap to.
|
| @@ -187,7 +195,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,13 +320,20 @@ 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 sticky_size;
|
| + if (event_flags & ui::EF_CONTROL_DOWN) {
|
| + sticky_size = 0;
|
| + } else if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kAshEnableStickyEdges)) {
|
| + sticky_size = kStickyDistancePixels;
|
| + } else {
|
| + sticky_size = kScreenEdgeInset;
|
| + }
|
| // |bounds| is in |window()->parent()|'s coordinates.
|
| gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent);
|
|
|
| if (wm::IsWindowNormal(window()))
|
| - AdjustBoundsForMainWindow(snap_size, &bounds);
|
| + AdjustBoundsForMainWindow(sticky_size, &bounds);
|
|
|
| if (bounds != window()->bounds()) {
|
| if (!did_move_or_resize_) {
|
| @@ -645,7 +660,7 @@ bool WorkspaceWindowResizer::UpdateMagnetismWindow(const gfx::Rect& bounds,
|
| }
|
|
|
| void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
|
| - int snap_size,
|
| + int sticky_size,
|
| gfx::Rect* bounds) {
|
| gfx::Point last_mouse_location_in_screen = last_mouse_location_;
|
| wm::ConvertPointToScreen(window()->parent(), &last_mouse_location_in_screen);
|
| @@ -665,14 +680,14 @@ void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
|
| bounds->set_y(work_area.y());
|
| }
|
|
|
| - if (snap_size > 0) {
|
| - SnapToWorkAreaEdges(work_area, snap_size, bounds);
|
| + if (sticky_size > 0) {
|
| + StickToWorkAreaOnMove(work_area, sticky_size, bounds);
|
| MagneticallySnapToOtherWindows(bounds);
|
| }
|
| - } else if (snap_size > 0) {
|
| + } else if (sticky_size > 0) {
|
| MagneticallySnapResizeToOtherWindows(bounds);
|
| - if (!magnetism_window_ && snap_size > 0)
|
| - SnapResizeToWorkAreaBounds(work_area, snap_size, bounds);
|
| + if (!magnetism_window_ && sticky_size > 0)
|
| + StickToWorkAreaOnResize(work_area, sticky_size, bounds);
|
| }
|
|
|
| if (attached_windows_.empty())
|
| @@ -688,23 +703,22 @@ void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
|
| }
|
| }
|
|
|
| -void WorkspaceWindowResizer::SnapToWorkAreaEdges(
|
| +void WorkspaceWindowResizer::StickToWorkAreaOnMove(
|
| 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 +727,9 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges(
|
| }
|
| }
|
|
|
| -void WorkspaceWindowResizer::SnapResizeToWorkAreaBounds(
|
| +void WorkspaceWindowResizer::StickToWorkAreaOnResize(
|
| 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 +737,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());
|
| }
|
| }
|
|
|