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/common/wm/panels/panel_window_resizer.h" | 5 #include "ash/common/wm/panels/panel_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/panels/panel_layout_manager.h" | 8 #include "ash/common/wm/panels/panel_layout_manager.h" |
9 #include "ash/common/wm/shelf/wm_shelf.h" | 9 #include "ash/common/wm/shelf/wm_shelf.h" |
10 #include "ash/common/wm/window_parenting_utils.h" | 10 #include "ash/common/wm/window_parenting_utils.h" |
11 #include "ash/common/wm/window_state.h" | 11 #include "ash/common/wm/window_state.h" |
12 #include "ash/common/wm/wm_lookup.h" | 12 #include "ash/common/wm_lookup.h" |
13 #include "ash/common/wm/wm_root_window_controller.h" | 13 #include "ash/common/wm_root_window_controller.h" |
14 #include "ash/common/wm/wm_window.h" | 14 #include "ash/common/wm_window.h" |
15 #include "ui/base/hit_test.h" | 15 #include "ui/base/hit_test.h" |
16 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
17 #include "ui/display/display.h" | 17 #include "ui/display/display.h" |
18 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const int kPanelSnapToLauncherDistance = 30; | 24 const int kPanelSnapToLauncherDistance = 30; |
(...skipping 22 matching lines...) Expand all Loading... |
47 screen->GetDisplayNearestPoint(last_location_); | 47 screen->GetDisplayNearestPoint(last_location_); |
48 if (dst_display.id() != | 48 if (dst_display.id() != |
49 panel_container_->GetRootWindow()->GetDisplayNearestWindow().id()) { | 49 panel_container_->GetRootWindow()->GetDisplayNearestWindow().id()) { |
50 // The panel is being dragged to a new display. If the previous container is | 50 // The panel is being dragged to a new display. If the previous container is |
51 // the current parent of the panel it will be informed of the end of drag | 51 // the current parent of the panel it will be informed of the end of drag |
52 // when the panel is reparented, otherwise let the previous container know | 52 // when the panel is reparented, otherwise let the previous container know |
53 // the drag is complete. If we told the panel's parent that the drag was | 53 // the drag is complete. If we told the panel's parent that the drag was |
54 // complete it would begin positioning the panel. | 54 // complete it would begin positioning the panel. |
55 if (GetTarget()->GetParent() != panel_container_) | 55 if (GetTarget()->GetParent() != panel_container_) |
56 PanelLayoutManager::Get(panel_container_)->FinishDragging(); | 56 PanelLayoutManager::Get(panel_container_)->FinishDragging(); |
57 wm::WmWindow* dst_root = | 57 WmWindow* dst_root = |
58 wm::WmLookup::Get() | 58 WmLookup::Get() |
59 ->GetRootWindowControllerWithDisplayId(dst_display.id()) | 59 ->GetRootWindowControllerWithDisplayId(dst_display.id()) |
60 ->GetWindow(); | 60 ->GetWindow(); |
61 panel_container_ = | 61 panel_container_ = |
62 dst_root->GetChildByShellWindowId(kShellWindowId_PanelContainer); | 62 dst_root->GetChildByShellWindowId(kShellWindowId_PanelContainer); |
63 | 63 |
64 // The panel's parent already knows that the drag is in progress for this | 64 // The panel's parent already knows that the drag is in progress for this |
65 // panel. | 65 // panel. |
66 if (panel_container_ && GetTarget()->GetParent() != panel_container_) | 66 if (panel_container_ && GetTarget()->GetParent() != panel_container_) |
67 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); | 67 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); |
68 } | 68 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 void PanelWindowResizer::StartedDragging() { | 152 void PanelWindowResizer::StartedDragging() { |
153 // Tell the panel layout manager that we are dragging this panel before | 153 // Tell the panel layout manager that we are dragging this panel before |
154 // attaching it so that it does not get repositioned. | 154 // attaching it so that it does not get repositioned. |
155 if (panel_container_) | 155 if (panel_container_) |
156 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); | 156 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); |
157 if (!was_attached_) { | 157 if (!was_attached_) { |
158 // Attach the panel while dragging placing it in front of other panels. | 158 // Attach the panel while dragging placing it in front of other panels. |
159 window_state_->set_panel_attached(true); | 159 window_state_->set_panel_attached(true); |
160 // We use root window coordinates to ensure that during the drag the panel | 160 // We use root window coordinates to ensure that during the drag the panel |
161 // is reparented to a container in the root window that has that window. | 161 // is reparented to a container in the root window that has that window. |
162 wm::WmWindow* target = GetTarget(); | 162 WmWindow* target = GetTarget(); |
163 wm::WmWindow* target_root = target->GetRootWindow(); | 163 WmWindow* target_root = target->GetRootWindow(); |
164 wm::WmWindow* old_parent = target->GetParent(); | 164 WmWindow* old_parent = target->GetParent(); |
165 target->SetParentUsingContext(target_root, | 165 target->SetParentUsingContext(target_root, |
166 target_root->GetBoundsInScreen()); | 166 target_root->GetBoundsInScreen()); |
167 wm::ReparentTransientChildrenOfChild(target, old_parent, | 167 wm::ReparentTransientChildrenOfChild(target, old_parent, |
168 target->GetParent()); | 168 target->GetParent()); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 void PanelWindowResizer::FinishDragging() { | 172 void PanelWindowResizer::FinishDragging() { |
173 if (!did_move_or_resize_) | 173 if (!did_move_or_resize_) |
174 return; | 174 return; |
175 if (window_state_->panel_attached() != details().should_attach_to_shelf) { | 175 if (window_state_->panel_attached() != details().should_attach_to_shelf) { |
176 window_state_->set_panel_attached(details().should_attach_to_shelf); | 176 window_state_->set_panel_attached(details().should_attach_to_shelf); |
177 // We use last known location to ensure that after the drag the panel | 177 // We use last known location to ensure that after the drag the panel |
178 // is reparented to a container in the root window that has that location. | 178 // is reparented to a container in the root window that has that location. |
179 wm::WmWindow* target = GetTarget(); | 179 WmWindow* target = GetTarget(); |
180 wm::WmWindow* target_root = target->GetRootWindow(); | 180 WmWindow* target_root = target->GetRootWindow(); |
181 wm::WmWindow* old_parent = target->GetParent(); | 181 WmWindow* old_parent = target->GetParent(); |
182 target->SetParentUsingContext(target_root, | 182 target->SetParentUsingContext(target_root, |
183 gfx::Rect(last_location_, gfx::Size())); | 183 gfx::Rect(last_location_, gfx::Size())); |
184 wm::ReparentTransientChildrenOfChild(target, old_parent, | 184 wm::ReparentTransientChildrenOfChild(target, old_parent, |
185 target->GetParent()); | 185 target->GetParent()); |
186 } | 186 } |
187 | 187 |
188 // If we started the drag in one root window and moved into another root | 188 // If we started the drag in one root window and moved into another root |
189 // but then canceled the drag we may need to inform the original layout | 189 // but then canceled the drag we may need to inform the original layout |
190 // manager that the drag is finished. | 190 // manager that the drag is finished. |
191 if (initial_panel_container_ != panel_container_) | 191 if (initial_panel_container_ != panel_container_) |
192 PanelLayoutManager::Get(initial_panel_container_)->FinishDragging(); | 192 PanelLayoutManager::Get(initial_panel_container_)->FinishDragging(); |
193 if (panel_container_) | 193 if (panel_container_) |
194 PanelLayoutManager::Get(panel_container_)->FinishDragging(); | 194 PanelLayoutManager::Get(panel_container_)->FinishDragging(); |
195 } | 195 } |
196 | 196 |
197 void PanelWindowResizer::UpdateLauncherPosition() { | 197 void PanelWindowResizer::UpdateLauncherPosition() { |
198 if (panel_container_) { | 198 if (panel_container_) { |
199 PanelLayoutManager::Get(panel_container_) | 199 PanelLayoutManager::Get(panel_container_) |
200 ->shelf() | 200 ->shelf() |
201 ->UpdateIconPositionForWindow(GetTarget()); | 201 ->UpdateIconPositionForWindow(GetTarget()); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 } // namespace ash | 205 } // namespace ash |
OLD | NEW |