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