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

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

Issue 10918077: Adding proper dragging behavior for L/R maximized windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: As requested Created 8 years, 3 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
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/wm/property_util.h"
10 #include "ash/wm/window_util.h"
9 #include "ui/aura/client/aura_constants.h" 11 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/root_window.h" 12 #include "ui/aura/root_window.h"
11 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
12 #include "ui/aura/window_delegate.h" 14 #include "ui/aura/window_delegate.h"
13 #include "ui/base/hit_test.h" 15 #include "ui/base/hit_test.h"
14 #include "ui/base/ui_base_types.h" 16 #include "ui/base/ui_base_types.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h" 17 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/gfx/screen.h" 18 #include "ui/gfx/screen.h"
17 19
18 namespace ash { 20 namespace ash {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 position_change_direction(0), 107 position_change_direction(0),
106 size_change_direction(0), 108 size_change_direction(0),
107 is_resizable(false) { 109 is_resizable(false) {
108 } 110 }
109 111
110 WindowResizer::Details::Details(aura::Window* window, 112 WindowResizer::Details::Details(aura::Window* window,
111 const gfx::Point& location, 113 const gfx::Point& location,
112 int window_component) 114 int window_component)
113 : window(window), 115 : window(window),
114 initial_bounds(window->bounds()), 116 initial_bounds(window->bounds()),
117 restore_bounds(gfx::Rect()),
115 initial_location_in_parent(location), 118 initial_location_in_parent(location),
116 initial_opacity(window->layer()->opacity()), 119 initial_opacity(window->layer()->opacity()),
117 window_component(window_component), 120 window_component(window_component),
118 bounds_change(GetBoundsChangeForWindowComponent(window_component)), 121 bounds_change(GetBoundsChangeForWindowComponent(window_component)),
119 position_change_direction( 122 position_change_direction(
120 GetPositionChangeDirectionForWindowComponent(window_component)), 123 GetPositionChangeDirectionForWindowComponent(window_component)),
121 size_change_direction( 124 size_change_direction(
122 GetSizeChangeDirectionForWindowComponent(window_component)), 125 GetSizeChangeDirectionForWindowComponent(window_component)),
123 is_resizable(bounds_change != kBoundsChangeDirection_None) { 126 is_resizable(bounds_change != kBoundsChangeDirection_None) {
127 if (wm::IsWindowNormal(window) &&
128 GetRestoreBoundsInScreen(window) &&
129 window_component == HTCAPTION)
130 restore_bounds = *GetRestoreBoundsInScreen(window);
124 } 131 }
125 132
126 WindowResizer::Details::~Details() { 133 WindowResizer::Details::~Details() {
127 } 134 }
128 135
129 WindowResizer::WindowResizer() { 136 WindowResizer::WindowResizer() {
130 } 137 }
131 138
132 WindowResizer::~WindowResizer() { 139 WindowResizer::~WindowResizer() {
133 } 140 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 198
192 int delta_x = location.x() - details.initial_location_in_parent.x(); 199 int delta_x = location.x() - details.initial_location_in_parent.x();
193 int delta_y = location.y() - details.initial_location_in_parent.y(); 200 int delta_y = location.y() - details.initial_location_in_parent.y();
194 201
195 // The minimize size constraint may limit how much we change the window 202 // The minimize size constraint may limit how much we change the window
196 // position. For example, dragging the left edge to the right should stop 203 // position. For example, dragging the left edge to the right should stop
197 // repositioning the window when the minimize size is reached. 204 // repositioning the window when the minimize size is reached.
198 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y, grid_size); 205 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y, grid_size);
199 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); 206 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y);
200 207
208 // When we might want to reposition a window which is also restored to its
209 // previous size, to keep the cursor within the dragged window.
210 if (!details.restore_bounds.IsEmpty() &&
211 details.bounds_change & kBoundsChange_Repositions) {
212 // However - it is not desirable to change the origin if the window would
213 // be still hit by the cursor.
214 if (details.initial_location_in_parent.x() >
215 details.initial_bounds.x() + details.restore_bounds.width())
216 origin.set_x(location.x() - details.restore_bounds.width() / 2);
217 }
218
201 gfx::Rect new_bounds(origin, size); 219 gfx::Rect new_bounds(origin, size);
202 // Update bottom edge to stay in the work area when we are resizing 220 // Update bottom edge to stay in the work area when we are resizing
203 // by dragging the bottome edge or corners. 221 // by dragging the bottome edge or corners.
204 if (details.window_component == HTBOTTOM || 222 if (details.window_component == HTBOTTOM ||
205 details.window_component == HTBOTTOMRIGHT || 223 details.window_component == HTBOTTOMRIGHT ||
206 details.window_component == HTBOTTOMLEFT) { 224 details.window_component == HTBOTTOMLEFT) {
207 gfx::Rect work_area = 225 gfx::Rect work_area =
208 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); 226 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window);
209 if (new_bounds.bottom() > work_area.bottom()) 227 if (new_bounds.bottom() > work_area.bottom())
210 new_bounds.Inset(0, 0, 0, 228 new_bounds.Inset(0, 0, 0,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 int grid_size) { 278 int grid_size) {
261 gfx::Size size = details.initial_bounds.size(); 279 gfx::Size size = details.initial_bounds.size();
262 if (details.bounds_change & kBoundsChange_Resizes) { 280 if (details.bounds_change & kBoundsChange_Resizes) {
263 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); 281 gfx::Size min_size = details.window->delegate()->GetMinimumSize();
264 min_size.set_width(AlignToGridRoundUp(min_size.width(), grid_size)); 282 min_size.set_width(AlignToGridRoundUp(min_size.width(), grid_size));
265 min_size.set_height(AlignToGridRoundUp(min_size.height(), grid_size)); 283 min_size.set_height(AlignToGridRoundUp(min_size.height(), grid_size));
266 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x, 284 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x,
267 grid_size), 285 grid_size),
268 GetHeightForDrag(details, min_size.height(), delta_y, 286 GetHeightForDrag(details, min_size.height(), delta_y,
269 grid_size)); 287 grid_size));
288 } else if (!details.restore_bounds.IsEmpty()) {
289 size = details.restore_bounds.size();
270 } 290 }
271 return size; 291 return size;
272 } 292 }
273 293
274 // static 294 // static
275 int WindowResizer::GetWidthForDrag(const Details& details, 295 int WindowResizer::GetWidthForDrag(const Details& details,
276 int min_width, 296 int min_width,
277 int* delta_x, 297 int* delta_x,
278 int grid_size) { 298 int grid_size) {
279 int width = details.initial_bounds.width(); 299 int width = details.initial_bounds.width();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height(); 353 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height();
334 if (height > max_height) { 354 if (height > max_height) {
335 height = max_height; 355 height = max_height;
336 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); 356 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height);
337 } 357 }
338 } 358 }
339 return height; 359 return height;
340 } 360 }
341 361
342 } // namespace aura 362 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698