| 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/common/dock/docked_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/wm/common/dock/docked_window_layout_manager.h" | 7 #include "ash/wm/common/dock/docked_window_layout_manager.h" |
| 8 #include "ash/wm/common/window_parenting_utils.h" | 8 #include "ash/wm/common/window_parenting_utils.h" |
| 9 #include "ash/wm/common/window_state.h" | 9 #include "ash/wm/common/window_state.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_shell_window_ids.h" | 12 #include "ash/wm/common/wm_shell_window_ids.h" |
| 13 #include "ash/wm/common/wm_window.h" | 13 #include "ash/wm/common/wm_window.h" |
| 14 #include "ash/wm/workspace/magnetism_matcher.h" | 14 #include "ash/wm/common/workspace/magnetism_matcher.h" |
| 15 #include "ui/base/hit_test.h" | 15 #include "ui/base/hit_test.h" |
| 16 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
| 17 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( | 22 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( |
| 23 const gfx::Point& point) { | 23 const gfx::Point& point) { |
| 24 display::Display display = | 24 display::Display display = |
| 25 display::Screen::GetScreen()->GetDisplayNearestPoint(point); | 25 display::Screen::GetScreen()->GetDisplayNearestPoint(point); |
| 26 if (!display.bounds().Contains(point)) | 26 if (!display.bounds().Contains(point)) |
| 27 return nullptr; | 27 return nullptr; |
| 28 | 28 |
| 29 return DockedWindowLayoutManager::Get( | 29 return DockedWindowLayoutManager::Get( |
| 30 wm::WmRootWindowController::GetWithDisplayId(display.id())->GetWindow()); | 30 wm::WmRootWindowController::GetWithDisplayId(display.id())->GetWindow()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 DockedWindowResizer::~DockedWindowResizer() { | 35 DockedWindowResizer::~DockedWindowResizer() {} |
| 36 } | |
| 37 | 36 |
| 38 // static | 37 // static |
| 39 DockedWindowResizer* | 38 DockedWindowResizer* DockedWindowResizer::Create( |
| 40 DockedWindowResizer::Create(WindowResizer* next_window_resizer, | 39 WindowResizer* next_window_resizer, |
| 41 wm::WindowState* window_state) { | 40 wm::WindowState* window_state) { |
| 42 return new DockedWindowResizer(next_window_resizer, window_state); | 41 return new DockedWindowResizer(next_window_resizer, window_state); |
| 43 } | 42 } |
| 44 | 43 |
| 45 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 44 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
| 46 last_location_ = GetTarget()->GetParent()->ConvertPointToScreen(location); | 45 last_location_ = GetTarget()->GetParent()->ConvertPointToScreen(location); |
| 47 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); | 46 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
| 48 | 47 |
| 49 if (!did_move_or_resize_) { | 48 if (!did_move_or_resize_) { |
| 50 did_move_or_resize_ = true; | 49 did_move_or_resize_ = true; |
| 51 StartedDragging(resizer); | 50 StartedDragging(resizer); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 70 // container is the current parent of the window it will be informed of | 69 // container is the current parent of the window it will be informed of |
| 71 // the end of drag when the window is reparented, otherwise let the | 70 // the end of drag when the window is reparented, otherwise let the |
| 72 // previous container know the drag is complete. If we told the | 71 // previous container know the drag is complete. If we told the |
| 73 // window's parent that the drag was complete it would begin | 72 // window's parent that the drag was complete it would begin |
| 74 // positioning the window. | 73 // positioning the window. |
| 75 if (is_docked_ && dock_layout_->is_dragged_window_docked()) | 74 if (is_docked_ && dock_layout_->is_dragged_window_docked()) |
| 76 dock_layout_->UndockDraggedWindow(); | 75 dock_layout_->UndockDraggedWindow(); |
| 77 if (dock_layout_ != initial_dock_layout_) | 76 if (dock_layout_ != initial_dock_layout_) |
| 78 dock_layout_->FinishDragging( | 77 dock_layout_->FinishDragging( |
| 79 DOCKED_ACTION_NONE, | 78 DOCKED_ACTION_NONE, |
| 80 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? | 79 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE |
| 81 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); | 80 ? DOCKED_ACTION_SOURCE_MOUSE |
| 81 : DOCKED_ACTION_SOURCE_TOUCH); |
| 82 is_docked_ = false; | 82 is_docked_ = false; |
| 83 dock_layout_ = new_dock_layout; | 83 dock_layout_ = new_dock_layout; |
| 84 // The window's initial layout manager already knows that the drag is | 84 // The window's initial layout manager already knows that the drag is |
| 85 // in progress for this window. | 85 // in progress for this window. |
| 86 if (new_dock_layout != initial_dock_layout_) | 86 if (new_dock_layout != initial_dock_layout_) |
| 87 new_dock_layout->StartDragging(GetTarget()); | 87 new_dock_layout->StartDragging(GetTarget()); |
| 88 } | 88 } |
| 89 // Window could get docked by the WorkspaceWindowResizer, update the state. | 89 // Window could get docked by the WorkspaceWindowResizer, update the state. |
| 90 is_docked_ = dock_layout_->is_dragged_window_docked(); | 90 is_docked_ = dock_layout_->is_dragged_window_docked(); |
| 91 // Whenever a window is dragged out of the dock it will be auto-sized | 91 // Whenever a window is dragged out of the dock it will be auto-sized |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 224 } |
| 225 // If a window has restore bounds, update the restore origin but not the size. | 225 // If a window has restore bounds, update the restore origin but not the size. |
| 226 // The size gets restored when a window is undocked. | 226 // The size gets restored when a window is undocked. |
| 227 if (is_resized && is_docked_ && window_state_->HasRestoreBounds()) { | 227 if (is_resized && is_docked_ && window_state_->HasRestoreBounds()) { |
| 228 gfx::Rect restore_bounds = window->GetBoundsInScreen(); | 228 gfx::Rect restore_bounds = window->GetBoundsInScreen(); |
| 229 restore_bounds.set_size(window_state_->GetRestoreBoundsInScreen().size()); | 229 restore_bounds.set_size(window_state_->GetRestoreBoundsInScreen().size()); |
| 230 window_state_->SetRestoreBoundsInScreen(restore_bounds); | 230 window_state_->SetRestoreBoundsInScreen(restore_bounds); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Check if the window needs to be docked or returned to workspace. | 233 // Check if the window needs to be docked or returned to workspace. |
| 234 DockedAction action = MaybeReparentWindowOnDragCompletion(is_resized, | 234 DockedAction action = |
| 235 is_attached_panel); | 235 MaybeReparentWindowOnDragCompletion(is_resized, is_attached_panel); |
| 236 dock_layout_->FinishDragging( | 236 dock_layout_->FinishDragging( |
| 237 move_result == aura::client::MOVE_CANCELED ? DOCKED_ACTION_NONE : action, | 237 move_result == aura::client::MOVE_CANCELED ? DOCKED_ACTION_NONE : action, |
| 238 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? | 238 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE |
| 239 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); | 239 ? DOCKED_ACTION_SOURCE_MOUSE |
| 240 : DOCKED_ACTION_SOURCE_TOUCH); |
| 240 | 241 |
| 241 // If we started the drag in one root window and moved into another root | 242 // If we started the drag in one root window and moved into another root |
| 242 // but then canceled the drag we may need to inform the original layout | 243 // but then canceled the drag we may need to inform the original layout |
| 243 // manager that the drag is finished. | 244 // manager that the drag is finished. |
| 244 if (initial_dock_layout_ != dock_layout_) | 245 if (initial_dock_layout_ != dock_layout_) |
| 245 initial_dock_layout_->FinishDragging( | 246 initial_dock_layout_->FinishDragging( |
| 246 DOCKED_ACTION_NONE, | 247 DOCKED_ACTION_NONE, |
| 247 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? | 248 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE |
| 248 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); | 249 ? DOCKED_ACTION_SOURCE_MOUSE |
| 250 : DOCKED_ACTION_SOURCE_TOUCH); |
| 249 is_docked_ = false; | 251 is_docked_ = false; |
| 250 } | 252 } |
| 251 | 253 |
| 252 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( | 254 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( |
| 253 bool is_resized, bool is_attached_panel) { | 255 bool is_resized, |
| 256 bool is_attached_panel) { |
| 254 wm::WmWindow* window = GetTarget(); | 257 wm::WmWindow* window = GetTarget(); |
| 255 | 258 |
| 256 // Check if the window needs to be docked or returned to workspace. | 259 // Check if the window needs to be docked or returned to workspace. |
| 257 DockedAction action = DOCKED_ACTION_NONE; | 260 DockedAction action = DOCKED_ACTION_NONE; |
| 258 wm::WmWindow* dock_container = | 261 wm::WmWindow* dock_container = |
| 259 window->GetRootWindow()->GetChildByShellWindowId( | 262 window->GetRootWindow()->GetChildByShellWindowId( |
| 260 kShellWindowId_DockedContainer); | 263 kShellWindowId_DockedContainer); |
| 261 if ((is_resized || !is_attached_panel) && | 264 if ((is_resized || !is_attached_panel) && |
| 262 is_docked_ != (window->GetParent() == dock_container)) { | 265 is_docked_ != (window->GetParent() == dock_container)) { |
| 263 if (is_docked_) { | 266 if (is_docked_) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } else if (window->GetWindowState()->IsDocked() && | 313 } else if (window->GetWindowState()->IsDocked() && |
| 311 action == DOCKED_ACTION_UNDOCK) { | 314 action == DOCKED_ACTION_UNDOCK) { |
| 312 const wm::WMEvent event(wm::WM_EVENT_NORMAL); | 315 const wm::WMEvent event(wm::WM_EVENT_NORMAL); |
| 313 window_state_->OnWMEvent(&event); | 316 window_state_->OnWMEvent(&event); |
| 314 } | 317 } |
| 315 | 318 |
| 316 return action; | 319 return action; |
| 317 } | 320 } |
| 318 | 321 |
| 319 } // namespace ash | 322 } // namespace ash |
| OLD | NEW |