| 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_util.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "ash/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
| 8 #include "ash/wm/common/root_window_finder.h" |
| 10 #include "ash/wm/common/window_positioning_utils.h" | 9 #include "ash/wm/common/window_positioning_utils.h" |
| 11 #include "ash/wm/coordinate_conversion.h" | |
| 12 #include "ash/wm/dock/docked_window_layout_manager.h" | 10 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 13 #include "ash/wm/window_state.h" | 11 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_util.h" | |
| 15 #include "ui/aura/client/aura_constants.h" | |
| 16 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_delegate.h" | |
| 18 #include "ui/aura/window_event_dispatcher.h" | |
| 19 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 20 #include "ui/base/ui_base_types.h" | 14 #include "ui/base/ui_base_types.h" |
| 21 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 22 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 16 #include "ui/gfx/geometry/rect.h" |
| 23 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 24 #include "ui/wm/core/coordinate_conversion.h" | |
| 25 | 18 |
| 26 namespace ash { | 19 namespace ash { |
| 27 | 20 |
| 28 namespace { | 21 namespace { |
| 29 | 22 |
| 30 // Returns true for resize components along the right edge, where a drag in | 23 // Returns true for resize components along the right edge, where a drag in |
| 31 // positive x will make the window larger. | 24 // positive x will make the window larger. |
| 32 bool IsRightEdge(int window_component) { | 25 bool IsRightEdge(int window_component) { |
| 33 return window_component == HTTOPRIGHT || | 26 return window_component == HTTOPRIGHT || |
| 34 window_component == HTRIGHT || | 27 window_component == HTRIGHT || |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // position. For example, dragging the left edge to the right should stop | 124 // position. For example, dragging the left edge to the right should stop |
| 132 // repositioning the window when the minimize size is reached. | 125 // repositioning the window when the minimize size is reached. |
| 133 gfx::Size size = GetSizeForDrag(&delta_x, &delta_y); | 126 gfx::Size size = GetSizeForDrag(&delta_x, &delta_y); |
| 134 gfx::Point origin = GetOriginForDrag(delta_x, delta_y); | 127 gfx::Point origin = GetOriginForDrag(delta_x, delta_y); |
| 135 gfx::Rect new_bounds(origin, size); | 128 gfx::Rect new_bounds(origin, size); |
| 136 | 129 |
| 137 // Sizing has to keep the result on the screen. Note that this correction | 130 // Sizing has to keep the result on the screen. Note that this correction |
| 138 // has to come first since it might have an impact on the origin as well as | 131 // has to come first since it might have an impact on the origin as well as |
| 139 // on the size. | 132 // on the size. |
| 140 if (details().bounds_change & kBoundsChange_Resizes) { | 133 if (details().bounds_change & kBoundsChange_Resizes) { |
| 141 gfx::Rect work_area = gfx::Screen::GetScreen() | 134 gfx::Rect work_area = GetTarget()->GetDisplayNearestWindow().work_area(); |
| 142 ->GetDisplayNearestWindow(GetTarget()) | 135 wm::WmWindow* dock_container = |
| 143 .work_area(); | 136 GetTarget()->GetRootWindow()->GetChildByShellWindowId( |
| 144 aura::Window* dock_container = Shell::GetContainer( | 137 kShellWindowId_DockedContainer); |
| 145 GetTarget()->GetRootWindow(), kShellWindowId_DockedContainer); | |
| 146 DockedWindowLayoutManager* dock_layout = | 138 DockedWindowLayoutManager* dock_layout = |
| 147 static_cast<DockedWindowLayoutManager*>( | 139 static_cast<DockedWindowLayoutManager*>( |
| 148 dock_container->layout_manager()); | 140 wm::WmWindowAura::GetAuraWindow(dock_container)->layout_manager()); |
| 149 | 141 |
| 150 work_area.Union(dock_layout->docked_bounds()); | 142 work_area.Union(dock_layout->docked_bounds()); |
| 151 work_area = ScreenUtil::ConvertRectFromScreen(GetTarget()->parent(), | 143 work_area = GetTarget()->GetParent()->ConvertRectFromScreen(work_area); |
| 152 work_area); | |
| 153 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { | 144 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { |
| 154 if (IsRightEdge(details().window_component) && | 145 if (IsRightEdge(details().window_component) && |
| 155 new_bounds.right() < work_area.x() + wm::kMinimumOnScreenArea) { | 146 new_bounds.right() < work_area.x() + wm::kMinimumOnScreenArea) { |
| 156 int delta = | 147 int delta = |
| 157 work_area.x() + wm::kMinimumOnScreenArea - new_bounds.right(); | 148 work_area.x() + wm::kMinimumOnScreenArea - new_bounds.right(); |
| 158 new_bounds.set_width(new_bounds.width() + delta); | 149 new_bounds.set_width(new_bounds.width() + delta); |
| 159 } else if (new_bounds.x() > | 150 } else if (new_bounds.x() > |
| 160 work_area.right() - wm::kMinimumOnScreenArea) { | 151 work_area.right() - wm::kMinimumOnScreenArea) { |
| 161 int width = | 152 int width = |
| 162 new_bounds.right() - work_area.right() + wm::kMinimumOnScreenArea; | 153 new_bounds.right() - work_area.right() + wm::kMinimumOnScreenArea; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // be still hit by the cursor. | 188 // be still hit by the cursor. |
| 198 if (details().initial_location_in_parent.x() > | 189 if (details().initial_location_in_parent.x() > |
| 199 details().initial_bounds_in_parent.x() + | 190 details().initial_bounds_in_parent.x() + |
| 200 details().restore_bounds.width()) | 191 details().restore_bounds.width()) |
| 201 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2); | 192 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2); |
| 202 } | 193 } |
| 203 | 194 |
| 204 // Make sure that |new_bounds| doesn't leave any of the displays. Note that | 195 // Make sure that |new_bounds| doesn't leave any of the displays. Note that |
| 205 // the |work_area| above isn't good for this check since it is the work area | 196 // the |work_area| above isn't good for this check since it is the work area |
| 206 // for the current display but the window can move to a different one. | 197 // for the current display but the window can move to a different one. |
| 207 aura::Window* parent = GetTarget()->parent(); | 198 wm::WmWindow* parent = GetTarget()->GetParent(); |
| 208 gfx::Point passed_location_in_screen(passed_location); | 199 gfx::Point passed_location_in_screen( |
| 209 ::wm::ConvertPointToScreen(parent, &passed_location_in_screen); | 200 parent->ConvertPointToScreen(passed_location)); |
| 210 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); | 201 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); |
| 211 // Use a pointer location (matching the logic in DragWindowResizer) to | 202 // Use a pointer location (matching the logic in DragWindowResizer) to |
| 212 // calculate the target display after the drag. | 203 // calculate the target display after the drag. |
| 213 const gfx::Display& display = | 204 const gfx::Display& display = |
| 214 gfx::Screen::GetScreen()->GetDisplayMatching(near_passed_location); | 205 gfx::Screen::GetScreen()->GetDisplayMatching(near_passed_location); |
| 215 aura::Window* dock_container = | 206 wm::WmWindow* dock_container = |
| 216 Shell::GetContainer(wm::GetRootWindowMatching(near_passed_location), | 207 wm::GetRootWindowMatching(near_passed_location) |
| 217 kShellWindowId_DockedContainer); | 208 ->GetChildByShellWindowId(kShellWindowId_DockedContainer); |
| 218 DockedWindowLayoutManager* dock_layout = | 209 DockedWindowLayoutManager* dock_layout = |
| 219 static_cast<DockedWindowLayoutManager*>( | 210 static_cast<DockedWindowLayoutManager*>( |
| 220 dock_container->layout_manager()); | 211 wm::WmWindowAura::GetAuraWindow(dock_container)->layout_manager()); |
| 221 | 212 |
| 222 gfx::Rect screen_work_area = display.work_area(); | 213 gfx::Rect screen_work_area = display.work_area(); |
| 223 screen_work_area.Union(dock_layout->docked_bounds()); | 214 screen_work_area.Union(dock_layout->docked_bounds()); |
| 224 screen_work_area.Inset(wm::kMinimumOnScreenArea, 0); | 215 screen_work_area.Inset(wm::kMinimumOnScreenArea, 0); |
| 225 gfx::Rect new_bounds_in_screen = | 216 gfx::Rect new_bounds_in_screen = parent->ConvertRectToScreen(new_bounds); |
| 226 ScreenUtil::ConvertRectToScreen(parent, new_bounds); | |
| 227 if (!screen_work_area.Intersects(new_bounds_in_screen)) { | 217 if (!screen_work_area.Intersects(new_bounds_in_screen)) { |
| 228 // Make sure that the x origin does not leave the current display. | 218 // Make sure that the x origin does not leave the current display. |
| 229 new_bounds_in_screen.set_x( | 219 new_bounds_in_screen.set_x( |
| 230 std::max(screen_work_area.x() - new_bounds.width(), | 220 std::max(screen_work_area.x() - new_bounds.width(), |
| 231 std::min(screen_work_area.right(), | 221 std::min(screen_work_area.right(), |
| 232 new_bounds_in_screen.x()))); | 222 new_bounds_in_screen.x()))); |
| 233 new_bounds = | 223 new_bounds = parent->ConvertRectFromScreen(new_bounds_in_screen); |
| 234 ScreenUtil::ConvertRectFromScreen(parent, new_bounds_in_screen); | |
| 235 } | 224 } |
| 236 } | 225 } |
| 237 | 226 |
| 238 return new_bounds; | 227 return new_bounds; |
| 239 } | 228 } |
| 240 | 229 |
| 241 // static | 230 // static |
| 242 bool WindowResizer::IsBottomEdge(int window_component) { | 231 bool WindowResizer::IsBottomEdge(int window_component) { |
| 243 return window_component == HTBOTTOMLEFT || | 232 return window_component == HTBOTTOMLEFT || |
| 244 window_component == HTBOTTOM || | 233 window_component == HTBOTTOM || |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 origin.Offset(delta_x, 0); | 269 origin.Offset(delta_x, 0); |
| 281 if (pos_change_direction & kBoundsChangeDirection_Vertical) | 270 if (pos_change_direction & kBoundsChangeDirection_Vertical) |
| 282 origin.Offset(0, delta_y); | 271 origin.Offset(0, delta_y); |
| 283 } | 272 } |
| 284 return origin; | 273 return origin; |
| 285 } | 274 } |
| 286 | 275 |
| 287 gfx::Size WindowResizer::GetSizeForDrag(int* delta_x, int* delta_y) { | 276 gfx::Size WindowResizer::GetSizeForDrag(int* delta_x, int* delta_y) { |
| 288 gfx::Size size = details().initial_bounds_in_parent.size(); | 277 gfx::Size size = details().initial_bounds_in_parent.size(); |
| 289 if (details().bounds_change & kBoundsChange_Resizes) { | 278 if (details().bounds_change & kBoundsChange_Resizes) { |
| 290 gfx::Size min_size = GetTarget()->delegate()->GetMinimumSize(); | 279 gfx::Size min_size = GetTarget()->GetMinimumSize(); |
| 291 size.SetSize(GetWidthForDrag(min_size.width(), delta_x), | 280 size.SetSize(GetWidthForDrag(min_size.width(), delta_x), |
| 292 GetHeightForDrag(min_size.height(), delta_y)); | 281 GetHeightForDrag(min_size.height(), delta_y)); |
| 293 } else if (!details().restore_bounds.IsEmpty()) { | 282 } else if (!details().restore_bounds.IsEmpty()) { |
| 294 size = details().restore_bounds.size(); | 283 size = details().restore_bounds.size(); |
| 295 } | 284 } |
| 296 return size; | 285 return size; |
| 297 } | 286 } |
| 298 | 287 |
| 299 int WindowResizer::GetWidthForDrag(int min_width, int* delta_x) { | 288 int WindowResizer::GetWidthForDrag(int min_width, int* delta_x) { |
| 300 int width = details().initial_bounds_in_parent.width(); | 289 int width = details().initial_bounds_in_parent.width(); |
| 301 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { | 290 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { |
| 302 // Along the right edge, positive delta_x increases the window size. | 291 // Along the right edge, positive delta_x increases the window size. |
| 303 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1; | 292 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1; |
| 304 width += x_multiplier * (*delta_x); | 293 width += x_multiplier * (*delta_x); |
| 305 | 294 |
| 306 // Ensure we don't shrink past the minimum width and clamp delta_x | 295 // Ensure we don't shrink past the minimum width and clamp delta_x |
| 307 // for the window origin computation. | 296 // for the window origin computation. |
| 308 if (width < min_width) { | 297 if (width < min_width) { |
| 309 width = min_width; | 298 width = min_width; |
| 310 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - | 299 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - |
| 311 min_width); | 300 min_width); |
| 312 } | 301 } |
| 313 | 302 |
| 314 // And don't let the window go bigger than the display. | 303 // And don't let the window go bigger than the display. |
| 315 int max_width = gfx::Screen::GetScreen() | 304 int max_width = GetTarget()->GetDisplayNearestWindow().bounds().width(); |
| 316 ->GetDisplayNearestWindow(GetTarget()) | 305 gfx::Size max_size = GetTarget()->GetMaximumSize(); |
| 317 .bounds() | |
| 318 .width(); | |
| 319 gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize(); | |
| 320 if (max_size.width() != 0) | 306 if (max_size.width() != 0) |
| 321 max_width = std::min(max_width, max_size.width()); | 307 max_width = std::min(max_width, max_size.width()); |
| 322 if (width > max_width) { | 308 if (width > max_width) { |
| 323 width = max_width; | 309 width = max_width; |
| 324 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - | 310 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - |
| 325 max_width); | 311 max_width); |
| 326 } | 312 } |
| 327 } | 313 } |
| 328 return width; | 314 return width; |
| 329 } | 315 } |
| 330 | 316 |
| 331 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) { | 317 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) { |
| 332 int height = details().initial_bounds_in_parent.height(); | 318 int height = details().initial_bounds_in_parent.height(); |
| 333 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { | 319 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { |
| 334 // Along the bottom edge, positive delta_y increases the window size. | 320 // Along the bottom edge, positive delta_y increases the window size. |
| 335 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1; | 321 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1; |
| 336 height += y_multiplier * (*delta_y); | 322 height += y_multiplier * (*delta_y); |
| 337 | 323 |
| 338 // Ensure we don't shrink past the minimum height and clamp delta_y | 324 // Ensure we don't shrink past the minimum height and clamp delta_y |
| 339 // for the window origin computation. | 325 // for the window origin computation. |
| 340 if (height < min_height) { | 326 if (height < min_height) { |
| 341 height = min_height; | 327 height = min_height; |
| 342 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - | 328 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - |
| 343 min_height); | 329 min_height); |
| 344 } | 330 } |
| 345 | 331 |
| 346 // And don't let the window go bigger than the display. | 332 // And don't let the window go bigger than the display. |
| 347 int max_height = gfx::Screen::GetScreen() | 333 int max_height = GetTarget()->GetDisplayNearestWindow().bounds().height(); |
| 348 ->GetDisplayNearestWindow(GetTarget()) | 334 gfx::Size max_size = GetTarget()->GetMaximumSize(); |
| 349 .bounds() | |
| 350 .height(); | |
| 351 gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize(); | |
| 352 if (max_size.height() != 0) | 335 if (max_size.height() != 0) |
| 353 max_height = std::min(max_height, max_size.height()); | 336 max_height = std::min(max_height, max_size.height()); |
| 354 if (height > max_height) { | 337 if (height > max_height) { |
| 355 height = max_height; | 338 height = max_height; |
| 356 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - | 339 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - |
| 357 max_height); | 340 max_height); |
| 358 } | 341 } |
| 359 } | 342 } |
| 360 return height; | 343 return height; |
| 361 } | 344 } |
| 362 | 345 |
| 363 } // namespace ash | 346 } // namespace ash |
| OLD | NEW |