| 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 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 144 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 145 if (bounds.bottom() >= (launcher_bounds.y() - | 145 if (bounds.bottom() >= (launcher_bounds.y() - |
| 146 kPanelSnapToLauncherDistance)) { | 146 kPanelSnapToLauncherDistance)) { |
| 147 should_attach = true; | 147 should_attach = true; |
| 148 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y()); | 148 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y()); |
| 149 } | 149 } |
| 150 break; | 150 break; |
| 151 case SHELF_ALIGNMENT_LEFT: | 151 case SHELF_ALIGNMENT_LEFT: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 164 break; | 164 break; |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 return should_attach; | 167 return should_attach; |
| 168 } | 168 } |
| 169 | 169 |
| 170 void PanelWindowResizer::StartedDragging() { | 170 void PanelWindowResizer::StartedDragging() { |
| 171 // Tell the panel layout manager that we are dragging this panel before | 171 // Tell the panel layout manager that we are dragging this panel before |
| 172 // attaching it so that it does not get repositioned. | 172 // attaching it so that it does not get repositioned. |
| 173 if (panel_container_) | 173 if (panel_container_) |
| 174 GetPanelLayoutManager(panel_container_)->StartDragging(GetTarget()); | 174 GetPanelLayoutManager(panel_container_)->StartDragging(GetAuraTarget()); |
| 175 if (!was_attached_) { | 175 if (!was_attached_) { |
| 176 // Attach the panel while dragging placing it in front of other panels. | 176 // Attach the panel while dragging placing it in front of other panels. |
| 177 window_state_->set_panel_attached(true); | 177 window_state_->set_panel_attached(true); |
| 178 // We use root window coordinates to ensure that during the drag the panel | 178 // We use root window coordinates to ensure that during the drag the panel |
| 179 // is reparented to a container in the root window that has that window. | 179 // is reparented to a container in the root window that has that window. |
| 180 aura::Window* target = GetTarget(); | 180 aura::Window* target = GetAuraTarget(); |
| 181 aura::Window* target_root = target->GetRootWindow(); | 181 aura::Window* target_root = target->GetRootWindow(); |
| 182 aura::Window* old_parent = target->parent(); | 182 aura::Window* old_parent = target->parent(); |
| 183 aura::client::ParentWindowWithContext( | 183 aura::client::ParentWindowWithContext( |
| 184 target, target_root, target_root->GetBoundsInScreen()); | 184 target, target_root, target_root->GetBoundsInScreen()); |
| 185 ash::wm::ReparentTransientChildrenOfChild( | 185 ash::wm::ReparentTransientChildrenOfChild( |
| 186 ash::wm::WmWindowAura::Get(target), | 186 ash::wm::WmWindowAura::Get(target), |
| 187 ash::wm::WmWindowAura::Get(old_parent), | 187 ash::wm::WmWindowAura::Get(old_parent), |
| 188 ash::wm::WmWindowAura::Get(target->parent())); | 188 ash::wm::WmWindowAura::Get(target->parent())); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 void PanelWindowResizer::FinishDragging() { | 192 void PanelWindowResizer::FinishDragging() { |
| 193 if (!did_move_or_resize_) | 193 if (!did_move_or_resize_) |
| 194 return; | 194 return; |
| 195 if (window_state_->panel_attached() != details().should_attach_to_shelf) { | 195 if (window_state_->panel_attached() != details().should_attach_to_shelf) { |
| 196 window_state_->set_panel_attached(details().should_attach_to_shelf); | 196 window_state_->set_panel_attached(details().should_attach_to_shelf); |
| 197 // We use last known location to ensure that after the drag the panel | 197 // We use last known location to ensure that after the drag the panel |
| 198 // is reparented to a container in the root window that has that location. | 198 // is reparented to a container in the root window that has that location. |
| 199 aura::Window* target = GetTarget(); | 199 aura::Window* target = GetAuraTarget(); |
| 200 aura::Window* target_root = target->GetRootWindow(); | 200 aura::Window* target_root = target->GetRootWindow(); |
| 201 aura::Window* old_parent = target->parent(); | 201 aura::Window* old_parent = target->parent(); |
| 202 aura::client::ParentWindowWithContext( | 202 aura::client::ParentWindowWithContext( |
| 203 target, target_root, gfx::Rect(last_location_, gfx::Size())); | 203 target, target_root, gfx::Rect(last_location_, gfx::Size())); |
| 204 ash::wm::ReparentTransientChildrenOfChild( | 204 ash::wm::ReparentTransientChildrenOfChild( |
| 205 ash::wm::WmWindowAura::Get(target), | 205 ash::wm::WmWindowAura::Get(target), |
| 206 ash::wm::WmWindowAura::Get(old_parent), | 206 ash::wm::WmWindowAura::Get(old_parent), |
| 207 ash::wm::WmWindowAura::Get(target->parent())); | 207 ash::wm::WmWindowAura::Get(target->parent())); |
| 208 } | 208 } |
| 209 | 209 |
| 210 // If we started the drag in one root window and moved into another root | 210 // If we started the drag in one root window and moved into another root |
| 211 // but then canceled the drag we may need to inform the original layout | 211 // but then canceled the drag we may need to inform the original layout |
| 212 // manager that the drag is finished. | 212 // manager that the drag is finished. |
| 213 if (initial_panel_container_ != panel_container_) | 213 if (initial_panel_container_ != panel_container_) |
| 214 GetPanelLayoutManager(initial_panel_container_)->FinishDragging(); | 214 GetPanelLayoutManager(initial_panel_container_)->FinishDragging(); |
| 215 if (panel_container_) | 215 if (panel_container_) |
| 216 GetPanelLayoutManager(panel_container_)->FinishDragging(); | 216 GetPanelLayoutManager(panel_container_)->FinishDragging(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void PanelWindowResizer::UpdateLauncherPosition() { | 219 void PanelWindowResizer::UpdateLauncherPosition() { |
| 220 if (panel_container_) { | 220 if (panel_container_) { |
| 221 GetPanelLayoutManager(panel_container_)->shelf()-> | 221 GetPanelLayoutManager(panel_container_) |
| 222 UpdateIconPositionForWindow(GetTarget()); | 222 ->shelf() |
| 223 ->UpdateIconPositionForWindow(GetAuraTarget()); |
| 223 } | 224 } |
| 224 } | 225 } |
| 225 | 226 |
| 226 } // namespace aura | 227 } // namespace aura |
| OLD | NEW |