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 <cmath> | |
8 | |
7 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 10 #include "ash/shell.h" |
9 #include "ash/wm/property_util.h" | 11 #include "ash/wm/property_util.h" |
10 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
11 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
14 #include "ui/aura/window_delegate.h" | 16 #include "ui/aura/window_delegate.h" |
15 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
16 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; | 102 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; |
101 // static | 103 // static |
102 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; | 104 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; |
103 | 105 |
104 WindowResizer::Details::Details() | 106 WindowResizer::Details::Details() |
105 : window(NULL), | 107 : window(NULL), |
106 window_component(HTNOWHERE), | 108 window_component(HTNOWHERE), |
107 bounds_change(0), | 109 bounds_change(0), |
108 position_change_direction(0), | 110 position_change_direction(0), |
109 size_change_direction(0), | 111 size_change_direction(0), |
110 is_resizable(false) { | 112 is_resizable(false), |
113 is_touch(false) { | |
111 } | 114 } |
112 | 115 |
113 WindowResizer::Details::Details(aura::Window* window, | 116 WindowResizer::Details::Details(aura::Window* window, |
114 const gfx::Point& location, | 117 const gfx::Point& location, |
115 int window_component) | 118 int window_component) |
116 : window(window), | 119 : window(window), |
117 initial_bounds_in_parent(window->bounds()), | 120 initial_bounds_in_parent(window->bounds()), |
118 restore_bounds(gfx::Rect()), | 121 restore_bounds(gfx::Rect()), |
119 initial_location_in_parent(location), | 122 initial_location_in_parent(location), |
120 initial_opacity(window->layer()->opacity()), | 123 initial_opacity(window->layer()->opacity()), |
121 window_component(window_component), | 124 window_component(window_component), |
122 bounds_change(GetBoundsChangeForWindowComponent(window_component)), | 125 bounds_change(GetBoundsChangeForWindowComponent(window_component)), |
123 position_change_direction( | 126 position_change_direction( |
124 GetPositionChangeDirectionForWindowComponent(window_component)), | 127 GetPositionChangeDirectionForWindowComponent(window_component)), |
125 size_change_direction( | 128 size_change_direction( |
126 GetSizeChangeDirectionForWindowComponent(window_component)), | 129 GetSizeChangeDirectionForWindowComponent(window_component)), |
127 is_resizable(bounds_change != kBoundsChangeDirection_None) { | 130 is_resizable(bounds_change != kBoundsChangeDirection_None), |
131 is_touch(false) { | |
132 // Set |is_touch| if |current_event| is not NULL. |current_event| may be NULL | |
133 // in unit tests that don't use synthetically generated events and test window | |
134 // resizers directly. | |
135 if (window->GetRootWindow()->current_event()) | |
sky
2013/06/04 21:18:55
I don't like grabbing the current event, it's too
| |
136 is_touch = window->GetRootWindow()->current_event()->IsGestureEvent(); | |
128 if (wm::IsWindowNormal(window) && | 137 if (wm::IsWindowNormal(window) && |
129 GetRestoreBoundsInScreen(window) && | 138 GetRestoreBoundsInScreen(window) && |
130 window_component == HTCAPTION) | 139 window_component == HTCAPTION) |
131 restore_bounds = *GetRestoreBoundsInScreen(window); | 140 restore_bounds = *GetRestoreBoundsInScreen(window); |
132 } | 141 } |
133 | 142 |
134 WindowResizer::Details::~Details() { | 143 WindowResizer::Details::~Details() { |
135 } | 144 } |
136 | 145 |
137 WindowResizer::WindowResizer() { | 146 WindowResizer::WindowResizer() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 if (!details.is_resizable) | 183 if (!details.is_resizable) |
175 return details.initial_bounds_in_parent; | 184 return details.initial_bounds_in_parent; |
176 | 185 |
177 gfx::Point location = passed_location; | 186 gfx::Point location = passed_location; |
178 gfx::Rect work_area = | 187 gfx::Rect work_area = |
179 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | 188 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); |
180 | 189 |
181 int delta_x = location.x() - details.initial_location_in_parent.x(); | 190 int delta_x = location.x() - details.initial_location_in_parent.x(); |
182 int delta_y = location.y() - details.initial_location_in_parent.y(); | 191 int delta_y = location.y() - details.initial_location_in_parent.y(); |
183 | 192 |
193 // Adjust values of |delta_x| and |delta_y| for touch resizes. | |
194 AdjustDeltaForTouch(details, &delta_x, &delta_y); | |
195 | |
184 // The minimize size constraint may limit how much we change the window | 196 // The minimize size constraint may limit how much we change the window |
185 // position. For example, dragging the left edge to the right should stop | 197 // position. For example, dragging the left edge to the right should stop |
186 // repositioning the window when the minimize size is reached. | 198 // repositioning the window when the minimize size is reached. |
187 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 199 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); |
188 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 200 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
189 gfx::Rect new_bounds(origin, size); | 201 gfx::Rect new_bounds(origin, size); |
190 | 202 |
191 // Sizing has to keep the result on the screen. Note that this correction | 203 // Sizing has to keep the result on the screen. Note that this correction |
192 // has to come first since it might have an impact on the origin as well as | 204 // has to come first since it might have an impact on the origin as well as |
193 // on the size. | 205 // on the size. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 new_bounds_in_screen.x()))); | 270 new_bounds_in_screen.x()))); |
259 new_bounds = | 271 new_bounds = |
260 ScreenAsh::ConvertRectFromScreen(parent, new_bounds_in_screen); | 272 ScreenAsh::ConvertRectFromScreen(parent, new_bounds_in_screen); |
261 } | 273 } |
262 } | 274 } |
263 | 275 |
264 return new_bounds; | 276 return new_bounds; |
265 } | 277 } |
266 | 278 |
267 // static | 279 // static |
280 void WindowResizer::AdjustDeltaForTouch(const Details& details, | |
sky
2013/06/04 21:18:55
Is all of this to snap the edge to the edge of the
mohsen
2013/06/05 16:20:00
This code is not for snapping. Its purpose is to m
sky
2013/06/07 19:26:30
This seems disconcerting and while I get what Dana
sky
2013/06/07 19:26:30
Aren't the changes in WorkspaceWindowResize enough
mohsen
2013/06/07 20:06:57
The change in WorkspaceWindowResizer increases sna
| |
281 int* delta_x, | |
282 int* delta_y) { | |
283 if (!details.is_touch || !(details.bounds_change & kBoundsChange_Resizes)) | |
284 return; | |
285 | |
286 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | |
287 if (IsRightEdge(details.window_component) && *delta_x > 0) { | |
288 int display_width = Shell::GetScreen()->GetDisplayNearestWindow( | |
289 details.window).bounds().width(); | |
290 int right = details.initial_bounds_in_parent.right(); | |
291 float window_distance = display_width - right; | |
292 float touch_distance = display_width - | |
293 details.initial_location_in_parent.x(); | |
294 *delta_x = static_cast<int>( | |
295 ceil(*delta_x * window_distance / touch_distance)); | |
296 } else if (!IsRightEdge(details.window_component) && *delta_x < 0) { | |
297 float window_distance = details.initial_bounds_in_parent.x(); | |
298 float touch_distance = details.initial_location_in_parent.x(); | |
299 *delta_x = static_cast<int>( | |
300 floor(*delta_x * window_distance / touch_distance)); | |
301 } | |
302 } | |
303 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { | |
304 if (IsBottomEdge(details.window_component) && *delta_y > 0) { | |
305 int display_height = Shell::GetScreen()->GetDisplayNearestWindow( | |
306 details.window).bounds().height(); | |
307 int bottom = details.initial_bounds_in_parent.bottom(); | |
308 float window_distance = display_height - bottom; | |
309 float touch_distance = display_height - | |
310 details.initial_location_in_parent.y(); | |
311 *delta_y = static_cast<int>( | |
312 ceil(*delta_y * window_distance / touch_distance)); | |
313 } else if (!IsBottomEdge(details.window_component) && *delta_y < 0) { | |
314 float window_distance = details.initial_bounds_in_parent.y(); | |
315 float touch_distance = details.initial_location_in_parent.y(); | |
316 *delta_y = static_cast<int>( | |
317 floor(*delta_y * window_distance / touch_distance)); | |
318 } | |
319 } | |
320 } | |
321 | |
322 // static | |
268 bool WindowResizer::IsBottomEdge(int window_component) { | 323 bool WindowResizer::IsBottomEdge(int window_component) { |
269 return window_component == HTBOTTOMLEFT || | 324 return window_component == HTBOTTOMLEFT || |
270 window_component == HTBOTTOM || | 325 window_component == HTBOTTOM || |
271 window_component == HTBOTTOMRIGHT || | 326 window_component == HTBOTTOMRIGHT || |
272 window_component == HTGROWBOX; | 327 window_component == HTGROWBOX; |
273 } | 328 } |
274 | 329 |
275 // static | 330 // static |
276 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, | 331 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, |
277 int delta_x, | 332 int delta_x, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 if (height > max_height) { | 418 if (height > max_height) { |
364 height = max_height; | 419 height = max_height; |
365 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - | 420 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - |
366 max_height); | 421 max_height); |
367 } | 422 } |
368 } | 423 } |
369 return height; | 424 return height; |
370 } | 425 } |
371 | 426 |
372 } // namespace aura | 427 } // namespace aura |
OLD | NEW |