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

Side by Side Diff: ash/wm/dock/docked_window_resizer.cc

Issue 121153003: Prevents panels attached to shelf from docking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Prevents panels attached to shelf from docking (nits) Created 6 years, 11 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/dock/docked_window_resizer.h ('k') | ash/wm/drag_details.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/dock/docked_window_resizer.h" 5 #include "ash/wm/dock/docked_window_resizer.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/shelf/shelf.h" 10 #include "ash/shelf/shelf.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 } // namespace 52 } // namespace
53 53
54 DockedWindowResizer::~DockedWindowResizer() { 54 DockedWindowResizer::~DockedWindowResizer() {
55 } 55 }
56 56
57 // static 57 // static
58 DockedWindowResizer* 58 DockedWindowResizer*
59 DockedWindowResizer::Create(WindowResizer* next_window_resizer, 59 DockedWindowResizer::Create(WindowResizer* next_window_resizer,
60 aura::Window* window, 60 wm::WindowState* window_state) {
61 const gfx::Point& location, 61 return new DockedWindowResizer(next_window_resizer, window_state);
62 int window_component,
63 aura::client::WindowMoveSource source) {
64 Details details(window, location, window_component, source);
65 return details.is_resizable ?
66 new DockedWindowResizer(next_window_resizer, details) : NULL;
67 } 62 }
68 63
69 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) { 64 void DockedWindowResizer::Drag(const gfx::Point& location, int event_flags) {
70 last_location_ = location; 65 last_location_ = location;
71 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_); 66 wm::ConvertPointToScreen(GetTarget()->parent(), &last_location_);
72 if (!did_move_or_resize_) { 67 if (!did_move_or_resize_) {
73 did_move_or_resize_ = true; 68 did_move_or_resize_ = true;
74 StartedDragging(); 69 StartedDragging();
75 } 70 }
76 gfx::Point offset; 71 gfx::Point offset;
77 gfx::Rect bounds(CalculateBoundsForDrag(details_, location)); 72 gfx::Rect bounds(CalculateBoundsForDrag(location));
78 MaybeSnapToEdge(bounds, &offset); 73 MaybeSnapToEdge(bounds, &offset);
79 gfx::Point modified_location(location); 74 gfx::Point modified_location(location);
80 modified_location.Offset(offset.x(), offset.y()); 75 modified_location.Offset(offset.x(), offset.y());
81 76
82 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); 77 base::WeakPtr<DockedWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
83 next_window_resizer_->Drag(modified_location, event_flags); 78 next_window_resizer_->Drag(modified_location, event_flags);
84 if (!resizer) 79 if (!resizer)
85 return; 80 return;
86 81
87 DockedWindowLayoutManager* new_dock_layout = 82 DockedWindowLayoutManager* new_dock_layout =
88 GetDockedLayoutManagerAtPoint(last_location_); 83 GetDockedLayoutManagerAtPoint(last_location_);
89 if (new_dock_layout && new_dock_layout != dock_layout_) { 84 if (new_dock_layout && new_dock_layout != dock_layout_) {
90 // The window is being dragged to a new display. If the previous 85 // The window is being dragged to a new display. If the previous
91 // container is the current parent of the window it will be informed of 86 // container is the current parent of the window it will be informed of
92 // the end of drag when the window is reparented, otherwise let the 87 // the end of drag when the window is reparented, otherwise let the
93 // previous container know the drag is complete. If we told the 88 // previous container know the drag is complete. If we told the
94 // window's parent that the drag was complete it would begin 89 // window's parent that the drag was complete it would begin
95 // positioning the window. 90 // positioning the window.
96 if (is_docked_ && dock_layout_->is_dragged_window_docked()) 91 if (is_docked_ && dock_layout_->is_dragged_window_docked())
97 dock_layout_->UndockDraggedWindow(); 92 dock_layout_->UndockDraggedWindow();
98 if (dock_layout_ != initial_dock_layout_) 93 if (dock_layout_ != initial_dock_layout_)
99 dock_layout_->FinishDragging( 94 dock_layout_->FinishDragging(
100 DOCKED_ACTION_NONE, 95 DOCKED_ACTION_NONE,
101 details_.source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? 96 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ?
102 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); 97 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH);
103 is_docked_ = false; 98 is_docked_ = false;
104 dock_layout_ = new_dock_layout; 99 dock_layout_ = new_dock_layout;
105 // The window's initial layout manager already knows that the drag is 100 // The window's initial layout manager already knows that the drag is
106 // in progress for this window. 101 // in progress for this window.
107 if (new_dock_layout != initial_dock_layout_) 102 if (new_dock_layout != initial_dock_layout_)
108 new_dock_layout->StartDragging(GetTarget()); 103 new_dock_layout->StartDragging(GetTarget());
109 } 104 }
110 // Window could get docked by the WorkspaceWindowResizer, update the state. 105 // Window could get docked by the WorkspaceWindowResizer, update the state.
111 is_docked_ = dock_layout_->is_dragged_window_docked(); 106 is_docked_ = dock_layout_->is_dragged_window_docked();
(...skipping 15 matching lines...) Expand all
127 if (is_docked_ != was_docked_) { 122 if (is_docked_ != was_docked_) {
128 is_docked_ = was_docked_; 123 is_docked_ = was_docked_;
129 if (is_docked_) 124 if (is_docked_)
130 dock_layout_->DockDraggedWindow(GetTarget()); 125 dock_layout_->DockDraggedWindow(GetTarget());
131 else 126 else
132 dock_layout_->UndockDraggedWindow(); 127 dock_layout_->UndockDraggedWindow();
133 } 128 }
134 FinishedDragging(); 129 FinishedDragging();
135 } 130 }
136 131
137 aura::Window* DockedWindowResizer::GetTarget() {
138 return next_window_resizer_->GetTarget();
139 }
140
141 const gfx::Point& DockedWindowResizer::GetInitialLocation() const {
142 return details_.initial_location_in_parent;
143 }
144
145 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer, 132 DockedWindowResizer::DockedWindowResizer(WindowResizer* next_window_resizer,
146 const Details& details) 133 wm::WindowState* window_state)
147 : details_(details), 134 : WindowResizer(window_state),
148 next_window_resizer_(next_window_resizer), 135 next_window_resizer_(next_window_resizer),
149 dock_layout_(NULL), 136 dock_layout_(NULL),
150 initial_dock_layout_(NULL), 137 initial_dock_layout_(NULL),
151 did_move_or_resize_(false), 138 did_move_or_resize_(false),
152 was_docked_(false), 139 was_docked_(false),
153 is_docked_(false), 140 is_docked_(false),
154 was_bounds_changed_by_user_( 141 was_bounds_changed_by_user_(window_state->bounds_changed_by_user()),
155 wm::GetWindowState(details.window)->bounds_changed_by_user()),
156 weak_ptr_factory_(this) { 142 weak_ptr_factory_(this) {
157 DCHECK(details_.is_resizable); 143 DCHECK(details().is_resizable);
158 aura::Window* dock_container = Shell::GetContainer( 144 aura::Window* dock_container = Shell::GetContainer(
159 details.window->GetRootWindow(), 145 GetTarget()->GetRootWindow(),
160 kShellWindowId_DockedContainer); 146 kShellWindowId_DockedContainer);
161 dock_layout_ = static_cast<DockedWindowLayoutManager*>( 147 dock_layout_ = static_cast<DockedWindowLayoutManager*>(
162 dock_container->layout_manager()); 148 dock_container->layout_manager());
163 initial_dock_layout_ = dock_layout_; 149 initial_dock_layout_ = dock_layout_;
164 was_docked_ = details.window->parent() == dock_container; 150 was_docked_ = GetTarget()->parent() == dock_container;
165 is_docked_ = was_docked_; 151 is_docked_ = was_docked_;
166 } 152 }
167 153
168 void DockedWindowResizer::MaybeSnapToEdge(const gfx::Rect& bounds, 154 void DockedWindowResizer::MaybeSnapToEdge(const gfx::Rect& bounds,
169 gfx::Point* offset) { 155 gfx::Point* offset) {
170 // Windows only snap magnetically when they were previously docked. 156 // Windows only snap magnetically when they were previously docked.
171 if (!was_docked_) 157 if (!was_docked_)
172 return; 158 return;
173 DockedAlignment dock_alignment = dock_layout_->CalculateAlignment(); 159 DockedAlignment dock_alignment = dock_layout_->CalculateAlignment();
174 gfx::Rect dock_bounds = ScreenAsh::ConvertRectFromScreen( 160 gfx::Rect dock_bounds = ScreenAsh::ConvertRectFromScreen(
(...skipping 15 matching lines...) Expand all
190 if (dock_alignment == DOCKED_ALIGNMENT_RIGHT || 176 if (dock_alignment == DOCKED_ALIGNMENT_RIGHT ||
191 dock_alignment == DOCKED_ALIGNMENT_NONE) { 177 dock_alignment == DOCKED_ALIGNMENT_NONE) {
192 const int distance = dock_bounds.right() - bounds.right(); 178 const int distance = dock_bounds.right() - bounds.right();
193 if (distance < kSnapToDockDistance && distance > 0) 179 if (distance < kSnapToDockDistance && distance > 0)
194 offset->set_x(distance); 180 offset->set_x(distance);
195 } 181 }
196 } 182 }
197 183
198 void DockedWindowResizer::StartedDragging() { 184 void DockedWindowResizer::StartedDragging() {
199 // During resizing the window width is preserved by DockedwindowLayoutManager. 185 // During resizing the window width is preserved by DockedwindowLayoutManager.
200 wm::WindowState* window_state = wm::GetWindowState(GetTarget());
201 if (is_docked_ && 186 if (is_docked_ &&
202 (details_.bounds_change & WindowResizer::kBoundsChange_Resizes)) { 187 (details().bounds_change & WindowResizer::kBoundsChange_Resizes)) {
203 window_state->set_bounds_changed_by_user(true); 188 window_state_->set_bounds_changed_by_user(true);
204 } 189 }
205 190
206 // Tell the dock layout manager that we are dragging this window. 191 // Tell the dock layout manager that we are dragging this window.
207 // At this point we are not yet animating the window as it may not be 192 // At this point we are not yet animating the window as it may not be
208 // inside the docked area. 193 // inside the docked area.
209 dock_layout_->StartDragging(GetTarget()); 194 dock_layout_->StartDragging(GetTarget());
210 // Reparent workspace windows during the drag to elevate them above workspace. 195 // Reparent workspace windows during the drag to elevate them above workspace.
211 // Other windows for which the DockedWindowResizer is instantiated include 196 // Other windows for which the DockedWindowResizer is instantiated include
212 // panels and windows that are already docked. Those do not need reparenting. 197 // panels and windows that are already docked. Those do not need reparenting.
213 if (GetTarget()->type() != ui::wm::WINDOW_TYPE_PANEL && 198 if (GetTarget()->type() != ui::wm::WINDOW_TYPE_PANEL &&
214 GetTarget()->parent()->id() == kShellWindowId_DefaultContainer) { 199 GetTarget()->parent()->id() == kShellWindowId_DefaultContainer) {
215 // The window is going to be reparented - avoid completing the drag. 200 // The window is going to be reparented - avoid completing the drag.
216 window_state->set_continue_drag_after_reparent(true); 201 window_state_->set_continue_drag_after_reparent(true);
217 202
218 // Reparent the window into the docked windows container in order to get it 203 // Reparent the window into the docked windows container in order to get it
219 // on top of other docked windows. 204 // on top of other docked windows.
220 aura::Window* docked_container = Shell::GetContainer( 205 aura::Window* docked_container = Shell::GetContainer(
221 GetTarget()->GetRootWindow(), 206 GetTarget()->GetRootWindow(),
222 kShellWindowId_DockedContainer); 207 kShellWindowId_DockedContainer);
223 wm::ReparentChildWithTransientChildren(GetTarget(), 208 wm::ReparentChildWithTransientChildren(GetTarget(),
224 GetTarget()->parent(), 209 GetTarget()->parent(),
225 docked_container); 210 docked_container);
226 } 211 }
227 if (is_docked_) 212 if (is_docked_)
228 dock_layout_->DockDraggedWindow(GetTarget()); 213 dock_layout_->DockDraggedWindow(GetTarget());
229 } 214 }
230 215
231 void DockedWindowResizer::FinishedDragging() { 216 void DockedWindowResizer::FinishedDragging() {
232 if (!did_move_or_resize_) 217 if (!did_move_or_resize_)
233 return; 218 return;
234 did_move_or_resize_ = false; 219 did_move_or_resize_ = false;
235 aura::Window* window = GetTarget(); 220 aura::Window* window = GetTarget();
236 wm::WindowState* window_state = wm::GetWindowState(window);
237 const bool is_attached_panel = window->type() == ui::wm::WINDOW_TYPE_PANEL && 221 const bool is_attached_panel = window->type() == ui::wm::WINDOW_TYPE_PANEL &&
238 window_state->panel_attached(); 222 window_state_->panel_attached();
239 const bool is_resized = 223 const bool is_resized =
240 (details_.bounds_change & WindowResizer::kBoundsChange_Resizes) != 0; 224 (details().bounds_change & WindowResizer::kBoundsChange_Resizes) != 0;
241 225
242 // When drag is completed the dragged docked window is resized to the bounds 226 // When drag is completed the dragged docked window is resized to the bounds
243 // calculated by the layout manager that conform to other docked windows. 227 // calculated by the layout manager that conform to other docked windows.
244 if (!is_attached_panel && is_docked_ && !is_resized) { 228 if (!is_attached_panel && is_docked_ && !is_resized) {
245 gfx::Rect bounds = ScreenAsh::ConvertRectFromScreen( 229 gfx::Rect bounds = ScreenAsh::ConvertRectFromScreen(
246 window->parent(), dock_layout_->dragged_bounds()); 230 window->parent(), dock_layout_->dragged_bounds());
247 if (!bounds.IsEmpty() && bounds.width() != window->bounds().width()) { 231 if (!bounds.IsEmpty() && bounds.width() != window->bounds().width()) {
248 window->SetBounds(bounds); 232 window->SetBounds(bounds);
249 } 233 }
250 } 234 }
251 // If a window has restore bounds, update the restore origin and width but not 235 // If a window has restore bounds, update the restore origin and width but not
252 // the height (since the height is auto-calculated for the docked windows). 236 // the height (since the height is auto-calculated for the docked windows).
253 if (is_resized && is_docked_ && window_state->HasRestoreBounds()) { 237 if (is_resized && is_docked_ && window_state_->HasRestoreBounds()) {
254 gfx::Rect restore_bounds = window->GetBoundsInScreen(); 238 gfx::Rect restore_bounds = window->GetBoundsInScreen();
255 restore_bounds.set_height( 239 restore_bounds.set_height(
256 window_state->GetRestoreBoundsInScreen().height()); 240 window_state_->GetRestoreBoundsInScreen().height());
257 window_state->SetRestoreBoundsInScreen(restore_bounds); 241 window_state_->SetRestoreBoundsInScreen(restore_bounds);
258 } 242 }
259 243
260 // Check if the window needs to be docked or returned to workspace. 244 // Check if the window needs to be docked or returned to workspace.
261 DockedAction action = MaybeReparentWindowOnDragCompletion(is_resized, 245 DockedAction action = MaybeReparentWindowOnDragCompletion(is_resized,
262 is_attached_panel); 246 is_attached_panel);
263 dock_layout_->FinishDragging( 247 dock_layout_->FinishDragging(
264 action, 248 action,
265 details_.source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? 249 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ?
266 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); 250 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH);
267 251
268 // If we started the drag in one root window and moved into another root 252 // If we started the drag in one root window and moved into another root
269 // but then canceled the drag we may need to inform the original layout 253 // but then canceled the drag we may need to inform the original layout
270 // manager that the drag is finished. 254 // manager that the drag is finished.
271 if (initial_dock_layout_ != dock_layout_) 255 if (initial_dock_layout_ != dock_layout_)
272 initial_dock_layout_->FinishDragging( 256 initial_dock_layout_->FinishDragging(
273 DOCKED_ACTION_NONE, 257 DOCKED_ACTION_NONE,
274 details_.source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ? 258 details().source == aura::client::WINDOW_MOVE_SOURCE_MOUSE ?
275 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH); 259 DOCKED_ACTION_SOURCE_MOUSE : DOCKED_ACTION_SOURCE_TOUCH);
276 is_docked_ = false; 260 is_docked_ = false;
277 } 261 }
278 262
279 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( 263 DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion(
280 bool is_resized, bool is_attached_panel) { 264 bool is_resized, bool is_attached_panel) {
281 aura::Window* window = GetTarget(); 265 aura::Window* window = GetTarget();
282 266
283 // Check if the window needs to be docked or returned to workspace. 267 // Check if the window needs to be docked or returned to workspace.
284 DockedAction action = DOCKED_ACTION_NONE; 268 DockedAction action = DOCKED_ACTION_NONE;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // before. 311 // before.
328 if (is_docked_) { 312 if (is_docked_) {
329 wm::GetWindowState(window)->set_bounds_changed_by_user( 313 wm::GetWindowState(window)->set_bounds_changed_by_user(
330 was_docked_ && (is_resized || was_bounds_changed_by_user_)); 314 was_docked_ && (is_resized || was_bounds_changed_by_user_));
331 } 315 }
332 return action; 316 return action;
333 } 317 }
334 318
335 } // namespace internal 319 } // namespace internal
336 } // namespace ash 320 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/dock/docked_window_resizer.h ('k') | ash/wm/drag_details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698