OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dock/docked_window_resizer.h" | 5 #include "ash/wm/dock/docked_window_resizer.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_controller.h" | 8 #include "ash/display/display_controller.h" |
9 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
11 #include "ash/screen_ash.h" | 11 #include "ash/screen_ash.h" |
12 #include "ash/shelf/shelf_types.h" | 12 #include "ash/shelf/shelf_types.h" |
13 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/shell_window_ids.h" | 15 #include "ash/shell_window_ids.h" |
16 #include "ash/wm/coordinate_conversion.h" | 16 #include "ash/wm/coordinate_conversion.h" |
17 #include "ash/wm/dock/docked_window_layout_manager.h" | 17 #include "ash/wm/dock/docked_window_layout_manager.h" |
18 #include "ash/wm/property_util.h" | 18 #include "ash/wm/window_state.h" |
19 #include "ash/wm/window_settings.h" | |
20 #include "ash/wm/workspace/magnetism_matcher.h" | 19 #include "ash/wm/workspace/magnetism_matcher.h" |
21 #include "ash/wm/workspace/workspace_window_resizer.h" | 20 #include "ash/wm/workspace/workspace_window_resizer.h" |
22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
23 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
24 #include "ui/aura/client/aura_constants.h" | 23 #include "ui/aura/client/aura_constants.h" |
25 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
26 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
27 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
28 #include "ui/aura/window_delegate.h" | 27 #include "ui/aura/window_delegate.h" |
29 #include "ui/base/hit_test.h" | 28 #include "ui/base/hit_test.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 did_move_or_resize_ = true; | 72 did_move_or_resize_ = true; |
74 StartedDragging(); | 73 StartedDragging(); |
75 } | 74 } |
76 gfx::Point offset; | 75 gfx::Point offset; |
77 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); | 76 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); |
78 bool set_tracked_by_workspace = MaybeSnapToEdge(bounds, &offset); | 77 bool set_tracked_by_workspace = MaybeSnapToEdge(bounds, &offset); |
79 | 78 |
80 // Temporarily clear kWindowTrackedByWorkspaceKey for windows that are snapped | 79 // Temporarily clear kWindowTrackedByWorkspaceKey for windows that are snapped |
81 // to screen edges e.g. when they are docked. This prevents the windows from | 80 // to screen edges e.g. when they are docked. This prevents the windows from |
82 // getting snapped to other nearby windows during the drag. | 81 // getting snapped to other nearby windows during the drag. |
83 wm::WindowSettings* window_settings = wm::GetWindowSettings(GetTarget()); | 82 wm::WindowState* window_state = wm::GetWindowState(GetTarget()); |
84 bool was_tracked_by_workspace = window_settings->tracked_by_workspace(); | 83 bool was_tracked_by_workspace = window_state->tracked_by_workspace(); |
85 if (set_tracked_by_workspace) | 84 if (set_tracked_by_workspace) |
86 window_settings->SetTrackedByWorkspace(false); | 85 window_state->SetTrackedByWorkspace(false); |
87 gfx::Point modified_location(location.x() + offset.x(), | 86 gfx::Point modified_location(location.x() + offset.x(), |
88 location.y() + offset.y()); | 87 location.y() + offset.y()); |
89 | 88 |
90 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); | 89 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
91 next_window_resizer_->Drag(modified_location, event_flags); | 90 next_window_resizer_->Drag(modified_location, event_flags); |
92 if (!resizer) | 91 if (!resizer) |
93 return; | 92 return; |
94 window_settings->SetTrackedByWorkspace(was_tracked_by_workspace); | 93 window_state->SetTrackedByWorkspace(was_tracked_by_workspace); |
95 | 94 |
96 DockedWindowLayoutManager* new_dock_layout = | 95 DockedWindowLayoutManager* new_dock_layout = |
97 GetDockedLayoutManagerAtPoint(last_location_); | 96 GetDockedLayoutManagerAtPoint(last_location_); |
98 if (new_dock_layout && new_dock_layout != dock_layout_) { | 97 if (new_dock_layout && new_dock_layout != dock_layout_) { |
99 // The window is being dragged to a new display. If the previous | 98 // The window is being dragged to a new display. If the previous |
100 // container is the current parent of the window it will be informed of | 99 // container is the current parent of the window it will be informed of |
101 // the end of drag when the window is reparented, otherwise let the | 100 // the end of drag when the window is reparented, otherwise let the |
102 // previous container know the drag is complete. If we told the | 101 // previous container know the drag is complete. If we told the |
103 // window's parent that the drag was complete it would begin | 102 // window's parent that the drag was complete it would begin |
104 // positioning the window. | 103 // positioning the window. |
105 if (is_docked_ && dock_layout_->is_dragged_window_docked()) | 104 if (is_docked_ && dock_layout_->is_dragged_window_docked()) |
106 dock_layout_->UndockDraggedWindow(); | 105 dock_layout_->UndockDraggedWindow(); |
107 if (dock_layout_ != initial_dock_layout_) | 106 if (dock_layout_ != initial_dock_layout_) |
108 dock_layout_->FinishDragging(); | 107 dock_layout_->FinishDragging(); |
109 is_docked_ = false; | 108 is_docked_ = false; |
110 dock_layout_ = new_dock_layout; | 109 dock_layout_ = new_dock_layout; |
111 // The window's initial layout manager already knows that the drag is | 110 // The window's initial layout manager already knows that the drag is |
112 // in progress for this window. | 111 // in progress for this window. |
113 if (new_dock_layout != initial_dock_layout_) | 112 if (new_dock_layout != initial_dock_layout_) |
114 new_dock_layout->StartDragging(GetTarget()); | 113 new_dock_layout->StartDragging(GetTarget()); |
115 } | 114 } |
116 // Window could get docked by the WorkspaceWindowResizer, update the state. | 115 // Window could get docked by the WorkspaceWindowResizer, update the state. |
117 is_docked_ = dock_layout_->is_dragged_window_docked(); | 116 is_docked_ = dock_layout_->is_dragged_window_docked(); |
118 } | 117 } |
119 | 118 |
120 void DockedWindowResizer::CompleteDrag(int event_flags) { | 119 void DockedWindowResizer::CompleteDrag(int event_flags) { |
121 // Temporarily clear kWindowTrackedByWorkspaceKey for panels so that they | 120 // Temporarily clear kWindowTrackedByWorkspaceKey for panels so that they |
122 // don't get forced into the workspace that may be shrunken because of docked | 121 // don't get forced into the workspace that may be shrunken because of docked |
123 // windows. | 122 // windows. |
124 wm::WindowSettings* window_settings = wm::GetWindowSettings(GetTarget()); | 123 wm::WindowState* window_state = wm::GetWindowState(GetTarget()); |
125 bool was_tracked_by_workspace = window_settings->tracked_by_workspace(); | 124 bool was_tracked_by_workspace = window_state->tracked_by_workspace(); |
126 if (was_docked_) | 125 if (was_docked_) |
127 window_settings->SetTrackedByWorkspace(false); | 126 window_state->SetTrackedByWorkspace(false); |
128 // The root window can change when dragging into a different screen. | 127 // The root window can change when dragging into a different screen. |
129 next_window_resizer_->CompleteDrag(event_flags); | 128 next_window_resizer_->CompleteDrag(event_flags); |
130 FinishedDragging(); | 129 FinishedDragging(); |
131 window_settings->SetTrackedByWorkspace(was_tracked_by_workspace); | 130 window_state->SetTrackedByWorkspace(was_tracked_by_workspace); |
132 } | 131 } |
133 | 132 |
134 void DockedWindowResizer::RevertDrag() { | 133 void DockedWindowResizer::RevertDrag() { |
135 // Temporarily clear kWindowTrackedByWorkspaceKey for panels so that they | 134 // Temporarily clear kWindowTrackedByWorkspaceKey for panels so that they |
136 // don't get forced into the workspace that may be shrunken because of docked | 135 // don't get forced into the workspace that may be shrunken because of docked |
137 // windows. | 136 // windows. |
138 wm::WindowSettings* window_settings = wm::GetWindowSettings(GetTarget()); | 137 wm::WindowState* window_state = wm::GetWindowState(GetTarget()); |
139 bool was_tracked_by_workspace = window_settings->tracked_by_workspace(); | 138 bool was_tracked_by_workspace = window_state->tracked_by_workspace(); |
140 if (was_docked_) | 139 if (was_docked_) |
141 window_settings->SetTrackedByWorkspace(false); | 140 window_state->SetTrackedByWorkspace(false); |
142 next_window_resizer_->RevertDrag(); | 141 next_window_resizer_->RevertDrag(); |
143 // Restore docked state to what it was before the drag if necessary. | 142 // Restore docked state to what it was before the drag if necessary. |
144 if (was_docked_ && !is_docked_) { | 143 if (was_docked_ && !is_docked_) { |
145 dock_layout_->DockDraggedWindow(GetTarget()); | 144 dock_layout_->DockDraggedWindow(GetTarget()); |
146 is_docked_ = was_docked_; | 145 is_docked_ = was_docked_; |
147 } | 146 } |
148 FinishedDragging(); | 147 FinishedDragging(); |
149 window_settings->SetTrackedByWorkspace(was_tracked_by_workspace); | 148 window_state->SetTrackedByWorkspace(was_tracked_by_workspace); |
150 } | 149 } |
151 | 150 |
152 aura::Window* DockedWindowResizer::GetTarget() { | 151 aura::Window* DockedWindowResizer::GetTarget() { |
153 return next_window_resizer_->GetTarget(); | 152 return next_window_resizer_->GetTarget(); |
154 } | 153 } |
155 | 154 |
156 const gfx::Point& DockedWindowResizer::GetInitialLocation() const { | 155 const gfx::Point& DockedWindowResizer::GetInitialLocation() const { |
157 return details_.initial_location_in_parent; | 156 return details_.initial_location_in_parent; |
158 } | 157 } |
159 | 158 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // Tell the dock layout manager that we are dragging this window. | 219 // Tell the dock layout manager that we are dragging this window. |
221 // At this point we are not yet animating the window as it may not be | 220 // At this point we are not yet animating the window as it may not be |
222 // inside the docked area. | 221 // inside the docked area. |
223 dock_layout_->StartDragging(GetTarget()); | 222 dock_layout_->StartDragging(GetTarget()); |
224 // Reparent workspace windows during the drag to elevate them above workspace. | 223 // Reparent workspace windows during the drag to elevate them above workspace. |
225 // Other windows for which the DockedWindowResizer is instantiated include | 224 // Other windows for which the DockedWindowResizer is instantiated include |
226 // panels and windows that are already docked. Those do not need reparenting. | 225 // panels and windows that are already docked. Those do not need reparenting. |
227 if (GetTarget()->type() != aura::client::WINDOW_TYPE_PANEL && | 226 if (GetTarget()->type() != aura::client::WINDOW_TYPE_PANEL && |
228 GetTarget()->parent()->id() == kShellWindowId_DefaultContainer) { | 227 GetTarget()->parent()->id() == kShellWindowId_DefaultContainer) { |
229 // The window is going to be reparented - avoid completing the drag. | 228 // The window is going to be reparented - avoid completing the drag. |
230 wm::GetWindowSettings(GetTarget())->set_continue_drag_after_reparent(true); | 229 wm::GetWindowState(GetTarget())->set_continue_drag_after_reparent(true); |
231 | 230 |
232 // Reparent the window into the docked windows container in order to get it | 231 // Reparent the window into the docked windows container in order to get it |
233 // on top of other docked windows. | 232 // on top of other docked windows. |
234 aura::Window* docked_container = Shell::GetContainer( | 233 aura::Window* docked_container = Shell::GetContainer( |
235 GetTarget()->GetRootWindow(), | 234 GetTarget()->GetRootWindow(), |
236 kShellWindowId_DockedContainer); | 235 kShellWindowId_DockedContainer); |
237 docked_container->AddChild(GetTarget()); | 236 docked_container->AddChild(GetTarget()); |
238 } | 237 } |
239 if (is_docked_) | 238 if (is_docked_) |
240 dock_layout_->DockDraggedWindow(GetTarget()); | 239 dock_layout_->DockDraggedWindow(GetTarget()); |
241 } | 240 } |
242 | 241 |
243 void DockedWindowResizer::FinishedDragging() { | 242 void DockedWindowResizer::FinishedDragging() { |
244 if (!did_move_or_resize_) | 243 if (!did_move_or_resize_) |
245 return; | 244 return; |
246 | |
247 aura::Window* window = GetTarget(); | 245 aura::Window* window = GetTarget(); |
| 246 wm::WindowState* window_state = wm::GetWindowState(window); |
248 const bool attached_panel = | 247 const bool attached_panel = |
249 window->type() == aura::client::WINDOW_TYPE_PANEL && | 248 window->type() == aura::client::WINDOW_TYPE_PANEL && |
250 wm::GetWindowSettings(window)->panel_attached(); | 249 window_state->panel_attached(); |
251 const bool is_resized = | 250 const bool is_resized = |
252 (details_.bounds_change & WindowResizer::kBoundsChange_Resizes) != 0; | 251 (details_.bounds_change & WindowResizer::kBoundsChange_Resizes) != 0; |
253 // No longer restore to pre-docked bounds if a window has been resized. | 252 // No longer restore to pre-docked bounds if a window has been resized. |
254 if (is_resized && is_docked_) | 253 if (is_resized && is_docked_) |
255 ClearRestoreBounds(window); | 254 window_state->ClearRestoreBounds(); |
256 | 255 |
257 // Check if the window needs to be docked or returned to workspace. | 256 // Check if the window needs to be docked or returned to workspace. |
258 aura::Window* dock_container = Shell::GetContainer( | 257 aura::Window* dock_container = Shell::GetContainer( |
259 window->GetRootWindow(), | 258 window->GetRootWindow(), |
260 kShellWindowId_DockedContainer); | 259 kShellWindowId_DockedContainer); |
261 if ((is_resized || !attached_panel) && | 260 if ((is_resized || !attached_panel) && |
262 is_docked_ != (window->parent() == dock_container)) { | 261 is_docked_ != (window->parent() == dock_container)) { |
263 if (is_docked_) { | 262 if (is_docked_) { |
264 dock_container->AddChild(window); | 263 dock_container->AddChild(window); |
265 } else if (window->parent()->id() == kShellWindowId_DockedContainer) { | 264 } else if (window->parent()->id() == kShellWindowId_DockedContainer) { |
(...skipping 14 matching lines...) Expand all Loading... |
280 // If we started the drag in one root window and moved into another root | 279 // If we started the drag in one root window and moved into another root |
281 // but then canceled the drag we may need to inform the original layout | 280 // but then canceled the drag we may need to inform the original layout |
282 // manager that the drag is finished. | 281 // manager that the drag is finished. |
283 if (initial_dock_layout_ != dock_layout_) | 282 if (initial_dock_layout_ != dock_layout_) |
284 initial_dock_layout_->FinishDragging(); | 283 initial_dock_layout_->FinishDragging(); |
285 is_docked_ = false; | 284 is_docked_ = false; |
286 } | 285 } |
287 | 286 |
288 } // namespace internal | 287 } // namespace internal |
289 } // namespace ash | 288 } // namespace ash |
OLD | NEW |