OLD | NEW |
---|---|
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" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 // static | 97 // static |
98 const int WindowResizer::kBoundsChange_Resizes = 2; | 98 const int WindowResizer::kBoundsChange_Resizes = 2; |
99 | 99 |
100 // static | 100 // static |
101 const int WindowResizer::kBoundsChangeDirection_None = 0; | 101 const int WindowResizer::kBoundsChangeDirection_None = 0; |
102 // static | 102 // static |
103 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; | 103 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; |
104 // static | 104 // static |
105 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; | 105 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; |
106 | 106 |
107 WindowResizer::Details::Details() | 107 DragDetails::DragDetails() |
108 : window(NULL), | 108 : initial_opacity(0.0), |
109 window_state(NULL), | |
110 window_component(HTNOWHERE), | 109 window_component(HTNOWHERE), |
111 bounds_change(0), | 110 bounds_change(0), |
112 position_change_direction(0), | 111 position_change_direction(0), |
113 size_change_direction(0), | 112 size_change_direction(0), |
114 is_resizable(false), | 113 is_resizable(false), |
115 source(aura::client::WINDOW_MOVE_SOURCE_MOUSE) { | 114 source(aura::client::WINDOW_MOVE_SOURCE_MOUSE), |
115 should_attach_to_shelf(false), | |
116 window_resizer(NULL) { | |
116 } | 117 } |
117 | 118 |
118 WindowResizer::Details::Details(aura::Window* window, | 119 DragDetails::DragDetails(aura::Window* window, |
119 const gfx::Point& location, | 120 const gfx::Point& location, |
120 int window_component, | 121 int window_component, |
121 aura::client::WindowMoveSource source) | 122 aura::client::WindowMoveSource source) |
122 : window(window), | 123 : initial_bounds_in_parent(window->bounds()), |
123 window_state(wm::GetWindowState(window)), | |
124 initial_bounds_in_parent(window->bounds()), | |
125 restore_bounds(gfx::Rect()), | 124 restore_bounds(gfx::Rect()), |
126 initial_location_in_parent(location), | 125 initial_location_in_parent(location), |
127 initial_opacity(window->layer()->opacity()), | 126 initial_opacity(window->layer()->opacity()), |
128 window_component(window_component), | 127 window_component(window_component), |
129 bounds_change(GetBoundsChangeForWindowComponent(window_component)), | 128 bounds_change( |
129 WindowResizer::GetBoundsChangeForWindowComponent(window_component)), | |
130 position_change_direction( | 130 position_change_direction( |
131 GetPositionChangeDirectionForWindowComponent(window_component)), | 131 GetPositionChangeDirectionForWindowComponent(window_component)), |
132 size_change_direction( | 132 size_change_direction( |
133 GetSizeChangeDirectionForWindowComponent(window_component)), | 133 GetSizeChangeDirectionForWindowComponent(window_component)), |
134 is_resizable(bounds_change != kBoundsChangeDirection_None), | 134 is_resizable(bounds_change != WindowResizer::kBoundsChangeDirection_None), |
135 source(source) { | 135 source(source), |
136 should_attach_to_shelf(window->type() == ui::wm::WINDOW_TYPE_PANEL && | |
137 wm::GetWindowState(window)->panel_attached()), | |
138 window_resizer(NULL) { | |
139 wm::WindowState* window_state = wm::GetWindowState(window); | |
136 if (window_state->IsNormalShowState() && | 140 if (window_state->IsNormalShowState() && |
137 window_state->HasRestoreBounds() && | 141 window_state->HasRestoreBounds() && |
138 window_component == HTCAPTION) | 142 window_component == HTCAPTION) |
139 restore_bounds = window_state->GetRestoreBoundsInScreen(); | 143 restore_bounds = window_state->GetRestoreBoundsInScreen(); |
140 } | 144 } |
141 | 145 |
142 WindowResizer::Details::~Details() { | 146 DragDetails::~DragDetails() { |
143 } | 147 } |
144 | 148 |
145 WindowResizer::WindowResizer() { | 149 WindowResizer::WindowResizer() { |
146 } | 150 } |
147 | 151 |
152 WindowResizer::WindowResizer(wm::WindowState* window_state) | |
153 : window_state_(window_state) { | |
oshima
2014/01/09 19:13:45
DCHECK to make sure window_state has drag details?
varkha
2014/01/10 01:34:50
Done.
| |
154 } | |
155 | |
148 WindowResizer::~WindowResizer() { | 156 WindowResizer::~WindowResizer() { |
149 } | 157 } |
150 | 158 |
151 // static | 159 // static |
152 int WindowResizer::GetBoundsChangeForWindowComponent(int component) { | 160 int WindowResizer::GetBoundsChangeForWindowComponent(int component) { |
153 int bounds_change = WindowResizer::kBoundsChange_None; | 161 int bounds_change = WindowResizer::kBoundsChange_None; |
154 switch (component) { | 162 switch (component) { |
155 case HTTOPLEFT: | 163 case HTTOPLEFT: |
156 case HTTOP: | 164 case HTTOP: |
157 case HTTOPRIGHT: | 165 case HTTOPRIGHT: |
(...skipping 10 matching lines...) Expand all Loading... | |
168 case HTBOTTOM: | 176 case HTBOTTOM: |
169 case HTGROWBOX: | 177 case HTGROWBOX: |
170 bounds_change |= WindowResizer::kBoundsChange_Resizes; | 178 bounds_change |= WindowResizer::kBoundsChange_Resizes; |
171 break; | 179 break; |
172 default: | 180 default: |
173 break; | 181 break; |
174 } | 182 } |
175 return bounds_change; | 183 return bounds_change; |
176 } | 184 } |
177 | 185 |
178 // static | |
179 gfx::Rect WindowResizer::CalculateBoundsForDrag( | 186 gfx::Rect WindowResizer::CalculateBoundsForDrag( |
180 const Details& details, | |
181 const gfx::Point& passed_location) { | 187 const gfx::Point& passed_location) { |
182 if (!details.is_resizable) | 188 if (!details().is_resizable) |
183 return details.initial_bounds_in_parent; | 189 return details().initial_bounds_in_parent; |
184 | 190 |
185 gfx::Point location = passed_location; | 191 gfx::Point location = passed_location; |
186 int delta_x = location.x() - details.initial_location_in_parent.x(); | 192 int delta_x = location.x() - details().initial_location_in_parent.x(); |
187 int delta_y = location.y() - details.initial_location_in_parent.y(); | 193 int delta_y = location.y() - details().initial_location_in_parent.y(); |
188 | 194 |
189 AdjustDeltaForTouchResize(details, &delta_x, &delta_y); | 195 AdjustDeltaForTouchResize(&delta_x, &delta_y); |
190 | 196 |
191 // The minimize size constraint may limit how much we change the window | 197 // 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 | 198 // position. For example, dragging the left edge to the right should stop |
193 // repositioning the window when the minimize size is reached. | 199 // repositioning the window when the minimize size is reached. |
194 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 200 gfx::Size size = GetSizeForDrag(&delta_x, &delta_y); |
195 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 201 gfx::Point origin = GetOriginForDrag(delta_x, delta_y); |
196 gfx::Rect new_bounds(origin, size); | 202 gfx::Rect new_bounds(origin, size); |
197 | 203 |
198 // Sizing has to keep the result on the screen. Note that this correction | 204 // 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 | 205 // has to come first since it might have an impact on the origin as well as |
200 // on the size. | 206 // on the size. |
201 if (details.bounds_change & kBoundsChange_Resizes) { | 207 if (details().bounds_change & kBoundsChange_Resizes) { |
202 gfx::Rect work_area = | 208 gfx::Rect work_area = |
203 Shell::GetScreen()->GetDisplayNearestWindow(details.window).work_area(); | 209 Shell::GetScreen()->GetDisplayNearestWindow(GetTarget()).work_area(); |
204 aura::Window* dock_container = Shell::GetContainer( | 210 aura::Window* dock_container = Shell::GetContainer( |
205 details.window->GetRootWindow(), | 211 GetTarget()->GetRootWindow(), |
206 internal::kShellWindowId_DockedContainer); | 212 internal::kShellWindowId_DockedContainer); |
207 internal::DockedWindowLayoutManager* dock_layout = | 213 internal::DockedWindowLayoutManager* dock_layout = |
208 static_cast<internal::DockedWindowLayoutManager*>( | 214 static_cast<internal::DockedWindowLayoutManager*>( |
209 dock_container->layout_manager()); | 215 dock_container->layout_manager()); |
210 | 216 |
211 work_area.Union(dock_layout->docked_bounds()); | 217 work_area.Union(dock_layout->docked_bounds()); |
212 work_area = ScreenAsh::ConvertRectFromScreen(details.window->parent(), | 218 work_area = ScreenAsh::ConvertRectFromScreen(GetTarget()->parent(), |
213 work_area); | 219 work_area); |
214 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | 220 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { |
215 if (IsRightEdge(details.window_component) && | 221 if (IsRightEdge(details().window_component) && |
216 new_bounds.right() < work_area.x() + kMinimumOnScreenArea) { | 222 new_bounds.right() < work_area.x() + kMinimumOnScreenArea) { |
217 int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right(); | 223 int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right(); |
218 new_bounds.set_width(new_bounds.width() + delta); | 224 new_bounds.set_width(new_bounds.width() + delta); |
219 } else if (new_bounds.x() > work_area.right() - kMinimumOnScreenArea) { | 225 } else if (new_bounds.x() > work_area.right() - kMinimumOnScreenArea) { |
220 int width = new_bounds.right() - work_area.right() + | 226 int width = new_bounds.right() - work_area.right() + |
221 kMinimumOnScreenArea; | 227 kMinimumOnScreenArea; |
222 new_bounds.set_x(work_area.right() - kMinimumOnScreenArea); | 228 new_bounds.set_x(work_area.right() - kMinimumOnScreenArea); |
223 new_bounds.set_width(width); | 229 new_bounds.set_width(width); |
224 } | 230 } |
225 } | 231 } |
226 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { | 232 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { |
227 if (!IsBottomEdge(details.window_component) && | 233 if (!IsBottomEdge(details().window_component) && |
228 new_bounds.y() > work_area.bottom() - kMinimumOnScreenArea) { | 234 new_bounds.y() > work_area.bottom() - kMinimumOnScreenArea) { |
229 int height = new_bounds.bottom() - work_area.bottom() + | 235 int height = new_bounds.bottom() - work_area.bottom() + |
230 kMinimumOnScreenArea; | 236 kMinimumOnScreenArea; |
231 new_bounds.set_y(work_area.bottom() - kMinimumOnScreenArea); | 237 new_bounds.set_y(work_area.bottom() - kMinimumOnScreenArea); |
232 new_bounds.set_height(height); | 238 new_bounds.set_height(height); |
233 } else if (details.window_component == HTBOTTOM || | 239 } else if (details().window_component == HTBOTTOM || |
234 details.window_component == HTBOTTOMRIGHT || | 240 details().window_component == HTBOTTOMRIGHT || |
235 details.window_component == HTBOTTOMLEFT) { | 241 details().window_component == HTBOTTOMLEFT) { |
236 // Update bottom edge to stay in the work area when we are resizing | 242 // Update bottom edge to stay in the work area when we are resizing |
237 // by dragging the bottom edge or corners. | 243 // by dragging the bottom edge or corners. |
238 if (new_bounds.bottom() > work_area.bottom()) | 244 if (new_bounds.bottom() > work_area.bottom()) |
239 new_bounds.Inset(0, 0, 0, | 245 new_bounds.Inset(0, 0, 0, |
240 new_bounds.bottom() - work_area.bottom()); | 246 new_bounds.bottom() - work_area.bottom()); |
241 } | 247 } |
242 } | 248 } |
243 if (details.bounds_change & kBoundsChange_Repositions && | 249 if (details().bounds_change & kBoundsChange_Repositions && |
244 new_bounds.y() < 0) { | 250 new_bounds.y() < 0) { |
245 int delta = new_bounds.y(); | 251 int delta = new_bounds.y(); |
246 new_bounds.set_y(0); | 252 new_bounds.set_y(0); |
247 new_bounds.set_height(new_bounds.height() + delta); | 253 new_bounds.set_height(new_bounds.height() + delta); |
248 } | 254 } |
249 } | 255 } |
250 | 256 |
251 if (details.bounds_change & kBoundsChange_Repositions) { | 257 if (details().bounds_change & kBoundsChange_Repositions) { |
252 // When we might want to reposition a window which is also restored to its | 258 // 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. | 259 // previous size, to keep the cursor within the dragged window. |
254 if (!details.restore_bounds.IsEmpty()) { | 260 if (!details().restore_bounds.IsEmpty()) { |
255 // However - it is not desirable to change the origin if the window would | 261 // However - it is not desirable to change the origin if the window would |
256 // be still hit by the cursor. | 262 // be still hit by the cursor. |
257 if (details.initial_location_in_parent.x() > | 263 if (details().initial_location_in_parent.x() > |
258 details.initial_bounds_in_parent.x() + details.restore_bounds.width()) | 264 details().initial_bounds_in_parent.x() + |
259 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); | 265 details().restore_bounds.width()) |
266 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2); | |
260 } | 267 } |
261 | 268 |
262 // Make sure that |new_bounds| doesn't leave any of the displays. Note that | 269 // 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 | 270 // 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. | 271 // for the current display but the window can move to a different one. |
265 aura::Window* parent = details.window->parent(); | 272 aura::Window* parent = GetTarget()->parent(); |
266 gfx::Point passed_location_in_screen(passed_location); | 273 gfx::Point passed_location_in_screen(passed_location); |
267 wm::ConvertPointToScreen(parent, &passed_location_in_screen); | 274 wm::ConvertPointToScreen(parent, &passed_location_in_screen); |
268 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); | 275 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); |
269 // Use a pointer location (matching the logic in DragWindowResizer) to | 276 // Use a pointer location (matching the logic in DragWindowResizer) to |
270 // calculate the target display after the drag. | 277 // calculate the target display after the drag. |
271 const gfx::Display& display = | 278 const gfx::Display& display = |
272 Shell::GetScreen()->GetDisplayMatching(near_passed_location); | 279 Shell::GetScreen()->GetDisplayMatching(near_passed_location); |
273 aura::Window* dock_container = Shell::GetContainer( | 280 aura::Window* dock_container = Shell::GetContainer( |
274 wm::GetRootWindowMatching(near_passed_location), | 281 wm::GetRootWindowMatching(near_passed_location), |
275 internal::kShellWindowId_DockedContainer); | 282 internal::kShellWindowId_DockedContainer); |
(...skipping 21 matching lines...) Expand all Loading... | |
297 } | 304 } |
298 | 305 |
299 // static | 306 // static |
300 bool WindowResizer::IsBottomEdge(int window_component) { | 307 bool WindowResizer::IsBottomEdge(int window_component) { |
301 return window_component == HTBOTTOMLEFT || | 308 return window_component == HTBOTTOMLEFT || |
302 window_component == HTBOTTOM || | 309 window_component == HTBOTTOM || |
303 window_component == HTBOTTOMRIGHT || | 310 window_component == HTBOTTOMRIGHT || |
304 window_component == HTGROWBOX; | 311 window_component == HTGROWBOX; |
305 } | 312 } |
306 | 313 |
307 // static | 314 void WindowResizer::AdjustDeltaForTouchResize(int* delta_x, int* delta_y) { |
308 void WindowResizer::AdjustDeltaForTouchResize(const Details& details, | 315 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH || |
309 int* delta_x, | 316 !(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; | 317 return; |
314 | 318 |
315 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | 319 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { |
316 if (IsRightEdge(details.window_component)) { | 320 if (IsRightEdge(details().window_component)) { |
317 *delta_x += details.initial_location_in_parent.x() - | 321 *delta_x += details().initial_location_in_parent.x() - |
318 details.initial_bounds_in_parent.right(); | 322 details().initial_bounds_in_parent.right(); |
319 } else { | 323 } else { |
320 *delta_x += details.initial_location_in_parent.x() - | 324 *delta_x += details().initial_location_in_parent.x() - |
321 details.initial_bounds_in_parent.x(); | 325 details().initial_bounds_in_parent.x(); |
322 } | 326 } |
323 } | 327 } |
324 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { | 328 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { |
325 if (IsBottomEdge(details.window_component)) { | 329 if (IsBottomEdge(details().window_component)) { |
326 *delta_y += details.initial_location_in_parent.y() - | 330 *delta_y += details().initial_location_in_parent.y() - |
327 details.initial_bounds_in_parent.bottom(); | 331 details().initial_bounds_in_parent.bottom(); |
328 } else { | 332 } else { |
329 *delta_y += details.initial_location_in_parent.y() - | 333 *delta_y += details().initial_location_in_parent.y() - |
330 details.initial_bounds_in_parent.y(); | 334 details().initial_bounds_in_parent.y(); |
331 } | 335 } |
332 } | 336 } |
333 } | 337 } |
334 | 338 |
335 // static | 339 gfx::Point WindowResizer::GetOriginForDrag(int delta_x, int delta_y) { |
336 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, | 340 gfx::Point origin = details().initial_bounds_in_parent.origin(); |
337 int delta_x, | 341 if (details().bounds_change & kBoundsChange_Repositions) { |
338 int delta_y) { | 342 int pos_change_direction = GetPositionChangeDirectionForWindowComponent( |
339 gfx::Point origin = details.initial_bounds_in_parent.origin(); | 343 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) | 344 if (pos_change_direction & kBoundsChangeDirection_Horizontal) |
344 origin.Offset(delta_x, 0); | 345 origin.Offset(delta_x, 0); |
345 if (pos_change_direction & kBoundsChangeDirection_Vertical) | 346 if (pos_change_direction & kBoundsChangeDirection_Vertical) |
346 origin.Offset(0, delta_y); | 347 origin.Offset(0, delta_y); |
347 } | 348 } |
348 return origin; | 349 return origin; |
349 } | 350 } |
350 | 351 |
351 // static | 352 gfx::Size WindowResizer::GetSizeForDrag(int* delta_x, int* delta_y) { |
352 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, | 353 gfx::Size size = details().initial_bounds_in_parent.size(); |
353 int* delta_x, | 354 if (details().bounds_change & kBoundsChange_Resizes) { |
354 int* delta_y) { | 355 gfx::Size min_size = GetTarget()->delegate()->GetMinimumSize(); |
355 gfx::Size size = details.initial_bounds_in_parent.size(); | 356 size.SetSize(GetWidthForDrag(min_size.width(), delta_x), |
356 if (details.bounds_change & kBoundsChange_Resizes) { | 357 GetHeightForDrag(min_size.height(), delta_y)); |
357 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); | 358 } else if (!details().restore_bounds.IsEmpty()) { |
358 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), | 359 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 } | 360 } |
363 return size; | 361 return size; |
364 } | 362 } |
365 | 363 |
366 // static | 364 int WindowResizer::GetWidthForDrag(int min_width, int* delta_x) { |
367 int WindowResizer::GetWidthForDrag(const Details& details, | 365 int width = details().initial_bounds_in_parent.width(); |
368 int min_width, | 366 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. | 367 // Along the right edge, positive delta_x increases the window size. |
373 int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; | 368 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1; |
374 width += x_multiplier * (*delta_x); | 369 width += x_multiplier * (*delta_x); |
375 | 370 |
376 // Ensure we don't shrink past the minimum width and clamp delta_x | 371 // Ensure we don't shrink past the minimum width and clamp delta_x |
377 // for the window origin computation. | 372 // for the window origin computation. |
378 if (width < min_width) { | 373 if (width < min_width) { |
379 width = min_width; | 374 width = min_width; |
380 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - | 375 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - |
381 min_width); | 376 min_width); |
382 } | 377 } |
383 | 378 |
384 // And don't let the window go bigger than the display. | 379 // And don't let the window go bigger than the display. |
385 int max_width = Shell::GetScreen()->GetDisplayNearestWindow( | 380 int max_width = Shell::GetScreen()->GetDisplayNearestWindow( |
386 details.window).bounds().width(); | 381 GetTarget()).bounds().width(); |
387 gfx::Size max_size = details.window->delegate()->GetMaximumSize(); | 382 gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize(); |
388 if (max_size.width() != 0) | 383 if (max_size.width() != 0) |
389 max_width = std::min(max_width, max_size.width()); | 384 max_width = std::min(max_width, max_size.width()); |
390 if (width > max_width) { | 385 if (width > max_width) { |
391 width = max_width; | 386 width = max_width; |
392 *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - | 387 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - |
393 max_width); | 388 max_width); |
394 } | 389 } |
395 } | 390 } |
396 return width; | 391 return width; |
397 } | 392 } |
398 | 393 |
399 // static | 394 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) { |
400 int WindowResizer::GetHeightForDrag(const Details& details, | 395 int height = details().initial_bounds_in_parent.height(); |
401 int min_height, | 396 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. | 397 // Along the bottom edge, positive delta_y increases the window size. |
406 int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; | 398 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1; |
407 height += y_multiplier * (*delta_y); | 399 height += y_multiplier * (*delta_y); |
408 | 400 |
409 // Ensure we don't shrink past the minimum height and clamp delta_y | 401 // Ensure we don't shrink past the minimum height and clamp delta_y |
410 // for the window origin computation. | 402 // for the window origin computation. |
411 if (height < min_height) { | 403 if (height < min_height) { |
412 height = min_height; | 404 height = min_height; |
413 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - | 405 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - |
414 min_height); | 406 min_height); |
415 } | 407 } |
416 | 408 |
417 // And don't let the window go bigger than the display. | 409 // And don't let the window go bigger than the display. |
418 int max_height = Shell::GetScreen()->GetDisplayNearestWindow( | 410 int max_height = Shell::GetScreen()->GetDisplayNearestWindow( |
419 details.window).bounds().height(); | 411 GetTarget()).bounds().height(); |
420 gfx::Size max_size = details.window->delegate()->GetMaximumSize(); | 412 gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize(); |
421 if (max_size.height() != 0) | 413 if (max_size.height() != 0) |
422 max_height = std::min(max_height, max_size.height()); | 414 max_height = std::min(max_height, max_size.height()); |
423 if (height > max_height) { | 415 if (height > max_height) { |
424 height = max_height; | 416 height = max_height; |
425 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - | 417 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - |
426 max_height); | 418 max_height); |
427 } | 419 } |
428 } | 420 } |
429 return height; | 421 return height; |
430 } | 422 } |
431 | 423 |
432 } // namespace aura | 424 } // namespace aura |
OLD | NEW |