| 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/dock_layout_manager.h" |
| 20 #include "ash/wm/dock/dock_window_resizer.h" |
| 19 #include "ash/wm/drag_window_resizer.h" | 21 #include "ash/wm/drag_window_resizer.h" |
| 20 #include "ash/wm/panels/panel_window_resizer.h" | 22 #include "ash/wm/panels/panel_window_resizer.h" |
| 21 #include "ash/wm/property_util.h" | 23 #include "ash/wm/property_util.h" |
| 22 #include "ash/wm/window_properties.h" | 24 #include "ash/wm/window_properties.h" |
| 23 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
| 24 #include "ash/wm/workspace/phantom_window_controller.h" | 26 #include "ash/wm/workspace/phantom_window_controller.h" |
| 25 #include "ash/wm/workspace/snap_sizer.h" | 27 #include "ash/wm/workspace/snap_sizer.h" |
| 26 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 27 #include "ui/aura/client/aura_constants.h" | 29 #include "ui/aura/client/aura_constants.h" |
| 28 #include "ui/aura/client/window_types.h" | 30 #include "ui/aura/client/window_types.h" |
| 29 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
| 30 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_delegate.h" | 33 #include "ui/aura/window_delegate.h" |
| 32 #include "ui/base/hit_test.h" | 34 #include "ui/base/hit_test.h" |
| 33 #include "ui/compositor/layer.h" | 35 #include "ui/compositor/layer.h" |
| 34 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
| 35 #include "ui/gfx/transform.h" | 37 #include "ui/gfx/transform.h" |
| 36 | 38 |
| 37 namespace ash { | 39 namespace ash { |
| 38 | 40 |
| 39 scoped_ptr<WindowResizer> CreateWindowResizer(aura::Window* window, | 41 scoped_ptr<WindowResizer> CreateWindowResizer(aura::Window* window, |
| 40 const gfx::Point& point_in_parent, | 42 const gfx::Point& point_in_parent, |
| 41 int window_component) { | 43 int window_component) { |
| 42 DCHECK(window); | 44 DCHECK(window); |
| 43 // No need to return a resizer when the window cannot get resized. | 45 // No need to return a resizer when the window cannot get resized. |
| 44 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) | 46 if (!wm::CanResizeWindow(window) && window_component != HTCAPTION) |
| 45 return scoped_ptr<WindowResizer>(); | 47 return scoped_ptr<WindowResizer>(); |
| 46 | 48 |
| 49 // TODO(varkha): The chaining of window resizers causes some of the logic |
| 50 // to be repeated and the logic flow difficult to control. With some windows |
| 51 // classes using reparenting during drag operations it becomes challenging to |
| 52 // implement proper transition from one resizer to another during or at the |
| 53 // end of the drag. This also causes http://crbug.com/247085. |
| 54 // It seems the only thing the panel or dock resizer needs to do is notify the |
| 55 // layout manager when a docked window is being dragged. We should have a |
| 56 // better way of doing this, perhaps by having a way of observing drags or |
| 57 // having a generic drag window wrapper which informs a layout manager that a |
| 58 // drag has started or stopped. |
| 59 // It may be possible to refactor and eliminate chaining. |
| 47 WindowResizer* window_resizer = NULL; | 60 WindowResizer* window_resizer = NULL; |
| 48 if (window->parent() && | 61 if (window->parent() && |
| 49 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { | 62 window->parent()->id() == internal::kShellWindowId_WorkspaceContainer) { |
| 50 // Allow dragging maximized windows if it's not tracked by workspace. This | 63 // Allow dragging maximized windows if it's not tracked by workspace. This |
| 51 // is set by tab dragging code. | 64 // is set by tab dragging code. |
| 52 if (!wm::IsWindowNormal(window) && | 65 if (!wm::IsWindowNormal(window) && |
| 53 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) | 66 (window_component != HTCAPTION || GetTrackedByWorkspace(window))) |
| 54 return scoped_ptr<WindowResizer>(); | 67 return scoped_ptr<WindowResizer>(); |
| 55 window_resizer = internal::WorkspaceWindowResizer::Create( | 68 window_resizer = internal::WorkspaceWindowResizer::Create( |
| 56 window, | 69 window, |
| 57 point_in_parent, | 70 point_in_parent, |
| 58 window_component, | 71 window_component, |
| 59 std::vector<aura::Window*>()); | 72 std::vector<aura::Window*>()); |
| 60 } else if (wm::IsWindowNormal(window)) { | 73 } else if (wm::IsWindowNormal(window)) { |
| 61 window_resizer = DefaultWindowResizer::Create( | 74 window_resizer = DefaultWindowResizer::Create( |
| 62 window, point_in_parent, window_component); | 75 window, point_in_parent, window_component); |
| 63 } | 76 } |
| 64 if (window_resizer) { | 77 if (window_resizer) { |
| 65 window_resizer = internal::DragWindowResizer::Create( | 78 window_resizer = internal::DragWindowResizer::Create( |
| 66 window_resizer, window, point_in_parent, window_component); | 79 window_resizer, window, point_in_parent, window_component); |
| 67 } | 80 } |
| 81 if (window_resizer && IsWindowDocked(window)) { |
| 82 window_resizer = DockWindowResizer::Create( |
| 83 window_resizer, window, point_in_parent, window_component); |
| 84 } |
| 68 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { | 85 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { |
| 69 window_resizer = PanelWindowResizer::Create( | 86 window_resizer = PanelWindowResizer::Create( |
| 70 window_resizer, window, point_in_parent, window_component); | 87 window_resizer, window, point_in_parent, window_component); |
| 71 } | 88 } |
| 72 return make_scoped_ptr<WindowResizer>(window_resizer); | 89 return make_scoped_ptr<WindowResizer>(window_resizer); |
| 73 } | 90 } |
| 74 | 91 |
| 75 namespace internal { | 92 namespace internal { |
| 76 | 93 |
| 77 namespace { | 94 namespace { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 if (bounds != window()->bounds()) | 378 if (bounds != window()->bounds()) |
| 362 window()->SetBounds(bounds); | 379 window()->SetBounds(bounds); |
| 363 } | 380 } |
| 364 | 381 |
| 365 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { | 382 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
| 366 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); | 383 wm::SetUserHasChangedWindowPositionOrSize(details_.window, true); |
| 367 snap_phantom_window_controller_.reset(); | 384 snap_phantom_window_controller_.reset(); |
| 368 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 385 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
| 369 return; | 386 return; |
| 370 | 387 |
| 371 // When the window is not in the normal show state, we do not snap thw window. | 388 // 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 | 389 // 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 | 390 // 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 | 391 // out of a maximized window, it's already in the normal show state when this |
| 375 // is called, so it does not matter. | 392 // is called, so it does not matter. |
| 376 if (wm::IsWindowNormal(window()) && | 393 if (wm::IsWindowNormal(window()) && |
| 377 (window()->type() != aura::client::WINDOW_TYPE_PANEL || | 394 (window()->type() != aura::client::WINDOW_TYPE_PANEL || |
| 378 !window()->GetProperty(kPanelAttachedKey)) && | 395 !window()->GetProperty(kPanelAttachedKey)) && |
| 379 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { | 396 (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { |
| 380 if (!GetRestoreBoundsInScreen(window())) { | 397 if (!GetRestoreBoundsInScreen(window())) { |
| 381 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( | 398 gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); | 861 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); |
| 845 if (location.x() <= area.x()) | 862 if (location.x() <= area.x()) |
| 846 return SNAP_LEFT_EDGE; | 863 return SNAP_LEFT_EDGE; |
| 847 if (location.x() >= area.right() - 1) | 864 if (location.x() >= area.right() - 1) |
| 848 return SNAP_RIGHT_EDGE; | 865 return SNAP_RIGHT_EDGE; |
| 849 return SNAP_NONE; | 866 return SNAP_NONE; |
| 850 } | 867 } |
| 851 | 868 |
| 852 } // namespace internal | 869 } // namespace internal |
| 853 } // namespace ash | 870 } // namespace ash |
| OLD | NEW |