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

Side by Side Diff: ash/wm/window_resizer.cc

Issue 15008002: Make touch-resizing windows to screen edge possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust unit tests with final behavior Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/window_resizer.h ('k') | ash/wm/workspace/multi_window_resize_controller.cc » ('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/window_resizer.h" 5 #include "ash/wm/window_resizer.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/wm/property_util.h" 9 #include "ash/wm/property_util.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; 100 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1;
101 // static 101 // static
102 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; 102 const int WindowResizer::kBoundsChangeDirection_Vertical = 2;
103 103
104 WindowResizer::Details::Details() 104 WindowResizer::Details::Details()
105 : window(NULL), 105 : window(NULL),
106 window_component(HTNOWHERE), 106 window_component(HTNOWHERE),
107 bounds_change(0), 107 bounds_change(0),
108 position_change_direction(0), 108 position_change_direction(0),
109 size_change_direction(0), 109 size_change_direction(0),
110 is_resizable(false) { 110 is_resizable(false),
111 source(aura::client::WINDOW_MOVE_SOURCE_MOUSE) {
111 } 112 }
112 113
113 WindowResizer::Details::Details(aura::Window* window, 114 WindowResizer::Details::Details(aura::Window* window,
114 const gfx::Point& location, 115 const gfx::Point& location,
115 int window_component) 116 int window_component,
117 aura::client::WindowMoveSource source)
116 : window(window), 118 : window(window),
117 initial_bounds_in_parent(window->bounds()), 119 initial_bounds_in_parent(window->bounds()),
118 restore_bounds(gfx::Rect()), 120 restore_bounds(gfx::Rect()),
119 initial_location_in_parent(location), 121 initial_location_in_parent(location),
120 initial_opacity(window->layer()->opacity()), 122 initial_opacity(window->layer()->opacity()),
121 window_component(window_component), 123 window_component(window_component),
122 bounds_change(GetBoundsChangeForWindowComponent(window_component)), 124 bounds_change(GetBoundsChangeForWindowComponent(window_component)),
123 position_change_direction( 125 position_change_direction(
124 GetPositionChangeDirectionForWindowComponent(window_component)), 126 GetPositionChangeDirectionForWindowComponent(window_component)),
125 size_change_direction( 127 size_change_direction(
126 GetSizeChangeDirectionForWindowComponent(window_component)), 128 GetSizeChangeDirectionForWindowComponent(window_component)),
127 is_resizable(bounds_change != kBoundsChangeDirection_None) { 129 is_resizable(bounds_change != kBoundsChangeDirection_None),
130 source(source) {
128 if (wm::IsWindowNormal(window) && 131 if (wm::IsWindowNormal(window) &&
129 GetRestoreBoundsInScreen(window) && 132 GetRestoreBoundsInScreen(window) &&
130 window_component == HTCAPTION) 133 window_component == HTCAPTION)
131 restore_bounds = *GetRestoreBoundsInScreen(window); 134 restore_bounds = *GetRestoreBoundsInScreen(window);
132 } 135 }
133 136
134 WindowResizer::Details::~Details() { 137 WindowResizer::Details::~Details() {
135 } 138 }
136 139
137 WindowResizer::WindowResizer() { 140 WindowResizer::WindowResizer() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (!details.is_resizable) 177 if (!details.is_resizable)
175 return details.initial_bounds_in_parent; 178 return details.initial_bounds_in_parent;
176 179
177 gfx::Point location = passed_location; 180 gfx::Point location = passed_location;
178 gfx::Rect work_area = 181 gfx::Rect work_area =
179 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); 182 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window);
180 183
181 int delta_x = location.x() - details.initial_location_in_parent.x(); 184 int delta_x = location.x() - details.initial_location_in_parent.x();
182 int delta_y = location.y() - details.initial_location_in_parent.y(); 185 int delta_y = location.y() - details.initial_location_in_parent.y();
183 186
187 AdjustDeltaForTouchResize(details, &delta_x, &delta_y);
188
184 // The minimize size constraint may limit how much we change the window 189 // The minimize size constraint may limit how much we change the window
185 // position. For example, dragging the left edge to the right should stop 190 // position. For example, dragging the left edge to the right should stop
186 // repositioning the window when the minimize size is reached. 191 // repositioning the window when the minimize size is reached.
187 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); 192 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y);
188 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); 193 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y);
189 gfx::Rect new_bounds(origin, size); 194 gfx::Rect new_bounds(origin, size);
190 195
191 // Sizing has to keep the result on the screen. Note that this correction 196 // Sizing has to keep the result on the screen. Note that this correction
192 // has to come first since it might have an impact on the origin as well as 197 // has to come first since it might have an impact on the origin as well as
193 // on the size. 198 // on the size.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 271
267 // static 272 // static
268 bool WindowResizer::IsBottomEdge(int window_component) { 273 bool WindowResizer::IsBottomEdge(int window_component) {
269 return window_component == HTBOTTOMLEFT || 274 return window_component == HTBOTTOMLEFT ||
270 window_component == HTBOTTOM || 275 window_component == HTBOTTOM ||
271 window_component == HTBOTTOMRIGHT || 276 window_component == HTBOTTOMRIGHT ||
272 window_component == HTGROWBOX; 277 window_component == HTGROWBOX;
273 } 278 }
274 279
275 // static 280 // static
281 void WindowResizer::AdjustDeltaForTouchResize(const Details& details,
282 int* delta_x,
283 int* delta_y) {
284 if (details.source != aura::client::WINDOW_MOVE_SOURCE_TOUCH ||
285 !(details.bounds_change & kBoundsChange_Resizes))
286 return;
287
288 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) {
289 if (IsRightEdge(details.window_component)) {
290 *delta_x += details.initial_location_in_parent.x() -
291 details.initial_bounds_in_parent.right();
292 } else {
293 *delta_x += details.initial_location_in_parent.x() -
294 details.initial_bounds_in_parent.x();
295 }
296 }
297 if (details.size_change_direction & kBoundsChangeDirection_Vertical) {
298 if (IsBottomEdge(details.window_component)) {
299 *delta_y += details.initial_location_in_parent.y() -
300 details.initial_bounds_in_parent.bottom();
301 } else {
302 *delta_y += details.initial_location_in_parent.y() -
303 details.initial_bounds_in_parent.y();
304 }
305 }
306 }
307
308 // static
276 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, 309 gfx::Point WindowResizer::GetOriginForDrag(const Details& details,
277 int delta_x, 310 int delta_x,
278 int delta_y) { 311 int delta_y) {
279 gfx::Point origin = details.initial_bounds_in_parent.origin(); 312 gfx::Point origin = details.initial_bounds_in_parent.origin();
280 if (details.bounds_change & kBoundsChange_Repositions) { 313 if (details.bounds_change & kBoundsChange_Repositions) {
281 int pos_change_direction = 314 int pos_change_direction =
282 GetPositionChangeDirectionForWindowComponent(details.window_component); 315 GetPositionChangeDirectionForWindowComponent(details.window_component);
283 if (pos_change_direction & kBoundsChangeDirection_Horizontal) 316 if (pos_change_direction & kBoundsChangeDirection_Horizontal)
284 origin.Offset(delta_x, 0); 317 origin.Offset(delta_x, 0);
285 if (pos_change_direction & kBoundsChangeDirection_Vertical) 318 if (pos_change_direction & kBoundsChangeDirection_Vertical)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (height > max_height) { 396 if (height > max_height) {
364 height = max_height; 397 height = max_height;
365 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - 398 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() -
366 max_height); 399 max_height);
367 } 400 }
368 } 401 }
369 return height; 402 return height;
370 } 403 }
371 404
372 } // namespace aura 405 } // namespace aura
OLDNEW
« no previous file with comments | « ash/wm/window_resizer.h ('k') | ash/wm/workspace/multi_window_resize_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698