Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/wm/dock/dock_window_resizer.h" | |
| 6 | |
| 7 #include "ash/display/display_controller.h" | |
| 8 #include "ash/launcher/launcher.h" | |
| 9 #include "ash/root_window_controller.h" | |
| 10 #include "ash/screen_ash.h" | |
| 11 #include "ash/shelf/shelf_types.h" | |
| 12 #include "ash/shelf/shelf_widget.h" | |
| 13 #include "ash/shell.h" | |
| 14 #include "ash/shell_window_ids.h" | |
| 15 #include "ash/wm/coordinate_conversion.h" | |
| 16 #include "ash/wm/dock/dock_layout_manager.h" | |
| 17 #include "ash/wm/property_util.h" | |
| 18 #include "ash/wm/window_properties.h" | |
| 19 #include "ash/wm/workspace_controller.h" | |
| 20 #include "ui/aura/client/aura_constants.h" | |
| 21 #include "ui/aura/env.h" | |
| 22 #include "ui/aura/root_window.h" | |
| 23 #include "ui/aura/window.h" | |
| 24 #include "ui/aura/window_delegate.h" | |
| 25 #include "ui/base/hit_test.h" | |
| 26 #include "ui/base/ui_base_types.h" | |
| 27 #include "ui/gfx/screen.h" | |
| 28 #include "ui/views/widget/widget.h" | |
| 29 | |
| 30 namespace ash { | |
| 31 | |
| 32 DockWindowResizer::~DockWindowResizer() { | |
| 33 } | |
| 34 | |
| 35 // static | |
| 36 DockWindowResizer* | |
| 37 DockWindowResizer::Create(WindowResizer* next_window_resizer, | |
| 38 aura::Window* window, | |
| 39 const gfx::Point& location, | |
| 40 int window_component) { | |
| 41 Details details(window, location, window_component); | |
| 42 return details.is_resizable ? | |
| 43 new DockWindowResizer(next_window_resizer, details) : NULL; | |
| 44 } | |
| 45 | |
| 46 void DockWindowResizer::Drag(const gfx::Point& location, int event_flags) { | |
| 47 last_mouse_location_ = location; | |
| 48 wm::ConvertPointToScreen(GetTarget()->parent(), &last_mouse_location_); | |
| 49 if (!did_move_or_resize_) { | |
| 50 did_move_or_resize_ = true; | |
| 51 StartedDragging(); | |
| 52 } | |
| 53 next_window_resizer_->Drag(location, event_flags); | |
| 54 } | |
| 55 | |
| 56 void DockWindowResizer::CompleteDrag(int event_flags) { | |
| 57 // The root window can change when dragging into a different screen. | |
| 58 next_window_resizer_->CompleteDrag(event_flags); | |
| 59 FinishDragging(); | |
| 60 } | |
| 61 | |
| 62 void DockWindowResizer::RevertDrag() { | |
| 63 next_window_resizer_->RevertDrag(); | |
| 64 FinishDragging(); | |
| 65 } | |
| 66 | |
| 67 aura::Window* DockWindowResizer::GetTarget() { | |
| 68 return next_window_resizer_->GetTarget(); | |
| 69 } | |
| 70 | |
| 71 DockWindowResizer::DockWindowResizer(WindowResizer* next_window_resizer, | |
| 72 const Details& details) | |
| 73 : details_(details), | |
| 74 next_window_resizer_(next_window_resizer), | |
| 75 dock_layout_(NULL), | |
| 76 was_docked_(false), | |
| 77 did_move_or_resize_(false) { | |
| 78 DCHECK(details_.is_resizable); | |
| 79 root_window_ = details.window->GetRootWindow(); | |
| 80 aura::Window* dock_container = Shell::GetContainer( | |
| 81 details.window->GetRootWindow(), | |
| 82 internal::kShellWindowId_DockContainer); | |
| 83 DCHECK(dock_container->id() == internal::kShellWindowId_DockContainer); | |
| 84 dock_layout_ = static_cast<internal::DockLayoutManager*>( | |
| 85 dock_container->layout_manager()); | |
| 86 } | |
| 87 | |
| 88 void DockWindowResizer::StartedDragging() { | |
| 89 // Tell the dock layout manager that we are dragging this window. | |
| 90 was_docked_ = IsWindowDocked(GetTarget()); | |
| 91 dock_layout_->StartDragging(GetTarget()); | |
| 92 } | |
| 93 | |
| 94 void DockWindowResizer::FinishDragging() { | |
| 95 if (!did_move_or_resize_) | |
| 96 return; | |
| 97 | |
| 98 aura::Window* window = GetTarget(); | |
| 99 if (was_docked_ && | |
| 100 !IsWindowDocked(window) && | |
| 101 window->parent()->id() == internal::kShellWindowId_DockContainer) { | |
| 102 // Reparent the window back to workspace. | |
| 103 // We need to be careful to give SetDefaultParentByRootWindow location in | |
| 104 // the right root window (matching the logic in DragWindowResizer) based on | |
| 105 // which root window a mouse pointer is in. We want to undock into the right | |
| 106 // screen near the edge of a multiscreen setup (based on where the mouse is) | |
| 107 gfx::Rect near_last_mouse_location(last_mouse_location_, gfx::Size()); | |
| 108 // Reparenting will cause Relayout and possible dock shrinking. | |
| 109 window->SetDefaultParentByRootWindow(root_window_, | |
| 110 near_last_mouse_location); | |
| 111 // A maximized workspace may be active so we may need to switch | |
| 112 // to a parent workspace of the window being dragged out. | |
| 113 internal::WorkspaceController* workspace_controller = | |
| 114 GetRootWindowController( | |
| 115 window->GetRootWindow())->workspace_controller(); | |
| 116 workspace_controller->SetActiveWorkspaceByWindow(window); | |
|
Jun Mukai
2013/06/10 20:40:57
This SetActiveworkspaceByWindow may not be necessa
varkha
2013/06/10 21:09:47
Thanks, It will probably be unnecessary once your
| |
| 117 } | |
| 118 dock_layout_->FinishDragging(); | |
| 119 } | |
| 120 | |
| 121 } // namespace aura | |
| OLD | NEW |