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

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

Issue 23431009: Windows docking should get triggered by pressing against the screen edge (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows docking by pressing against the screen edge (rebase) Created 7 years, 3 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.h ('k') | ash/wm/workspace/workspace_window_resizer.h » ('j') | 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/snap_sizer.h" 5 #include "ash/wm/workspace/snap_sizer.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/screen_ash.h" 10 #include "ash/screen_ash.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // and close). 71 // and close).
72 width = work_area.width() / 2; 72 width = work_area.width() / 2;
73 } else { 73 } else {
74 width = std::max(kDefaultWidthSmallScreen, work_area.width() / 2); 74 width = std::max(kDefaultWidthSmallScreen, work_area.width() / 2);
75 } 75 }
76 76
77 width = std::min(width, GetMaxWidth(window)); 77 width = std::min(width, GetMaxWidth(window));
78 return std::max(width, GetMinWidth(window)); 78 return std::max(width, GetMinWidth(window));
79 } 79 }
80 80
81 // Create the list of possible widths for the current screen configuration: 81 // Creates the list of possible width for the current screen configuration:
82 // Fill the |usable_width_| list with items from |kIdealWidth| which fit on 82 // Returns a list with items from |kIdealWidth| which fit on the screen and
83 // the screen and supplement it with the 'half of screen' size. Furthermore, 83 // supplement it with the 'half of screen' size. Furthermore, add an entry for
84 // add an entry for 90% of the screen size if it is smaller than the biggest 84 // 90% of the screen size if it is smaller than the biggest value in the
85 // value in the |kIdealWidth| list (to get a step between the values). 85 // |kIdealWidth| list (to get a step between the values).
86 std::vector<int> BuildIdealWidthList(aura::Window* window) { 86 std::vector<int> BuildIdealWidthList(aura::Window* window) {
87 if (ash::switches::UseAlternateFrameCaptionButtonStyle()) { 87 if (ash::switches::UseAlternateFrameCaptionButtonStyle()) {
88 // Only the 'half of screen' width is supported when using the alternate 88 // Only the 'half of screen' width is supported when using the alternate
89 // visual style for the frame caption buttons (minimize, maximize, 89 // visual style for the frame caption buttons (minimize, maximize,
90 // restore, and close). 90 // restore, and close).
91 return std::vector<int>(1u, GetDefaultWidth(window)); 91 return std::vector<int>(1u, GetDefaultWidth(window));
92 } 92 }
93 93
94 int minimum_width = GetMinWidth(window); 94 int minimum_width = GetMinWidth(window);
95 int maximum_width = GetMaxWidth(window); 95 int maximum_width = GetMaxWidth(window);
(...skipping 30 matching lines...) Expand all
126 } // namespace 126 } // namespace
127 127
128 SnapSizer::SnapSizer(aura::Window* window, 128 SnapSizer::SnapSizer(aura::Window* window,
129 const gfx::Point& start, 129 const gfx::Point& start,
130 Edge edge, 130 Edge edge,
131 InputType input_type) 131 InputType input_type)
132 : window_(window), 132 : window_(window),
133 edge_(edge), 133 edge_(edge),
134 time_last_update_(base::TimeTicks::Now()), 134 time_last_update_(base::TimeTicks::Now()),
135 size_index_(0), 135 size_index_(0),
136 end_of_sequence_(false),
136 resize_disabled_(false), 137 resize_disabled_(false),
137 num_moves_since_adjust_(0), 138 num_moves_since_adjust_(0),
138 last_adjust_x_(start.x()), 139 last_adjust_x_(start.x()),
139 last_update_x_(start.x()), 140 last_update_x_(start.x()),
140 start_x_(start.x()), 141 start_x_(start.x()),
141 input_type_(input_type), 142 input_type_(input_type),
142 usable_width_(BuildIdealWidthList(window)) { 143 usable_width_(BuildIdealWidthList(window)) {
143 DCHECK(!usable_width_.empty()); 144 DCHECK(!usable_width_.empty());
144 target_bounds_ = GetTargetBounds(); 145 target_bounds_ = GetTargetBounds();
145 } 146 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 212 }
212 } 213 }
213 if (current < 0) 214 if (current < 0)
214 current = 0; 215 current = 0;
215 return GetTargetBoundsForSize(current % usable_width_.size()); 216 return GetTargetBoundsForSize(current % usable_width_.size());
216 } 217 }
217 218
218 void SnapSizer::SelectDefaultSizeAndDisableResize() { 219 void SnapSizer::SelectDefaultSizeAndDisableResize() {
219 resize_disabled_ = true; 220 resize_disabled_ = true;
220 size_index_ = 0; 221 size_index_ = 0;
222 end_of_sequence_ = false;
221 target_bounds_ = GetTargetBounds(); 223 target_bounds_ = GetTargetBounds();
222 } 224 }
223 225
224 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { 226 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const {
225 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_)); 227 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_));
226 int y = work_area.y(); 228 int y = work_area.y();
227 int max_y = work_area.bottom(); 229 int max_y = work_area.bottom();
228 int width = 0; 230 int width = 0;
229 if (resize_disabled_) { 231 if (resize_disabled_) {
230 width = GetDefaultWidth(window_); 232 width = GetDefaultWidth(window_);
(...skipping 22 matching lines...) Expand all
253 return 1; 255 return 1;
254 return -1; 256 return -1;
255 } 257 }
256 // edge_ == RIGHT_EDGE. 258 // edge_ == RIGHT_EDGE.
257 if (x > reference_x) 259 if (x > reference_x)
258 return 1; 260 return 1;
259 return -1; 261 return -1;
260 } 262 }
261 263
262 void SnapSizer::ChangeBounds(int x, int delta) { 264 void SnapSizer::ChangeBounds(int x, int delta) {
265 end_of_sequence_ =
266 delta > 0 && size_index_ == static_cast<int>(usable_width_.size()) - 1;
263 int index = std::min(static_cast<int>(usable_width_.size()) - 1, 267 int index = std::min(static_cast<int>(usable_width_.size()) - 1,
264 std::max(size_index_ + delta, 0)); 268 std::max(size_index_ + delta, 0));
265 if (index != size_index_) { 269 if (index != size_index_) {
266 size_index_ = index; 270 size_index_ = index;
267 target_bounds_ = GetTargetBounds(); 271 target_bounds_ = GetTargetBounds();
268 } 272 }
269 num_moves_since_adjust_ = 0; 273 num_moves_since_adjust_ = 0;
270 last_adjust_x_ = x; 274 last_adjust_x_ = x;
271 } 275 }
272 276
273 gfx::Rect SnapSizer::GetTargetBounds() const { 277 gfx::Rect SnapSizer::GetTargetBounds() const {
274 return GetTargetBoundsForSize(size_index_); 278 return GetTargetBoundsForSize(size_index_);
275 } 279 }
276 280
277 bool SnapSizer::AlongEdge(int x) const { 281 bool SnapSizer::AlongEdge(int x) const {
278 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); 282 gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_));
279 return (x <= area.x()) || (x >= area.right() - 1); 283 return (x <= area.x()) || (x >= area.right() - 1);
280 } 284 }
281 285
282 } // namespace internal 286 } // namespace internal
283 } // namespace ash 287 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/snap_sizer.h ('k') | ash/wm/workspace/workspace_window_resizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698