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/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_types.h" | 10 #include "ash/shelf/shelf_types.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 PanelWindowResizer::~PanelWindowResizer() { | 44 PanelWindowResizer::~PanelWindowResizer() { |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 PanelWindowResizer* | 48 PanelWindowResizer* |
49 PanelWindowResizer::Create(WindowResizer* next_window_resizer, | 49 PanelWindowResizer::Create(WindowResizer* next_window_resizer, |
50 aura::Window* window, | 50 wm::WindowState* window_state) { |
51 const gfx::Point& location, | 51 return new PanelWindowResizer(next_window_resizer, window_state); |
52 int window_component, | |
53 aura::client::WindowMoveSource source) { | |
54 Details details(window, location, window_component, source); | |
55 return details.is_resizable ? | |
56 new PanelWindowResizer(next_window_resizer, details) : NULL; | |
57 } | 52 } |
58 | 53 |
59 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 54 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
60 last_location_ = location; | 55 last_location_ = location; |
61 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); | 56 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); |
62 if (!did_move_or_resize_) { | 57 if (!did_move_or_resize_) { |
63 did_move_or_resize_ = true; | 58 did_move_or_resize_ = true; |
64 StartedDragging(); | 59 StartedDragging(); |
65 } | 60 } |
66 | 61 |
(...skipping 14 matching lines...) Expand all Loading... |
81 GetRootWindowForDisplayId(dst_display.id()); | 76 GetRootWindowForDisplayId(dst_display.id()); |
82 panel_container_ = Shell::GetContainer( | 77 panel_container_ = Shell::GetContainer( |
83 dst_root, internal::kShellWindowId_PanelContainer); | 78 dst_root, internal::kShellWindowId_PanelContainer); |
84 | 79 |
85 // The panel's parent already knows that the drag is in progress for this | 80 // The panel's parent already knows that the drag is in progress for this |
86 // panel. | 81 // panel. |
87 if (panel_container_ && GetTarget()->parent() != panel_container_) | 82 if (panel_container_ && GetTarget()->parent() != panel_container_) |
88 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); | 83 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); |
89 } | 84 } |
90 gfx::Point offset; | 85 gfx::Point offset; |
91 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); | 86 gfx::Rect bounds(CalculateBoundsForDrag(location)); |
92 should_attach_ = AttachToLauncher(bounds, &offset); | 87 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { |
| 88 window_state_->drag_details()->should_attach_to_shelf = |
| 89 AttachToLauncher(bounds, &offset); |
| 90 } |
93 gfx::Point modified_location(location.x() + offset.x(), | 91 gfx::Point modified_location(location.x() + offset.x(), |
94 location.y() + offset.y()); | 92 location.y() + offset.y()); |
95 | 93 |
96 base::WeakPtr<PanelWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); | 94 base::WeakPtr<PanelWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); |
97 next_window_resizer_->Drag(modified_location, event_flags); | 95 next_window_resizer_->Drag(modified_location, event_flags); |
98 if (!resizer) | 96 if (!resizer) |
99 return; | 97 return; |
100 | 98 |
101 if (should_attach_ && | 99 if (details().should_attach_to_shelf && |
102 !(details_.bounds_change & WindowResizer::kBoundsChange_Resizes)) { | 100 !(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { |
103 UpdateLauncherPosition(); | 101 UpdateLauncherPosition(); |
104 } | 102 } |
105 } | 103 } |
106 | 104 |
107 void PanelWindowResizer::CompleteDrag() { | 105 void PanelWindowResizer::CompleteDrag() { |
108 // The root window can change when dragging into a different screen. | 106 // The root window can change when dragging into a different screen. |
109 next_window_resizer_->CompleteDrag(); | 107 next_window_resizer_->CompleteDrag(); |
110 FinishDragging(); | 108 FinishDragging(); |
111 } | 109 } |
112 | 110 |
113 void PanelWindowResizer::RevertDrag() { | 111 void PanelWindowResizer::RevertDrag() { |
114 next_window_resizer_->RevertDrag(); | 112 next_window_resizer_->RevertDrag(); |
115 should_attach_ = was_attached_; | 113 window_state_->drag_details()->should_attach_to_shelf = was_attached_; |
116 FinishDragging(); | 114 FinishDragging(); |
117 } | 115 } |
118 | 116 |
119 aura::Window* PanelWindowResizer::GetTarget() { | |
120 return next_window_resizer_->GetTarget(); | |
121 } | |
122 | |
123 const gfx::Point& PanelWindowResizer::GetInitialLocation() const { | |
124 return details_.initial_location_in_parent; | |
125 } | |
126 | |
127 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, | 117 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, |
128 const Details& details) | 118 wm::WindowState* window_state) |
129 : details_(details), | 119 : WindowResizer(window_state), |
130 next_window_resizer_(next_window_resizer), | 120 next_window_resizer_(next_window_resizer), |
131 panel_container_(NULL), | 121 panel_container_(NULL), |
132 initial_panel_container_(NULL), | 122 initial_panel_container_(NULL), |
133 did_move_or_resize_(false), | 123 did_move_or_resize_(false), |
134 was_attached_(wm::GetWindowState(GetTarget())->panel_attached()), | 124 was_attached_(window_state->panel_attached()), |
135 should_attach_(was_attached_), | |
136 weak_ptr_factory_(this) { | 125 weak_ptr_factory_(this) { |
137 DCHECK(details_.is_resizable); | 126 DCHECK(details().is_resizable); |
138 panel_container_ = Shell::GetContainer( | 127 panel_container_ = Shell::GetContainer( |
139 details.window->GetRootWindow(), | 128 GetTarget()->GetRootWindow(), |
140 internal::kShellWindowId_PanelContainer); | 129 internal::kShellWindowId_PanelContainer); |
141 initial_panel_container_ = panel_container_; | 130 initial_panel_container_ = panel_container_; |
142 } | 131 } |
143 | 132 |
144 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, | 133 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, |
145 gfx::Point* offset) { | 134 gfx::Point* offset) { |
146 bool should_attach = false; | 135 bool should_attach = false; |
147 if (panel_container_) { | 136 if (panel_container_) { |
148 internal::PanelLayoutManager* panel_layout_manager = | 137 internal::PanelLayoutManager* panel_layout_manager = |
149 GetPanelLayoutManager(panel_container_); | 138 GetPanelLayoutManager(panel_container_); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return should_attach; | 174 return should_attach; |
186 } | 175 } |
187 | 176 |
188 void PanelWindowResizer::StartedDragging() { | 177 void PanelWindowResizer::StartedDragging() { |
189 // Tell the panel layout manager that we are dragging this panel before | 178 // Tell the panel layout manager that we are dragging this panel before |
190 // attaching it so that it does not get repositioned. | 179 // attaching it so that it does not get repositioned. |
191 if (panel_container_) | 180 if (panel_container_) |
192 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); | 181 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); |
193 if (!was_attached_) { | 182 if (!was_attached_) { |
194 // Attach the panel while dragging placing it in front of other panels. | 183 // Attach the panel while dragging placing it in front of other panels. |
195 wm::GetWindowState(GetTarget())->set_continue_drag_after_reparent(true); | 184 window_state_->set_continue_drag_after_reparent(true); |
196 wm::GetWindowState(GetTarget())->set_panel_attached(true); | 185 window_state_->set_panel_attached(true); |
197 // We use root window coordinates to ensure that during the drag the panel | 186 // We use root window coordinates to ensure that during the drag the panel |
198 // is reparented to a container in the root window that has that window. | 187 // is reparented to a container in the root window that has that window. |
199 aura::Window* target = GetTarget(); | 188 aura::Window* target = GetTarget(); |
200 aura::Window* target_root = target->GetRootWindow(); | 189 aura::Window* target_root = target->GetRootWindow(); |
201 aura::Window* old_parent = target->parent(); | 190 aura::Window* old_parent = target->parent(); |
202 aura::client::ParentWindowWithContext( | 191 aura::client::ParentWindowWithContext( |
203 target, target_root, target_root->GetBoundsInScreen()); | 192 target, target_root, target_root->GetBoundsInScreen()); |
204 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent()); | 193 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent()); |
205 } | 194 } |
206 } | 195 } |
207 | 196 |
208 void PanelWindowResizer::FinishDragging() { | 197 void PanelWindowResizer::FinishDragging() { |
209 if (!did_move_or_resize_) | 198 if (!did_move_or_resize_) |
210 return; | 199 return; |
211 if (details_.bounds_change & WindowResizer::kBoundsChange_Resizes) | 200 if (window_state_->panel_attached() != details().should_attach_to_shelf) { |
212 should_attach_ = was_attached_; | 201 window_state_->set_panel_attached(details().should_attach_to_shelf); |
213 if (wm::GetWindowState(GetTarget())->panel_attached() != should_attach_) { | |
214 wm::GetWindowState(GetTarget())->set_panel_attached(should_attach_); | |
215 // We use last known location to ensure that after the drag the panel | 202 // We use last known location to ensure that after the drag the panel |
216 // is reparented to a container in the root window that has that location. | 203 // is reparented to a container in the root window that has that location. |
217 aura::Window* target = GetTarget(); | 204 aura::Window* target = GetTarget(); |
218 aura::Window* target_root = target->GetRootWindow(); | 205 aura::Window* target_root = target->GetRootWindow(); |
219 aura::Window* old_parent = target->parent(); | 206 aura::Window* old_parent = target->parent(); |
220 aura::client::ParentWindowWithContext( | 207 aura::client::ParentWindowWithContext( |
221 target, target_root, gfx::Rect(last_location_, gfx::Size())); | 208 target, target_root, gfx::Rect(last_location_, gfx::Size())); |
222 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent()); | 209 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent()); |
223 } | 210 } |
224 | 211 |
225 // If we started the drag in one root window and moved into another root | 212 // If we started the drag in one root window and moved into another root |
226 // but then canceled the drag we may need to inform the original layout | 213 // but then canceled the drag we may need to inform the original layout |
227 // manager that the drag is finished. | 214 // manager that the drag is finished. |
228 if (initial_panel_container_ != panel_container_) | 215 if (initial_panel_container_ != panel_container_) |
229 GetPanelLayoutManager(initial_panel_container_)->FinishDragging(); | 216 GetPanelLayoutManager(initial_panel_container_)->FinishDragging(); |
230 if (panel_container_) | 217 if (panel_container_) |
231 GetPanelLayoutManager(panel_container_)->FinishDragging(); | 218 GetPanelLayoutManager(panel_container_)->FinishDragging(); |
232 } | 219 } |
233 | 220 |
234 void PanelWindowResizer::UpdateLauncherPosition() { | 221 void PanelWindowResizer::UpdateLauncherPosition() { |
235 if (panel_container_) { | 222 if (panel_container_) { |
236 GetPanelLayoutManager(panel_container_)->shelf()-> | 223 GetPanelLayoutManager(panel_container_)->shelf()-> |
237 UpdateIconPositionForWindow(GetTarget()); | 224 UpdateIconPositionForWindow(GetTarget()); |
238 } | 225 } |
239 } | 226 } |
240 | 227 |
241 } // namespace aura | 228 } // namespace aura |
OLD | NEW |