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/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
10 #include "ash/shelf/shelf_types.h" | 10 #include "ash/shelf/shelf_types.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 | 58 |
59 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 59 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
60 last_location_ = location; | 60 last_location_ = location; |
61 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); | 61 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); |
62 bool destroyed = false; | 62 bool destroyed = false; |
63 if (!did_move_or_resize_) { | 63 if (!did_move_or_resize_) { |
64 did_move_or_resize_ = true; | 64 did_move_or_resize_ = true; |
65 StartedDragging(); | 65 StartedDragging(); |
66 } | 66 } |
67 gfx::Point location_in_screen = location; | |
68 wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen); | |
69 | 67 |
70 // Check if the destination has changed displays. | 68 // Check if the destination has changed displays. |
71 gfx::Screen* screen = Shell::GetScreen(); | 69 gfx::Screen* screen = Shell::GetScreen(); |
72 const gfx::Display dst_display = | 70 const gfx::Display dst_display = |
73 screen->GetDisplayNearestPoint(location_in_screen); | 71 screen->GetDisplayNearestPoint(last_location_); |
74 if (dst_display.id() != | 72 if (dst_display.id() != |
75 screen->GetDisplayNearestWindow(panel_container_->GetRootWindow()).id()) { | 73 screen->GetDisplayNearestWindow(panel_container_->GetRootWindow()).id()) { |
76 // The panel is being dragged to a new display. If the previous container is | 74 // The panel is being dragged to a new display. If the previous container is |
77 // the current parent of the panel it will be informed of the end of drag | 75 // the current parent of the panel it will be informed of the end of drag |
78 // when the panel is reparented, otherwise let the previous container know | 76 // when the panel is reparented, otherwise let the previous container know |
79 // the drag is complete. If we told the panel's parent that the drag was | 77 // the drag is complete. If we told the panel's parent that the drag was |
80 // complete it would begin positioning the panel. | 78 // complete it would begin positioning the panel. |
81 if (GetTarget()->parent() != panel_container_) | 79 if (GetTarget()->parent() != panel_container_) |
82 GetPanelLayoutManager(panel_container_)->FinishDragging(); | 80 GetPanelLayoutManager(panel_container_)->FinishDragging(); |
83 aura::RootWindow* dst_root = Shell::GetInstance()->display_controller()-> | 81 aura::RootWindow* dst_root = Shell::GetInstance()->display_controller()-> |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 189 |
192 void PanelWindowResizer::StartedDragging() { | 190 void PanelWindowResizer::StartedDragging() { |
193 // Tell the panel layout manager that we are dragging this panel before | 191 // Tell the panel layout manager that we are dragging this panel before |
194 // attaching it so that it does not get repositioned. | 192 // attaching it so that it does not get repositioned. |
195 if (panel_container_) | 193 if (panel_container_) |
196 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); | 194 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); |
197 if (!was_attached_) { | 195 if (!was_attached_) { |
198 // Attach the panel while dragging placing it in front of other panels. | 196 // Attach the panel while dragging placing it in front of other panels. |
199 GetTarget()->SetProperty(internal::kContinueDragAfterReparent, true); | 197 GetTarget()->SetProperty(internal::kContinueDragAfterReparent, true); |
200 GetTarget()->SetProperty(internal::kPanelAttachedKey, true); | 198 GetTarget()->SetProperty(internal::kPanelAttachedKey, true); |
| 199 // We use root window coordinates to ensure that during the drag the panel |
| 200 // is reparented to a container in the root window that has that window. |
201 GetTarget()->SetDefaultParentByRootWindow( | 201 GetTarget()->SetDefaultParentByRootWindow( |
202 GetTarget()->GetRootWindow(), | 202 GetTarget()->GetRootWindow(), |
203 GetTarget()->GetBoundsInScreen()); | 203 GetTarget()->GetRootWindow()->GetBoundsInScreen()); |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 void PanelWindowResizer::FinishDragging() { | 207 void PanelWindowResizer::FinishDragging() { |
208 if (!did_move_or_resize_) | 208 if (!did_move_or_resize_) |
209 return; | 209 return; |
210 if (GetTarget()->GetProperty(internal::kPanelAttachedKey) != | 210 if (GetTarget()->GetProperty(internal::kPanelAttachedKey) != |
211 should_attach_) { | 211 should_attach_) { |
212 GetTarget()->SetProperty(internal::kPanelAttachedKey, should_attach_); | 212 GetTarget()->SetProperty(internal::kPanelAttachedKey, should_attach_); |
213 gfx::Rect near_last_location(last_location_, gfx::Size()); | 213 // We use last known location to ensure that after the drag the panel |
214 GetTarget()->SetDefaultParentByRootWindow(GetTarget()->GetRootWindow(), | 214 // is reparented to a container in the root window that has that location. |
215 near_last_location); | 215 GetTarget()->SetDefaultParentByRootWindow( |
| 216 GetTarget()->GetRootWindow(), |
| 217 gfx::Rect(last_location_, gfx::Size())); |
216 } | 218 } |
217 if (panel_container_) | 219 if (panel_container_) |
218 GetPanelLayoutManager(panel_container_)->FinishDragging(); | 220 GetPanelLayoutManager(panel_container_)->FinishDragging(); |
219 } | 221 } |
220 | 222 |
221 void PanelWindowResizer::UpdateLauncherPosition() { | 223 void PanelWindowResizer::UpdateLauncherPosition() { |
222 if (panel_container_) { | 224 if (panel_container_) { |
223 GetPanelLayoutManager(panel_container_)->launcher()-> | 225 GetPanelLayoutManager(panel_container_)->launcher()-> |
224 UpdateIconPositionForWindow(GetTarget()); | 226 UpdateIconPositionForWindow(GetTarget()); |
225 } | 227 } |
226 } | 228 } |
227 | 229 |
228 } // namespace aura | 230 } // namespace aura |
OLD | NEW |