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

Side by Side Diff: ash/wm/workspace/workspace_window_resizer.cc

Issue 153893005: Makes it easier to snap or dock windows near the edges when using touch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 unified diff | Download patch
« no previous file with comments | « ash/wm/workspace/snap_sizer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 window_resizer = internal::DockedWindowResizer::Create(window_resizer, 102 window_resizer = internal::DockedWindowResizer::Create(window_resizer,
103 window_state); 103 window_state);
104 } 104 }
105 return make_scoped_ptr<WindowResizer>(window_resizer); 105 return make_scoped_ptr<WindowResizer>(window_resizer);
106 } 106 }
107 107
108 namespace internal { 108 namespace internal {
109 109
110 namespace { 110 namespace {
111 111
112 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset
113 // when resizing a window using touchscreen.
114 const int kScreenEdgeInsetForTouchResize = 32;
115
116 // Returns true if the window should stick to the edge. 112 // Returns true if the window should stick to the edge.
117 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { 113 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) {
118 if (CommandLine::ForCurrentProcess()->HasSwitch( 114 if (CommandLine::ForCurrentProcess()->HasSwitch(
119 switches::kAshEnableStickyEdges)) { 115 switches::kAshEnableStickyEdges)) {
120 // TODO(varkha): Consider keeping snapping behavior for touch drag. 116 // TODO(varkha): Consider keeping snapping behavior for touch drag.
121 return distance_from_edge < 0 && 117 return distance_from_edge < 0 &&
122 distance_from_edge > -sticky_size; 118 distance_from_edge > -sticky_size;
123 } 119 }
124 return distance_from_edge < sticky_size && 120 return distance_from_edge < sticky_size &&
125 distance_from_edge > -sticky_size * 2; 121 distance_from_edge > -sticky_size * 2;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 last_mouse_location_ = location_in_parent; 357 last_mouse_location_ = location_in_parent;
362 358
363 int sticky_size; 359 int sticky_size;
364 if (event_flags & ui::EF_CONTROL_DOWN) { 360 if (event_flags & ui::EF_CONTROL_DOWN) {
365 sticky_size = 0; 361 sticky_size = 0;
366 } else if (CommandLine::ForCurrentProcess()->HasSwitch( 362 } else if (CommandLine::ForCurrentProcess()->HasSwitch(
367 switches::kAshEnableStickyEdges)) { 363 switches::kAshEnableStickyEdges)) {
368 sticky_size = kStickyDistancePixels; 364 sticky_size = kStickyDistancePixels;
369 } else if ((details().bounds_change & kBoundsChange_Resizes) && 365 } else if ((details().bounds_change & kBoundsChange_Resizes) &&
370 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 366 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
371 sticky_size = kScreenEdgeInsetForTouchResize; 367 sticky_size = SnapSizer::kScreenEdgeInsetForTouchDrag;
372 } else { 368 } else {
373 sticky_size = kScreenEdgeInset; 369 sticky_size = kScreenEdgeInset;
374 } 370 }
375 // |bounds| is in |GetTarget()->parent()|'s coordinates. 371 // |bounds| is in |GetTarget()->parent()|'s coordinates.
376 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent); 372 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent);
377 AdjustBoundsForMainWindow(sticky_size, &bounds); 373 AdjustBoundsForMainWindow(sticky_size, &bounds);
378 374
379 if (bounds != GetTarget()->bounds()) { 375 if (bounds != GetTarget()->bounds()) {
380 if (!did_move_or_resize_) { 376 if (!did_move_or_resize_) {
381 if (!details().restore_bounds.IsEmpty()) 377 if (!details().restore_bounds.IsEmpty())
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 if (!can_snap && !can_dock) { 908 if (!can_snap && !can_dock) {
913 snap_type_ = SNAP_NONE; 909 snap_type_ = SNAP_NONE;
914 snap_phantom_window_controller_.reset(); 910 snap_phantom_window_controller_.reset();
915 snap_sizer_.reset(); 911 snap_sizer_.reset();
916 SetDraggedWindowDocked(false); 912 SetDraggedWindowDocked(false);
917 return; 913 return;
918 } 914 }
919 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT) ? 915 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT) ?
920 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; 916 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE;
921 if (!snap_sizer_) { 917 if (!snap_sizer_) {
922 snap_sizer_.reset(new SnapSizer(window_state(), 918 SnapSizer::InputType input =
923 location, 919 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH ?
924 edge, 920 SnapSizer::TOUCH_DRAG_INPUT : SnapSizer::OTHER_INPUT;
925 internal::SnapSizer::OTHER_INPUT)); 921 snap_sizer_.reset(new SnapSizer(window_state(), location, edge, input));
926 } else { 922 } else {
927 snap_sizer_->Update(location); 923 snap_sizer_->Update(location);
928 } 924 }
929 925
930 // Update phantom window with snapped or docked guide bounds. 926 // Update phantom window with snapped or docked guide bounds.
931 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get 927 // Windows that cannot be snapped or are less wide than kMaxDockWidth can get
932 // docked without going through a snapping sequence. 928 // docked without going through a snapping sequence.
933 gfx::Rect phantom_bounds; 929 gfx::Rect phantom_bounds;
934 if (can_snap && (!can_dock || GetTarget()->bounds().width() > 930 if (can_snap && (!can_dock || GetTarget()->bounds().width() >
935 DockedWindowLayoutManager::kMaxDockWidth)) { 931 DockedWindowLayoutManager::kMaxDockWidth)) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 const gfx::Point& location) const { 990 const gfx::Point& location) const {
995 // TODO: this likely only wants total display area, not the area of a single 991 // TODO: this likely only wants total display area, not the area of a single
996 // display. 992 // display.
997 gfx::Rect area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(GetTarget())); 993 gfx::Rect area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(GetTarget()));
998 if (details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { 994 if (details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) {
999 // Increase tolerance for touch-snapping near the screen edges. This is only 995 // Increase tolerance for touch-snapping near the screen edges. This is only
1000 // necessary when the work area left or right edge is same as screen edge. 996 // necessary when the work area left or right edge is same as screen edge.
1001 gfx::Rect display_bounds(ScreenUtil::GetDisplayBoundsInParent(GetTarget())); 997 gfx::Rect display_bounds(ScreenUtil::GetDisplayBoundsInParent(GetTarget()));
1002 int inset_left = 0; 998 int inset_left = 0;
1003 if (area.x() == display_bounds.x()) 999 if (area.x() == display_bounds.x())
1004 inset_left = kScreenEdgeInsetForTouchResize; 1000 inset_left = SnapSizer::kScreenEdgeInsetForTouchDrag;
1005 int inset_right = 0; 1001 int inset_right = 0;
1006 if (area.right() == display_bounds.right()) 1002 if (area.right() == display_bounds.right())
1007 inset_right = kScreenEdgeInsetForTouchResize; 1003 inset_right = SnapSizer::kScreenEdgeInsetForTouchDrag;
1008 area.Inset(inset_left, 0, inset_right, 0); 1004 area.Inset(inset_left, 0, inset_right, 0);
1009 } 1005 }
1010 if (location.x() <= area.x()) 1006 if (location.x() <= area.x())
1011 return SNAP_LEFT; 1007 return SNAP_LEFT;
1012 if (location.x() >= area.right() - 1) 1008 if (location.x() >= area.right() - 1)
1013 return SNAP_RIGHT; 1009 return SNAP_RIGHT;
1014 return SNAP_NONE; 1010 return SNAP_NONE;
1015 } 1011 }
1016 1012
1017 void WorkspaceWindowResizer::SetDraggedWindowDocked(bool should_dock) { 1013 void WorkspaceWindowResizer::SetDraggedWindowDocked(bool should_dock) {
1018 if (should_dock && 1014 if (should_dock &&
1019 dock_layout_->GetAlignmentOfWindow(GetTarget()) != 1015 dock_layout_->GetAlignmentOfWindow(GetTarget()) !=
1020 DOCKED_ALIGNMENT_NONE) { 1016 DOCKED_ALIGNMENT_NONE) {
1021 if (!dock_layout_->is_dragged_window_docked()) { 1017 if (!dock_layout_->is_dragged_window_docked()) {
1022 window_state()->set_bounds_changed_by_user(false); 1018 window_state()->set_bounds_changed_by_user(false);
1023 dock_layout_->DockDraggedWindow(GetTarget()); 1019 dock_layout_->DockDraggedWindow(GetTarget());
1024 } 1020 }
1025 } else { 1021 } else {
1026 if (dock_layout_->is_dragged_window_docked()) { 1022 if (dock_layout_->is_dragged_window_docked()) {
1027 dock_layout_->UndockDraggedWindow(); 1023 dock_layout_->UndockDraggedWindow();
1028 window_state()->set_bounds_changed_by_user(true); 1024 window_state()->set_bounds_changed_by_user(true);
1029 } 1025 }
1030 } 1026 }
1031 } 1027 }
1032 1028
1033 } // namespace internal 1029 } // namespace internal
1034 } // namespace ash 1030 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/snap_sizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698