| 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/shelf/wm_shelf.h" | 7 #include "ash/common/shelf/wm_shelf.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/window_parenting_utils.h" | 9 #include "ash/common/wm/window_parenting_utils.h" |
| 10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| 11 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
| 12 #include "ash/common/wm_window_property.h" | |
| 13 #include "ash/public/cpp/shell_window_ids.h" | 12 #include "ash/public/cpp/shell_window_ids.h" |
| 13 #include "ash/public/cpp/window_properties.h" |
| 14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
| 17 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
| 18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 FinishDragging(); | 98 FinishDragging(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, | 101 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, |
| 102 wm::WindowState* window_state) | 102 wm::WindowState* window_state) |
| 103 : WindowResizer(window_state), | 103 : WindowResizer(window_state), |
| 104 next_window_resizer_(next_window_resizer), | 104 next_window_resizer_(next_window_resizer), |
| 105 panel_container_(NULL), | 105 panel_container_(NULL), |
| 106 initial_panel_container_(NULL), | 106 initial_panel_container_(NULL), |
| 107 did_move_or_resize_(false), | 107 did_move_or_resize_(false), |
| 108 was_attached_( | 108 was_attached_(GetTarget()->aura_window()->GetProperty(kPanelAttachedKey)), |
| 109 GetTarget()->GetBoolProperty(WmWindowProperty::PANEL_ATTACHED)), | |
| 110 weak_ptr_factory_(this) { | 109 weak_ptr_factory_(this) { |
| 111 DCHECK(details().is_resizable); | 110 DCHECK(details().is_resizable); |
| 112 panel_container_ = GetTarget()->GetRootWindow()->GetChildByShellWindowId( | 111 panel_container_ = GetTarget()->GetRootWindow()->GetChildByShellWindowId( |
| 113 kShellWindowId_PanelContainer); | 112 kShellWindowId_PanelContainer); |
| 114 initial_panel_container_ = panel_container_; | 113 initial_panel_container_ = panel_container_; |
| 115 } | 114 } |
| 116 | 115 |
| 117 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, | 116 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, |
| 118 gfx::Point* offset) { | 117 gfx::Point* offset) { |
| 119 bool should_attach = false; | 118 bool should_attach = false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 150 } |
| 152 | 151 |
| 153 void PanelWindowResizer::StartedDragging() { | 152 void PanelWindowResizer::StartedDragging() { |
| 154 // 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 |
| 155 // attaching it so that it does not get repositioned. | 154 // attaching it so that it does not get repositioned. |
| 156 if (panel_container_) | 155 if (panel_container_) |
| 157 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); | 156 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); |
| 158 if (!was_attached_) { | 157 if (!was_attached_) { |
| 159 // 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. |
| 160 WmWindow* target = GetTarget(); | 159 WmWindow* target = GetTarget(); |
| 161 target->SetBoolProperty(WmWindowProperty::PANEL_ATTACHED, true); | 160 target->aura_window()->SetProperty(kPanelAttachedKey, true); |
| 162 // We use root window coordinates to ensure that during the drag the panel | 161 // We use root window coordinates to ensure that during the drag the panel |
| 163 // is reparented to a container in the root window that has that window. | 162 // is reparented to a container in the root window that has that window. |
| 164 WmWindow* target_root = target->GetRootWindow(); | 163 WmWindow* target_root = target->GetRootWindow(); |
| 165 WmWindow* old_parent = target->GetParent(); | 164 WmWindow* old_parent = target->GetParent(); |
| 166 target->SetParentUsingContext(target_root, | 165 target->SetParentUsingContext(target_root, |
| 167 target_root->GetBoundsInScreen()); | 166 target_root->GetBoundsInScreen()); |
| 168 wm::ReparentTransientChildrenOfChild(target, old_parent, | 167 wm::ReparentTransientChildrenOfChild(target, old_parent, |
| 169 target->GetParent()); | 168 target->GetParent()); |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 | 171 |
| 173 void PanelWindowResizer::FinishDragging() { | 172 void PanelWindowResizer::FinishDragging() { |
| 174 if (!did_move_or_resize_) | 173 if (!did_move_or_resize_) |
| 175 return; | 174 return; |
| 176 if (GetTarget()->GetBoolProperty(WmWindowProperty::PANEL_ATTACHED) != | 175 if (GetTarget()->aura_window()->GetProperty(kPanelAttachedKey) != |
| 177 details().should_attach_to_shelf) { | 176 details().should_attach_to_shelf) { |
| 178 GetTarget()->SetBoolProperty(WmWindowProperty::PANEL_ATTACHED, | 177 GetTarget()->aura_window()->SetProperty(kPanelAttachedKey, |
| 179 details().should_attach_to_shelf); | 178 details().should_attach_to_shelf); |
| 180 // We use last known location to ensure that after the drag the panel | 179 // We use last known location to ensure that after the drag the panel |
| 181 // is reparented to a container in the root window that has that location. | 180 // is reparented to a container in the root window that has that location. |
| 182 WmWindow* target = GetTarget(); | 181 WmWindow* target = GetTarget(); |
| 183 WmWindow* target_root = target->GetRootWindow(); | 182 WmWindow* target_root = target->GetRootWindow(); |
| 184 WmWindow* old_parent = target->GetParent(); | 183 WmWindow* old_parent = target->GetParent(); |
| 185 target->SetParentUsingContext(target_root, | 184 target->SetParentUsingContext(target_root, |
| 186 gfx::Rect(last_location_, gfx::Size())); | 185 gfx::Rect(last_location_, gfx::Size())); |
| 187 wm::ReparentTransientChildrenOfChild(target, old_parent, | 186 wm::ReparentTransientChildrenOfChild(target, old_parent, |
| 188 target->GetParent()); | 187 target->GetParent()); |
| 189 } | 188 } |
| 190 | 189 |
| 191 // If we started the drag in one root window and moved into another root | 190 // If we started the drag in one root window and moved into another root |
| 192 // but then canceled the drag we may need to inform the original layout | 191 // but then canceled the drag we may need to inform the original layout |
| 193 // manager that the drag is finished. | 192 // manager that the drag is finished. |
| 194 if (initial_panel_container_ != panel_container_) | 193 if (initial_panel_container_ != panel_container_) |
| 195 PanelLayoutManager::Get(initial_panel_container_)->FinishDragging(); | 194 PanelLayoutManager::Get(initial_panel_container_)->FinishDragging(); |
| 196 if (panel_container_) | 195 if (panel_container_) |
| 197 PanelLayoutManager::Get(panel_container_)->FinishDragging(); | 196 PanelLayoutManager::Get(panel_container_)->FinishDragging(); |
| 198 } | 197 } |
| 199 | 198 |
| 200 void PanelWindowResizer::UpdateLauncherPosition() { | 199 void PanelWindowResizer::UpdateLauncherPosition() { |
| 201 if (panel_container_) { | 200 if (panel_container_) { |
| 202 PanelLayoutManager::Get(panel_container_) | 201 PanelLayoutManager::Get(panel_container_) |
| 203 ->shelf() | 202 ->shelf() |
| 204 ->UpdateIconPositionForPanel(GetTarget()); | 203 ->UpdateIconPositionForPanel(GetTarget()); |
| 205 } | 204 } |
| 206 } | 205 } |
| 207 | 206 |
| 208 } // namespace ash | 207 } // namespace ash |
| OLD | NEW |