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

Side by Side Diff: ash/wm/window_resizer.cc

Issue 15008002: Make touch-resizing windows to screen edge possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased + Applied reviews Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/window_resizer.h ('k') | ash/wm/workspace/workspace_window_resizer.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 <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
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(window->GetRootWindow()->current_event()->IsGestureEvent()) {
128 if (wm::IsWindowNormal(window) && 132 if (wm::IsWindowNormal(window) &&
129 GetRestoreBoundsInScreen(window) && 133 GetRestoreBoundsInScreen(window) &&
130 window_component == HTCAPTION) 134 window_component == HTCAPTION)
131 restore_bounds = *GetRestoreBoundsInScreen(window); 135 restore_bounds = *GetRestoreBoundsInScreen(window);
132 } 136 }
133 137
134 WindowResizer::Details::~Details() { 138 WindowResizer::Details::~Details() {
135 } 139 }
136 140
137 WindowResizer::WindowResizer() { 141 WindowResizer::WindowResizer() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (!details.is_resizable) 178 if (!details.is_resizable)
175 return details.initial_bounds_in_parent; 179 return details.initial_bounds_in_parent;
176 180
177 gfx::Point location = passed_location; 181 gfx::Point location = passed_location;
178 gfx::Rect work_area = 182 gfx::Rect work_area =
179 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); 183 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window);
180 184
181 int delta_x = location.x() - details.initial_location_in_parent.x(); 185 int delta_x = location.x() - details.initial_location_in_parent.x();
182 int delta_y = location.y() - details.initial_location_in_parent.y(); 186 int delta_y = location.y() - details.initial_location_in_parent.y();
183 187
188 // Adjust values of |delta_x| and |delta_y| for touch resizes.
189 AdjustDeltaForTouch(details, &delta_x, &delta_y);
sadrul 2013/05/29 04:01:51 My suggestion was to make AdjustDeltaForTouch more
190
184 // The minimize size constraint may limit how much we change the window 191 // 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 192 // position. For example, dragging the left edge to the right should stop
186 // repositioning the window when the minimize size is reached. 193 // repositioning the window when the minimize size is reached.
187 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); 194 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y);
188 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); 195 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y);
189 gfx::Rect new_bounds(origin, size); 196 gfx::Rect new_bounds(origin, size);
190 197
191 // Sizing has to keep the result on the screen. Note that this correction 198 // 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 199 // has to come first since it might have an impact on the origin as well as
193 // on the size. 200 // on the size.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 new_bounds_in_screen.x()))); 265 new_bounds_in_screen.x())));
259 new_bounds = 266 new_bounds =
260 ScreenAsh::ConvertRectFromScreen(parent, new_bounds_in_screen); 267 ScreenAsh::ConvertRectFromScreen(parent, new_bounds_in_screen);
261 } 268 }
262 } 269 }
263 270
264 return new_bounds; 271 return new_bounds;
265 } 272 }
266 273
267 // static 274 // static
275 void WindowResizer::AdjustDeltaForTouch(const Details& details,
276 int* delta_x,
277 int* delta_y) {
278 if (!details.is_touch || !(details.bounds_change & kBoundsChange_Resizes))
279 return;
280
281 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) {
282 if (IsRightEdge(details.window_component) && *delta_x > 0) {
283 int display_width = Shell::GetScreen()->GetDisplayNearestWindow(
284 details.window).bounds().width();
285 int right = details.initial_bounds_in_parent.right();
286 float window_distance = display_width - right;
287 float touch_distance = display_width -
288 details.initial_location_in_parent.x();
289 *delta_x = static_cast<int>(
290 ceil(*delta_x * window_distance / touch_distance));
291 } else if (!IsRightEdge(details.window_component) && *delta_x < 0) {
292 float window_distance = details.initial_bounds_in_parent.x();
293 float touch_distance = details.initial_location_in_parent.x();
294 *delta_x = static_cast<int>(
295 ceil(*delta_x * window_distance / touch_distance));
296 }
297 }
298 if (details.size_change_direction & kBoundsChangeDirection_Vertical) {
299 if (IsBottomEdge(details.window_component) && *delta_y > 0) {
300 int display_height = Shell::GetScreen()->GetDisplayNearestWindow(
301 details.window).bounds().height();
302 int bottom = details.initial_bounds_in_parent.bottom();
303 float window_distance = display_height - bottom;
304 float touch_distance = display_height -
305 details.initial_location_in_parent.y();
306 *delta_y = static_cast<int>(
307 ceil(*delta_y * window_distance / touch_distance));
308 } else if (!IsBottomEdge(details.window_component) && *delta_y < 0) {
309 float window_distance = details.initial_bounds_in_parent.y();
310 float touch_distance = details.initial_location_in_parent.y();
311 *delta_y = static_cast<int>(
312 ceil(*delta_y * window_distance / touch_distance));
313 }
314 }
315 }
316
317 // static
268 bool WindowResizer::IsBottomEdge(int window_component) { 318 bool WindowResizer::IsBottomEdge(int window_component) {
269 return window_component == HTBOTTOMLEFT || 319 return window_component == HTBOTTOMLEFT ||
270 window_component == HTBOTTOM || 320 window_component == HTBOTTOM ||
271 window_component == HTBOTTOMRIGHT || 321 window_component == HTBOTTOMRIGHT ||
272 window_component == HTGROWBOX; 322 window_component == HTGROWBOX;
273 } 323 }
274 324
275 // static 325 // static
276 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, 326 gfx::Point WindowResizer::GetOriginForDrag(const Details& details,
277 int delta_x, 327 int delta_x,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (height > max_height) { 413 if (height > max_height) {
364 height = max_height; 414 height = max_height;
365 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - 415 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() -
366 max_height); 416 max_height);
367 } 417 }
368 } 418 }
369 return height; 419 return height;
370 } 420 }
371 421
372 } // namespace aura 422 } // namespace aura
OLDNEW
« no previous file with comments | « ash/wm/window_resizer.h ('k') | ash/wm/workspace/workspace_window_resizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698