| 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/window_tree_host_manager.h" | 7 #include "ash/display/window_tree_host_manager.h" |
| 8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 PanelWindowResizer* | 47 PanelWindowResizer* |
| 48 PanelWindowResizer::Create(WindowResizer* next_window_resizer, | 48 PanelWindowResizer::Create(WindowResizer* next_window_resizer, |
| 49 wm::WindowState* window_state) { | 49 wm::WindowState* window_state) { |
| 50 return new PanelWindowResizer(next_window_resizer, window_state); | 50 return new PanelWindowResizer(next_window_resizer, window_state); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 53 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
| 54 last_location_ = location; | 54 last_location_ = location; |
| 55 ::wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); | 55 ::wm::ConvertPointToScreen(GetAuraTarget()->parent(), &last_location_); |
| 56 if (!did_move_or_resize_) { | 56 if (!did_move_or_resize_) { |
| 57 did_move_or_resize_ = true; | 57 did_move_or_resize_ = true; |
| 58 StartedDragging(); | 58 StartedDragging(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Check if the destination has changed displays. | 61 // Check if the destination has changed displays. |
| 62 gfx::Screen* screen = gfx::Screen::GetScreen(); | 62 gfx::Screen* screen = gfx::Screen::GetScreen(); |
| 63 const gfx::Display dst_display = | 63 const gfx::Display dst_display = |
| 64 screen->GetDisplayNearestPoint(last_location_); | 64 screen->GetDisplayNearestPoint(last_location_); |
| 65 if (dst_display.id() != | 65 if (dst_display.id() != |
| 66 screen->GetDisplayNearestWindow(panel_container_->GetRootWindow()).id()) { | 66 screen->GetDisplayNearestWindow(panel_container_->GetRootWindow()).id()) { |
| 67 // The panel is being dragged to a new display. If the previous container is | 67 // The panel is being dragged to a new display. If the previous container is |
| 68 // the current parent of the panel it will be informed of the end of drag | 68 // the current parent of the panel it will be informed of the end of drag |
| 69 // when the panel is reparented, otherwise let the previous container know | 69 // when the panel is reparented, otherwise let the previous container know |
| 70 // the drag is complete. If we told the panel's parent that the drag was | 70 // the drag is complete. If we told the panel's parent that the drag was |
| 71 // complete it would begin positioning the panel. | 71 // complete it would begin positioning the panel. |
| 72 if (GetTarget()->parent() != panel_container_) | 72 if (GetAuraTarget()->parent() != panel_container_) |
| 73 GetPanelLayoutManager(panel_container_)->FinishDragging(); | 73 GetPanelLayoutManager(panel_container_)->FinishDragging(); |
| 74 aura::Window* dst_root = Shell::GetInstance() | 74 aura::Window* dst_root = Shell::GetInstance() |
| 75 ->window_tree_host_manager() | 75 ->window_tree_host_manager() |
| 76 ->GetRootWindowForDisplayId(dst_display.id()); | 76 ->GetRootWindowForDisplayId(dst_display.id()); |
| 77 panel_container_ = | 77 panel_container_ = |
| 78 Shell::GetContainer(dst_root, kShellWindowId_PanelContainer); | 78 Shell::GetContainer(dst_root, kShellWindowId_PanelContainer); |
| 79 | 79 |
| 80 // 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 |
| 81 // panel. | 81 // panel. |
| 82 if (panel_container_ && GetTarget()->parent() != panel_container_) | 82 if (panel_container_ && GetAuraTarget()->parent() != panel_container_) |
| 83 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); | 83 GetPanelLayoutManager(panel_container_)->StartDragging(GetAuraTarget()); |
| 84 } | 84 } |
| 85 gfx::Point offset; | 85 gfx::Point offset; |
| 86 gfx::Rect bounds(CalculateBoundsForDrag(location)); | 86 gfx::Rect bounds(CalculateBoundsForDrag(location)); |
| 87 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { | 87 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { |
| 88 window_state_->drag_details()->should_attach_to_shelf = | 88 window_state_->drag_details()->should_attach_to_shelf = |
| 89 AttachToLauncher(bounds, &offset); | 89 AttachToLauncher(bounds, &offset); |
| 90 } | 90 } |
| 91 gfx::Point modified_location(location.x() + offset.x(), | 91 gfx::Point modified_location(location.x() + offset.x(), |
| 92 location.y() + offset.y()); | 92 location.y() + offset.y()); |
| 93 | 93 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 117 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, | 117 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, |
| 118 wm::WindowState* window_state) | 118 wm::WindowState* window_state) |
| 119 : WindowResizer(window_state), | 119 : WindowResizer(window_state), |
| 120 next_window_resizer_(next_window_resizer), | 120 next_window_resizer_(next_window_resizer), |
| 121 panel_container_(NULL), | 121 panel_container_(NULL), |
| 122 initial_panel_container_(NULL), | 122 initial_panel_container_(NULL), |
| 123 did_move_or_resize_(false), | 123 did_move_or_resize_(false), |
| 124 was_attached_(window_state->panel_attached()), | 124 was_attached_(window_state->panel_attached()), |
| 125 weak_ptr_factory_(this) { | 125 weak_ptr_factory_(this) { |
| 126 DCHECK(details().is_resizable); | 126 DCHECK(details().is_resizable); |
| 127 panel_container_ = Shell::GetContainer(GetTarget()->GetRootWindow(), | 127 panel_container_ = Shell::GetContainer(GetAuraTarget()->GetRootWindow(), |
| 128 kShellWindowId_PanelContainer); | 128 kShellWindowId_PanelContainer); |
| 129 initial_panel_container_ = panel_container_; | 129 initial_panel_container_ = panel_container_; |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, | 132 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, |
| 133 gfx::Point* offset) { | 133 gfx::Point* offset) { |
| 134 bool should_attach = false; | 134 bool should_attach = false; |
| 135 if (panel_container_) { | 135 if (panel_container_) { |
| 136 PanelLayoutManager* panel_layout_manager = | 136 PanelLayoutManager* panel_layout_manager = |
| 137 GetPanelLayoutManager(panel_container_); | 137 GetPanelLayoutManager(panel_container_); |
| 138 gfx::Rect launcher_bounds = ScreenUtil::ConvertRectFromScreen( | 138 gfx::Rect launcher_bounds = ScreenUtil::ConvertRectFromScreen( |
| 139 GetTarget()->parent(), | 139 GetAuraTarget()->parent(), panel_layout_manager->shelf() |
| 140 panel_layout_manager->shelf()-> | 140 ->shelf_widget() |
| 141 shelf_widget()->GetWindowBoundsInScreen()); | 141 ->GetWindowBoundsInScreen()); |
| 142 switch (panel_layout_manager->shelf()->alignment()) { | 142 switch (panel_layout_manager->shelf()->alignment()) { |
| 143 case SHELF_ALIGNMENT_BOTTOM: | 143 case SHELF_ALIGNMENT_BOTTOM: |
| 144 if (bounds.bottom() >= (launcher_bounds.y() - | 144 if (bounds.bottom() >= (launcher_bounds.y() - |
| 145 kPanelSnapToLauncherDistance)) { | 145 kPanelSnapToLauncherDistance)) { |
| 146 should_attach = true; | 146 should_attach = true; |
| 147 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y()); | 147 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y()); |
| 148 } | 148 } |
| 149 break; | 149 break; |
| 150 case SHELF_ALIGNMENT_LEFT: | 150 case SHELF_ALIGNMENT_LEFT: |
| 151 if (bounds.x() <= (launcher_bounds.right() + | 151 if (bounds.x() <= (launcher_bounds.right() + |
| (...skipping 11 matching lines...) Expand all Loading... |
| 163 break; | 163 break; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 return should_attach; | 166 return should_attach; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void PanelWindowResizer::StartedDragging() { | 169 void PanelWindowResizer::StartedDragging() { |
| 170 // Tell the panel layout manager that we are dragging this panel before | 170 // Tell the panel layout manager that we are dragging this panel before |
| 171 // attaching it so that it does not get repositioned. | 171 // attaching it so that it does not get repositioned. |
| 172 if (panel_container_) | 172 if (panel_container_) |
| 173 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); | 173 GetPanelLayoutManager(panel_container_)->StartDragging(GetAuraTarget()); |
| 174 if (!was_attached_) { | 174 if (!was_attached_) { |
| 175 // Attach the panel while dragging placing it in front of other panels. | 175 // Attach the panel while dragging placing it in front of other panels. |
| 176 window_state_->set_panel_attached(true); | 176 window_state_->set_panel_attached(true); |
| 177 // We use root window coordinates to ensure that during the drag the panel | 177 // We use root window coordinates to ensure that during the drag the panel |
| 178 // is reparented to a container in the root window that has that window. | 178 // is reparented to a container in the root window that has that window. |
| 179 aura::Window* target = GetTarget(); | 179 aura::Window* target = GetAuraTarget(); |
| 180 aura::Window* target_root = target->GetRootWindow(); | 180 aura::Window* target_root = target->GetRootWindow(); |
| 181 aura::Window* old_parent = target->parent(); | 181 aura::Window* old_parent = target->parent(); |
| 182 aura::client::ParentWindowWithContext( | 182 aura::client::ParentWindowWithContext( |
| 183 target, target_root, target_root->GetBoundsInScreen()); | 183 target, target_root, target_root->GetBoundsInScreen()); |
| 184 ash::wm::ReparentTransientChildrenOfChild( | 184 ash::wm::ReparentTransientChildrenOfChild( |
| 185 ash::wm::WmWindowAura::Get(target), | 185 ash::wm::WmWindowAura::Get(target), |
| 186 ash::wm::WmWindowAura::Get(old_parent), | 186 ash::wm::WmWindowAura::Get(old_parent), |
| 187 ash::wm::WmWindowAura::Get(target->parent())); | 187 ash::wm::WmWindowAura::Get(target->parent())); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 void PanelWindowResizer::FinishDragging() { | 191 void PanelWindowResizer::FinishDragging() { |
| 192 if (!did_move_or_resize_) | 192 if (!did_move_or_resize_) |
| 193 return; | 193 return; |
| 194 if (window_state_->panel_attached() != details().should_attach_to_shelf) { | 194 if (window_state_->panel_attached() != details().should_attach_to_shelf) { |
| 195 window_state_->set_panel_attached(details().should_attach_to_shelf); | 195 window_state_->set_panel_attached(details().should_attach_to_shelf); |
| 196 // We use last known location to ensure that after the drag the panel | 196 // We use last known location to ensure that after the drag the panel |
| 197 // is reparented to a container in the root window that has that location. | 197 // is reparented to a container in the root window that has that location. |
| 198 aura::Window* target = GetTarget(); | 198 aura::Window* target = GetAuraTarget(); |
| 199 aura::Window* target_root = target->GetRootWindow(); | 199 aura::Window* target_root = target->GetRootWindow(); |
| 200 aura::Window* old_parent = target->parent(); | 200 aura::Window* old_parent = target->parent(); |
| 201 aura::client::ParentWindowWithContext( | 201 aura::client::ParentWindowWithContext( |
| 202 target, target_root, gfx::Rect(last_location_, gfx::Size())); | 202 target, target_root, gfx::Rect(last_location_, gfx::Size())); |
| 203 ash::wm::ReparentTransientChildrenOfChild( | 203 ash::wm::ReparentTransientChildrenOfChild( |
| 204 ash::wm::WmWindowAura::Get(target), | 204 ash::wm::WmWindowAura::Get(target), |
| 205 ash::wm::WmWindowAura::Get(old_parent), | 205 ash::wm::WmWindowAura::Get(old_parent), |
| 206 ash::wm::WmWindowAura::Get(target->parent())); | 206 ash::wm::WmWindowAura::Get(target->parent())); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // If we started the drag in one root window and moved into another root | 209 // If we started the drag in one root window and moved into another root |
| 210 // but then canceled the drag we may need to inform the original layout | 210 // but then canceled the drag we may need to inform the original layout |
| 211 // manager that the drag is finished. | 211 // manager that the drag is finished. |
| 212 if (initial_panel_container_ != panel_container_) | 212 if (initial_panel_container_ != panel_container_) |
| 213 GetPanelLayoutManager(initial_panel_container_)->FinishDragging(); | 213 GetPanelLayoutManager(initial_panel_container_)->FinishDragging(); |
| 214 if (panel_container_) | 214 if (panel_container_) |
| 215 GetPanelLayoutManager(panel_container_)->FinishDragging(); | 215 GetPanelLayoutManager(panel_container_)->FinishDragging(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void PanelWindowResizer::UpdateLauncherPosition() { | 218 void PanelWindowResizer::UpdateLauncherPosition() { |
| 219 if (panel_container_) { | 219 if (panel_container_) { |
| 220 GetPanelLayoutManager(panel_container_)->shelf()-> | 220 GetPanelLayoutManager(panel_container_) |
| 221 UpdateIconPositionForWindow(GetTarget()); | 221 ->shelf() |
| 222 ->UpdateIconPositionForWindow(GetAuraTarget()); |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 | 225 |
| 225 } // namespace aura | 226 } // namespace aura |
| OLD | NEW |