| 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/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/ash_switches.h" | 12 #include "ash/ash_switches.h" |
| 13 #include "ash/display/display_controller.h" | 13 #include "ash/display/display_controller.h" |
| 14 #include "ash/screen_ash.h" | 14 #include "ash/screen_ash.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
| 17 #include "ash/wm/coordinate_conversion.h" | 17 #include "ash/wm/coordinate_conversion.h" |
| 18 #include "ash/wm/default_window_resizer.h" | 18 #include "ash/wm/default_window_resizer.h" |
| 19 #include "ash/wm/dock/docked_window_resizer.h" |
| 19 #include "ash/wm/drag_window_resizer.h" | 20 #include "ash/wm/drag_window_resizer.h" |
| 20 #include "ash/wm/panels/panel_window_resizer.h" | 21 #include "ash/wm/panels/panel_window_resizer.h" |
| 21 #include "ash/wm/property_util.h" | 22 #include "ash/wm/property_util.h" |
| 22 #include "ash/wm/window_properties.h" | 23 #include "ash/wm/window_properties.h" |
| 23 #include "ash/wm/window_util.h" | 24 #include "ash/wm/window_util.h" |
| 24 #include "ash/wm/workspace/phantom_window_controller.h" | 25 #include "ash/wm/workspace/phantom_window_controller.h" |
| 25 #include "ash/wm/workspace/snap_sizer.h" | 26 #include "ash/wm/workspace/snap_sizer.h" |
| 26 #include "base/command_line.h" | 27 #include "base/command_line.h" |
| 27 #include "ui/aura/client/aura_constants.h" | 28 #include "ui/aura/client/aura_constants.h" |
| 28 #include "ui/aura/client/window_types.h" | 29 #include "ui/aura/client/window_types.h" |
| 29 #include "ui/aura/root_window.h" | 30 #include "ui/aura/root_window.h" |
| 30 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_delegate.h" | 32 #include "ui/aura/window_delegate.h" |
| 32 #include "ui/base/hit_test.h" | 33 #include "ui/base/hit_test.h" |
| 33 #include "ui/compositor/layer.h" | 34 #include "ui/compositor/layer.h" |
| 34 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
| 35 #include "ui/gfx/transform.h" | 36 #include "ui/gfx/transform.h" |
| 36 | 37 |
| 37 namespace ash { | 38 namespace ash { |
| 38 | 39 |
| 39 scoped_ptr<WindowResizer> CreateWindowResizer(aura::Window* window, | 40 scoped_ptr<WindowResizer> CreateWindowResizer(aura::Window* window, |
| 40 const gfx::Point& point_in_parent, | 41 const gfx::Point& point_in_parent, |
| 41 int window_component) { | 42 int window_component) { |
| 42 DCHECK(window); | 43 DCHECK(window); |
| 43 // No need to return a resizer when the window cannot get resized. | 44 // No need to return a resizer when the window cannot get resized. |
| 44 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) | 45 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) |
| 45 return scoped_ptr<WindowResizer>(); | 46 return scoped_ptr<WindowResizer>(); |
| 46 | 47 |
| 48 // TODO(varkha): The chaining of window resizers causes some of the logic |
| 49 // to be repeated and the logic flow difficult to control. With some windows |
| 50 // classes using reparenting during drag operations it becomes challenging to |
| 51 // implement proper transition from one resizer to another during or at the |
| 52 // end of the drag. This also causes http://crbug.com/247085. |
| 53 // It seems the only thing the panel or dock resizer needs to do is notify the |
| 54 // layout manager when a docked window is being dragged. We should have a |
| 55 // better way of doing this, perhaps by having a way of observing drags or |
| 56 // having a generic drag window wrapper which informs a layout manager that a |
| 57 // drag has started or stopped. |
| 58 // It may be possible to refactor and eliminate chaining. |
| 47 WindowResizer* window_resizer = NULL; | 59 WindowResizer* window_resizer = NULL; |
| 48 if (window->parent() && | 60 if (window->parent() && |
| 49 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { | 61 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { |
| 50 // Allow dragging maximized windows if it's not tracked by workspace. This | 62 // Allow dragging maximized windows if it's not tracked by workspace. This |
| 51 // is set by tab dragging code. | 63 // is set by tab dragging code. |
| 52 if (!wm::IsWindowNormal(window) && | 64 if (!wm::IsWindowNormal(window) && |
| 53 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) | 65 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) |
| 54 return scoped_ptr<WindowResizer>(); | 66 return scoped_ptr<WindowResizer>(); |
| 55 window_resizer = internal::WorkspaceWindowResizer::Create( | 67 window_resizer = internal::WorkspaceWindowResizer::Create( |
| 56 window, | 68 window, |
| 57 point_in_parent, | 69 point_in_parent, |
| 58 window_component, | 70 window_component, |
| 59 std::vector<aura::Window*>()); | 71 std::vector<aura::Window*>()); |
| 60 } else if (wm::IsWindowNormal(window)) { | 72 } else if (wm::IsWindowNormal(window)) { |
| 61 window_resizer = DefaultWindowResizer::Create( | 73 window_resizer = DefaultWindowResizer::Create( |
| 62 window, point_in_parent, window_component); | 74 window, point_in_parent, window_component); |
| 63 } | 75 } |
| 64 if (window_resizer) { | 76 if (window_resizer) { |
| 65 window_resizer = internal::DragWindowResizer::Create( | 77 window_resizer = internal::DragWindowResizer::Create( |
| 66 window_resizer, window, point_in_parent, window_component); | 78 window_resizer, window, point_in_parent, window_component); |
| 67 } | 79 } |
| 68 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { | 80 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { |
| 69 window_resizer = PanelWindowResizer::Create( | 81 window_resizer = PanelWindowResizer::Create( |
| 70 window_resizer, window, point_in_parent, window_component); | 82 window_resizer, window, point_in_parent, window_component); |
| 71 } | 83 } |
| 84 if (window_resizer) { |
| 85 window_resizer = DockedWindowResizer::Create( |
| 86 window_resizer, window, point_in_parent, window_component); |
| 87 } |
| 72 return make_scoped_ptr<WindowResizer>(window_resizer); | 88 return make_scoped_ptr<WindowResizer>(window_resizer); |
| 73 } | 89 } |
| 74 | 90 |
| 75 namespace internal { | 91 namespace internal { |
| 76 | 92 |
| 77 namespace { | 93 namespace { |
| 78 | 94 |
| 79 // Distance in pixels that the cursor must move past an edge for a window | 95 // Distance in pixels that the cursor must move past an edge for a window |
| 80 // to move or resize beyond that edge. | 96 // to move or resize beyond that edge. |
| 81 const int kStickyDistancePixels = 64; | 97 const int kStickyDistancePixels = 64; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 if (bounds != window()->bounds()) | 377 if (bounds != window()->bounds()) |
| 362 window()->SetBounds(bounds); | 378 window()->SetBounds(bounds); |
| 363 } | 379 } |
| 364 | 380 |
| 365 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { | 381 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
| 366 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); | 382 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); |
| 367 snap_phantom_window_controller_.reset(); | 383 snap_phantom_window_controller_.reset(); |
| 368 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 384 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
| 369 return; | 385 return; |
| 370 | 386 |
| 371 // When the window is not in the normal show state, we do not snap thw window. | 387 // When the window is not in the normal show state, we do not snap the window. |
| 372 // This happens when the user minimizes or maximizes the window by keyboard | 388 // This happens when the user minimizes or maximizes the window by keyboard |
| 373 // shortcut while dragging it. If the window is the result of dragging a tab | 389 // shortcut while dragging it. If the window is the result of dragging a tab |
| 374 // out of a maximized window, it's already in the normal show state when this | 390 // out of a maximized window, it's already in the normal show state when this |
| 375 // is called, so it does not matter. | 391 // is called, so it does not matter. |
| 376 if (wm::IsWindowNormal(window()) && | 392 if (wm::IsWindowNormal(window()) && |
| 377 (window()->type() != aura::client::WINDOW_TYPE_PANEL || | 393 (window()->type() != aura::client::WINDOW_TYPE_PANEL || |
| 378 !window()->GetProperty(kPanelAttachedKey)) && | 394 !window()->GetProperty(kPanelAttachedKey)) && |
| 379 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { | 395 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { |
| 380 if (!GetRestoreBoundsInScreen(window())) { | 396 if (!GetRestoreBoundsInScreen(window())) { |
| 381 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( | 397 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 attached_windows_[i]->SetBounds(bounds); | 433 attached_windows_[i]->SetBounds(bounds); |
| 418 last_y = attached_windows_[i]->bounds().bottom(); | 434 last_y = attached_windows_[i]->bounds().bottom(); |
| 419 } | 435 } |
| 420 } | 436 } |
| 421 } | 437 } |
| 422 | 438 |
| 423 aura::Window* WorkspaceWindowResizer::GetTarget() { | 439 aura::Window* WorkspaceWindowResizer::GetTarget() { |
| 424 return details_.window; | 440 return details_.window; |
| 425 } | 441 } |
| 426 | 442 |
| 443 const gfx::Point& WorkspaceWindowResizer::GetInitialLocationForTest() const { |
| 444 return details_.initial_location_in_parent; |
| 445 } |
| 446 |
| 427 WorkspaceWindowResizer::WorkspaceWindowResizer( | 447 WorkspaceWindowResizer::WorkspaceWindowResizer( |
| 428 const Details& details, | 448 const Details& details, |
| 429 const std::vector<aura::Window*>& attached_windows) | 449 const std::vector<aura::Window*>& attached_windows) |
| 430 : details_(details), | 450 : details_(details), |
| 431 attached_windows_(attached_windows), | 451 attached_windows_(attached_windows), |
| 432 did_move_or_resize_(false), | 452 did_move_or_resize_(false), |
| 433 total_min_(0), | 453 total_min_(0), |
| 434 total_initial_size_(0), | 454 total_initial_size_(0), |
| 435 snap_type_(SNAP_NONE), | 455 snap_type_(SNAP_NONE), |
| 436 num_mouse_moves_since_bounds_change_(0), | 456 num_mouse_moves_since_bounds_change_(0), |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); | 864 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); |
| 845 if (location.x() <= area.x()) | 865 if (location.x() <= area.x()) |
| 846 return SNAP_LEFT_EDGE; | 866 return SNAP_LEFT_EDGE; |
| 847 if (location.x() >= area.right() - 1) | 867 if (location.x() >= area.right() - 1) |
| 848 return SNAP_RIGHT_EDGE; | 868 return SNAP_RIGHT_EDGE; |
| 849 return SNAP_NONE; | 869 return SNAP_NONE; |
| 850 } | 870 } |
| 851 | 871 |
| 852 } // namespace internal | 872 } // namespace internal |
| 853 } // namespace ash | 873 } // namespace ash |
| OLD | NEW |