| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/panels/panel_window_resizer.h" | 5 #include "ash/wm/panels/panel_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_types.h" | 9 #include "ash/shelf/shelf_types.h" |
| 10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/wm/panels/panel_layout_manager.h" | 13 #include "ash/wm/panels/panel_layout_manager.h" |
| 14 #include "ash/wm/property_util.h" | 14 #include "ash/wm/property_util.h" |
| 15 #include "ash/wm/toplevel_window_event_handler.h" |
| 15 #include "ash/wm/window_properties.h" | 16 #include "ash/wm/window_properties.h" |
| 17 #include "ash/wm/window_resizer_owner.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
| 18 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
| 19 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
| 21 #include "ui/base/hit_test.h" | 23 #include "ui/base/hit_test.h" |
| 22 #include "ui/base/ui_base_types.h" | 24 #include "ui/base/ui_base_types.h" |
| 23 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
| 24 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 25 | 27 |
| 26 namespace ash { | 28 namespace ash { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 const int kPanelSnapToLauncherDistance = 30; | 31 const int kPanelSnapToLauncherDistance = 30; |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 PanelWindowResizer::~PanelWindowResizer() { | 34 PanelWindowResizer::~PanelWindowResizer() { |
| 33 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); | 35 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); |
| 34 } | 36 } |
| 35 | 37 |
| 36 // static | 38 // static |
| 37 PanelWindowResizer* | 39 PanelWindowResizer* |
| 38 PanelWindowResizer::Create(aura::Window* window, | 40 PanelWindowResizer::Create(WindowResizerOwner* owner, |
| 39 const gfx::Point& location, | 41 aura::Window* window, |
| 40 int window_component) { | 42 const gfx::Point& location, |
| 43 int window_component) { |
| 41 Details details(window, location, window_component); | 44 Details details(window, location, window_component); |
| 42 return details.is_resizable ? new PanelWindowResizer(details) : NULL; | 45 return details.is_resizable ? new PanelWindowResizer(owner, details) : NULL; |
| 43 } | 46 } |
| 44 | 47 |
| 45 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 48 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
| 46 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); | 49 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); |
| 47 if (bounds != details_.window->bounds()) { | 50 if (bounds != details_.window->bounds()) { |
| 48 if (!did_move_or_resize_) { | 51 if (!did_move_or_resize_) { |
| 49 if (!details_.restore_bounds.IsEmpty()) | 52 if (!details_.restore_bounds.IsEmpty()) |
| 50 ClearRestoreBounds(details_.window); | 53 ClearRestoreBounds(details_.window); |
| 51 StartedDragging(); | 54 StartedDragging(); |
| 52 } | 55 } |
| 53 did_move_or_resize_ = true; | 56 did_move_or_resize_ = true; |
| 54 should_attach_ = AttachToLauncher(&bounds); | 57 should_attach_ = AttachToLauncher(&bounds); |
| 55 details_.window->SetBounds(bounds); | 58 details_.window->SetBounds(bounds); |
| 56 } | 59 } |
| 57 } | 60 } |
| 58 | 61 |
| 59 void PanelWindowResizer::CompleteDrag(int event_flags) { | 62 void PanelWindowResizer::CompleteDrag(int event_flags) { |
| 60 if (should_attach_ != was_attached_) { | 63 if (details_.window->GetProperty(internal::kPanelAttachedKey) != |
| 64 should_attach_) { |
| 61 details_.window->SetProperty(internal::kPanelAttachedKey, should_attach_); | 65 details_.window->SetProperty(internal::kPanelAttachedKey, should_attach_); |
| 62 details_.window->SetDefaultParentByRootWindow( | 66 details_.window->SetDefaultParentByRootWindow( |
| 63 details_.window->GetRootWindow(), | 67 details_.window->GetRootWindow(), |
| 64 details_.window->bounds()); | 68 details_.window->bounds()); |
| 65 } | 69 } |
| 66 FinishDragging(); | 70 FinishDragging(); |
| 67 } | 71 } |
| 68 | 72 |
| 69 void PanelWindowResizer::RevertDrag() { | 73 void PanelWindowResizer::RevertDrag() { |
| 70 if (!did_move_or_resize_) | 74 if (!did_move_or_resize_) |
| 71 return; | 75 return; |
| 72 | 76 |
| 73 details_.window->SetBounds(details_.initial_bounds_in_parent); | 77 details_.window->SetBounds(details_.initial_bounds_in_parent); |
| 74 | 78 |
| 75 if (!details_.restore_bounds.IsEmpty()) | 79 if (!details_.restore_bounds.IsEmpty()) |
| 76 SetRestoreBoundsInScreen(details_.window, details_.restore_bounds); | 80 SetRestoreBoundsInScreen(details_.window, details_.restore_bounds); |
| 77 FinishDragging(); | 81 FinishDragging(); |
| 78 } | 82 } |
| 79 | 83 |
| 80 aura::Window* PanelWindowResizer::GetTarget() { | 84 aura::Window* PanelWindowResizer::GetTarget() { |
| 81 return details_.window; | 85 return details_.window; |
| 82 } | 86 } |
| 83 | 87 |
| 84 PanelWindowResizer::PanelWindowResizer(const Details& details) | 88 PanelWindowResizer::PanelWindowResizer(WindowResizerOwner* owner, |
| 85 : details_(details), | 89 const Details& details) |
| 90 : owner_(owner), |
| 91 details_(details), |
| 86 panel_container_(NULL), | 92 panel_container_(NULL), |
| 87 panel_layout_manager_(NULL), | 93 panel_layout_manager_(NULL), |
| 88 did_move_or_resize_(false), | 94 did_move_or_resize_(false), |
| 89 was_attached_(details_.window->GetProperty(internal::kPanelAttachedKey)), | 95 was_attached_(details_.window->GetProperty(internal::kPanelAttachedKey)), |
| 90 should_attach_(was_attached_) { | 96 should_attach_(was_attached_) { |
| 91 DCHECK(details_.is_resizable); | 97 DCHECK(details_.is_resizable); |
| 92 ash::internal::RootWindowController* root_window_controller = | 98 ash::internal::RootWindowController* root_window_controller = |
| 93 GetRootWindowController(details.window->GetRootWindow()); | 99 GetRootWindowController(details.window->GetRootWindow()); |
| 94 panel_container_ = root_window_controller->GetContainer( | 100 panel_container_ = root_window_controller->GetContainer( |
| 95 internal::kShellWindowId_PanelContainer); | 101 internal::kShellWindowId_PanelContainer); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 should_attach = true; | 139 should_attach = true; |
| 134 bounds->set_y(launcher_bounds.bottom()); | 140 bounds->set_y(launcher_bounds.bottom()); |
| 135 } | 141 } |
| 136 break; | 142 break; |
| 137 } | 143 } |
| 138 } | 144 } |
| 139 return should_attach; | 145 return should_attach; |
| 140 } | 146 } |
| 141 | 147 |
| 142 void PanelWindowResizer::StartedDragging() { | 148 void PanelWindowResizer::StartedDragging() { |
| 143 if (was_attached_) | 149 // Tell the panel layout manager that we are dragging this panel before |
| 144 panel_layout_manager_->StartDragging(details_.window); | 150 // attaching it so that it does not get repositioned. |
| 151 panel_layout_manager_->StartDragging(details_.window); |
| 152 if (!was_attached_) { |
| 153 // Attach the panel while dragging placing it in front of other panels. |
| 154 details_.window->SetProperty(internal::kPanelAttachedKey, true); |
| 155 details_.window->SetDefaultParentByRootWindow( |
| 156 details_.window->GetRootWindow(), |
| 157 details_.window->bounds()); |
| 158 |
| 159 if (owner_) { |
| 160 ash::internal::RootWindowController* root_window_controller = |
| 161 GetRootWindowController(details_.window->GetRootWindow()); |
| 162 WindowResizerOwner* new_owner = |
| 163 root_window_controller->panel_container_handler(); |
| 164 owner_->PassResizer(new_owner); |
| 165 owner_ = new_owner; |
| 166 } |
| 167 } |
| 145 } | 168 } |
| 146 | 169 |
| 147 void PanelWindowResizer::FinishDragging() { | 170 void PanelWindowResizer::FinishDragging() { |
| 148 if (was_attached_) | 171 panel_layout_manager_->FinishDragging(); |
| 149 panel_layout_manager_->FinishDragging(); | |
| 150 } | 172 } |
| 151 | 173 |
| 152 } // namespace aura | 174 } // namespace aura |
| OLD | NEW |