Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: ash/wm/panels/panel_window_resizer.cc

Issue 2897993003: chromeos: converts WindowResizer to aura::Window (Closed)
Patch Set: remove include from exo Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/panels/panel_window_resizer.h ('k') | ash/wm/panels/panel_window_resizer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/cpp/shell_window_ids.h" 7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "ash/public/cpp/window_properties.h" 8 #include "ash/public/cpp/window_properties.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/shelf/wm_shelf.h" 10 #include "ash/shelf/wm_shelf.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wm/panels/panel_layout_manager.h" 12 #include "ash/wm/panels/panel_layout_manager.h"
13 #include "ash/wm/window_parenting_utils.h" 13 #include "ash/wm/window_parenting_utils.h"
14 #include "ash/wm/window_state.h" 14 #include "ash/wm/window_state.h"
15 #include "ash/wm_window.h" 15 #include "ash/wm_window.h"
16 #include "ui/aura/client/window_parenting_client.h"
16 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
17 #include "ui/base/ui_base_types.h" 18 #include "ui/base/ui_base_types.h"
18 #include "ui/display/display.h" 19 #include "ui/display/display.h"
19 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
21 #include "ui/wm/core/coordinate_conversion.h"
20 22
21 namespace ash { 23 namespace ash {
22 24
23 namespace { 25 namespace {
24 26
25 const int kPanelSnapToLauncherDistance = 30; 27 const int kPanelSnapToLauncherDistance = 30;
26 28
27 } // namespace 29 } // namespace
28 30
29 PanelWindowResizer::~PanelWindowResizer() {} 31 PanelWindowResizer::~PanelWindowResizer() {}
30 32
31 // static 33 // static
32 PanelWindowResizer* PanelWindowResizer::Create( 34 PanelWindowResizer* PanelWindowResizer::Create(
33 WindowResizer* next_window_resizer, 35 WindowResizer* next_window_resizer,
34 wm::WindowState* window_state) { 36 wm::WindowState* window_state) {
35 return new PanelWindowResizer(next_window_resizer, window_state); 37 return new PanelWindowResizer(next_window_resizer, window_state);
36 } 38 }
37 39
38 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { 40 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) {
39 last_location_ = GetTarget()->GetParent()->ConvertPointToScreen(location); 41 last_location_ = location;
42 ::wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_);
40 if (!did_move_or_resize_) { 43 if (!did_move_or_resize_) {
41 did_move_or_resize_ = true; 44 did_move_or_resize_ = true;
42 StartedDragging(); 45 StartedDragging();
43 } 46 }
44 47
45 // Check if the destination has changed displays. 48 // Check if the destination has changed displays.
46 display::Screen* screen = display::Screen::GetScreen(); 49 display::Screen* screen = display::Screen::GetScreen();
47 const display::Display dst_display = 50 const display::Display dst_display =
48 screen->GetDisplayNearestPoint(last_location_); 51 screen->GetDisplayNearestPoint(last_location_);
49 if (dst_display.id() != 52 if (dst_display.id() != display::Screen::GetScreen()
50 panel_container_->GetRootWindow()->GetDisplayNearestWindow().id()) { 53 ->GetDisplayNearestWindow(panel_container_)
54 .id()) {
51 // The panel is being dragged to a new display. If the previous container is 55 // The panel is being dragged to a new display. If the previous container is
52 // the current parent of the panel it will be informed of the end of drag 56 // the current parent of the panel it will be informed of the end of drag
53 // when the panel is reparented, otherwise let the previous container know 57 // when the panel is reparented, otherwise let the previous container know
54 // the drag is complete. If we told the panel's parent that the drag was 58 // the drag is complete. If we told the panel's parent that the drag was
55 // complete it would begin positioning the panel. 59 // complete it would begin positioning the panel.
56 if (GetTarget()->GetParent() != panel_container_) 60 if (GetTarget()->parent() != panel_container_)
57 PanelLayoutManager::Get(panel_container_)->FinishDragging(); 61 GetPanelLayoutManager()->FinishDragging();
58 WmWindow* dst_root = 62 aura::Window* dst_root =
59 Shell::GetRootWindowControllerWithDisplayId(dst_display.id()) 63 Shell::GetRootWindowControllerWithDisplayId(dst_display.id())
60 ->GetWindow(); 64 ->GetRootWindow();
61 panel_container_ = 65 panel_container_ = dst_root->GetChildById(kShellWindowId_PanelContainer);
62 dst_root->GetChildByShellWindowId(kShellWindowId_PanelContainer);
63 66
64 // The panel's parent already knows that the drag is in progress for this 67 // The panel's parent already knows that the drag is in progress for this
65 // panel. 68 // panel.
66 if (panel_container_ && GetTarget()->GetParent() != panel_container_) 69 if (panel_container_ && GetTarget()->parent() != panel_container_)
67 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); 70 GetPanelLayoutManager()->StartDragging(WmWindow::Get(GetTarget()));
68 } 71 }
69 gfx::Point offset; 72 gfx::Point offset;
70 gfx::Rect bounds(CalculateBoundsForDrag(location)); 73 gfx::Rect bounds(CalculateBoundsForDrag(location));
71 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { 74 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) {
72 window_state_->drag_details()->should_attach_to_shelf = 75 window_state_->drag_details()->should_attach_to_shelf =
73 AttachToLauncher(bounds, &offset); 76 AttachToLauncher(bounds, &offset);
74 } 77 }
75 gfx::Point modified_location(location.x() + offset.x(), 78 gfx::Point modified_location(location.x() + offset.x(),
76 location.y() + offset.y()); 79 location.y() + offset.y());
77 80
(...skipping 20 matching lines...) Expand all
98 FinishDragging(); 101 FinishDragging();
99 } 102 }
100 103
101 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, 104 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer,
102 wm::WindowState* window_state) 105 wm::WindowState* window_state)
103 : WindowResizer(window_state), 106 : WindowResizer(window_state),
104 next_window_resizer_(next_window_resizer), 107 next_window_resizer_(next_window_resizer),
105 panel_container_(NULL), 108 panel_container_(NULL),
106 initial_panel_container_(NULL), 109 initial_panel_container_(NULL),
107 did_move_or_resize_(false), 110 did_move_or_resize_(false),
108 was_attached_(GetTarget()->aura_window()->GetProperty(kPanelAttachedKey)), 111 was_attached_(GetTarget()->GetProperty(kPanelAttachedKey)),
109 weak_ptr_factory_(this) { 112 weak_ptr_factory_(this) {
110 DCHECK(details().is_resizable); 113 DCHECK(details().is_resizable);
111 panel_container_ = GetTarget()->GetRootWindow()->GetChildByShellWindowId( 114 panel_container_ =
112 kShellWindowId_PanelContainer); 115 GetTarget()->GetRootWindow()->GetChildById(kShellWindowId_PanelContainer);
113 initial_panel_container_ = panel_container_; 116 initial_panel_container_ = panel_container_;
114 } 117 }
115 118
116 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, 119 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds,
117 gfx::Point* offset) { 120 gfx::Point* offset) {
118 bool should_attach = false; 121 bool should_attach = false;
119 if (panel_container_) { 122 if (panel_container_) {
120 PanelLayoutManager* panel_layout_manager = 123 PanelLayoutManager* panel_layout_manager = GetPanelLayoutManager();
121 PanelLayoutManager::Get(panel_container_); 124 gfx::Rect launcher_bounds =
122 gfx::Rect launcher_bounds = GetTarget()->GetParent()->ConvertRectFromScreen( 125 panel_layout_manager->shelf()->GetWindow()->GetBoundsInScreen();
123 panel_layout_manager->shelf()->GetWindow()->GetBoundsInScreen()); 126 ::wm::ConvertRectFromScreen(GetTarget()->parent(), &launcher_bounds);
124 switch (panel_layout_manager->shelf()->GetAlignment()) { 127 switch (panel_layout_manager->shelf()->GetAlignment()) {
125 case SHELF_ALIGNMENT_BOTTOM: 128 case SHELF_ALIGNMENT_BOTTOM:
126 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 129 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
127 if (bounds.bottom() >= 130 if (bounds.bottom() >=
128 (launcher_bounds.y() - kPanelSnapToLauncherDistance)) { 131 (launcher_bounds.y() - kPanelSnapToLauncherDistance)) {
129 should_attach = true; 132 should_attach = true;
130 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y()); 133 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y());
131 } 134 }
132 break; 135 break;
133 case SHELF_ALIGNMENT_LEFT: 136 case SHELF_ALIGNMENT_LEFT:
(...skipping 12 matching lines...) Expand all
146 break; 149 break;
147 } 150 }
148 } 151 }
149 return should_attach; 152 return should_attach;
150 } 153 }
151 154
152 void PanelWindowResizer::StartedDragging() { 155 void PanelWindowResizer::StartedDragging() {
153 // Tell the panel layout manager that we are dragging this panel before 156 // Tell the panel layout manager that we are dragging this panel before
154 // attaching it so that it does not get repositioned. 157 // attaching it so that it does not get repositioned.
155 if (panel_container_) 158 if (panel_container_)
156 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); 159 GetPanelLayoutManager()->StartDragging(WmWindow::Get(GetTarget()));
157 if (!was_attached_) { 160 if (!was_attached_) {
158 // Attach the panel while dragging, placing it in front of other panels. 161 // Attach the panel while dragging, placing it in front of other panels.
159 WmWindow* target = GetTarget(); 162 aura::Window* target = GetTarget();
160 target->aura_window()->SetProperty(kPanelAttachedKey, true); 163 target->SetProperty(kPanelAttachedKey, true);
161 // We use root window coordinates to ensure that during the drag the panel 164 // We use root window coordinates to ensure that during the drag the panel
162 // is reparented to a container in the root window that has that window. 165 // is reparented to a container in the root window that has that window.
163 WmWindow* target_root = target->GetRootWindow(); 166 aura::Window* target_root = target->GetRootWindow();
164 aura::Window* old_parent = target->aura_window()->parent(); 167 aura::Window* old_parent = target->parent();
165 target->SetParentUsingContext(target_root, 168 aura::client::ParentWindowWithContext(target, target_root,
166 target_root->GetBoundsInScreen()); 169 target_root->GetBoundsInScreen());
167 wm::ReparentTransientChildrenOfChild(target->aura_window(), old_parent, 170 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent());
168 target->aura_window()->parent());
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 (GetTarget()->aura_window()->GetProperty(kPanelAttachedKey) != 177 if (GetTarget()->GetProperty(kPanelAttachedKey) !=
176 details().should_attach_to_shelf) { 178 details().should_attach_to_shelf) {
177 GetTarget()->aura_window()->SetProperty(kPanelAttachedKey, 179 GetTarget()->SetProperty(kPanelAttachedKey,
178 details().should_attach_to_shelf); 180 details().should_attach_to_shelf);
179 // 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
180 // 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.
181 WmWindow* target = GetTarget(); 183 aura::Window* target = GetTarget();
182 WmWindow* target_root = target->GetRootWindow(); 184 aura::Window* target_root = target->GetRootWindow();
183 aura::Window* old_parent = target->aura_window()->parent(); 185 aura::Window* old_parent = target->parent();
184 target->SetParentUsingContext(target_root, 186 aura::client::ParentWindowWithContext(target, target_root,
185 target_root->GetBoundsInScreen()); 187 target_root->GetBoundsInScreen());
186 wm::ReparentTransientChildrenOfChild(target->aura_window(), old_parent, 188 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent());
187 target->aura_window()->parent());
188 } 189 }
189 190
190 // If we started the drag in one root window and moved into another root 191 // If we started the drag in one root window and moved into another root
191 // but then canceled the drag we may need to inform the original layout 192 // but then canceled the drag we may need to inform the original layout
192 // manager that the drag is finished. 193 // manager that the drag is finished.
193 if (initial_panel_container_ != panel_container_) 194 if (initial_panel_container_ != panel_container_) {
194 PanelLayoutManager::Get(initial_panel_container_)->FinishDragging(); 195 PanelLayoutManager::Get(WmWindow::Get(initial_panel_container_))
196 ->FinishDragging();
197 }
195 if (panel_container_) 198 if (panel_container_)
196 PanelLayoutManager::Get(panel_container_)->FinishDragging(); 199 GetPanelLayoutManager()->FinishDragging();
197 } 200 }
198 201
199 void PanelWindowResizer::UpdateLauncherPosition() { 202 void PanelWindowResizer::UpdateLauncherPosition() {
200 if (panel_container_) { 203 if (panel_container_) {
201 PanelLayoutManager::Get(panel_container_) 204 GetPanelLayoutManager()->shelf()->UpdateIconPositionForPanel(
202 ->shelf() 205 WmWindow::Get(GetTarget()));
203 ->UpdateIconPositionForPanel(GetTarget());
204 } 206 }
205 } 207 }
206 208
209 PanelLayoutManager* PanelWindowResizer::GetPanelLayoutManager() {
210 return PanelLayoutManager::Get(WmWindow::Get(panel_container_));
211 }
212
207 } // namespace ash 213 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panels/panel_window_resizer.h ('k') | ash/wm/panels/panel_window_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698