OLD | NEW |
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/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/root_window_event_filter.h" | 8 #include "ash/wm/root_window_event_filter.h" |
9 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // static | 179 // static |
180 int WindowResizer::AlignToGridRoundDown(int location, int grid_size) { | 180 int WindowResizer::AlignToGridRoundDown(int location, int grid_size) { |
181 if (grid_size <= 1 || location % grid_size == 0) | 181 if (grid_size <= 1 || location % grid_size == 0) |
182 return location; | 182 return location; |
183 return location / grid_size * grid_size; | 183 return location / grid_size * grid_size; |
184 } | 184 } |
185 | 185 |
186 // static | 186 // static |
187 gfx::Rect WindowResizer::CalculateBoundsForDrag( | 187 gfx::Rect WindowResizer::CalculateBoundsForDrag( |
188 const Details& details, | 188 const Details& details, |
189 const gfx::Point& location) { | 189 const gfx::Point& location, |
| 190 bool disable_snap_to_grid) { |
190 if (!details.is_resizable) | 191 if (!details.is_resizable) |
191 return details.initial_bounds; | 192 return details.initial_bounds; |
192 | 193 |
193 int delta_x = location.x() - details.initial_location_in_parent.x(); | 194 int delta_x = location.x() - details.initial_location_in_parent.x(); |
194 int delta_y = location.y() - details.initial_location_in_parent.y(); | 195 int delta_y = location.y() - details.initial_location_in_parent.y(); |
195 | 196 |
196 // The minimize size constraint may limit how much we change the window | 197 // The minimize size constraint may limit how much we change the window |
197 // position. For example, dragging the left edge to the right should stop | 198 // position. For example, dragging the left edge to the right should stop |
198 // repositioning the window when the minimize size is reached. | 199 // repositioning the window when the minimize size is reached. |
199 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 200 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y, |
| 201 disable_snap_to_grid); |
200 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 202 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
201 | 203 |
202 gfx::Rect new_bounds(origin, size); | 204 gfx::Rect new_bounds(origin, size); |
203 // Update bottom edge to stay in the work area when we are resizing | 205 // Update bottom edge to stay in the work area when we are resizing |
204 // by dragging the bottome edge or corners. | 206 // by dragging the bottome edge or corners. |
205 if (details.window_component == HTBOTTOM || | 207 if (details.window_component == HTBOTTOM || |
206 details.window_component == HTBOTTOMRIGHT || | 208 details.window_component == HTBOTTOMRIGHT || |
207 details.window_component == HTBOTTOMLEFT) { | 209 details.window_component == HTBOTTOMLEFT) { |
208 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow( | 210 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
209 details.window); | 211 details.window); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 origin.Offset(delta_x, 0); | 252 origin.Offset(delta_x, 0); |
251 if (pos_change_direction & kBoundsChangeDirection_Vertical) | 253 if (pos_change_direction & kBoundsChangeDirection_Vertical) |
252 origin.Offset(0, delta_y); | 254 origin.Offset(0, delta_y); |
253 } | 255 } |
254 return origin; | 256 return origin; |
255 } | 257 } |
256 | 258 |
257 // static | 259 // static |
258 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, | 260 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, |
259 int* delta_x, | 261 int* delta_x, |
260 int* delta_y) { | 262 int* delta_y, |
| 263 bool disable_snap_to_grid) { |
261 gfx::Size size = details.initial_bounds.size(); | 264 gfx::Size size = details.initial_bounds.size(); |
262 if (details.bounds_change & kBoundsChange_Resizes) { | 265 if (details.bounds_change & kBoundsChange_Resizes) { |
263 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); | 266 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); |
264 min_size.set_width(AlignToGridRoundUp(min_size.width(), details.grid_size)); | 267 min_size.set_width( |
265 min_size.set_height(AlignToGridRoundUp(min_size.height(), | 268 AlignToGridRoundUp(min_size.width(), |
266 details.grid_size)); | 269 disable_snap_to_grid ? 0 : details.grid_size)); |
267 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), | 270 min_size.set_height( |
268 GetHeightForDrag(details, min_size.height(), delta_y)); | 271 AlignToGridRoundUp(min_size.height(), |
| 272 disable_snap_to_grid? 0 : details.grid_size)); |
| 273 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x, |
| 274 disable_snap_to_grid), |
| 275 GetHeightForDrag(details, min_size.height(), delta_y, |
| 276 disable_snap_to_grid)); |
269 } | 277 } |
270 return size; | 278 return size; |
271 } | 279 } |
272 | 280 |
273 // static | 281 // static |
274 int WindowResizer::GetWidthForDrag(const Details& details, | 282 int WindowResizer::GetWidthForDrag(const Details& details, |
275 int min_width, | 283 int min_width, |
276 int* delta_x) { | 284 int* delta_x, |
| 285 bool disable_snap_to_grid) { |
277 int width = details.initial_bounds.width(); | 286 int width = details.initial_bounds.width(); |
278 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | 287 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { |
279 // Along the right edge, positive delta_x increases the window size. | 288 // Along the right edge, positive delta_x increases the window size. |
280 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; | 289 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; |
281 width += x_multiplier * (*delta_x); | 290 width += x_multiplier * (*delta_x); |
282 int adjusted_width = AlignToGrid(width, details.grid_size); | 291 int adjusted_width = |
| 292 AlignToGrid(width, disable_snap_to_grid ? 0 : details.grid_size); |
283 if (adjusted_width != width) { | 293 if (adjusted_width != width) { |
284 *delta_x += -x_multiplier * (width - adjusted_width); | 294 *delta_x += -x_multiplier * (width - adjusted_width); |
285 width = adjusted_width; | 295 width = adjusted_width; |
286 } | 296 } |
287 | 297 |
288 // Ensure we don't shrink past the minimum width and clamp delta_x | 298 // Ensure we don't shrink past the minimum width and clamp delta_x |
289 // for the window origin computation. | 299 // for the window origin computation. |
290 if (width < min_width) { | 300 if (width < min_width) { |
291 width = min_width; | 301 width = min_width; |
292 *delta_x = -x_multiplier * (details.initial_bounds.width() - min_width); | 302 *delta_x = -x_multiplier * (details.initial_bounds.width() - min_width); |
293 } | 303 } |
294 | 304 |
295 // And don't let the window go bigger than the monitor. | 305 // And don't let the window go bigger than the monitor. |
296 int max_width = | 306 int max_width = |
297 gfx::Screen::GetMonitorAreaNearestWindow(details.window).width(); | 307 gfx::Screen::GetMonitorAreaNearestWindow(details.window).width(); |
298 if (width > max_width) { | 308 if (width > max_width) { |
299 width = max_width; | 309 width = max_width; |
300 *delta_x = -x_multiplier * (details.initial_bounds.width() - max_width); | 310 *delta_x = -x_multiplier * (details.initial_bounds.width() - max_width); |
301 } | 311 } |
302 } | 312 } |
303 return width; | 313 return width; |
304 } | 314 } |
305 | 315 |
306 // static | 316 // static |
307 int WindowResizer::GetHeightForDrag(const Details& details, | 317 int WindowResizer::GetHeightForDrag(const Details& details, |
308 int min_height, | 318 int min_height, |
309 int* delta_y) { | 319 int* delta_y, |
| 320 bool disable_snap_to_grid) { |
310 int height = details.initial_bounds.height(); | 321 int height = details.initial_bounds.height(); |
311 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { | 322 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { |
312 // Along the bottom edge, positive delta_y increases the window size. | 323 // Along the bottom edge, positive delta_y increases the window size. |
313 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; | 324 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; |
314 height += y_multiplier * (*delta_y); | 325 height += y_multiplier * (*delta_y); |
315 int adjusted_height = AlignToGrid(height, details.grid_size); | 326 int adjusted_height = |
| 327 AlignToGrid(height, disable_snap_to_grid ? 0 : details.grid_size); |
316 if (height != adjusted_height) { | 328 if (height != adjusted_height) { |
317 *delta_y += -y_multiplier * (height - adjusted_height); | 329 *delta_y += -y_multiplier * (height - adjusted_height); |
318 height = adjusted_height; | 330 height = adjusted_height; |
319 } | 331 } |
320 | 332 |
321 // Ensure we don't shrink past the minimum height and clamp delta_y | 333 // Ensure we don't shrink past the minimum height and clamp delta_y |
322 // for the window origin computation. | 334 // for the window origin computation. |
323 if (height < min_height) { | 335 if (height < min_height) { |
324 height = min_height; | 336 height = min_height; |
325 *delta_y = -y_multiplier * (details.initial_bounds.height() - min_height); | 337 *delta_y = -y_multiplier * (details.initial_bounds.height() - min_height); |
326 } | 338 } |
327 | 339 |
328 // And don't let the window go bigger than the monitor. | 340 // And don't let the window go bigger than the monitor. |
329 int max_height = | 341 int max_height = |
330 gfx::Screen::GetMonitorAreaNearestWindow(details.window).height(); | 342 gfx::Screen::GetMonitorAreaNearestWindow(details.window).height(); |
331 if (height > max_height) { | 343 if (height > max_height) { |
332 height = max_height; | 344 height = max_height; |
333 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); | 345 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); |
334 } | 346 } |
335 } | 347 } |
336 return height; | 348 return height; |
337 } | 349 } |
338 | 350 |
339 } // namespace aura | 351 } // namespace aura |
OLD | NEW |