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

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

Issue 2897993003: chromeos: converts WindowResizer to aura::Window (Closed)
Patch Set: tweak 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
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() !=
50 panel_container_->GetRootWindow()->GetDisplayNearestWindow().id()) { 53 display::Screen::GetScreen()
54 ->GetDisplayNearestWindow(panel_container_->GetRootWindow())
msw 2017/05/22 19:26:11 optional nit: ->GetRootWindow() may not be needed.
sky 2017/05/22 19:50:58 You are right. Removed.
55 .id()) {
51 // The panel is being dragged to a new display. If the previous container is 56 // 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 57 // 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 58 // 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 59 // the drag is complete. If we told the panel's parent that the drag was
55 // complete it would begin positioning the panel. 60 // complete it would begin positioning the panel.
56 if (GetTarget()->GetParent() != panel_container_) 61 if (GetTarget()->parent() != panel_container_)
57 PanelLayoutManager::Get(panel_container_)->FinishDragging(); 62 GetPanelLayoutManager()->FinishDragging();
58 WmWindow* dst_root = 63 aura::Window* dst_root =
59 Shell::GetRootWindowControllerWithDisplayId(dst_display.id()) 64 Shell::GetRootWindowControllerWithDisplayId(dst_display.id())
60 ->GetWindow(); 65 ->GetRootWindow();
61 panel_container_ = 66 panel_container_ = dst_root->GetChildById(kShellWindowId_PanelContainer);
62 dst_root->GetChildByShellWindowId(kShellWindowId_PanelContainer);
63 67
64 // The panel's parent already knows that the drag is in progress for this 68 // The panel's parent already knows that the drag is in progress for this
65 // panel. 69 // panel.
66 if (panel_container_ && GetTarget()->GetParent() != panel_container_) 70 if (panel_container_ && GetTarget()->parent() != panel_container_)
67 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); 71 GetPanelLayoutManager()->StartDragging(WmWindow::Get(GetTarget()));
68 } 72 }
69 gfx::Point offset; 73 gfx::Point offset;
70 gfx::Rect bounds(CalculateBoundsForDrag(location)); 74 gfx::Rect bounds(CalculateBoundsForDrag(location));
71 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { 75 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) {
72 window_state_->drag_details()->should_attach_to_shelf = 76 window_state_->drag_details()->should_attach_to_shelf =
73 AttachToLauncher(bounds, &offset); 77 AttachToLauncher(bounds, &offset);
74 } 78 }
75 gfx::Point modified_location(location.x() + offset.x(), 79 gfx::Point modified_location(location.x() + offset.x(),
76 location.y() + offset.y()); 80 location.y() + offset.y());
77 81
(...skipping 20 matching lines...) Expand all
98 FinishDragging(); 102 FinishDragging();
99 } 103 }
100 104
101 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, 105 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer,
102 wm::WindowState* window_state) 106 wm::WindowState* window_state)
103 : WindowResizer(window_state), 107 : WindowResizer(window_state),
104 next_window_resizer_(next_window_resizer), 108 next_window_resizer_(next_window_resizer),
105 panel_container_(NULL), 109 panel_container_(NULL),
106 initial_panel_container_(NULL), 110 initial_panel_container_(NULL),
107 did_move_or_resize_(false), 111 did_move_or_resize_(false),
108 was_attached_(GetTarget()->aura_window()->GetProperty(kPanelAttachedKey)), 112 was_attached_(GetTarget()->GetProperty(kPanelAttachedKey)),
109 weak_ptr_factory_(this) { 113 weak_ptr_factory_(this) {
110 DCHECK(details().is_resizable); 114 DCHECK(details().is_resizable);
111 panel_container_ = GetTarget()->GetRootWindow()->GetChildByShellWindowId( 115 panel_container_ =
112 kShellWindowId_PanelContainer); 116 GetTarget()->GetRootWindow()->GetChildById(kShellWindowId_PanelContainer);
113 initial_panel_container_ = panel_container_; 117 initial_panel_container_ = panel_container_;
114 } 118 }
115 119
116 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, 120 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds,
117 gfx::Point* offset) { 121 gfx::Point* offset) {
118 bool should_attach = false; 122 bool should_attach = false;
119 if (panel_container_) { 123 if (panel_container_) {
120 PanelLayoutManager* panel_layout_manager = 124 PanelLayoutManager* panel_layout_manager = GetPanelLayoutManager();
121 PanelLayoutManager::Get(panel_container_); 125 gfx::Rect launcher_bounds =
122 gfx::Rect launcher_bounds = GetTarget()->GetParent()->ConvertRectFromScreen( 126 panel_layout_manager->shelf()->GetWindow()->GetBoundsInScreen();
123 panel_layout_manager->shelf()->GetWindow()->GetBoundsInScreen()); 127 ::wm::ConvertRectFromScreen(GetTarget()->parent(), &launcher_bounds);
124 switch (panel_layout_manager->shelf()->GetAlignment()) { 128 switch (panel_layout_manager->shelf()->GetAlignment()) {
125 case SHELF_ALIGNMENT_BOTTOM: 129 case SHELF_ALIGNMENT_BOTTOM:
126 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 130 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
127 if (bounds.bottom() >= 131 if (bounds.bottom() >=
128 (launcher_bounds.y() - kPanelSnapToLauncherDistance)) { 132 (launcher_bounds.y() - kPanelSnapToLauncherDistance)) {
129 should_attach = true; 133 should_attach = true;
130 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y()); 134 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y());
131 } 135 }
132 break; 136 break;
133 case SHELF_ALIGNMENT_LEFT: 137 case SHELF_ALIGNMENT_LEFT:
(...skipping 12 matching lines...) Expand all
146 break; 150 break;
147 } 151 }
148 } 152 }
149 return should_attach; 153 return should_attach;
150 } 154 }
151 155
152 void PanelWindowResizer::StartedDragging() { 156 void PanelWindowResizer::StartedDragging() {
153 // Tell the panel layout manager that we are dragging this panel before 157 // Tell the panel layout manager that we are dragging this panel before
154 // attaching it so that it does not get repositioned. 158 // attaching it so that it does not get repositioned.
155 if (panel_container_) 159 if (panel_container_)
156 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget()); 160 GetPanelLayoutManager()->StartDragging(WmWindow::Get(GetTarget()));
157 if (!was_attached_) { 161 if (!was_attached_) {
158 // Attach the panel while dragging, placing it in front of other panels. 162 // Attach the panel while dragging, placing it in front of other panels.
159 WmWindow* target = GetTarget(); 163 aura::Window* target = GetTarget();
160 target->aura_window()->SetProperty(kPanelAttachedKey, true); 164 target->SetProperty(kPanelAttachedKey, true);
161 // We use root window coordinates to ensure that during the drag the panel 165 // 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. 166 // is reparented to a container in the root window that has that window.
163 WmWindow* target_root = target->GetRootWindow(); 167 aura::Window* target_root = target->GetRootWindow();
164 aura::Window* old_parent = target->aura_window()->parent(); 168 aura::Window* old_parent = target->parent();
165 target->SetParentUsingContext(target_root, 169 aura::client::ParentWindowWithContext(target, target_root,
166 target_root->GetBoundsInScreen()); 170 target_root->GetBoundsInScreen());
167 wm::ReparentTransientChildrenOfChild(target->aura_window(), old_parent, 171 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent());
168 target->aura_window()->parent());
169 } 172 }
170 } 173 }
171 174
172 void PanelWindowResizer::FinishDragging() { 175 void PanelWindowResizer::FinishDragging() {
173 if (!did_move_or_resize_) 176 if (!did_move_or_resize_)
174 return; 177 return;
175 if (GetTarget()->aura_window()->GetProperty(kPanelAttachedKey) != 178 if (GetTarget()->GetProperty(kPanelAttachedKey) !=
176 details().should_attach_to_shelf) { 179 details().should_attach_to_shelf) {
177 GetTarget()->aura_window()->SetProperty(kPanelAttachedKey, 180 GetTarget()->SetProperty(kPanelAttachedKey,
178 details().should_attach_to_shelf); 181 details().should_attach_to_shelf);
179 // We use last known location to ensure that after the drag the panel 182 // 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. 183 // is reparented to a container in the root window that has that location.
181 WmWindow* target = GetTarget(); 184 aura::Window* target = GetTarget();
182 WmWindow* target_root = target->GetRootWindow(); 185 aura::Window* target_root = target->GetRootWindow();
183 aura::Window* old_parent = target->aura_window()->parent(); 186 aura::Window* old_parent = target->parent();
184 target->SetParentUsingContext(target_root, 187 aura::client::ParentWindowWithContext(target, target_root,
185 target_root->GetBoundsInScreen()); 188 target_root->GetBoundsInScreen());
186 wm::ReparentTransientChildrenOfChild(target->aura_window(), old_parent, 189 wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent());
187 target->aura_window()->parent());
188 } 190 }
189 191
190 // 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
191 // 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
192 // manager that the drag is finished. 194 // manager that the drag is finished.
193 if (initial_panel_container_ != panel_container_) 195 if (initial_panel_container_ != panel_container_)
msw 2017/05/22 19:26:11 optional nit: curlies
sky 2017/05/22 19:50:58 Done.
194 PanelLayoutManager::Get(initial_panel_container_)->FinishDragging(); 196 PanelLayoutManager::Get(WmWindow::Get(initial_panel_container_))
197 ->FinishDragging();
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

Powered by Google App Engine
This is Rietveld 408576698