| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; | 97 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; |
| 98 // static | 98 // static |
| 99 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; | 99 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; |
| 100 | 100 |
| 101 WindowResizer::Details::Details() | 101 WindowResizer::Details::Details() |
| 102 : window(NULL), | 102 : window(NULL), |
| 103 window_component(HTNOWHERE), | 103 window_component(HTNOWHERE), |
| 104 bounds_change(0), | 104 bounds_change(0), |
| 105 position_change_direction(0), | 105 position_change_direction(0), |
| 106 size_change_direction(0), | 106 size_change_direction(0), |
| 107 is_resizable(false), | 107 is_resizable(false) { |
| 108 grid_size(0) { | |
| 109 } | 108 } |
| 110 | 109 |
| 111 WindowResizer::Details::Details(aura::Window* window, | 110 WindowResizer::Details::Details(aura::Window* window, |
| 112 const gfx::Point& location, | 111 const gfx::Point& location, |
| 113 int window_component, | 112 int window_component) |
| 114 int grid_size) | |
| 115 : window(window), | 113 : window(window), |
| 116 initial_bounds(window->bounds()), | 114 initial_bounds(window->bounds()), |
| 117 initial_location_in_parent(location), | 115 initial_location_in_parent(location), |
| 118 window_component(window_component), | 116 window_component(window_component), |
| 119 bounds_change(GetBoundsChangeForWindowComponent(window_component)), | 117 bounds_change(GetBoundsChangeForWindowComponent(window_component)), |
| 120 position_change_direction( | 118 position_change_direction( |
| 121 GetPositionChangeDirectionForWindowComponent(window_component)), | 119 GetPositionChangeDirectionForWindowComponent(window_component)), |
| 122 size_change_direction( | 120 size_change_direction( |
| 123 GetSizeChangeDirectionForWindowComponent(window_component)), | 121 GetSizeChangeDirectionForWindowComponent(window_component)), |
| 124 is_resizable(bounds_change != kBoundsChangeDirection_None), | 122 is_resizable(bounds_change != kBoundsChangeDirection_None) { |
| 125 grid_size(grid_size) { | |
| 126 } | 123 } |
| 127 | 124 |
| 128 WindowResizer::Details::~Details() { | 125 WindowResizer::Details::~Details() { |
| 129 } | 126 } |
| 130 | 127 |
| 131 WindowResizer::WindowResizer() { | 128 WindowResizer::WindowResizer() { |
| 132 } | 129 } |
| 133 | 130 |
| 134 WindowResizer::~WindowResizer() { | 131 WindowResizer::~WindowResizer() { |
| 135 } | 132 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // static | 176 // static |
| 180 int WindowResizer::AlignToGridRoundDown(int location, int grid_size) { | 177 int WindowResizer::AlignToGridRoundDown(int location, int grid_size) { |
| 181 if (grid_size <= 1 || location % grid_size == 0) | 178 if (grid_size <= 1 || location % grid_size == 0) |
| 182 return location; | 179 return location; |
| 183 return location / grid_size * grid_size; | 180 return location / grid_size * grid_size; |
| 184 } | 181 } |
| 185 | 182 |
| 186 // static | 183 // static |
| 187 gfx::Rect WindowResizer::CalculateBoundsForDrag( | 184 gfx::Rect WindowResizer::CalculateBoundsForDrag( |
| 188 const Details& details, | 185 const Details& details, |
| 189 const gfx::Point& location) { | 186 const gfx::Point& location, |
| 187 int grid_size) { |
| 190 if (!details.is_resizable) | 188 if (!details.is_resizable) |
| 191 return details.initial_bounds; | 189 return details.initial_bounds; |
| 192 | 190 |
| 193 int delta_x = location.x() - details.initial_location_in_parent.x(); | 191 int delta_x = location.x() - details.initial_location_in_parent.x(); |
| 194 int delta_y = location.y() - details.initial_location_in_parent.y(); | 192 int delta_y = location.y() - details.initial_location_in_parent.y(); |
| 195 | 193 |
| 196 // The minimize size constraint may limit how much we change the window | 194 // 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 | 195 // position. For example, dragging the left edge to the right should stop |
| 198 // repositioning the window when the minimize size is reached. | 196 // repositioning the window when the minimize size is reached. |
| 199 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 197 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y, grid_size); |
| 200 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 198 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
| 201 | 199 |
| 202 gfx::Rect new_bounds(origin, size); | 200 gfx::Rect new_bounds(origin, size); |
| 203 // Update bottom edge to stay in the work area when we are resizing | 201 // Update bottom edge to stay in the work area when we are resizing |
| 204 // by dragging the bottome edge or corners. | 202 // by dragging the bottome edge or corners. |
| 205 if (details.window_component == HTBOTTOM || | 203 if (details.window_component == HTBOTTOM || |
| 206 details.window_component == HTBOTTOMRIGHT || | 204 details.window_component == HTBOTTOMRIGHT || |
| 207 details.window_component == HTBOTTOMLEFT) { | 205 details.window_component == HTBOTTOMLEFT) { |
| 208 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow( | 206 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
| 209 details.window); | 207 details.window); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 origin.Offset(delta_x, 0); | 248 origin.Offset(delta_x, 0); |
| 251 if (pos_change_direction & kBoundsChangeDirection_Vertical) | 249 if (pos_change_direction & kBoundsChangeDirection_Vertical) |
| 252 origin.Offset(0, delta_y); | 250 origin.Offset(0, delta_y); |
| 253 } | 251 } |
| 254 return origin; | 252 return origin; |
| 255 } | 253 } |
| 256 | 254 |
| 257 // static | 255 // static |
| 258 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, | 256 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, |
| 259 int* delta_x, | 257 int* delta_x, |
| 260 int* delta_y) { | 258 int* delta_y, |
| 259 int grid_size) { |
| 261 gfx::Size size = details.initial_bounds.size(); | 260 gfx::Size size = details.initial_bounds.size(); |
| 262 if (details.bounds_change & kBoundsChange_Resizes) { | 261 if (details.bounds_change & kBoundsChange_Resizes) { |
| 263 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); | 262 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); |
| 264 min_size.set_width(AlignToGridRoundUp(min_size.width(), details.grid_size)); | 263 min_size.set_width(AlignToGridRoundUp(min_size.width(), grid_size)); |
| 265 min_size.set_height(AlignToGridRoundUp(min_size.height(), | 264 min_size.set_height(AlignToGridRoundUp(min_size.height(), grid_size)); |
| 266 details.grid_size)); | 265 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x, |
| 267 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), | 266 grid_size), |
| 268 GetHeightForDrag(details, min_size.height(), delta_y)); | 267 GetHeightForDrag(details, min_size.height(), delta_y, |
| 268 grid_size)); |
| 269 } | 269 } |
| 270 return size; | 270 return size; |
| 271 } | 271 } |
| 272 | 272 |
| 273 // static | 273 // static |
| 274 int WindowResizer::GetWidthForDrag(const Details& details, | 274 int WindowResizer::GetWidthForDrag(const Details& details, |
| 275 int min_width, | 275 int min_width, |
| 276 int* delta_x) { | 276 int* delta_x, |
| 277 int grid_size) { |
| 277 int width = details.initial_bounds.width(); | 278 int width = details.initial_bounds.width(); |
| 278 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | 279 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { |
| 279 // Along the right edge, positive delta_x increases the window size. | 280 // Along the right edge, positive delta_x increases the window size. |
| 280 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; | 281 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; |
| 281 width += x_multiplier * (*delta_x); | 282 width += x_multiplier * (*delta_x); |
| 282 int adjusted_width = AlignToGrid(width, details.grid_size); | 283 int adjusted_width = AlignToGrid(width, grid_size); |
| 283 if (adjusted_width != width) { | 284 if (adjusted_width != width) { |
| 284 *delta_x += -x_multiplier * (width - adjusted_width); | 285 *delta_x += -x_multiplier * (width - adjusted_width); |
| 285 width = adjusted_width; | 286 width = adjusted_width; |
| 286 } | 287 } |
| 287 | 288 |
| 288 // Ensure we don't shrink past the minimum width and clamp delta_x | 289 // Ensure we don't shrink past the minimum width and clamp delta_x |
| 289 // for the window origin computation. | 290 // for the window origin computation. |
| 290 if (width < min_width) { | 291 if (width < min_width) { |
| 291 width = min_width; | 292 width = min_width; |
| 292 *delta_x = -x_multiplier * (details.initial_bounds.width() - min_width); | 293 *delta_x = -x_multiplier * (details.initial_bounds.width() - min_width); |
| 293 } | 294 } |
| 294 | 295 |
| 295 // And don't let the window go bigger than the monitor. | 296 // And don't let the window go bigger than the monitor. |
| 296 int max_width = | 297 int max_width = |
| 297 gfx::Screen::GetMonitorAreaNearestWindow(details.window).width(); | 298 gfx::Screen::GetMonitorAreaNearestWindow(details.window).width(); |
| 298 if (width > max_width) { | 299 if (width > max_width) { |
| 299 width = max_width; | 300 width = max_width; |
| 300 *delta_x = -x_multiplier * (details.initial_bounds.width() - max_width); | 301 *delta_x = -x_multiplier * (details.initial_bounds.width() - max_width); |
| 301 } | 302 } |
| 302 } | 303 } |
| 303 return width; | 304 return width; |
| 304 } | 305 } |
| 305 | 306 |
| 306 // static | 307 // static |
| 307 int WindowResizer::GetHeightForDrag(const Details& details, | 308 int WindowResizer::GetHeightForDrag(const Details& details, |
| 308 int min_height, | 309 int min_height, |
| 309 int* delta_y) { | 310 int* delta_y, |
| 311 int grid_size) { |
| 310 int height = details.initial_bounds.height(); | 312 int height = details.initial_bounds.height(); |
| 311 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { | 313 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { |
| 312 // Along the bottom edge, positive delta_y increases the window size. | 314 // Along the bottom edge, positive delta_y increases the window size. |
| 313 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; | 315 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; |
| 314 height += y_multiplier * (*delta_y); | 316 height += y_multiplier * (*delta_y); |
| 315 int adjusted_height = AlignToGrid(height, details.grid_size); | 317 int adjusted_height = AlignToGrid(height, grid_size); |
| 316 if (height != adjusted_height) { | 318 if (height != adjusted_height) { |
| 317 *delta_y += -y_multiplier * (height - adjusted_height); | 319 *delta_y += -y_multiplier * (height - adjusted_height); |
| 318 height = adjusted_height; | 320 height = adjusted_height; |
| 319 } | 321 } |
| 320 | 322 |
| 321 // Ensure we don't shrink past the minimum height and clamp delta_y | 323 // Ensure we don't shrink past the minimum height and clamp delta_y |
| 322 // for the window origin computation. | 324 // for the window origin computation. |
| 323 if (height < min_height) { | 325 if (height < min_height) { |
| 324 height = min_height; | 326 height = min_height; |
| 325 *delta_y = -y_multiplier * (details.initial_bounds.height() - min_height); | 327 *delta_y = -y_multiplier * (details.initial_bounds.height() - min_height); |
| 326 } | 328 } |
| 327 | 329 |
| 328 // And don't let the window go bigger than the monitor. | 330 // And don't let the window go bigger than the monitor. |
| 329 int max_height = | 331 int max_height = |
| 330 gfx::Screen::GetMonitorAreaNearestWindow(details.window).height(); | 332 gfx::Screen::GetMonitorAreaNearestWindow(details.window).height(); |
| 331 if (height > max_height) { | 333 if (height > max_height) { |
| 332 height = max_height; | 334 height = max_height; |
| 333 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); | 335 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); |
| 334 } | 336 } |
| 335 } | 337 } |
| 336 return height; | 338 return height; |
| 337 } | 339 } |
| 338 | 340 |
| 339 } // namespace aura | 341 } // namespace aura |
| OLD | NEW |