| 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/screen_ash.h" | 7 #include "ash/screen_ash.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/wm/coordinate_conversion.h" | 10 #include "ash/wm/coordinate_conversion.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 const int WindowResizer::kBoundsChange_Resizes = 2; | 98 const int WindowResizer::kBoundsChange_Resizes = 2; |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 const int WindowResizer::kBoundsChangeDirection_None = 0; | 101 const int WindowResizer::kBoundsChangeDirection_None = 0; |
| 102 // static | 102 // static |
| 103 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; | 103 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; |
| 104 // static | 104 // static |
| 105 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; | 105 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; |
| 106 | 106 |
| 107 WindowResizer::Details::Details() | 107 WindowResizer::Details::Details() |
| 108 : window(NULL), | 108 : window_state(NULL), |
| 109 window_state(NULL), | |
| 110 window_component(HTNOWHERE), | 109 window_component(HTNOWHERE), |
| 111 bounds_change(0), | 110 bounds_change(0), |
| 112 position_change_direction(0), | 111 position_change_direction(0), |
| 113 size_change_direction(0), | 112 size_change_direction(0), |
| 114 is_resizable(false), | 113 is_resizable(false), |
| 115 source(aura::client::WINDOW_MOVE_SOURCE_MOUSE) { | 114 source(aura::client::WINDOW_MOVE_SOURCE_MOUSE) { |
| 116 } | 115 } |
| 117 | 116 |
| 118 WindowResizer::Details::Details(aura::Window* window, | 117 WindowResizer::Details::Details(aura::Window* window, |
| 119 const gfx::Point& location, | 118 const gfx::Point& location, |
| 120 int window_component, | 119 int window_component, |
| 121 aura::client::WindowMoveSource source) | 120 aura::client::WindowMoveSource source) |
| 122 : window(window), | 121 : window_state(wm::GetWindowState(window)), |
| 123 window_state(wm::GetWindowState(window)), | |
| 124 initial_bounds_in_parent(window->bounds()), | 122 initial_bounds_in_parent(window->bounds()), |
| 125 restore_bounds(gfx::Rect()), | 123 restore_bounds(gfx::Rect()), |
| 126 initial_location_in_parent(location), | 124 initial_location_in_parent(location), |
| 127 initial_opacity(window->layer()->opacity()), | 125 initial_opacity(window->layer()->opacity()), |
| 128 window_component(window_component), | 126 window_component(window_component), |
| 129 bounds_change(GetBoundsChangeForWindowComponent(window_component)), | 127 bounds_change(GetBoundsChangeForWindowComponent(window_component)), |
| 130 position_change_direction( | 128 position_change_direction( |
| 131 GetPositionChangeDirectionForWindowComponent(window_component)), | 129 GetPositionChangeDirectionForWindowComponent(window_component)), |
| 132 size_change_direction( | 130 size_change_direction( |
| 133 GetSizeChangeDirectionForWindowComponent(window_component)), | 131 GetSizeChangeDirectionForWindowComponent(window_component)), |
| 134 is_resizable(bounds_change != kBoundsChangeDirection_None), | 132 is_resizable(bounds_change != kBoundsChangeDirection_None), |
| 135 source(source) { | 133 source(source) { |
| 136 if (window_state->IsNormalShowState() && | 134 if (window_state->IsNormalShowState() && |
| 137 window_state->HasRestoreBounds() && | 135 window_state->HasRestoreBounds() && |
| 138 window_component == HTCAPTION) | 136 window_component == HTCAPTION) |
| 139 restore_bounds = window_state->GetRestoreBoundsInScreen(); | 137 restore_bounds = window_state->GetRestoreBoundsInScreen(); |
| 140 } | 138 } |
| 141 | 139 |
| 142 WindowResizer::Details::~Details() { | 140 WindowResizer::Details::~Details() { |
| 143 } | 141 } |
| 144 | 142 |
| 143 aura::Window* WindowResizer::Details::window() const { |
| 144 return window_state ? window_state->window() : NULL; |
| 145 } |
| 146 |
| 145 WindowResizer::WindowResizer() { | 147 WindowResizer::WindowResizer() { |
| 146 } | 148 } |
| 147 | 149 |
| 148 WindowResizer::~WindowResizer() { | 150 WindowResizer::~WindowResizer() { |
| 149 } | 151 } |
| 150 | 152 |
| 151 // static | 153 // static |
| 152 int WindowResizer::GetBoundsChangeForWindowComponent(int component) { | 154 int WindowResizer::GetBoundsChangeForWindowComponent(int component) { |
| 153 int bounds_change = WindowResizer::kBoundsChange_None; | 155 int bounds_change = WindowResizer::kBoundsChange_None; |
| 154 switch (component) { | 156 switch (component) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // position. For example, dragging the left edge to the right should stop | 194 // position. For example, dragging the left edge to the right should stop |
| 193 // repositioning the window when the minimize size is reached. | 195 // repositioning the window when the minimize size is reached. |
| 194 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 196 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); |
| 195 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 197 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
| 196 gfx::Rect new_bounds(origin, size); | 198 gfx::Rect new_bounds(origin, size); |
| 197 | 199 |
| 198 // Sizing has to keep the result on the screen. Note that this correction | 200 // Sizing has to keep the result on the screen. Note that this correction |
| 199 // has to come first since it might have an impact on the origin as well as | 201 // has to come first since it might have an impact on the origin as well as |
| 200 // on the size. | 202 // on the size. |
| 201 if (details.bounds_change & kBoundsChange_Resizes) { | 203 if (details.bounds_change & kBoundsChange_Resizes) { |
| 202 gfx::Rect work_area = | 204 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( |
| 203 Shell::GetScreen()->GetDisplayNearestWindow(details.window).work_area(); | 205 details.window()).work_area(); |
| 204 aura::Window* dock_container = Shell::GetContainer( | 206 aura::Window* dock_container = Shell::GetContainer( |
| 205 details.window->GetRootWindow(), | 207 details.window()->GetRootWindow(), |
| 206 internal::kShellWindowId_DockedContainer); | 208 internal::kShellWindowId_DockedContainer); |
| 207 internal::DockedWindowLayoutManager* dock_layout = | 209 internal::DockedWindowLayoutManager* dock_layout = |
| 208 static_cast<internal::DockedWindowLayoutManager*>( | 210 static_cast<internal::DockedWindowLayoutManager*>( |
| 209 dock_container->layout_manager()); | 211 dock_container->layout_manager()); |
| 210 | 212 |
| 211 work_area.Union(dock_layout->docked_bounds()); | 213 work_area.Union(dock_layout->docked_bounds()); |
| 212 work_area = ScreenAsh::ConvertRectFromScreen(details.window->parent(), | 214 work_area = ScreenAsh::ConvertRectFromScreen(details.window()->parent(), |
| 213 work_area); | 215 work_area); |
| 214 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | 216 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { |
| 215 if (IsRightEdge(details.window_component) && | 217 if (IsRightEdge(details.window_component) && |
| 216 new_bounds.right() < work_area.x() + kMinimumOnScreenArea) { | 218 new_bounds.right() < work_area.x() + kMinimumOnScreenArea) { |
| 217 int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right(); | 219 int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right(); |
| 218 new_bounds.set_width(new_bounds.width() + delta); | 220 new_bounds.set_width(new_bounds.width() + delta); |
| 219 } else if (new_bounds.x() > work_area.right() - kMinimumOnScreenArea) { | 221 } else if (new_bounds.x() > work_area.right() - kMinimumOnScreenArea) { |
| 220 int width = new_bounds.right() - work_area.right() + | 222 int width = new_bounds.right() - work_area.right() + |
| 221 kMinimumOnScreenArea; | 223 kMinimumOnScreenArea; |
| 222 new_bounds.set_x(work_area.right() - kMinimumOnScreenArea); | 224 new_bounds.set_x(work_area.right() - kMinimumOnScreenArea); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // However - it is not desirable to change the origin if the window would | 257 // However - it is not desirable to change the origin if the window would |
| 256 // be still hit by the cursor. | 258 // be still hit by the cursor. |
| 257 if (details.initial_location_in_parent.x() > | 259 if (details.initial_location_in_parent.x() > |
| 258 details.initial_bounds_in_parent.x() + details.restore_bounds.width()) | 260 details.initial_bounds_in_parent.x() + details.restore_bounds.width()) |
| 259 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); | 261 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); |
| 260 } | 262 } |
| 261 | 263 |
| 262 // Make sure that |new_bounds| doesn't leave any of the displays. Note that | 264 // Make sure that |new_bounds| doesn't leave any of the displays. Note that |
| 263 // the |work_area| above isn't good for this check since it is the work area | 265 // the |work_area| above isn't good for this check since it is the work area |
| 264 // for the current display but the window can move to a different one. | 266 // for the current display but the window can move to a different one. |
| 265 aura::Window* parent = details.window->parent(); | 267 aura::Window* parent = details.window()->parent(); |
| 266 gfx::Point passed_location_in_screen(passed_location); | 268 gfx::Point passed_location_in_screen(passed_location); |
| 267 wm::ConvertPointToScreen(parent, &passed_location_in_screen); | 269 wm::ConvertPointToScreen(parent, &passed_location_in_screen); |
| 268 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); | 270 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); |
| 269 // Use a pointer location (matching the logic in DragWindowResizer) to | 271 // Use a pointer location (matching the logic in DragWindowResizer) to |
| 270 // calculate the target display after the drag. | 272 // calculate the target display after the drag. |
| 271 const gfx::Display& display = | 273 const gfx::Display& display = |
| 272 Shell::GetScreen()->GetDisplayMatching(near_passed_location); | 274 Shell::GetScreen()->GetDisplayMatching(near_passed_location); |
| 273 aura::Window* dock_container = Shell::GetContainer( | 275 aura::Window* dock_container = Shell::GetContainer( |
| 274 wm::GetRootWindowMatching(near_passed_location), | 276 wm::GetRootWindowMatching(near_passed_location), |
| 275 internal::kShellWindowId_DockedContainer); | 277 internal::kShellWindowId_DockedContainer); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 349 } |
| 348 return origin; | 350 return origin; |
| 349 } | 351 } |
| 350 | 352 |
| 351 // static | 353 // static |
| 352 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, | 354 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, |
| 353 int* delta_x, | 355 int* delta_x, |
| 354 int* delta_y) { | 356 int* delta_y) { |
| 355 gfx::Size size = details.initial_bounds_in_parent.size(); | 357 gfx::Size size = details.initial_bounds_in_parent.size(); |
| 356 if (details.bounds_change & kBoundsChange_Resizes) { | 358 if (details.bounds_change & kBoundsChange_Resizes) { |
| 357 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); | 359 gfx::Size min_size = details.window()->delegate()->GetMinimumSize(); |
| 358 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), | 360 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), |
| 359 GetHeightForDrag(details, min_size.height(), delta_y)); | 361 GetHeightForDrag(details, min_size.height(), delta_y)); |
| 360 } else if (!details.restore_bounds.IsEmpty()) { | 362 } else if (!details.restore_bounds.IsEmpty()) { |
| 361 size = details.restore_bounds.size(); | 363 size = details.restore_bounds.size(); |
| 362 } | 364 } |
| 363 return size; | 365 return size; |
| 364 } | 366 } |
| 365 | 367 |
| 366 // static | 368 // static |
| 367 int WindowResizer::GetWidthForDrag(const Details& details, | 369 int WindowResizer::GetWidthForDrag(const Details& details, |
| 368 int min_width, | 370 int min_width, |
| 369 int* delta_x) { | 371 int* delta_x) { |
| 370 int width = details.initial_bounds_in_parent.width(); | 372 int width = details.initial_bounds_in_parent.width(); |
| 371 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | 373 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { |
| 372 // Along the right edge, positive delta_x increases the window size. | 374 // Along the right edge, positive delta_x increases the window size. |
| 373 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; | 375 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; |
| 374 width += x_multiplier * (*delta_x); | 376 width += x_multiplier * (*delta_x); |
| 375 | 377 |
| 376 // Ensure we don't shrink past the minimum width and clamp delta_x | 378 // Ensure we don't shrink past the minimum width and clamp delta_x |
| 377 // for the window origin computation. | 379 // for the window origin computation. |
| 378 if (width < min_width) { | 380 if (width < min_width) { |
| 379 width = min_width; | 381 width = min_width; |
| 380 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - | 382 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - |
| 381 min_width); | 383 min_width); |
| 382 } | 384 } |
| 383 | 385 |
| 384 // And don't let the window go bigger than the display. | 386 // And don't let the window go bigger than the display. |
| 385 int max_width = Shell::GetScreen()->GetDisplayNearestWindow( | 387 int max_width = Shell::GetScreen()->GetDisplayNearestWindow( |
| 386 details.window).bounds().width(); | 388 details.window()).bounds().width(); |
| 387 gfx::Size max_size = details.window->delegate()->GetMaximumSize(); | 389 gfx::Size max_size = details.window()->delegate()->GetMaximumSize(); |
| 388 if (max_size.width() != 0) | 390 if (max_size.width() != 0) |
| 389 max_width = std::min(max_width, max_size.width()); | 391 max_width = std::min(max_width, max_size.width()); |
| 390 if (width > max_width) { | 392 if (width > max_width) { |
| 391 width = max_width; | 393 width = max_width; |
| 392 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - | 394 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - |
| 393 max_width); | 395 max_width); |
| 394 } | 396 } |
| 395 } | 397 } |
| 396 return width; | 398 return width; |
| 397 } | 399 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 409 // Ensure we don't shrink past the minimum height and clamp delta_y | 411 // Ensure we don't shrink past the minimum height and clamp delta_y |
| 410 // for the window origin computation. | 412 // for the window origin computation. |
| 411 if (height < min_height) { | 413 if (height < min_height) { |
| 412 height = min_height; | 414 height = min_height; |
| 413 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - | 415 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - |
| 414 min_height); | 416 min_height); |
| 415 } | 417 } |
| 416 | 418 |
| 417 // And don't let the window go bigger than the display. | 419 // And don't let the window go bigger than the display. |
| 418 int max_height = Shell::GetScreen()->GetDisplayNearestWindow( | 420 int max_height = Shell::GetScreen()->GetDisplayNearestWindow( |
| 419 details.window).bounds().height(); | 421 details.window()).bounds().height(); |
| 420 gfx::Size max_size = details.window->delegate()->GetMaximumSize(); | 422 gfx::Size max_size = details.window()->delegate()->GetMaximumSize(); |
| 421 if (max_size.height() != 0) | 423 if (max_size.height() != 0) |
| 422 max_height = std::min(max_height, max_size.height()); | 424 max_height = std::min(max_height, max_size.height()); |
| 423 if (height > max_height) { | 425 if (height > max_height) { |
| 424 height = max_height; | 426 height = max_height; |
| 425 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - | 427 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - |
| 426 max_height); | 428 max_height); |
| 427 } | 429 } |
| 428 } | 430 } |
| 429 return height; | 431 return height; |
| 430 } | 432 } |
| 431 | 433 |
| 432 } // namespace aura | 434 } // namespace aura |
| OLD | NEW |