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

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

Issue 1918883002: Makes Panel related classes use ash/wm/common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@phantom_window_controller
Patch Set: feedback Created 4 years, 8 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/toplevel_window_event_handler.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/display/window_tree_host_manager.h"
8 #include "ash/screen_util.h"
9 #include "ash/shelf/shelf.h" 7 #include "ash/shelf/shelf.h"
10 #include "ash/shelf/shelf_types.h" 8 #include "ash/shelf/shelf_types.h"
11 #include "ash/shelf/shelf_widget.h" 9 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "ash/wm/aura/wm_window_aura.h"
14 #include "ash/wm/common/window_parenting_utils.h" 12 #include "ash/wm/common/window_parenting_utils.h"
13 #include "ash/wm/common/wm_root_window_controller.h"
14 #include "ash/wm/common/wm_window.h"
15 #include "ash/wm/panels/panel_layout_manager.h" 15 #include "ash/wm/panels/panel_layout_manager.h"
16 #include "ash/wm/window_state.h" 16 #include "ash/wm/window_state.h"
17 #include "ash/wm/window_util.h"
18 #include "base/memory/weak_ptr.h"
19 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/client/window_tree_client.h"
21 #include "ui/aura/env.h"
22 #include "ui/aura/window.h"
23 #include "ui/aura/window_delegate.h"
24 #include "ui/aura/window_event_dispatcher.h"
25 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
26 #include "ui/base/ui_base_types.h" 18 #include "ui/base/ui_base_types.h"
27 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
28 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
29 #include "ui/wm/core/coordinate_conversion.h"
30 21
31 namespace ash { 22 namespace ash {
32 23
33 namespace { 24 namespace {
25
34 const int kPanelSnapToLauncherDistance = 30; 26 const int kPanelSnapToLauncherDistance = 30;
35 27
36 PanelLayoutManager* GetPanelLayoutManager(aura::Window* panel_container) {
37 DCHECK(panel_container->id() == kShellWindowId_PanelContainer);
38 return static_cast<PanelLayoutManager*>(panel_container->layout_manager());
39 }
40
41 } // namespace 28 } // namespace
42 29
43 PanelWindowResizer::~PanelWindowResizer() { 30 PanelWindowResizer::~PanelWindowResizer() {
44 } 31 }
45 32
46 // static 33 // static
47 PanelWindowResizer* 34 PanelWindowResizer*
48 PanelWindowResizer::Create(WindowResizer* next_window_resizer, 35 PanelWindowResizer::Create(WindowResizer* next_window_resizer,
49 wm::WindowState* window_state) { 36 wm::WindowState* window_state) {
50 return new PanelWindowResizer(next_window_resizer, window_state); 37 return new PanelWindowResizer(next_window_resizer, window_state);
51 } 38 }
52 39
53 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) { 40 void PanelWindowResizer::Drag(const gfx::Point& location, int event_flags) {
54 last_location_ = location; 41 last_location_ = GetTarget()->GetParent()->ConvertPointToScreen(location);
55 ::wm::ConvertPointToScreen(GetAuraTarget()->parent(), &last_location_);
56 if (!did_move_or_resize_) { 42 if (!did_move_or_resize_) {
57 did_move_or_resize_ = true; 43 did_move_or_resize_ = true;
58 StartedDragging(); 44 StartedDragging();
59 } 45 }
60 46
61 // Check if the destination has changed displays. 47 // Check if the destination has changed displays.
62 gfx::Screen* screen = gfx::Screen::GetScreen(); 48 gfx::Screen* screen = gfx::Screen::GetScreen();
63 const gfx::Display dst_display = 49 const gfx::Display dst_display =
64 screen->GetDisplayNearestPoint(last_location_); 50 screen->GetDisplayNearestPoint(last_location_);
65 if (dst_display.id() != 51 if (dst_display.id() !=
66 screen->GetDisplayNearestWindow(panel_container_->GetRootWindow()).id()) { 52 panel_container_->GetRootWindow()->GetDisplayNearestWindow().id()) {
67 // The panel is being dragged to a new display. If the previous container is 53 // 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 54 // 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 55 // 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 56 // the drag is complete. If we told the panel's parent that the drag was
71 // complete it would begin positioning the panel. 57 // complete it would begin positioning the panel.
72 if (GetAuraTarget()->parent() != panel_container_) 58 if (GetTarget()->GetParent() != panel_container_)
73 GetPanelLayoutManager(panel_container_)->FinishDragging(); 59 PanelLayoutManager::Get(panel_container_)->FinishDragging();
74 aura::Window* dst_root = Shell::GetInstance() 60 wm::WmWindow* dst_root =
75 ->window_tree_host_manager() 61 wm::WmRootWindowController::GetWithDisplayId(dst_display.id())
76 ->GetRootWindowForDisplayId(dst_display.id()); 62 ->GetWindow();
77 panel_container_ = 63 panel_container_ =
78 Shell::GetContainer(dst_root, kShellWindowId_PanelContainer); 64 dst_root->GetChildByShellWindowId(kShellWindowId_PanelContainer);
79 65
80 // The panel's parent already knows that the drag is in progress for this 66 // The panel's parent already knows that the drag is in progress for this
81 // panel. 67 // panel.
82 if (panel_container_ && GetAuraTarget()->parent() != panel_container_) 68 if (panel_container_ && GetTarget()->GetParent() != panel_container_)
83 GetPanelLayoutManager(panel_container_)->StartDragging(GetAuraTarget()); 69 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget());
84 } 70 }
85 gfx::Point offset; 71 gfx::Point offset;
86 gfx::Rect bounds(CalculateBoundsForDrag(location)); 72 gfx::Rect bounds(CalculateBoundsForDrag(location));
87 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) { 73 if (!(details().bounds_change & WindowResizer::kBoundsChange_Resizes)) {
88 window_state_->drag_details()->should_attach_to_shelf = 74 window_state_->drag_details()->should_attach_to_shelf =
89 AttachToLauncher(bounds, &offset); 75 AttachToLauncher(bounds, &offset);
90 } 76 }
91 gfx::Point modified_location(location.x() + offset.x(), 77 gfx::Point modified_location(location.x() + offset.x(),
92 location.y() + offset.y()); 78 location.y() + offset.y());
93 79
(...skipping 23 matching lines...) Expand all
117 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer, 103 PanelWindowResizer::PanelWindowResizer(WindowResizer* next_window_resizer,
118 wm::WindowState* window_state) 104 wm::WindowState* window_state)
119 : WindowResizer(window_state), 105 : WindowResizer(window_state),
120 next_window_resizer_(next_window_resizer), 106 next_window_resizer_(next_window_resizer),
121 panel_container_(NULL), 107 panel_container_(NULL),
122 initial_panel_container_(NULL), 108 initial_panel_container_(NULL),
123 did_move_or_resize_(false), 109 did_move_or_resize_(false),
124 was_attached_(window_state->panel_attached()), 110 was_attached_(window_state->panel_attached()),
125 weak_ptr_factory_(this) { 111 weak_ptr_factory_(this) {
126 DCHECK(details().is_resizable); 112 DCHECK(details().is_resizable);
127 panel_container_ = Shell::GetContainer(GetAuraTarget()->GetRootWindow(), 113 panel_container_ = GetTarget()->GetRootWindow()->GetChildByShellWindowId(
128 kShellWindowId_PanelContainer); 114 kShellWindowId_PanelContainer);
129 initial_panel_container_ = panel_container_; 115 initial_panel_container_ = panel_container_;
130 } 116 }
131 117
132 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds, 118 bool PanelWindowResizer::AttachToLauncher(const gfx::Rect& bounds,
133 gfx::Point* offset) { 119 gfx::Point* offset) {
134 bool should_attach = false; 120 bool should_attach = false;
135 if (panel_container_) { 121 if (panel_container_) {
136 PanelLayoutManager* panel_layout_manager = 122 PanelLayoutManager* panel_layout_manager =
137 GetPanelLayoutManager(panel_container_); 123 PanelLayoutManager::Get(panel_container_);
138 gfx::Rect launcher_bounds = ScreenUtil::ConvertRectFromScreen( 124 gfx::Rect launcher_bounds = GetTarget()->GetParent()->ConvertRectFromScreen(
139 GetAuraTarget()->parent(), panel_layout_manager->shelf() 125 panel_layout_manager->shelf()
140 ->shelf_widget() 126 ->shelf_widget()
141 ->GetWindowBoundsInScreen()); 127 ->GetWindowBoundsInScreen());
142 switch (panel_layout_manager->shelf()->alignment()) { 128 switch (panel_layout_manager->shelf()->alignment()) {
143 case SHELF_ALIGNMENT_BOTTOM: 129 case SHELF_ALIGNMENT_BOTTOM:
144 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 130 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
145 if (bounds.bottom() >= (launcher_bounds.y() - 131 if (bounds.bottom() >= (launcher_bounds.y() -
146 kPanelSnapToLauncherDistance)) { 132 kPanelSnapToLauncherDistance)) {
147 should_attach = true; 133 should_attach = true;
148 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y()); 134 offset->set_y(launcher_bounds.y() - bounds.height() - bounds.y());
149 } 135 }
150 break; 136 break;
151 case SHELF_ALIGNMENT_LEFT: 137 case SHELF_ALIGNMENT_LEFT:
(...skipping 12 matching lines...) Expand all
164 break; 150 break;
165 } 151 }
166 } 152 }
167 return should_attach; 153 return should_attach;
168 } 154 }
169 155
170 void PanelWindowResizer::StartedDragging() { 156 void PanelWindowResizer::StartedDragging() {
171 // 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
172 // attaching it so that it does not get repositioned. 158 // attaching it so that it does not get repositioned.
173 if (panel_container_) 159 if (panel_container_)
174 GetPanelLayoutManager(panel_container_)->StartDragging(GetAuraTarget()); 160 PanelLayoutManager::Get(panel_container_)->StartDragging(GetTarget());
175 if (!was_attached_) { 161 if (!was_attached_) {
176 // 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.
177 window_state_->set_panel_attached(true); 163 window_state_->set_panel_attached(true);
178 // 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
179 // 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.
180 aura::Window* target = GetAuraTarget(); 166 wm::WmWindow* target = GetTarget();
181 aura::Window* target_root = target->GetRootWindow(); 167 wm::WmWindow* target_root = target->GetRootWindow();
182 aura::Window* old_parent = target->parent(); 168 wm::WmWindow* old_parent = target->GetParent();
183 aura::client::ParentWindowWithContext( 169 target->SetParentUsingContext(target_root,
184 target, target_root, target_root->GetBoundsInScreen()); 170 target_root->GetBoundsInScreen());
185 ash::wm::ReparentTransientChildrenOfChild( 171 wm::ReparentTransientChildrenOfChild(target, old_parent,
186 ash::wm::WmWindowAura::Get(target), 172 target->GetParent());
187 ash::wm::WmWindowAura::Get(old_parent),
188 ash::wm::WmWindowAura::Get(target->parent()));
189 } 173 }
190 } 174 }
191 175
192 void PanelWindowResizer::FinishDragging() { 176 void PanelWindowResizer::FinishDragging() {
193 if (!did_move_or_resize_) 177 if (!did_move_or_resize_)
194 return; 178 return;
195 if (window_state_->panel_attached() != details().should_attach_to_shelf) { 179 if (window_state_->panel_attached() != details().should_attach_to_shelf) {
196 window_state_->set_panel_attached(details().should_attach_to_shelf); 180 window_state_->set_panel_attached(details().should_attach_to_shelf);
197 // 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
198 // 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.
199 aura::Window* target = GetAuraTarget(); 183 wm::WmWindow* target = GetTarget();
200 aura::Window* target_root = target->GetRootWindow(); 184 wm::WmWindow* target_root = target->GetRootWindow();
201 aura::Window* old_parent = target->parent(); 185 wm::WmWindow* old_parent = target->GetParent();
202 aura::client::ParentWindowWithContext( 186 target->SetParentUsingContext(target_root,
203 target, target_root, gfx::Rect(last_location_, gfx::Size())); 187 gfx::Rect(last_location_, gfx::Size()));
204 ash::wm::ReparentTransientChildrenOfChild( 188 wm::ReparentTransientChildrenOfChild(target, old_parent,
205 ash::wm::WmWindowAura::Get(target), 189 target->GetParent());
206 ash::wm::WmWindowAura::Get(old_parent),
207 ash::wm::WmWindowAura::Get(target->parent()));
208 } 190 }
209 191
210 // 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
211 // 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
212 // manager that the drag is finished. 194 // manager that the drag is finished.
213 if (initial_panel_container_ != panel_container_) 195 if (initial_panel_container_ != panel_container_)
214 GetPanelLayoutManager(initial_panel_container_)->FinishDragging(); 196 PanelLayoutManager::Get(initial_panel_container_)->FinishDragging();
215 if (panel_container_) 197 if (panel_container_)
216 GetPanelLayoutManager(panel_container_)->FinishDragging(); 198 PanelLayoutManager::Get(panel_container_)->FinishDragging();
217 } 199 }
218 200
219 void PanelWindowResizer::UpdateLauncherPosition() { 201 void PanelWindowResizer::UpdateLauncherPosition() {
220 if (panel_container_) { 202 if (panel_container_) {
221 GetPanelLayoutManager(panel_container_) 203 PanelLayoutManager::Get(panel_container_)
222 ->shelf() 204 ->shelf()
223 ->UpdateIconPositionForWindow(GetAuraTarget()); 205 ->UpdateIconPositionForWindow(
206 wm::WmWindowAura::GetAuraWindow(GetTarget()));
224 } 207 }
225 } 208 }
226 209
227 } // namespace aura 210 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panels/panel_window_resizer.h ('k') | ash/wm/toplevel_window_event_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698