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

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

Issue 11364052: Revert "Disabled WorkspaceWindowResizerTest.Edge since it got broken by https://chromiumcodereview.… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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/frame_maximize_button.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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 window_component(HTNOWHERE), 107 window_component(HTNOWHERE),
108 bounds_change(0), 108 bounds_change(0),
109 position_change_direction(0), 109 position_change_direction(0),
110 size_change_direction(0), 110 size_change_direction(0),
111 is_resizable(false) { 111 is_resizable(false) {
112 } 112 }
113 113
114 WindowResizer::Details::Details(aura::Window* window, 114 WindowResizer::Details::Details(aura::Window* window,
115 const gfx::Point& location, 115 const gfx::Point& location,
116 int window_component) 116 int window_component)
117 : window(window), 117 : window(window),
118 initial_bounds_in_parent(window->bounds()), 118 initial_bounds(window->bounds()),
119 restore_bounds(gfx::Rect()), 119 restore_bounds(gfx::Rect()),
120 initial_location_in_parent(location), 120 initial_location_in_parent(location),
121 initial_opacity(window->layer()->opacity()), 121 initial_opacity(window->layer()->opacity()),
122 window_component(window_component), 122 window_component(window_component),
123 bounds_change(GetBoundsChangeForWindowComponent(window_component)), 123 bounds_change(GetBoundsChangeForWindowComponent(window_component)),
124 position_change_direction( 124 position_change_direction(
125 GetPositionChangeDirectionForWindowComponent(window_component)), 125 GetPositionChangeDirectionForWindowComponent(window_component)),
126 size_change_direction( 126 size_change_direction(
127 GetSizeChangeDirectionForWindowComponent(window_component)), 127 GetSizeChangeDirectionForWindowComponent(window_component)),
128 is_resizable(bounds_change != kBoundsChangeDirection_None) { 128 is_resizable(bounds_change != kBoundsChangeDirection_None) {
129 if (wm::IsWindowNormal(window) && 129 if (wm::IsWindowNormal(window) &&
130 GetRestoreBoundsInScreen(window) && 130 GetRestoreBoundsInScreen(window) &&
131 window_component == HTCAPTION) 131 window_component == HTCAPTION)
132 restore_bounds = *GetRestoreBoundsInScreen(window); 132 restore_bounds = *GetRestoreBoundsInScreen(window);
133 } 133 }
134 134
135 WindowResizer::Details::~Details() { 135 WindowResizer::Details::~Details() {
136 } 136 }
137 137
138 WindowResizer::WindowResizer() { 138 WindowResizer::WindowResizer() {
(...skipping 27 matching lines...) Expand all
166 break; 166 break;
167 } 167 }
168 return bounds_change; 168 return bounds_change;
169 } 169 }
170 170
171 // static 171 // static
172 gfx::Rect WindowResizer::CalculateBoundsForDrag( 172 gfx::Rect WindowResizer::CalculateBoundsForDrag(
173 const Details& details, 173 const Details& details,
174 const gfx::Point& passed_location) { 174 const gfx::Point& passed_location) {
175 if (!details.is_resizable) 175 if (!details.is_resizable)
176 return details.initial_bounds_in_parent; 176 return details.initial_bounds;
177 177
178 gfx::Point location = passed_location; 178 gfx::Point location = passed_location;
179 gfx::Rect work_area = 179 gfx::Rect work_area =
180 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); 180 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window);
181 181
182 int delta_x = location.x() - details.initial_location_in_parent.x(); 182 int delta_x = location.x() - details.initial_location_in_parent.x();
183 int delta_y = location.y() - details.initial_location_in_parent.y(); 183 int delta_y = location.y() - details.initial_location_in_parent.y();
184 184
185 // The minimize size constraint may limit how much we change the window 185 // The minimize size constraint may limit how much we change the window
186 // position. For example, dragging the left edge to the right should stop 186 // position. For example, dragging the left edge to the right should stop
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 230 }
231 } 231 }
232 232
233 if (details.bounds_change & kBoundsChange_Repositions) { 233 if (details.bounds_change & kBoundsChange_Repositions) {
234 // When we might want to reposition a window which is also restored to its 234 // When we might want to reposition a window which is also restored to its
235 // previous size, to keep the cursor within the dragged window. 235 // previous size, to keep the cursor within the dragged window.
236 if (!details.restore_bounds.IsEmpty()) { 236 if (!details.restore_bounds.IsEmpty()) {
237 // However - it is not desirable to change the origin if the window would 237 // However - it is not desirable to change the origin if the window would
238 // be still hit by the cursor. 238 // be still hit by the cursor.
239 if (details.initial_location_in_parent.x() > 239 if (details.initial_location_in_parent.x() >
240 details.initial_bounds_in_parent.x() + details.restore_bounds.width()) 240 details.initial_bounds.x() + details.restore_bounds.width())
241 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); 241 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2);
242 } 242 }
243 243
244 // Make sure that |new_bounds| doesn't leave any of the displays. Note that 244 // Make sure that |new_bounds| doesn't leave any of the displays. Note that
245 // the |work_area| above isn't good for this check since it is the work area 245 // the |work_area| above isn't good for this check since it is the work area
246 // for the current display but the window can move to a different one. 246 // for the current display but the window can move to a different one.
247 aura::Window* parent = details.window->parent(); 247 aura::Window* parent = details.window->parent();
248 gfx::Rect new_bounds_in_screen = 248 gfx::Rect new_bounds_in_screen =
249 ScreenAsh::ConvertRectToScreen(parent, new_bounds); 249 ScreenAsh::ConvertRectToScreen(parent, new_bounds);
250 const gfx::Display& display = 250 const gfx::Display& display =
(...skipping 19 matching lines...) Expand all
270 return window_component == HTBOTTOMLEFT || 270 return window_component == HTBOTTOMLEFT ||
271 window_component == HTBOTTOM || 271 window_component == HTBOTTOM ||
272 window_component == HTBOTTOMRIGHT || 272 window_component == HTBOTTOMRIGHT ||
273 window_component == HTGROWBOX; 273 window_component == HTGROWBOX;
274 } 274 }
275 275
276 // static 276 // static
277 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, 277 gfx::Point WindowResizer::GetOriginForDrag(const Details& details,
278 int delta_x, 278 int delta_x,
279 int delta_y) { 279 int delta_y) {
280 gfx::Point origin = details.initial_bounds_in_parent.origin(); 280 gfx::Point origin = details.initial_bounds.origin();
281 if (details.bounds_change & kBoundsChange_Repositions) { 281 if (details.bounds_change & kBoundsChange_Repositions) {
282 int pos_change_direction = 282 int pos_change_direction =
283 GetPositionChangeDirectionForWindowComponent(details.window_component); 283 GetPositionChangeDirectionForWindowComponent(details.window_component);
284 if (pos_change_direction & kBoundsChangeDirection_Horizontal) 284 if (pos_change_direction & kBoundsChangeDirection_Horizontal)
285 origin.Offset(delta_x, 0); 285 origin.Offset(delta_x, 0);
286 if (pos_change_direction & kBoundsChangeDirection_Vertical) 286 if (pos_change_direction & kBoundsChangeDirection_Vertical)
287 origin.Offset(0, delta_y); 287 origin.Offset(0, delta_y);
288 } 288 }
289 return origin; 289 return origin;
290 } 290 }
291 291
292 // static 292 // static
293 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, 293 gfx::Size WindowResizer::GetSizeForDrag(const Details& details,
294 int* delta_x, 294 int* delta_x,
295 int* delta_y) { 295 int* delta_y) {
296 gfx::Size size = details.initial_bounds_in_parent.size(); 296 gfx::Size size = details.initial_bounds.size();
297 if (details.bounds_change & kBoundsChange_Resizes) { 297 if (details.bounds_change & kBoundsChange_Resizes) {
298 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); 298 gfx::Size min_size = details.window->delegate()->GetMinimumSize();
299 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), 299 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x),
300 GetHeightForDrag(details, min_size.height(), delta_y)); 300 GetHeightForDrag(details, min_size.height(), delta_y));
301 } else if (!details.restore_bounds.IsEmpty()) { 301 } else if (!details.restore_bounds.IsEmpty()) {
302 size = details.restore_bounds.size(); 302 size = details.restore_bounds.size();
303 } 303 }
304 return size; 304 return size;
305 } 305 }
306 306
307 // static 307 // static
308 int WindowResizer::GetWidthForDrag(const Details& details, 308 int WindowResizer::GetWidthForDrag(const Details& details,
309 int min_width, 309 int min_width,
310 int* delta_x) { 310 int* delta_x) {
311 int width = details.initial_bounds_in_parent.width(); 311 int width = details.initial_bounds.width();
312 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { 312 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) {
313 // Along the right edge, positive delta_x increases the window size. 313 // Along the right edge, positive delta_x increases the window size.
314 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; 314 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1;
315 width += x_multiplier * (*delta_x); 315 width += x_multiplier * (*delta_x);
316 316
317 // Ensure we don't shrink past the minimum width and clamp delta_x 317 // Ensure we don't shrink past the minimum width and clamp delta_x
318 // for the window origin computation. 318 // for the window origin computation.
319 if (width < min_width) { 319 if (width < min_width) {
320 width = min_width; 320 width = min_width;
321 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - 321 *delta_x = -x_multiplier * (details.initial_bounds.width() - min_width);
322 min_width);
323 } 322 }
324 323
325 // And don't let the window go bigger than the display. 324 // And don't let the window go bigger than the display.
326 int max_width = Shell::GetScreen()->GetDisplayNearestWindow( 325 int max_width = Shell::GetScreen()->GetDisplayNearestWindow(
327 details.window).bounds().width(); 326 details.window).bounds().width();
328 if (width > max_width) { 327 if (width > max_width) {
329 width = max_width; 328 width = max_width;
330 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - 329 *delta_x = -x_multiplier * (details.initial_bounds.width() - max_width);
331 max_width);
332 } 330 }
333 } 331 }
334 return width; 332 return width;
335 } 333 }
336 334
337 // static 335 // static
338 int WindowResizer::GetHeightForDrag(const Details& details, 336 int WindowResizer::GetHeightForDrag(const Details& details,
339 int min_height, 337 int min_height,
340 int* delta_y) { 338 int* delta_y) {
341 int height = details.initial_bounds_in_parent.height(); 339 int height = details.initial_bounds.height();
342 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { 340 if (details.size_change_direction & kBoundsChangeDirection_Vertical) {
343 // Along the bottom edge, positive delta_y increases the window size. 341 // Along the bottom edge, positive delta_y increases the window size.
344 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; 342 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1;
345 height += y_multiplier * (*delta_y); 343 height += y_multiplier * (*delta_y);
346 344
347 // Ensure we don't shrink past the minimum height and clamp delta_y 345 // Ensure we don't shrink past the minimum height and clamp delta_y
348 // for the window origin computation. 346 // for the window origin computation.
349 if (height < min_height) { 347 if (height < min_height) {
350 height = min_height; 348 height = min_height;
351 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - 349 *delta_y = -y_multiplier * (details.initial_bounds.height() - min_height);
352 min_height);
353 } 350 }
354 351
355 // And don't let the window go bigger than the display. 352 // And don't let the window go bigger than the display.
356 int max_height = Shell::GetScreen()->GetDisplayNearestWindow( 353 int max_height = Shell::GetScreen()->GetDisplayNearestWindow(
357 details.window).bounds().height(); 354 details.window).bounds().height();
358 if (height > max_height) { 355 if (height > max_height) {
359 height = max_height; 356 height = max_height;
360 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - 357 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height);
361 max_height);
362 } 358 }
363 } 359 }
364 return height; 360 return height;
365 } 361 }
366 362
367 } // namespace aura 363 } // namespace aura
OLDNEW
« no previous file with comments | « ash/wm/window_resizer.h ('k') | ash/wm/workspace/frame_maximize_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698