| 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/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
| 8 #include "ash/wm/aura/wm_window_aura.h" | 8 #include "ash/wm/aura/wm_window_aura.h" |
| 9 #include "ash/wm/common/window_parenting_utils.h" | 9 #include "ash/wm/common/window_parenting_utils.h" |
| 10 #include "ash/wm/common/wm_event.h" | 10 #include "ash/wm/common/wm_event.h" |
| 11 #include "ash/wm/common/wm_root_window_controller.h" | 11 #include "ash/wm/common/wm_root_window_controller.h" |
| 12 #include "ash/wm/common/wm_window.h" | 12 #include "ash/wm/common/wm_window.h" |
| 13 #include "ash/wm/dock/docked_window_layout_manager.h" | 13 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 15 #include "ash/wm/workspace/magnetism_matcher.h" | 15 #include "ash/wm/workspace/magnetism_matcher.h" |
| 16 #include "ui/aura/window.h" | |
| 17 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
| 18 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
| 19 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 20 | 19 |
| 21 namespace ash { | 20 namespace ash { |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 DockedWindowLayoutManager* GetDockedLayoutManagerInRoot(wm::WmWindow* root) { | |
| 25 wm::WmWindow* dock_container = | |
| 26 root->GetChildByShellWindowId(kShellWindowId_DockedContainer); | |
| 27 return static_cast<DockedWindowLayoutManager*>( | |
| 28 wm::WmWindowAura::GetAuraWindow(dock_container)->layout_manager()); | |
| 29 } | |
| 30 | |
| 31 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( | 23 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( |
| 32 const gfx::Point& point) { | 24 const gfx::Point& point) { |
| 33 gfx::Display display = | 25 gfx::Display display = |
| 34 gfx::Screen::GetScreen()->GetDisplayNearestPoint(point); | 26 gfx::Screen::GetScreen()->GetDisplayNearestPoint(point); |
| 35 if (!display.bounds().Contains(point)) | 27 if (!display.bounds().Contains(point)) |
| 36 return nullptr; | 28 return nullptr; |
| 37 | 29 |
| 38 return GetDockedLayoutManagerInRoot( | 30 return DockedWindowLayoutManager::Get( |
| 39 wm::WmRootWindowController::GetWithDisplayId(display.id())->GetWindow()); | 31 wm::WmRootWindowController::GetWithDisplayId(display.id())->GetWindow()); |
| 40 } | 32 } |
| 41 | 33 |
| 42 } // namespace | 34 } // namespace |
| 43 | 35 |
| 44 DockedWindowResizer::~DockedWindowResizer() { | 36 DockedWindowResizer::~DockedWindowResizer() { |
| 45 } | 37 } |
| 46 | 38 |
| 47 // static | 39 // static |
| 48 DockedWindowResizer* | 40 DockedWindowResizer* |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (dock_layout_ != initial_dock_layout_) | 78 if (dock_layout_ != initial_dock_layout_) |
| 87 dock_layout_->FinishDragging( | 79 dock_layout_->FinishDragging( |
| 88 DOCKED_ACTION_NONE, | 80 DOCKED_ACTION_NONE, |
| 89 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? | 81 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? |
| 90 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); | 82 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); |
| 91 is_docked_ = false; | 83 is_docked_ = false; |
| 92 dock_layout_ = new_dock_layout; | 84 dock_layout_ = new_dock_layout; |
| 93 // The window's initial layout manager already knows that the drag is | 85 // The window's initial layout manager already knows that the drag is |
| 94 // in progress for this window. | 86 // in progress for this window. |
| 95 if (new_dock_layout != initial_dock_layout_) | 87 if (new_dock_layout != initial_dock_layout_) |
| 96 new_dock_layout->StartDragging(GetAuraTarget()); | 88 new_dock_layout->StartDragging(GetTarget()); |
| 97 } | 89 } |
| 98 // Window could get docked by the WorkspaceWindowResizer, update the state. | 90 // Window could get docked by the WorkspaceWindowResizer, update the state. |
| 99 is_docked_ = dock_layout_->is_dragged_window_docked(); | 91 is_docked_ = dock_layout_->is_dragged_window_docked(); |
| 100 // Whenever a window is dragged out of the dock it will be auto-sized | 92 // Whenever a window is dragged out of the dock it will be auto-sized |
| 101 // in the dock if it gets docked again. | 93 // in the dock if it gets docked again. |
| 102 if (!is_docked_) | 94 if (!is_docked_) |
| 103 was_bounds_changed_by_user_ = false; | 95 was_bounds_changed_by_user_ = false; |
| 104 } | 96 } |
| 105 | 97 |
| 106 void DockedWindowResizer::CompleteDrag() { | 98 void DockedWindowResizer::CompleteDrag() { |
| 107 // The root window can change when dragging into a different screen. | 99 // The root window can change when dragging into a different screen. |
| 108 next_window_resizer_->CompleteDrag(); | 100 next_window_resizer_->CompleteDrag(); |
| 109 FinishedDragging(aura::client::MOVE_SUCCESSFUL); | 101 FinishedDragging(aura::client::MOVE_SUCCESSFUL); |
| 110 } | 102 } |
| 111 | 103 |
| 112 void DockedWindowResizer::RevertDrag() { | 104 void DockedWindowResizer::RevertDrag() { |
| 113 next_window_resizer_->RevertDrag(); | 105 next_window_resizer_->RevertDrag(); |
| 114 // Restore docked state to what it was before the drag if necessary. | 106 // Restore docked state to what it was before the drag if necessary. |
| 115 if (is_docked_ != was_docked_) { | 107 if (is_docked_ != was_docked_) { |
| 116 is_docked_ = was_docked_; | 108 is_docked_ = was_docked_; |
| 117 if (is_docked_) | 109 if (is_docked_) |
| 118 dock_layout_->DockDraggedWindow(GetAuraTarget()); | 110 dock_layout_->DockDraggedWindow(GetTarget()); |
| 119 else | 111 else |
| 120 dock_layout_->UndockDraggedWindow(); | 112 dock_layout_->UndockDraggedWindow(); |
| 121 } | 113 } |
| 122 FinishedDragging(aura::client::MOVE_CANCELED); | 114 FinishedDragging(aura::client::MOVE_CANCELED); |
| 123 } | 115 } |
| 124 | 116 |
| 125 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, | 117 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, |
| 126 wm::WindowState* window_state) | 118 wm::WindowState* window_state) |
| 127 : WindowResizer(window_state), | 119 : WindowResizer(window_state), |
| 128 next_window_resizer_(next_window_resizer), | 120 next_window_resizer_(next_window_resizer), |
| 129 dock_layout_(NULL), | 121 dock_layout_(NULL), |
| 130 initial_dock_layout_(NULL), | 122 initial_dock_layout_(NULL), |
| 131 did_move_or_resize_(false), | 123 did_move_or_resize_(false), |
| 132 was_docked_(false), | 124 was_docked_(false), |
| 133 is_docked_(false), | 125 is_docked_(false), |
| 134 was_bounds_changed_by_user_(window_state->bounds_changed_by_user()), | 126 was_bounds_changed_by_user_(window_state->bounds_changed_by_user()), |
| 135 weak_ptr_factory_(this) { | 127 weak_ptr_factory_(this) { |
| 136 DCHECK(details().is_resizable); | 128 DCHECK(details().is_resizable); |
| 137 wm::WmWindow* dock_container = | 129 dock_layout_ = DockedWindowLayoutManager::Get(GetTarget()->GetRootWindow()); |
| 138 GetTarget()->GetRootWindow()->GetChildByShellWindowId( | |
| 139 kShellWindowId_DockedContainer); | |
| 140 dock_layout_ = GetDockedLayoutManagerInRoot(GetTarget()->GetRootWindow()); | |
| 141 initial_dock_layout_ = dock_layout_; | 130 initial_dock_layout_ = dock_layout_; |
| 142 was_docked_ = GetTarget()->GetParent() == dock_container; | 131 was_docked_ = GetTarget()->GetParent() == dock_layout_->dock_container(); |
| 143 is_docked_ = was_docked_; | 132 is_docked_ = was_docked_; |
| 144 } | 133 } |
| 145 | 134 |
| 146 void DockedWindowResizer::MaybeSnapToEdge(const gfx::Rect& bounds, | 135 void DockedWindowResizer::MaybeSnapToEdge(const gfx::Rect& bounds, |
| 147 gfx::Point* offset) { | 136 gfx::Point* offset) { |
| 148 // Windows only snap magnetically when they were previously docked. | 137 // Windows only snap magnetically when they were previously docked. |
| 149 if (!was_docked_) | 138 if (!was_docked_) |
| 150 return; | 139 return; |
| 151 DockedAlignment dock_alignment = dock_layout_->CalculateAlignment(); | 140 DockedAlignment dock_alignment = dock_layout_->CalculateAlignment(); |
| 152 gfx::Rect dock_bounds = GetTarget()->GetParent()->ConvertRectFromScreen( | 141 gfx::Rect dock_bounds = GetTarget()->GetParent()->ConvertRectFromScreen( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 176 base::WeakPtr<DockedWindowResizer>& resizer) { | 165 base::WeakPtr<DockedWindowResizer>& resizer) { |
| 177 // During resizing the window width is preserved by DockedwindowLayoutManager. | 166 // During resizing the window width is preserved by DockedwindowLayoutManager. |
| 178 if (is_docked_ && | 167 if (is_docked_ && |
| 179 (details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { | 168 (details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { |
| 180 window_state_->set_bounds_changed_by_user(true); | 169 window_state_->set_bounds_changed_by_user(true); |
| 181 } | 170 } |
| 182 | 171 |
| 183 // Tell the dock layout manager that we are dragging this window. | 172 // Tell the dock layout manager that we are dragging this window. |
| 184 // At this point we are not yet animating the window as it may not be | 173 // At this point we are not yet animating the window as it may not be |
| 185 // inside the docked area. | 174 // inside the docked area. |
| 186 dock_layout_->StartDragging(GetAuraTarget()); | 175 dock_layout_->StartDragging(GetTarget()); |
| 187 if (!resizer) | 176 if (!resizer) |
| 188 return; | 177 return; |
| 189 // Reparent workspace windows during the drag to elevate them above workspace. | 178 // Reparent workspace windows during the drag to elevate them above workspace. |
| 190 // Other windows for which the DockedWindowResizer is instantiated include | 179 // Other windows for which the DockedWindowResizer is instantiated include |
| 191 // panels and windows that are already docked. Those do not need reparenting. | 180 // panels and windows that are already docked. Those do not need reparenting. |
| 192 if (GetTarget()->GetType() != ui::wm::WINDOW_TYPE_PANEL && | 181 if (GetTarget()->GetType() != ui::wm::WINDOW_TYPE_PANEL && |
| 193 GetTarget()->GetParent()->GetShellWindowId() == | 182 GetTarget()->GetParent()->GetShellWindowId() == |
| 194 kShellWindowId_DefaultContainer) { | 183 kShellWindowId_DefaultContainer) { |
| 195 // Reparent the window into the docked windows container in order to get it | 184 // Reparent the window into the docked windows container in order to get it |
| 196 // on top of other docked windows. | 185 // on top of other docked windows. |
| 197 wm::WmWindow* docked_container = | 186 wm::WmWindow* docked_container = |
| 198 GetTarget()->GetRootWindow()->GetChildByShellWindowId( | 187 GetTarget()->GetRootWindow()->GetChildByShellWindowId( |
| 199 kShellWindowId_DockedContainer); | 188 kShellWindowId_DockedContainer); |
| 200 ReparentChildWithTransientChildren(GetTarget(), GetTarget()->GetParent(), | 189 ReparentChildWithTransientChildren(GetTarget(), GetTarget()->GetParent(), |
| 201 docked_container); | 190 docked_container); |
| 202 if (!resizer) | 191 if (!resizer) |
| 203 return; | 192 return; |
| 204 } | 193 } |
| 205 if (is_docked_) | 194 if (is_docked_) |
| 206 dock_layout_->DockDraggedWindow(GetAuraTarget()); | 195 dock_layout_->DockDraggedWindow(GetTarget()); |
| 207 } | 196 } |
| 208 | 197 |
| 209 void DockedWindowResizer::FinishedDragging( | 198 void DockedWindowResizer::FinishedDragging( |
| 210 aura::client::WindowMoveResult move_result) { | 199 aura::client::WindowMoveResult move_result) { |
| 211 if (!did_move_or_resize_) | 200 if (!did_move_or_resize_) |
| 212 return; | 201 return; |
| 213 did_move_or_resize_ = false; | 202 did_move_or_resize_ = false; |
| 214 wm::WmWindow* window = GetTarget(); | 203 wm::WmWindow* window = GetTarget(); |
| 215 const bool is_attached_panel = | 204 const bool is_attached_panel = |
| 216 window->GetType() == ui::wm::WINDOW_TYPE_PANEL && | 205 window->GetType() == ui::wm::WINDOW_TYPE_PANEL && |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } else if (window->GetWindowState()->IsDocked() && | 311 } else if (window->GetWindowState()->IsDocked() && |
| 323 action == DOCKED_ACTION_UNDOCK) { | 312 action == DOCKED_ACTION_UNDOCK) { |
| 324 const wm::WMEvent event(wm::WM_EVENT_NORMAL); | 313 const wm::WMEvent event(wm::WM_EVENT_NORMAL); |
| 325 window_state_->OnWMEvent(&event); | 314 window_state_->OnWMEvent(&event); |
| 326 } | 315 } |
| 327 | 316 |
| 328 return action; | 317 return action; |
| 329 } | 318 } |
| 330 | 319 |
| 331 } // namespace ash | 320 } // namespace ash |
| OLD | NEW |