| 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/display/window_tree_host_manager.h" | 7 #include "ash/display/window_tree_host_manager.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
| 10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 // static | 60 // static |
| 61 DockedWindowResizer* | 61 DockedWindowResizer* |
| 62 DockedWindowResizer::Create(WindowResizer* next_window_resizer, | 62 DockedWindowResizer::Create(WindowResizer* next_window_resizer, |
| 63 wm::WindowState* window_state) { | 63 wm::WindowState* window_state) { |
| 64 return new DockedWindowResizer(next_window_resizer, window_state); | 64 return new DockedWindowResizer(next_window_resizer, window_state); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 67 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
| 68 last_location_ = location; | 68 last_location_ = location; |
| 69 ::wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); | 69 ::wm::ConvertPointToScreen(GetAuraTarget()->parent(), &last_location_); |
| 70 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); | 70 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
| 71 | 71 |
| 72 if (!did_move_or_resize_) { | 72 if (!did_move_or_resize_) { |
| 73 did_move_or_resize_ = true; | 73 did_move_or_resize_ = true; |
| 74 StartedDragging(resizer); | 74 StartedDragging(resizer); |
| 75 } | 75 } |
| 76 if (!resizer) | 76 if (!resizer) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 gfx::Point offset; | 79 gfx::Point offset; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 if (dock_layout_ != initial_dock_layout_) | 100 if (dock_layout_ != initial_dock_layout_) |
| 101 dock_layout_->FinishDragging( | 101 dock_layout_->FinishDragging( |
| 102 DOCKED_ACTION_NONE, | 102 DOCKED_ACTION_NONE, |
| 103 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? | 103 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? |
| 104 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); | 104 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); |
| 105 is_docked_ = false; | 105 is_docked_ = false; |
| 106 dock_layout_ = new_dock_layout; | 106 dock_layout_ = new_dock_layout; |
| 107 // The window's initial layout manager already knows that the drag is | 107 // The window's initial layout manager already knows that the drag is |
| 108 // in progress for this window. | 108 // in progress for this window. |
| 109 if (new_dock_layout != initial_dock_layout_) | 109 if (new_dock_layout != initial_dock_layout_) |
| 110 new_dock_layout->StartDragging(GetTarget()); | 110 new_dock_layout->StartDragging(GetAuraTarget()); |
| 111 } | 111 } |
| 112 // Window could get docked by the WorkspaceWindowResizer, update the state. | 112 // Window could get docked by the WorkspaceWindowResizer, update the state. |
| 113 is_docked_ = dock_layout_->is_dragged_window_docked(); | 113 is_docked_ = dock_layout_->is_dragged_window_docked(); |
| 114 // Whenever a window is dragged out of the dock it will be auto-sized | 114 // Whenever a window is dragged out of the dock it will be auto-sized |
| 115 // in the dock if it gets docked again. | 115 // in the dock if it gets docked again. |
| 116 if (!is_docked_) | 116 if (!is_docked_) |
| 117 was_bounds_changed_by_user_ = false; | 117 was_bounds_changed_by_user_ = false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void DockedWindowResizer::CompleteDrag() { | 120 void DockedWindowResizer::CompleteDrag() { |
| 121 // The root window can change when dragging into a different screen. | 121 // The root window can change when dragging into a different screen. |
| 122 next_window_resizer_->CompleteDrag(); | 122 next_window_resizer_->CompleteDrag(); |
| 123 FinishedDragging(aura::client::MOVE_SUCCESSFUL); | 123 FinishedDragging(aura::client::MOVE_SUCCESSFUL); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void DockedWindowResizer::RevertDrag() { | 126 void DockedWindowResizer::RevertDrag() { |
| 127 next_window_resizer_->RevertDrag(); | 127 next_window_resizer_->RevertDrag(); |
| 128 // Restore docked state to what it was before the drag if necessary. | 128 // Restore docked state to what it was before the drag if necessary. |
| 129 if (is_docked_ != was_docked_) { | 129 if (is_docked_ != was_docked_) { |
| 130 is_docked_ = was_docked_; | 130 is_docked_ = was_docked_; |
| 131 if (is_docked_) | 131 if (is_docked_) |
| 132 dock_layout_->DockDraggedWindow(GetTarget()); | 132 dock_layout_->DockDraggedWindow(GetAuraTarget()); |
| 133 else | 133 else |
| 134 dock_layout_->UndockDraggedWindow(); | 134 dock_layout_->UndockDraggedWindow(); |
| 135 } | 135 } |
| 136 FinishedDragging(aura::client::MOVE_CANCELED); | 136 FinishedDragging(aura::client::MOVE_CANCELED); |
| 137 } | 137 } |
| 138 | 138 |
| 139 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, | 139 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, |
| 140 wm::WindowState* window_state) | 140 wm::WindowState* window_state) |
| 141 : WindowResizer(window_state), | 141 : WindowResizer(window_state), |
| 142 next_window_resizer_(next_window_resizer), | 142 next_window_resizer_(next_window_resizer), |
| 143 dock_layout_(NULL), | 143 dock_layout_(NULL), |
| 144 initial_dock_layout_(NULL), | 144 initial_dock_layout_(NULL), |
| 145 did_move_or_resize_(false), | 145 did_move_or_resize_(false), |
| 146 was_docked_(false), | 146 was_docked_(false), |
| 147 is_docked_(false), | 147 is_docked_(false), |
| 148 was_bounds_changed_by_user_(window_state->bounds_changed_by_user()), | 148 was_bounds_changed_by_user_(window_state->bounds_changed_by_user()), |
| 149 weak_ptr_factory_(this) { | 149 weak_ptr_factory_(this) { |
| 150 DCHECK(details().is_resizable); | 150 DCHECK(details().is_resizable); |
| 151 aura::Window* dock_container = Shell::GetContainer( | 151 aura::Window* dock_container = Shell::GetContainer( |
| 152 GetTarget()->GetRootWindow(), | 152 GetAuraTarget()->GetRootWindow(), kShellWindowId_DockedContainer); |
| 153 kShellWindowId_DockedContainer); | |
| 154 dock_layout_ = static_cast<DockedWindowLayoutManager*>( | 153 dock_layout_ = static_cast<DockedWindowLayoutManager*>( |
| 155 dock_container->layout_manager()); | 154 dock_container->layout_manager()); |
| 156 initial_dock_layout_ = dock_layout_; | 155 initial_dock_layout_ = dock_layout_; |
| 157 was_docked_ = GetTarget()->parent() == dock_container; | 156 was_docked_ = GetAuraTarget()->parent() == dock_container; |
| 158 is_docked_ = was_docked_; | 157 is_docked_ = was_docked_; |
| 159 } | 158 } |
| 160 | 159 |
| 161 void DockedWindowResizer::MaybeSnapToEdge(const gfx::Rect& bounds, | 160 void DockedWindowResizer::MaybeSnapToEdge(const gfx::Rect& bounds, |
| 162 gfx::Point* offset) { | 161 gfx::Point* offset) { |
| 163 // Windows only snap magnetically when they were previously docked. | 162 // Windows only snap magnetically when they were previously docked. |
| 164 if (!was_docked_) | 163 if (!was_docked_) |
| 165 return; | 164 return; |
| 166 DockedAlignment dock_alignment = dock_layout_->CalculateAlignment(); | 165 DockedAlignment dock_alignment = dock_layout_->CalculateAlignment(); |
| 167 gfx::Rect dock_bounds = ScreenUtil::ConvertRectFromScreen( | 166 gfx::Rect dock_bounds = ScreenUtil::ConvertRectFromScreen( |
| 168 GetTarget()->parent(), | 167 GetAuraTarget()->parent(), |
| 169 dock_layout_->dock_container()->GetBoundsInScreen()); | 168 dock_layout_->dock_container()->GetBoundsInScreen()); |
| 170 | 169 |
| 171 // Short-range magnetism when retaining docked state. Same constant as in | 170 // Short-range magnetism when retaining docked state. Same constant as in |
| 172 // MagnetismMatcher is used for consistency. | 171 // MagnetismMatcher is used for consistency. |
| 173 const int kSnapToDockDistance = MagnetismMatcher::kMagneticDistance; | 172 const int kSnapToDockDistance = MagnetismMatcher::kMagneticDistance; |
| 174 | 173 |
| 175 if (dock_alignment == DOCKED_ALIGNMENT_LEFT || | 174 if (dock_alignment == DOCKED_ALIGNMENT_LEFT || |
| 176 dock_alignment == DOCKED_ALIGNMENT_NONE) { | 175 dock_alignment == DOCKED_ALIGNMENT_NONE) { |
| 177 const int distance = bounds.x() - dock_bounds.x(); | 176 const int distance = bounds.x() - dock_bounds.x(); |
| 178 if (distance < kSnapToDockDistance && distance > 0) { | 177 if (distance < kSnapToDockDistance && distance > 0) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 192 base::WeakPtr<DockedWindowResizer>& resizer) { | 191 base::WeakPtr<DockedWindowResizer>& resizer) { |
| 193 // During resizing the window width is preserved by DockedwindowLayoutManager. | 192 // During resizing the window width is preserved by DockedwindowLayoutManager. |
| 194 if (is_docked_ && | 193 if (is_docked_ && |
| 195 (details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { | 194 (details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { |
| 196 window_state_->set_bounds_changed_by_user(true); | 195 window_state_->set_bounds_changed_by_user(true); |
| 197 } | 196 } |
| 198 | 197 |
| 199 // Tell the dock layout manager that we are dragging this window. | 198 // Tell the dock layout manager that we are dragging this window. |
| 200 // At this point we are not yet animating the window as it may not be | 199 // At this point we are not yet animating the window as it may not be |
| 201 // inside the docked area. | 200 // inside the docked area. |
| 202 dock_layout_->StartDragging(GetTarget()); | 201 dock_layout_->StartDragging(GetAuraTarget()); |
| 203 if (!resizer) | 202 if (!resizer) |
| 204 return; | 203 return; |
| 205 // Reparent workspace windows during the drag to elevate them above workspace. | 204 // Reparent workspace windows during the drag to elevate them above workspace. |
| 206 // Other windows for which the DockedWindowResizer is instantiated include | 205 // Other windows for which the DockedWindowResizer is instantiated include |
| 207 // panels and windows that are already docked. Those do not need reparenting. | 206 // panels and windows that are already docked. Those do not need reparenting. |
| 208 if (GetTarget()->type() != ui::wm::WINDOW_TYPE_PANEL && | 207 if (GetAuraTarget()->type() != ui::wm::WINDOW_TYPE_PANEL && |
| 209 GetTarget()->parent()->id() == kShellWindowId_DefaultContainer) { | 208 GetAuraTarget()->parent()->id() == kShellWindowId_DefaultContainer) { |
| 210 // Reparent the window into the docked windows container in order to get it | 209 // Reparent the window into the docked windows container in order to get it |
| 211 // on top of other docked windows. | 210 // on top of other docked windows. |
| 212 aura::Window* docked_container = Shell::GetContainer( | 211 aura::Window* docked_container = Shell::GetContainer( |
| 213 GetTarget()->GetRootWindow(), | 212 GetAuraTarget()->GetRootWindow(), kShellWindowId_DockedContainer); |
| 214 kShellWindowId_DockedContainer); | |
| 215 ReparentChildWithTransientChildren( | 213 ReparentChildWithTransientChildren( |
| 216 ash::wm::WmWindowAura::Get(GetTarget()), | 214 ash::wm::WmWindowAura::Get(GetAuraTarget()), |
| 217 ash::wm::WmWindowAura::Get(GetTarget()->parent()), | 215 ash::wm::WmWindowAura::Get(GetAuraTarget()->parent()), |
| 218 ash::wm::WmWindowAura::Get(docked_container)); | 216 ash::wm::WmWindowAura::Get(docked_container)); |
| 219 if (!resizer) | 217 if (!resizer) |
| 220 return; | 218 return; |
| 221 } | 219 } |
| 222 if (is_docked_) | 220 if (is_docked_) |
| 223 dock_layout_->DockDraggedWindow(GetTarget()); | 221 dock_layout_->DockDraggedWindow(GetAuraTarget()); |
| 224 } | 222 } |
| 225 | 223 |
| 226 void DockedWindowResizer::FinishedDragging( | 224 void DockedWindowResizer::FinishedDragging( |
| 227 aura::client::WindowMoveResult move_result) { | 225 aura::client::WindowMoveResult move_result) { |
| 228 if (!did_move_or_resize_) | 226 if (!did_move_or_resize_) |
| 229 return; | 227 return; |
| 230 did_move_or_resize_ = false; | 228 did_move_or_resize_ = false; |
| 231 aura::Window* window = GetTarget(); | 229 aura::Window* window = GetAuraTarget(); |
| 232 const bool is_attached_panel = window->type() == ui::wm::WINDOW_TYPE_PANEL && | 230 const bool is_attached_panel = window->type() == ui::wm::WINDOW_TYPE_PANEL && |
| 233 window_state_->panel_attached(); | 231 window_state_->panel_attached(); |
| 234 const bool is_resized = | 232 const bool is_resized = |
| 235 (details().bounds_change & WindowResizer::kBoundsChange_Resizes) != 0; | 233 (details().bounds_change & WindowResizer::kBoundsChange_Resizes) != 0; |
| 236 | 234 |
| 237 // Undock the window if it is not in the normal, docked or minimized state | 235 // Undock the window if it is not in the normal, docked or minimized state |
| 238 // type. This happens if a user snaps or maximizes a window using a | 236 // type. This happens if a user snaps or maximizes a window using a |
| 239 // keyboard shortcut while it is being dragged. | 237 // keyboard shortcut while it is being dragged. |
| 240 if (!window_state_->IsMinimized() && !window_state_->IsDocked() && | 238 if (!window_state_->IsMinimized() && !window_state_->IsDocked() && |
| 241 !window_state_->IsNormalStateType()) | 239 !window_state_->IsNormalStateType()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 272 if (initial_dock_layout_ != dock_layout_) | 270 if (initial_dock_layout_ != dock_layout_) |
| 273 initial_dock_layout_->FinishDragging( | 271 initial_dock_layout_->FinishDragging( |
| 274 DOCKED_ACTION_NONE, | 272 DOCKED_ACTION_NONE, |
| 275 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? | 273 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? |
| 276 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); | 274 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); |
| 277 is_docked_ = false; | 275 is_docked_ = false; |
| 278 } | 276 } |
| 279 | 277 |
| 280 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( | 278 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( |
| 281 bool is_resized, bool is_attached_panel) { | 279 bool is_resized, bool is_attached_panel) { |
| 282 aura::Window* window = GetTarget(); | 280 aura::Window* window = GetAuraTarget(); |
| 283 | 281 |
| 284 // Check if the window needs to be docked or returned to workspace. | 282 // Check if the window needs to be docked or returned to workspace. |
| 285 DockedAction action = DOCKED_ACTION_NONE; | 283 DockedAction action = DOCKED_ACTION_NONE; |
| 286 aura::Window* dock_container = Shell::GetContainer( | 284 aura::Window* dock_container = Shell::GetContainer( |
| 287 window->GetRootWindow(), | 285 window->GetRootWindow(), |
| 288 kShellWindowId_DockedContainer); | 286 kShellWindowId_DockedContainer); |
| 289 if ((is_resized || !is_attached_panel) && | 287 if ((is_resized || !is_attached_panel) && |
| 290 is_docked_ != (window->parent() == dock_container)) { | 288 is_docked_ != (window->parent() == dock_container)) { |
| 291 if (is_docked_) { | 289 if (is_docked_) { |
| 292 wm::ReparentChildWithTransientChildren( | 290 wm::ReparentChildWithTransientChildren( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } else if (wm::GetWindowState(window)->IsDocked() && | 339 } else if (wm::GetWindowState(window)->IsDocked() && |
| 342 action == DOCKED_ACTION_UNDOCK) { | 340 action == DOCKED_ACTION_UNDOCK) { |
| 343 const wm::WMEvent event(wm::WM_EVENT_NORMAL); | 341 const wm::WMEvent event(wm::WM_EVENT_NORMAL); |
| 344 window_state_->OnWMEvent(&event); | 342 window_state_->OnWMEvent(&event); |
| 345 } | 343 } |
| 346 | 344 |
| 347 return action; | 345 return action; |
| 348 } | 346 } |
| 349 | 347 |
| 350 } // namespace ash | 348 } // namespace ash |
| OLD | NEW |