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/display/window_tree_host_manager.h" | 12 #include "ash/display/window_tree_host_manager.h" |
13 #include "ash/metrics/user_metrics_recorder.h" | 13 #include "ash/metrics/user_metrics_recorder.h" |
14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
15 #include "ash/screen_util.h" | 15 #include "ash/screen_util.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
17 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
18 #include "ash/wm/default_window_resizer.h" | 18 #include "ash/wm/default_window_resizer.h" |
19 #include "ash/wm/dock/docked_window_layout_manager.h" | 19 #include "ash/wm/dock/docked_window_layout_manager.h" |
20 #include "ash/wm/dock/docked_window_resizer.h" | 20 #include "ash/wm/dock/docked_window_resizer.h" |
21 #include "ash/wm/drag_window_resizer.h" | 21 #include "ash/wm/drag_window_resizer.h" |
22 #include "ash/wm/panels/panel_window_resizer.h" | 22 #include "ash/wm/panels/panel_window_resizer.h" |
23 #include "ash/wm/window_state.h" | 23 #include "ash/wm/window_state.h" |
24 #include "ash/wm/window_util.h" | 24 #include "ash/wm/window_util.h" |
25 #include "ash/wm/wm_event.h" | 25 #include "ash/wm/wm_event.h" |
26 #include "ash/wm/workspace/phantom_window_controller.h" | 26 #include "ash/wm/workspace/phantom_window_controller.h" |
27 #include "ash/wm/workspace/two_step_edge_cycler.h" | 27 #include "ash/wm/workspace/two_step_edge_cycler.h" |
28 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 29 #include "base/memory/ptr_util.h" |
29 #include "base/memory/weak_ptr.h" | 30 #include "base/memory/weak_ptr.h" |
30 #include "ui/aura/client/aura_constants.h" | 31 #include "ui/aura/client/aura_constants.h" |
31 #include "ui/aura/client/screen_position_client.h" | 32 #include "ui/aura/client/screen_position_client.h" |
32 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
33 #include "ui/aura/window_delegate.h" | 34 #include "ui/aura/window_delegate.h" |
34 #include "ui/aura/window_event_dispatcher.h" | 35 #include "ui/aura/window_event_dispatcher.h" |
35 #include "ui/base/hit_test.h" | 36 #include "ui/base/hit_test.h" |
36 #include "ui/compositor/layer.h" | 37 #include "ui/compositor/layer.h" |
37 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
38 #include "ui/gfx/transform.h" | 39 #include "ui/gfx/transform.h" |
39 #include "ui/wm/core/coordinate_conversion.h" | 40 #include "ui/wm/core/coordinate_conversion.h" |
40 #include "ui/wm/core/window_util.h" | 41 #include "ui/wm/core/window_util.h" |
41 #include "ui/wm/public/window_types.h" | 42 #include "ui/wm/public/window_types.h" |
42 | 43 |
43 namespace ash { | 44 namespace ash { |
44 | 45 |
45 scoped_ptr<WindowResizer> CreateWindowResizer( | 46 std::unique_ptr<WindowResizer> CreateWindowResizer( |
46 aura::Window* window, | 47 aura::Window* window, |
47 const gfx::Point& point_in_parent, | 48 const gfx::Point& point_in_parent, |
48 int window_component, | 49 int window_component, |
49 aura::client::WindowMoveSource source) { | 50 aura::client::WindowMoveSource source) { |
50 DCHECK(window); | 51 DCHECK(window); |
51 wm::WindowState* window_state = wm::GetWindowState(window); | 52 wm::WindowState* window_state = wm::GetWindowState(window); |
52 // No need to return a resizer when the window cannot get resized or when a | 53 // No need to return a resizer when the window cannot get resized or when a |
53 // resizer already exists for this window. | 54 // resizer already exists for this window. |
54 if ((!window_state->CanResize() && window_component != HTCAPTION) || | 55 if ((!window_state->CanResize() && window_component != HTCAPTION) || |
55 window_state->drag_details()) { | 56 window_state->drag_details()) { |
56 return scoped_ptr<WindowResizer>(); | 57 return std::unique_ptr<WindowResizer>(); |
57 } | 58 } |
58 | 59 |
59 if (window_component == HTCAPTION && !window_state->can_be_dragged()) | 60 if (window_component == HTCAPTION && !window_state->can_be_dragged()) |
60 return scoped_ptr<WindowResizer>(); | 61 return std::unique_ptr<WindowResizer>(); |
61 | 62 |
62 // TODO(varkha): The chaining of window resizers causes some of the logic | 63 // TODO(varkha): The chaining of window resizers causes some of the logic |
63 // to be repeated and the logic flow difficult to control. With some windows | 64 // to be repeated and the logic flow difficult to control. With some windows |
64 // classes using reparenting during drag operations it becomes challenging to | 65 // classes using reparenting during drag operations it becomes challenging to |
65 // implement proper transition from one resizer to another during or at the | 66 // implement proper transition from one resizer to another during or at the |
66 // end of the drag. This also causes http://crbug.com/247085. | 67 // end of the drag. This also causes http://crbug.com/247085. |
67 // It seems the only thing the panel or dock resizer needs to do is notify the | 68 // It seems the only thing the panel or dock resizer needs to do is notify the |
68 // layout manager when a docked window is being dragged. We should have a | 69 // layout manager when a docked window is being dragged. We should have a |
69 // better way of doing this, perhaps by having a way of observing drags or | 70 // better way of doing this, perhaps by having a way of observing drags or |
70 // having a generic drag window wrapper which informs a layout manager that a | 71 // having a generic drag window wrapper which informs a layout manager that a |
71 // drag has started or stopped. | 72 // drag has started or stopped. |
72 // It may be possible to refactor and eliminate chaining. | 73 // It may be possible to refactor and eliminate chaining. |
73 WindowResizer* window_resizer = NULL; | 74 WindowResizer* window_resizer = NULL; |
74 | 75 |
75 if (!window_state->IsNormalOrSnapped() && !window_state->IsDocked()) | 76 if (!window_state->IsNormalOrSnapped() && !window_state->IsDocked()) |
76 return scoped_ptr<WindowResizer>(); | 77 return std::unique_ptr<WindowResizer>(); |
77 | 78 |
78 int bounds_change = WindowResizer::GetBoundsChangeForWindowComponent( | 79 int bounds_change = WindowResizer::GetBoundsChangeForWindowComponent( |
79 window_component); | 80 window_component); |
80 if (bounds_change == WindowResizer::kBoundsChangeDirection_None) | 81 if (bounds_change == WindowResizer::kBoundsChangeDirection_None) |
81 return scoped_ptr<WindowResizer>(); | 82 return std::unique_ptr<WindowResizer>(); |
82 | 83 |
83 window_state->CreateDragDetails(window, point_in_parent, window_component, | 84 window_state->CreateDragDetails(window, point_in_parent, window_component, |
84 source); | 85 source); |
85 if (window->parent() && | 86 if (window->parent() && |
86 (window->parent()->id() == kShellWindowId_DefaultContainer || | 87 (window->parent()->id() == kShellWindowId_DefaultContainer || |
87 window->parent()->id() == kShellWindowId_DockedContainer || | 88 window->parent()->id() == kShellWindowId_DockedContainer || |
88 window->parent()->id() == kShellWindowId_PanelContainer)) { | 89 window->parent()->id() == kShellWindowId_PanelContainer)) { |
89 window_resizer = WorkspaceWindowResizer::Create( | 90 window_resizer = WorkspaceWindowResizer::Create( |
90 window_state, std::vector<aura::Window*>()); | 91 window_state, std::vector<aura::Window*>()); |
91 } else { | 92 } else { |
92 window_resizer = DefaultWindowResizer::Create(window_state); | 93 window_resizer = DefaultWindowResizer::Create(window_state); |
93 } | 94 } |
94 window_resizer = DragWindowResizer::Create(window_resizer, window_state); | 95 window_resizer = DragWindowResizer::Create(window_resizer, window_state); |
95 if (window->type() == ui::wm::WINDOW_TYPE_PANEL) | 96 if (window->type() == ui::wm::WINDOW_TYPE_PANEL) |
96 window_resizer = PanelWindowResizer::Create(window_resizer, window_state); | 97 window_resizer = PanelWindowResizer::Create(window_resizer, window_state); |
97 if (window_resizer && window->parent() && | 98 if (window_resizer && window->parent() && |
98 !::wm::GetTransientParent(window) && | 99 !::wm::GetTransientParent(window) && |
99 (window->parent()->id() == kShellWindowId_DefaultContainer || | 100 (window->parent()->id() == kShellWindowId_DefaultContainer || |
100 window->parent()->id() == kShellWindowId_DockedContainer || | 101 window->parent()->id() == kShellWindowId_DockedContainer || |
101 window->parent()->id() == kShellWindowId_PanelContainer)) { | 102 window->parent()->id() == kShellWindowId_PanelContainer)) { |
102 window_resizer = DockedWindowResizer::Create(window_resizer, window_state); | 103 window_resizer = DockedWindowResizer::Create(window_resizer, window_state); |
103 } | 104 } |
104 return make_scoped_ptr<WindowResizer>(window_resizer); | 105 return base::WrapUnique<WindowResizer>(window_resizer); |
105 } | 106 } |
106 | 107 |
107 namespace { | 108 namespace { |
108 | 109 |
109 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset | 110 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset |
110 // when resizing a window using touchscreen. | 111 // when resizing a window using touchscreen. |
111 const int kScreenEdgeInsetForTouchDrag = 32; | 112 const int kScreenEdgeInsetForTouchDrag = 32; |
112 | 113 |
113 // Current instance for use by the WorkspaceWindowResizerTest. | 114 // Current instance for use by the WorkspaceWindowResizerTest. |
114 WorkspaceWindowResizer* instance = NULL; | 115 WorkspaceWindowResizer* instance = NULL; |
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); | 1056 snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
1056 gfx::Rect snapped_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 1057 gfx::Rect snapped_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
1057 GetTarget()); | 1058 GetTarget()); |
1058 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) | 1059 if (snapped_type == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) |
1059 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); | 1060 snapped_bounds.set_x(snapped_bounds.right() - bounds_in_parent.width()); |
1060 snapped_bounds.set_width(bounds_in_parent.width()); | 1061 snapped_bounds.set_width(bounds_in_parent.width()); |
1061 return bounds_in_parent == snapped_bounds; | 1062 return bounds_in_parent == snapped_bounds; |
1062 } | 1063 } |
1063 | 1064 |
1064 } // namespace ash | 1065 } // namespace ash |
OLD | NEW |