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

Side by Side Diff: ash/wm/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/window_resizer.h ('k') | ash/wm/window_state.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 (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/window_resizer.h" 5 #include "ash/wm/window_resizer.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/wm/coordinate_conversion.h" 10 #include "ash/wm/coordinate_conversion.h"
11 #include "ash/wm/dock/docked_window_layout_manager.h" 11 #include "ash/wm/dock/docked_window_layout_manager.h"
12 #include "ash/wm/window_state.h" 12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/aura/window_delegate.h" 17 #include "ui/aura/window_delegate.h"
18 #include "ui/base/hit_test.h" 18 #include "ui/base/hit_test.h"
19 #include "ui/base/ui_base_types.h" 19 #include "ui/base/ui_base_types.h"
20 #include "ui/compositor/scoped_layer_animation_settings.h" 20 #include "ui/compositor/scoped_layer_animation_settings.h"
21 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
22 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
23 23
24 namespace ash { 24 namespace ash {
25 25
26 namespace { 26 namespace {
27 27
28 int GetPositionChangeDirectionForWindowComponent(int window_component) {
29 int pos_change_direction = WindowResizer::kBoundsChangeDirection_None;
30 switch (window_component) {
31 case HTTOPLEFT:
32 case HTBOTTOMRIGHT:
33 case HTGROWBOX:
34 case HTCAPTION:
35 pos_change_direction |=
36 WindowResizer::kBoundsChangeDirection_Horizontal |
37 WindowResizer::kBoundsChangeDirection_Vertical;
38 break;
39 case HTTOP:
40 case HTTOPRIGHT:
41 case HTBOTTOM:
42 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical;
43 break;
44 case HTBOTTOMLEFT:
45 case HTRIGHT:
46 case HTLEFT:
47 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal;
48 break;
49 default:
50 break;
51 }
52 return pos_change_direction;
53 }
54
55 int GetSizeChangeDirectionForWindowComponent(int window_component) {
56 int size_change_direction = WindowResizer::kBoundsChangeDirection_None;
57 switch (window_component) {
58 case HTTOPLEFT:
59 case HTTOPRIGHT:
60 case HTBOTTOMLEFT:
61 case HTBOTTOMRIGHT:
62 case HTGROWBOX:
63 case HTCAPTION:
64 size_change_direction |=
65 WindowResizer::kBoundsChangeDirection_Horizontal |
66 WindowResizer::kBoundsChangeDirection_Vertical;
67 break;
68 case HTTOP:
69 case HTBOTTOM:
70 size_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical;
71 break;
72 case HTRIGHT:
73 case HTLEFT:
74 size_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal;
75 break;
76 default:
77 break;
78 }
79 return size_change_direction;
80 }
81
82 // Returns true for resize components along the right edge, where a drag in 28 // Returns true for resize components along the right edge, where a drag in
83 // positive x will make the window larger. 29 // positive x will make the window larger.
84 bool IsRightEdge(int window_component) { 30 bool IsRightEdge(int window_component) {
85 return window_component == HTTOPRIGHT || 31 return window_component == HTTOPRIGHT ||
86 window_component == HTRIGHT || 32 window_component == HTRIGHT ||
87 window_component == HTBOTTOMRIGHT || 33 window_component == HTBOTTOMRIGHT ||
88 window_component == HTGROWBOX; 34 window_component == HTGROWBOX;
89 } 35 }
90 36
91 } // namespace 37 } // namespace
92 38
93 // static 39 // static
94 const int WindowResizer::kBoundsChange_None = 0; 40 const int WindowResizer::kBoundsChange_None = 0;
95 // static 41 // static
96 const int WindowResizer::kBoundsChange_Repositions = 1; 42 const int WindowResizer::kBoundsChange_Repositions = 1;
97 // static 43 // static
98 const int WindowResizer::kBoundsChange_Resizes = 2; 44 const int WindowResizer::kBoundsChange_Resizes = 2;
99 45
100 // static 46 // static
101 const int WindowResizer::kBoundsChangeDirection_None = 0; 47 const int WindowResizer::kBoundsChangeDirection_None = 0;
102 // static 48 // static
103 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; 49 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1;
104 // static 50 // static
105 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; 51 const int WindowResizer::kBoundsChangeDirection_Vertical = 2;
106 52
107 WindowResizer::Details::Details()
108 : window(NULL),
109 window_state(NULL),
110 window_component(HTNOWHERE),
111 bounds_change(0),
112 position_change_direction(0),
113 size_change_direction(0),
114 is_resizable(false),
115 source(aura::client::WINDOW_MOVE_SOURCE_MOUSE) {
116 }
117
118 WindowResizer::Details::Details(aura::Window* window,
119 const gfx::Point& location,
120 int window_component,
121 aura::client::WindowMoveSource source)
122 : window(window),
123 window_state(wm::GetWindowState(window)),
124 initial_bounds_in_parent(window->bounds()),
125 restore_bounds(gfx::Rect()),
126 initial_location_in_parent(location),
127 initial_opacity(window->layer()->opacity()),
128 window_component(window_component),
129 bounds_change(GetBoundsChangeForWindowComponent(window_component)),
130 position_change_direction(
131 GetPositionChangeDirectionForWindowComponent(window_component)),
132 size_change_direction(
133 GetSizeChangeDirectionForWindowComponent(window_component)),
134 is_resizable(bounds_change != kBoundsChangeDirection_None),
135 source(source) {
136 if (window_state->IsNormalShowState() &&
137 window_state->HasRestoreBounds() &&
138 window_component == HTCAPTION)
139 restore_bounds = window_state->GetRestoreBoundsInScreen();
140 }
141
142 WindowResizer::Details::~Details() {
143 }
144
145 WindowResizer::WindowResizer() { 53 WindowResizer::WindowResizer() {
146 } 54 }
147 55
56 WindowResizer::WindowResizer(wm::WindowState* window_state)
57 : window_state_(window_state) {
58 DCHECK(window_state_->drag_details());
59 }
60
148 WindowResizer::~WindowResizer() { 61 WindowResizer::~WindowResizer() {
149 } 62 }
150 63
151 // static 64 // static
152 int WindowResizer::GetBoundsChangeForWindowComponent(int component) { 65 int WindowResizer::GetBoundsChangeForWindowComponent(int component) {
153 int bounds_change = WindowResizer::kBoundsChange_None; 66 int bounds_change = WindowResizer::kBoundsChange_None;
154 switch (component) { 67 switch (component) {
155 case HTTOPLEFT: 68 case HTTOPLEFT:
156 case HTTOP: 69 case HTTOP:
157 case HTTOPRIGHT: 70 case HTTOPRIGHT:
(...skipping 10 matching lines...) Expand all
168 case HTBOTTOM: 81 case HTBOTTOM:
169 case HTGROWBOX: 82 case HTGROWBOX:
170 bounds_change |= WindowResizer::kBoundsChange_Resizes; 83 bounds_change |= WindowResizer::kBoundsChange_Resizes;
171 break; 84 break;
172 default: 85 default:
173 break; 86 break;
174 } 87 }
175 return bounds_change; 88 return bounds_change;
176 } 89 }
177 90
178 // static 91 //static
92 int WindowResizer::GetPositionChangeDirectionForWindowComponent(
93 int window_component) {
94 int pos_change_direction = WindowResizer::kBoundsChangeDirection_None;
95 switch (window_component) {
96 case HTTOPLEFT:
97 case HTBOTTOMRIGHT:
98 case HTGROWBOX:
99 case HTCAPTION:
100 pos_change_direction |=
101 WindowResizer::kBoundsChangeDirection_Horizontal |
102 WindowResizer::kBoundsChangeDirection_Vertical;
103 break;
104 case HTTOP:
105 case HTTOPRIGHT:
106 case HTBOTTOM:
107 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical;
108 break;
109 case HTBOTTOMLEFT:
110 case HTRIGHT:
111 case HTLEFT:
112 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal;
113 break;
114 default:
115 break;
116 }
117 return pos_change_direction;
118 }
119
179 gfx::Rect WindowResizer::CalculateBoundsForDrag( 120 gfx::Rect WindowResizer::CalculateBoundsForDrag(
180 const Details& details,
181 const gfx::Point& passed_location) { 121 const gfx::Point& passed_location) {
182 if (!details.is_resizable) 122 if (!details().is_resizable)
183 return details.initial_bounds_in_parent; 123 return details().initial_bounds_in_parent;
184 124
185 gfx::Point location = passed_location; 125 gfx::Point location = passed_location;
186 int delta_x = location.x() - details.initial_location_in_parent.x(); 126 int delta_x = location.x() - details().initial_location_in_parent.x();
187 int delta_y = location.y() - details.initial_location_in_parent.y(); 127 int delta_y = location.y() - details().initial_location_in_parent.y();
188 128
189 AdjustDeltaForTouchResize(details, &delta_x, &delta_y); 129 AdjustDeltaForTouchResize(&delta_x, &delta_y);
190 130
191 // The minimize size constraint may limit how much we change the window 131 // The minimize size constraint may limit how much we change the window
192 // position. For example, dragging the left edge to the right should stop 132 // position. For example, dragging the left edge to the right should stop
193 // repositioning the window when the minimize size is reached. 133 // repositioning the window when the minimize size is reached.
194 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); 134 gfx::Size size = GetSizeForDrag(&delta_x, &delta_y);
195 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); 135 gfx::Point origin = GetOriginForDrag(delta_x, delta_y);
196 gfx::Rect new_bounds(origin, size); 136 gfx::Rect new_bounds(origin, size);
197 137
198 // Sizing has to keep the result on the screen. Note that this correction 138 // Sizing has to keep the result on the screen. Note that this correction
199 // has to come first since it might have an impact on the origin as well as 139 // has to come first since it might have an impact on the origin as well as
200 // on the size. 140 // on the size.
201 if (details.bounds_change & kBoundsChange_Resizes) { 141 if (details().bounds_change & kBoundsChange_Resizes) {
202 gfx::Rect work_area = 142 gfx::Rect work_area =
203 Shell::GetScreen()->GetDisplayNearestWindow(details.window).work_area(); 143 Shell::GetScreen()->GetDisplayNearestWindow(GetTarget()).work_area();
204 aura::Window* dock_container = Shell::GetContainer( 144 aura::Window* dock_container = Shell::GetContainer(
205 details.window->GetRootWindow(), 145 GetTarget()->GetRootWindow(),
206 internal::kShellWindowId_DockedContainer); 146 internal::kShellWindowId_DockedContainer);
207 internal::DockedWindowLayoutManager* dock_layout = 147 internal::DockedWindowLayoutManager* dock_layout =
208 static_cast<internal::DockedWindowLayoutManager*>( 148 static_cast<internal::DockedWindowLayoutManager*>(
209 dock_container->layout_manager()); 149 dock_container->layout_manager());
210 150
211 work_area.Union(dock_layout->docked_bounds()); 151 work_area.Union(dock_layout->docked_bounds());
212 work_area = ScreenAsh::ConvertRectFromScreen(details.window->parent(), 152 work_area = ScreenAsh::ConvertRectFromScreen(GetTarget()->parent(),
213 work_area); 153 work_area);
214 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { 154 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) {
215 if (IsRightEdge(details.window_component) && 155 if (IsRightEdge(details().window_component) &&
216 new_bounds.right() < work_area.x() + kMinimumOnScreenArea) { 156 new_bounds.right() < work_area.x() + kMinimumOnScreenArea) {
217 int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right(); 157 int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right();
218 new_bounds.set_width(new_bounds.width() + delta); 158 new_bounds.set_width(new_bounds.width() + delta);
219 } else if (new_bounds.x() > work_area.right() - kMinimumOnScreenArea) { 159 } else if (new_bounds.x() > work_area.right() - kMinimumOnScreenArea) {
220 int width = new_bounds.right() - work_area.right() + 160 int width = new_bounds.right() - work_area.right() +
221 kMinimumOnScreenArea; 161 kMinimumOnScreenArea;
222 new_bounds.set_x(work_area.right() - kMinimumOnScreenArea); 162 new_bounds.set_x(work_area.right() - kMinimumOnScreenArea);
223 new_bounds.set_width(width); 163 new_bounds.set_width(width);
224 } 164 }
225 } 165 }
226 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { 166 if (details().size_change_direction & kBoundsChangeDirection_Vertical) {
227 if (!IsBottomEdge(details.window_component) && 167 if (!IsBottomEdge(details().window_component) &&
228 new_bounds.y() > work_area.bottom() - kMinimumOnScreenArea) { 168 new_bounds.y() > work_area.bottom() - kMinimumOnScreenArea) {
229 int height = new_bounds.bottom() - work_area.bottom() + 169 int height = new_bounds.bottom() - work_area.bottom() +
230 kMinimumOnScreenArea; 170 kMinimumOnScreenArea;
231 new_bounds.set_y(work_area.bottom() - kMinimumOnScreenArea); 171 new_bounds.set_y(work_area.bottom() - kMinimumOnScreenArea);
232 new_bounds.set_height(height); 172 new_bounds.set_height(height);
233 } else if (details.window_component == HTBOTTOM || 173 } else if (details().window_component == HTBOTTOM ||
234 details.window_component == HTBOTTOMRIGHT || 174 details().window_component == HTBOTTOMRIGHT ||
235 details.window_component == HTBOTTOMLEFT) { 175 details().window_component == HTBOTTOMLEFT) {
236 // Update bottom edge to stay in the work area when we are resizing 176 // Update bottom edge to stay in the work area when we are resizing
237 // by dragging the bottom edge or corners. 177 // by dragging the bottom edge or corners.
238 if (new_bounds.bottom() > work_area.bottom()) 178 if (new_bounds.bottom() > work_area.bottom())
239 new_bounds.Inset(0, 0, 0, 179 new_bounds.Inset(0, 0, 0,
240 new_bounds.bottom() - work_area.bottom()); 180 new_bounds.bottom() - work_area.bottom());
241 } 181 }
242 } 182 }
243 if (details.bounds_change & kBoundsChange_Repositions && 183 if (details().bounds_change & kBoundsChange_Repositions &&
244 new_bounds.y() < 0) { 184 new_bounds.y() < 0) {
245 int delta = new_bounds.y(); 185 int delta = new_bounds.y();
246 new_bounds.set_y(0); 186 new_bounds.set_y(0);
247 new_bounds.set_height(new_bounds.height() + delta); 187 new_bounds.set_height(new_bounds.height() + delta);
248 } 188 }
249 } 189 }
250 190
251 if (details.bounds_change & kBoundsChange_Repositions) { 191 if (details().bounds_change & kBoundsChange_Repositions) {
252 // When we might want to reposition a window which is also restored to its 192 // When we might want to reposition a window which is also restored to its
253 // previous size, to keep the cursor within the dragged window. 193 // previous size, to keep the cursor within the dragged window.
254 if (!details.restore_bounds.IsEmpty()) { 194 if (!details().restore_bounds.IsEmpty()) {
255 // However - it is not desirable to change the origin if the window would 195 // However - it is not desirable to change the origin if the window would
256 // be still hit by the cursor. 196 // be still hit by the cursor.
257 if (details.initial_location_in_parent.x() > 197 if (details().initial_location_in_parent.x() >
258 details.initial_bounds_in_parent.x() + details.restore_bounds.width()) 198 details().initial_bounds_in_parent.x() +
259 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); 199 details().restore_bounds.width())
200 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2);
260 } 201 }
261 202
262 // Make sure that |new_bounds| doesn't leave any of the displays. Note that 203 // Make sure that |new_bounds| doesn't leave any of the displays. Note that
263 // the |work_area| above isn't good for this check since it is the work area 204 // the |work_area| above isn't good for this check since it is the work area
264 // for the current display but the window can move to a different one. 205 // for the current display but the window can move to a different one.
265 aura::Window* parent = details.window->parent(); 206 aura::Window* parent = GetTarget()->parent();
266 gfx::Point passed_location_in_screen(passed_location); 207 gfx::Point passed_location_in_screen(passed_location);
267 wm::ConvertPointToScreen(parent, &passed_location_in_screen); 208 wm::ConvertPointToScreen(parent, &passed_location_in_screen);
268 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); 209 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size());
269 // Use a pointer location (matching the logic in DragWindowResizer) to 210 // Use a pointer location (matching the logic in DragWindowResizer) to
270 // calculate the target display after the drag. 211 // calculate the target display after the drag.
271 const gfx::Display& display = 212 const gfx::Display& display =
272 Shell::GetScreen()->GetDisplayMatching(near_passed_location); 213 Shell::GetScreen()->GetDisplayMatching(near_passed_location);
273 aura::Window* dock_container = Shell::GetContainer( 214 aura::Window* dock_container = Shell::GetContainer(
274 wm::GetRootWindowMatching(near_passed_location), 215 wm::GetRootWindowMatching(near_passed_location),
275 internal::kShellWindowId_DockedContainer); 216 internal::kShellWindowId_DockedContainer);
(...skipping 21 matching lines...) Expand all
297 } 238 }
298 239
299 // static 240 // static
300 bool WindowResizer::IsBottomEdge(int window_component) { 241 bool WindowResizer::IsBottomEdge(int window_component) {
301 return window_component == HTBOTTOMLEFT || 242 return window_component == HTBOTTOMLEFT ||
302 window_component == HTBOTTOM || 243 window_component == HTBOTTOM ||
303 window_component == HTBOTTOMRIGHT || 244 window_component == HTBOTTOMRIGHT ||
304 window_component == HTGROWBOX; 245 window_component == HTGROWBOX;
305 } 246 }
306 247
307 // static 248 void WindowResizer::AdjustDeltaForTouchResize(int* delta_x, int* delta_y) {
308 void WindowResizer::AdjustDeltaForTouchResize(const Details& details, 249 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH ||
309 int* delta_x, 250 !(details().bounds_change & kBoundsChange_Resizes))
310 int* delta_y) {
311 if (details.source != aura::client::WINDOW_MOVE_SOURCE_TOUCH ||
312 !(details.bounds_change & kBoundsChange_Resizes))
313 return; 251 return;
314 252
315 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { 253 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) {
316 if (IsRightEdge(details.window_component)) { 254 if (IsRightEdge(details().window_component)) {
317 *delta_x += details.initial_location_in_parent.x() - 255 *delta_x += details().initial_location_in_parent.x() -
318 details.initial_bounds_in_parent.right(); 256 details().initial_bounds_in_parent.right();
319 } else { 257 } else {
320 *delta_x += details.initial_location_in_parent.x() - 258 *delta_x += details().initial_location_in_parent.x() -
321 details.initial_bounds_in_parent.x(); 259 details().initial_bounds_in_parent.x();
322 } 260 }
323 } 261 }
324 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { 262 if (details().size_change_direction & kBoundsChangeDirection_Vertical) {
325 if (IsBottomEdge(details.window_component)) { 263 if (IsBottomEdge(details().window_component)) {
326 *delta_y += details.initial_location_in_parent.y() - 264 *delta_y += details().initial_location_in_parent.y() -
327 details.initial_bounds_in_parent.bottom(); 265 details().initial_bounds_in_parent.bottom();
328 } else { 266 } else {
329 *delta_y += details.initial_location_in_parent.y() - 267 *delta_y += details().initial_location_in_parent.y() -
330 details.initial_bounds_in_parent.y(); 268 details().initial_bounds_in_parent.y();
331 } 269 }
332 } 270 }
333 } 271 }
334 272
335 // static 273 gfx::Point WindowResizer::GetOriginForDrag(int delta_x, int delta_y) {
336 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, 274 gfx::Point origin = details().initial_bounds_in_parent.origin();
337 int delta_x, 275 if (details().bounds_change & kBoundsChange_Repositions) {
338 int delta_y) { 276 int pos_change_direction = GetPositionChangeDirectionForWindowComponent(
339 gfx::Point origin = details.initial_bounds_in_parent.origin(); 277 details().window_component);
340 if (details.bounds_change & kBoundsChange_Repositions) {
341 int pos_change_direction =
342 GetPositionChangeDirectionForWindowComponent(details.window_component);
343 if (pos_change_direction & kBoundsChangeDirection_Horizontal) 278 if (pos_change_direction & kBoundsChangeDirection_Horizontal)
344 origin.Offset(delta_x, 0); 279 origin.Offset(delta_x, 0);
345 if (pos_change_direction & kBoundsChangeDirection_Vertical) 280 if (pos_change_direction & kBoundsChangeDirection_Vertical)
346 origin.Offset(0, delta_y); 281 origin.Offset(0, delta_y);
347 } 282 }
348 return origin; 283 return origin;
349 } 284 }
350 285
351 // static 286 gfx::Size WindowResizer::GetSizeForDrag(int* delta_x, int* delta_y) {
352 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, 287 gfx::Size size = details().initial_bounds_in_parent.size();
353 int* delta_x, 288 if (details().bounds_change & kBoundsChange_Resizes) {
354 int* delta_y) { 289 gfx::Size min_size = GetTarget()->delegate()->GetMinimumSize();
355 gfx::Size size = details.initial_bounds_in_parent.size(); 290 size.SetSize(GetWidthForDrag(min_size.width(), delta_x),
356 if (details.bounds_change & kBoundsChange_Resizes) { 291 GetHeightForDrag(min_size.height(), delta_y));
357 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); 292 } else if (!details().restore_bounds.IsEmpty()) {
358 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), 293 size = details().restore_bounds.size();
359 GetHeightForDrag(details, min_size.height(), delta_y));
360 } else if (!details.restore_bounds.IsEmpty()) {
361 size = details.restore_bounds.size();
362 } 294 }
363 return size; 295 return size;
364 } 296 }
365 297
366 // static 298 int WindowResizer::GetWidthForDrag(int min_width, int* delta_x) {
367 int WindowResizer::GetWidthForDrag(const Details& details, 299 int width = details().initial_bounds_in_parent.width();
368 int min_width, 300 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) {
369 int* delta_x) {
370 int width = details.initial_bounds_in_parent.width();
371 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) {
372 // Along the right edge, positive delta_x increases the window size. 301 // Along the right edge, positive delta_x increases the window size.
373 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; 302 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1;
374 width += x_multiplier * (*delta_x); 303 width += x_multiplier * (*delta_x);
375 304
376 // Ensure we don't shrink past the minimum width and clamp delta_x 305 // Ensure we don't shrink past the minimum width and clamp delta_x
377 // for the window origin computation. 306 // for the window origin computation.
378 if (width < min_width) { 307 if (width < min_width) {
379 width = min_width; 308 width = min_width;
380 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - 309 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() -
381 min_width); 310 min_width);
382 } 311 }
383 312
384 // And don't let the window go bigger than the display. 313 // And don't let the window go bigger than the display.
385 int max_width = Shell::GetScreen()->GetDisplayNearestWindow( 314 int max_width = Shell::GetScreen()->GetDisplayNearestWindow(
386 details.window).bounds().width(); 315 GetTarget()).bounds().width();
387 gfx::Size max_size = details.window->delegate()->GetMaximumSize(); 316 gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize();
388 if (max_size.width() != 0) 317 if (max_size.width() != 0)
389 max_width = std::min(max_width, max_size.width()); 318 max_width = std::min(max_width, max_size.width());
390 if (width > max_width) { 319 if (width > max_width) {
391 width = max_width; 320 width = max_width;
392 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - 321 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() -
393 max_width); 322 max_width);
394 } 323 }
395 } 324 }
396 return width; 325 return width;
397 } 326 }
398 327
399 // static 328 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) {
400 int WindowResizer::GetHeightForDrag(const Details& details, 329 int height = details().initial_bounds_in_parent.height();
401 int min_height, 330 if (details().size_change_direction & kBoundsChangeDirection_Vertical) {
402 int* delta_y) {
403 int height = details.initial_bounds_in_parent.height();
404 if (details.size_change_direction & kBoundsChangeDirection_Vertical) {
405 // Along the bottom edge, positive delta_y increases the window size. 331 // Along the bottom edge, positive delta_y increases the window size.
406 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; 332 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1;
407 height += y_multiplier * (*delta_y); 333 height += y_multiplier * (*delta_y);
408 334
409 // Ensure we don't shrink past the minimum height and clamp delta_y 335 // Ensure we don't shrink past the minimum height and clamp delta_y
410 // for the window origin computation. 336 // for the window origin computation.
411 if (height < min_height) { 337 if (height < min_height) {
412 height = min_height; 338 height = min_height;
413 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - 339 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() -
414 min_height); 340 min_height);
415 } 341 }
416 342
417 // And don't let the window go bigger than the display. 343 // And don't let the window go bigger than the display.
418 int max_height = Shell::GetScreen()->GetDisplayNearestWindow( 344 int max_height = Shell::GetScreen()->GetDisplayNearestWindow(
419 details.window).bounds().height(); 345 GetTarget()).bounds().height();
420 gfx::Size max_size = details.window->delegate()->GetMaximumSize(); 346 gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize();
421 if (max_size.height() != 0) 347 if (max_size.height() != 0)
422 max_height = std::min(max_height, max_size.height()); 348 max_height = std::min(max_height, max_size.height());
423 if (height > max_height) { 349 if (height > max_height) {
424 height = max_height; 350 height = max_height;
425 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - 351 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() -
426 max_height); 352 max_height);
427 } 353 }
428 } 354 }
429 return height; 355 return height;
430 } 356 }
431 357
432 } // namespace aura 358 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_resizer.h ('k') | ash/wm/window_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698