| 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/common/wm/dock/docked_window_resizer.h" | 5 #include "ash/common/wm/dock/docked_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/common/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 8 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 9 #include "ash/common/wm/window_parenting_utils.h" | 9 #include "ash/common/wm/window_parenting_utils.h" |
| 10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| 11 #include "ash/common/wm/wm_event.h" | 11 #include "ash/common/wm/wm_event.h" |
| 12 #include "ash/common/wm/wm_lookup.h" | |
| 13 #include "ash/common/wm/wm_root_window_controller.h" | |
| 14 #include "ash/common/wm/wm_window.h" | |
| 15 #include "ash/common/wm/workspace/magnetism_matcher.h" | 12 #include "ash/common/wm/workspace/magnetism_matcher.h" |
| 13 #include "ash/common/wm_lookup.h" |
| 14 #include "ash/common/wm_root_window_controller.h" |
| 15 #include "ash/common/wm_window.h" |
| 16 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
| 17 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
| 18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( | 24 DockedWindowLayoutManager* GetDockedLayoutManagerAtPoint( |
| 25 const gfx::Point& point) { | 25 const gfx::Point& point) { |
| 26 display::Display display = | 26 display::Display display = |
| 27 display::Screen::GetScreen()->GetDisplayNearestPoint(point); | 27 display::Screen::GetScreen()->GetDisplayNearestPoint(point); |
| 28 if (!display.bounds().Contains(point)) | 28 if (!display.bounds().Contains(point)) |
| 29 return nullptr; | 29 return nullptr; |
| 30 | 30 |
| 31 return DockedWindowLayoutManager::Get( | 31 return DockedWindowLayoutManager::Get( |
| 32 wm::WmLookup::Get() | 32 WmLookup::Get() |
| 33 ->GetRootWindowControllerWithDisplayId(display.id()) | 33 ->GetRootWindowControllerWithDisplayId(display.id()) |
| 34 ->GetWindow()); | 34 ->GetWindow()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 DockedWindowResizer::~DockedWindowResizer() {} | 39 DockedWindowResizer::~DockedWindowResizer() {} |
| 40 | 40 |
| 41 // static | 41 // static |
| 42 DockedWindowResizer* DockedWindowResizer::Create( | 42 DockedWindowResizer* DockedWindowResizer::Create( |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (!resizer) | 179 if (!resizer) |
| 180 return; | 180 return; |
| 181 // Reparent workspace windows during the drag to elevate them above workspace. | 181 // Reparent workspace windows during the drag to elevate them above workspace. |
| 182 // Other windows for which the DockedWindowResizer is instantiated include | 182 // Other windows for which the DockedWindowResizer is instantiated include |
| 183 // panels and windows that are already docked. Those do not need reparenting. | 183 // panels and windows that are already docked. Those do not need reparenting. |
| 184 if (GetTarget()->GetType() != ui::wm::WINDOW_TYPE_PANEL && | 184 if (GetTarget()->GetType() != ui::wm::WINDOW_TYPE_PANEL && |
| 185 GetTarget()->GetParent()->GetShellWindowId() == | 185 GetTarget()->GetParent()->GetShellWindowId() == |
| 186 kShellWindowId_DefaultContainer) { | 186 kShellWindowId_DefaultContainer) { |
| 187 // Reparent the window into the docked windows container in order to get it | 187 // Reparent the window into the docked windows container in order to get it |
| 188 // on top of other docked windows. | 188 // on top of other docked windows. |
| 189 wm::WmWindow* docked_container = | 189 WmWindow* docked_container = |
| 190 GetTarget()->GetRootWindow()->GetChildByShellWindowId( | 190 GetTarget()->GetRootWindow()->GetChildByShellWindowId( |
| 191 kShellWindowId_DockedContainer); | 191 kShellWindowId_DockedContainer); |
| 192 ReparentChildWithTransientChildren(GetTarget(), GetTarget()->GetParent(), | 192 wm::ReparentChildWithTransientChildren( |
| 193 docked_container); | 193 GetTarget(), GetTarget()->GetParent(), docked_container); |
| 194 if (!resizer) | 194 if (!resizer) |
| 195 return; | 195 return; |
| 196 } | 196 } |
| 197 if (is_docked_) | 197 if (is_docked_) |
| 198 dock_layout_->DockDraggedWindow(GetTarget()); | 198 dock_layout_->DockDraggedWindow(GetTarget()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void DockedWindowResizer::FinishedDragging( | 201 void DockedWindowResizer::FinishedDragging( |
| 202 aura::client::WindowMoveResult move_result) { | 202 aura::client::WindowMoveResult move_result) { |
| 203 if (!did_move_or_resize_) | 203 if (!did_move_or_resize_) |
| 204 return; | 204 return; |
| 205 did_move_or_resize_ = false; | 205 did_move_or_resize_ = false; |
| 206 wm::WmWindow* window = GetTarget(); | 206 WmWindow* window = GetTarget(); |
| 207 const bool is_attached_panel = | 207 const bool is_attached_panel = |
| 208 window->GetType() == ui::wm::WINDOW_TYPE_PANEL && | 208 window->GetType() == ui::wm::WINDOW_TYPE_PANEL && |
| 209 window_state_->panel_attached(); | 209 window_state_->panel_attached(); |
| 210 const bool is_resized = | 210 const bool is_resized = |
| 211 (details().bounds_change & WindowResizer::kBoundsChange_Resizes) != 0; | 211 (details().bounds_change & WindowResizer::kBoundsChange_Resizes) != 0; |
| 212 | 212 |
| 213 // Undock the window if it is not in the normal, docked or minimized state | 213 // Undock the window if it is not in the normal, docked or minimized state |
| 214 // type. This happens if a user snaps or maximizes a window using a | 214 // type. This happens if a user snaps or maximizes a window using a |
| 215 // keyboard shortcut while it is being dragged. | 215 // keyboard shortcut while it is being dragged. |
| 216 if (!window_state_->IsMinimized() && !window_state_->IsDocked() && | 216 if (!window_state_->IsMinimized() && !window_state_->IsDocked() && |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 DOCKED_ACTION_NONE, | 251 DOCKED_ACTION_NONE, |
| 252 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE | 252 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE |
| 253 ? DOCKED_ACTION_SOURCE_MOUSE | 253 ? DOCKED_ACTION_SOURCE_MOUSE |
| 254 : DOCKED_ACTION_SOURCE_TOUCH); | 254 : DOCKED_ACTION_SOURCE_TOUCH); |
| 255 is_docked_ = false; | 255 is_docked_ = false; |
| 256 } | 256 } |
| 257 | 257 |
| 258 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( | 258 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( |
| 259 bool is_resized, | 259 bool is_resized, |
| 260 bool is_attached_panel) { | 260 bool is_attached_panel) { |
| 261 wm::WmWindow* window = GetTarget(); | 261 WmWindow* window = GetTarget(); |
| 262 | 262 |
| 263 // Check if the window needs to be docked or returned to workspace. | 263 // Check if the window needs to be docked or returned to workspace. |
| 264 DockedAction action = DOCKED_ACTION_NONE; | 264 DockedAction action = DOCKED_ACTION_NONE; |
| 265 wm::WmWindow* dock_container = | 265 WmWindow* dock_container = window->GetRootWindow()->GetChildByShellWindowId( |
| 266 window->GetRootWindow()->GetChildByShellWindowId( | 266 kShellWindowId_DockedContainer); |
| 267 kShellWindowId_DockedContainer); | |
| 268 if ((is_resized || !is_attached_panel) && | 267 if ((is_resized || !is_attached_panel) && |
| 269 is_docked_ != (window->GetParent() == dock_container)) { | 268 is_docked_ != (window->GetParent() == dock_container)) { |
| 270 if (is_docked_) { | 269 if (is_docked_) { |
| 271 wm::ReparentChildWithTransientChildren(window, window->GetParent(), | 270 wm::ReparentChildWithTransientChildren(window, window->GetParent(), |
| 272 dock_container); | 271 dock_container); |
| 273 action = DOCKED_ACTION_DOCK; | 272 action = DOCKED_ACTION_DOCK; |
| 274 } else if (window->GetParent()->GetShellWindowId() == | 273 } else if (window->GetParent()->GetShellWindowId() == |
| 275 kShellWindowId_DockedContainer) { | 274 kShellWindowId_DockedContainer) { |
| 276 // Reparent the window back to workspace. | 275 // Reparent the window back to workspace. |
| 277 // We need to be careful to give ParentWindowWithContext a location in | 276 // We need to be careful to give ParentWindowWithContext a location in |
| 278 // the right root window (matching the logic in DragWindowResizer) based | 277 // the right root window (matching the logic in DragWindowResizer) based |
| 279 // on which root window a mouse pointer is in. We want to undock into the | 278 // on which root window a mouse pointer is in. We want to undock into the |
| 280 // right screen near the edge of a multiscreen setup (based on where the | 279 // right screen near the edge of a multiscreen setup (based on where the |
| 281 // mouse is). | 280 // mouse is). |
| 282 gfx::Rect near_last_location(last_location_, gfx::Size()); | 281 gfx::Rect near_last_location(last_location_, gfx::Size()); |
| 283 // Reparenting will cause Relayout and possible dock shrinking. | 282 // Reparenting will cause Relayout and possible dock shrinking. |
| 284 wm::WmWindow* previous_parent = window->GetParent(); | 283 WmWindow* previous_parent = window->GetParent(); |
| 285 window->SetParentUsingContext(window, near_last_location); | 284 window->SetParentUsingContext(window, near_last_location); |
| 286 if (window->GetParent() != previous_parent) { | 285 if (window->GetParent() != previous_parent) { |
| 287 wm::ReparentTransientChildrenOfChild(window, previous_parent, | 286 wm::ReparentTransientChildrenOfChild(window, previous_parent, |
| 288 window->GetParent()); | 287 window->GetParent()); |
| 289 } | 288 } |
| 290 action = was_docked_ ? DOCKED_ACTION_UNDOCK : DOCKED_ACTION_NONE; | 289 action = was_docked_ ? DOCKED_ACTION_UNDOCK : DOCKED_ACTION_NONE; |
| 291 } | 290 } |
| 292 } else { | 291 } else { |
| 293 // |action| is recorded in UMA and used to maintain |window_state_|. | 292 // |action| is recorded in UMA and used to maintain |window_state_|. |
| 294 if (is_resized && is_docked_ && was_docked_) | 293 if (is_resized && is_docked_ && was_docked_) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 317 } else if (window->GetWindowState()->IsDocked() && | 316 } else if (window->GetWindowState()->IsDocked() && |
| 318 action == DOCKED_ACTION_UNDOCK) { | 317 action == DOCKED_ACTION_UNDOCK) { |
| 319 const wm::WMEvent event(wm::WM_EVENT_NORMAL); | 318 const wm::WMEvent event(wm::WM_EVENT_NORMAL); |
| 320 window_state_->OnWMEvent(&event); | 319 window_state_->OnWMEvent(&event); |
| 321 } | 320 } |
| 322 | 321 |
| 323 return action; | 322 return action; |
| 324 } | 323 } |
| 325 | 324 |
| 326 } // namespace ash | 325 } // namespace ash |
| OLD | NEW |