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

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

Issue 1921353002: Moves handful of files to ash/wm/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shell_ids
Patch Set: merge to trunk Created 4 years, 8 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/common/window_resizer.h ('k') | ash/wm/common/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/common/window_resizer.h"
6 6
7 #include "ash/shell_window_ids.h" 7 #include "ash/wm/common/dock/docked_window_layout_manager.h"
8 #include "ash/wm/common/root_window_finder.h" 8 #include "ash/wm/common/root_window_finder.h"
9 #include "ash/wm/common/window_positioning_utils.h" 9 #include "ash/wm/common/window_positioning_utils.h"
10 #include "ash/wm/common/window_state.h"
10 #include "ash/wm/common/wm_window.h" 11 #include "ash/wm/common/wm_window.h"
11 #include "ash/wm/dock/docked_window_layout_manager.h"
12 #include "ash/wm/window_state.h"
13 #include "ui/base/hit_test.h" 12 #include "ui/base/hit_test.h"
14 #include "ui/base/ui_base_types.h" 13 #include "ui/base/ui_base_types.h"
15 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
16 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/screen.h" 16 #include "ui/gfx/screen.h"
18 17
19 namespace ash { 18 namespace ash {
20 19
21 namespace { 20 namespace {
22 21
23 // Returns true for resize components along the right edge, where a drag in 22 // Returns true for resize components along the right edge, where a drag in
24 // positive x will make the window larger. 23 // positive x will make the window larger.
25 bool IsRightEdge(int window_component) { 24 bool IsRightEdge(int window_component) {
26 return window_component == HTTOPRIGHT || 25 return window_component == HTTOPRIGHT || window_component == HTRIGHT ||
27 window_component == HTRIGHT || 26 window_component == HTBOTTOMRIGHT || window_component == HTGROWBOX;
28 window_component == HTBOTTOMRIGHT ||
29 window_component == HTGROWBOX;
30 } 27 }
31 28
32 } // namespace 29 } // namespace
33 30
34 // static 31 // static
35 const int WindowResizer::kBoundsChange_None = 0; 32 const int WindowResizer::kBoundsChange_None = 0;
36 // static 33 // static
37 const int WindowResizer::kBoundsChange_Repositions = 1; 34 const int WindowResizer::kBoundsChange_Repositions = 1;
38 // static 35 // static
39 const int WindowResizer::kBoundsChange_Resizes = 2; 36 const int WindowResizer::kBoundsChange_Resizes = 2;
40 37
41 // static 38 // static
42 const int WindowResizer::kBoundsChangeDirection_None = 0; 39 const int WindowResizer::kBoundsChangeDirection_None = 0;
43 // static 40 // static
44 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; 41 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1;
45 // static 42 // static
46 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; 43 const int WindowResizer::kBoundsChangeDirection_Vertical = 2;
47 44
48 WindowResizer::WindowResizer(wm::WindowState* window_state) 45 WindowResizer::WindowResizer(wm::WindowState* window_state)
49 : window_state_(window_state) { 46 : window_state_(window_state) {
50 DCHECK(window_state_->drag_details()); 47 DCHECK(window_state_->drag_details());
51 } 48 }
52 49
53 WindowResizer::~WindowResizer() { 50 WindowResizer::~WindowResizer() {}
54 }
55 51
56 // static 52 // static
57 int WindowResizer::GetBoundsChangeForWindowComponent(int component) { 53 int WindowResizer::GetBoundsChangeForWindowComponent(int component) {
58 int bounds_change = WindowResizer::kBoundsChange_None; 54 int bounds_change = WindowResizer::kBoundsChange_None;
59 switch (component) { 55 switch (component) {
60 case HTTOPLEFT: 56 case HTTOPLEFT:
61 case HTTOP: 57 case HTTOP:
62 case HTTOPRIGHT: 58 case HTTOPRIGHT:
63 case HTLEFT: 59 case HTLEFT:
64 case HTBOTTOMLEFT: 60 case HTBOTTOMLEFT:
65 bounds_change |= WindowResizer::kBoundsChange_Repositions | 61 bounds_change |= WindowResizer::kBoundsChange_Repositions |
66 WindowResizer::kBoundsChange_Resizes; 62 WindowResizer::kBoundsChange_Resizes;
67 break; 63 break;
68 case HTCAPTION: 64 case HTCAPTION:
69 bounds_change |= WindowResizer::kBoundsChange_Repositions; 65 bounds_change |= WindowResizer::kBoundsChange_Repositions;
70 break; 66 break;
71 case HTRIGHT: 67 case HTRIGHT:
72 case HTBOTTOMRIGHT: 68 case HTBOTTOMRIGHT:
73 case HTBOTTOM: 69 case HTBOTTOM:
74 case HTGROWBOX: 70 case HTGROWBOX:
75 bounds_change |= WindowResizer::kBoundsChange_Resizes; 71 bounds_change |= WindowResizer::kBoundsChange_Resizes;
76 break; 72 break;
77 default: 73 default:
78 break; 74 break;
79 } 75 }
80 return bounds_change; 76 return bounds_change;
81 } 77 }
82 78
83 // static 79 // static
84 int WindowResizer::GetPositionChangeDirectionForWindowComponent( 80 int WindowResizer::GetPositionChangeDirectionForWindowComponent(
85 int window_component) { 81 int window_component) {
86 int pos_change_direction = WindowResizer::kBoundsChangeDirection_None; 82 int pos_change_direction = WindowResizer::kBoundsChangeDirection_None;
87 switch (window_component) { 83 switch (window_component) {
88 case HTTOPLEFT: 84 case HTTOPLEFT:
89 case HTBOTTOMRIGHT: 85 case HTBOTTOMRIGHT:
90 case HTGROWBOX: 86 case HTGROWBOX:
91 case HTCAPTION: 87 case HTCAPTION:
92 pos_change_direction |= 88 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal |
93 WindowResizer::kBoundsChangeDirection_Horizontal | 89 WindowResizer::kBoundsChangeDirection_Vertical;
94 WindowResizer::kBoundsChangeDirection_Vertical;
95 break; 90 break;
96 case HTTOP: 91 case HTTOP:
97 case HTTOPRIGHT: 92 case HTTOPRIGHT:
98 case HTBOTTOM: 93 case HTBOTTOM:
99 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical; 94 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical;
100 break; 95 break;
101 case HTBOTTOMLEFT: 96 case HTBOTTOMLEFT:
102 case HTRIGHT: 97 case HTRIGHT:
103 case HTLEFT: 98 case HTLEFT:
104 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal; 99 pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 int height = 152 int height =
158 new_bounds.bottom() - work_area.bottom() + wm::kMinimumOnScreenArea; 153 new_bounds.bottom() - work_area.bottom() + wm::kMinimumOnScreenArea;
159 new_bounds.set_y(work_area.bottom() - wm::kMinimumOnScreenArea); 154 new_bounds.set_y(work_area.bottom() - wm::kMinimumOnScreenArea);
160 new_bounds.set_height(height); 155 new_bounds.set_height(height);
161 } else if (details().window_component == HTBOTTOM || 156 } else if (details().window_component == HTBOTTOM ||
162 details().window_component == HTBOTTOMRIGHT || 157 details().window_component == HTBOTTOMRIGHT ||
163 details().window_component == HTBOTTOMLEFT) { 158 details().window_component == HTBOTTOMLEFT) {
164 // Update bottom edge to stay in the work area when we are resizing 159 // Update bottom edge to stay in the work area when we are resizing
165 // by dragging the bottom edge or corners. 160 // by dragging the bottom edge or corners.
166 if (new_bounds.bottom() > work_area.bottom()) 161 if (new_bounds.bottom() > work_area.bottom())
167 new_bounds.Inset(0, 0, 0, 162 new_bounds.Inset(0, 0, 0, new_bounds.bottom() - work_area.bottom());
168 new_bounds.bottom() - work_area.bottom());
169 } 163 }
170 } 164 }
171 if (details().bounds_change & kBoundsChange_Repositions && 165 if (details().bounds_change & kBoundsChange_Repositions &&
172 new_bounds.y() < 0) { 166 new_bounds.y() < 0) {
173 int delta = new_bounds.y(); 167 int delta = new_bounds.y();
174 new_bounds.set_y(0); 168 new_bounds.set_y(0);
175 new_bounds.set_height(new_bounds.height() + delta); 169 new_bounds.set_height(new_bounds.height() + delta);
176 } 170 }
177 } 171 }
178 172
179 if (details().bounds_change & kBoundsChange_Repositions) { 173 if (details().bounds_change & kBoundsChange_Repositions) {
180 // When we might want to reposition a window which is also restored to its 174 // When we might want to reposition a window which is also restored to its
181 // previous size, to keep the cursor within the dragged window. 175 // previous size, to keep the cursor within the dragged window.
182 if (!details().restore_bounds.IsEmpty()) { 176 if (!details().restore_bounds.IsEmpty()) {
183 // However - it is not desirable to change the origin if the window would 177 // However - it is not desirable to change the origin if the window would
184 // be still hit by the cursor. 178 // be still hit by the cursor.
185 if (details().initial_location_in_parent.x() > 179 if (details().initial_location_in_parent.x() >
186 details().initial_bounds_in_parent.x() + 180 details().initial_bounds_in_parent.x() +
187 details().restore_bounds.width()) 181 details().restore_bounds.width())
188 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2); 182 new_bounds.set_x(location.x() - details().restore_bounds.width() / 2);
189 } 183 }
190 184
191 // Make sure that |new_bounds| doesn't leave any of the displays. Note that 185 // Make sure that |new_bounds| doesn't leave any of the displays. Note that
192 // the |work_area| above isn't good for this check since it is the work area 186 // the |work_area| above isn't good for this check since it is the work area
193 // for the current display but the window can move to a different one. 187 // for the current display but the window can move to a different one.
194 wm::WmWindow* parent = GetTarget()->GetParent(); 188 wm::WmWindow* parent = GetTarget()->GetParent();
195 gfx::Point passed_location_in_screen( 189 gfx::Point passed_location_in_screen(
196 parent->ConvertPointToScreen(passed_location)); 190 parent->ConvertPointToScreen(passed_location));
197 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); 191 gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size());
198 // Use a pointer location (matching the logic in DragWindowResizer) to 192 // Use a pointer location (matching the logic in DragWindowResizer) to
199 // calculate the target display after the drag. 193 // calculate the target display after the drag.
200 const gfx::Display& display = 194 const gfx::Display& display =
201 gfx::Screen::GetScreen()->GetDisplayMatching(near_passed_location); 195 gfx::Screen::GetScreen()->GetDisplayMatching(near_passed_location);
202 DockedWindowLayoutManager* dock_layout = DockedWindowLayoutManager::Get( 196 DockedWindowLayoutManager* dock_layout = DockedWindowLayoutManager::Get(
203 wm::GetRootWindowMatching(near_passed_location)); 197 wm::GetRootWindowMatching(near_passed_location));
204 198
205 gfx::Rect screen_work_area = display.work_area(); 199 gfx::Rect screen_work_area = display.work_area();
206 screen_work_area.Union(dock_layout->docked_bounds()); 200 screen_work_area.Union(dock_layout->docked_bounds());
207 screen_work_area.Inset(wm::kMinimumOnScreenArea, 0); 201 screen_work_area.Inset(wm::kMinimumOnScreenArea, 0);
208 gfx::Rect new_bounds_in_screen = parent->ConvertRectToScreen(new_bounds); 202 gfx::Rect new_bounds_in_screen = parent->ConvertRectToScreen(new_bounds);
209 if (!screen_work_area.Intersects(new_bounds_in_screen)) { 203 if (!screen_work_area.Intersects(new_bounds_in_screen)) {
210 // Make sure that the x origin does not leave the current display. 204 // Make sure that the x origin does not leave the current display.
211 new_bounds_in_screen.set_x( 205 new_bounds_in_screen.set_x(std::max(
212 std::max(screen_work_area.x() - new_bounds.width(), 206 screen_work_area.x() - new_bounds.width(),
213 std::min(screen_work_area.right(), 207 std::min(screen_work_area.right(), new_bounds_in_screen.x())));
214 new_bounds_in_screen.x())));
215 new_bounds = parent->ConvertRectFromScreen(new_bounds_in_screen); 208 new_bounds = parent->ConvertRectFromScreen(new_bounds_in_screen);
216 } 209 }
217 } 210 }
218 211
219 return new_bounds; 212 return new_bounds;
220 } 213 }
221 214
222 // static 215 // static
223 bool WindowResizer::IsBottomEdge(int window_component) { 216 bool WindowResizer::IsBottomEdge(int window_component) {
224 return window_component == HTBOTTOMLEFT || 217 return window_component == HTBOTTOMLEFT || window_component == HTBOTTOM ||
225 window_component == HTBOTTOM || 218 window_component == HTBOTTOMRIGHT || window_component == HTGROWBOX;
226 window_component == HTBOTTOMRIGHT ||
227 window_component == HTGROWBOX;
228 } 219 }
229 220
230 void WindowResizer::AdjustDeltaForTouchResize(int* delta_x, int* delta_y) { 221 void WindowResizer::AdjustDeltaForTouchResize(int* delta_x, int* delta_y) {
231 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH || 222 if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH ||
232 !(details().bounds_change & kBoundsChange_Resizes)) 223 !(details().bounds_change & kBoundsChange_Resizes))
233 return; 224 return;
234 225
235 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { 226 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) {
236 if (IsRightEdge(details().window_component)) { 227 if (IsRightEdge(details().window_component)) {
237 *delta_x += details().initial_location_in_parent.x() - 228 *delta_x += details().initial_location_in_parent.x() -
238 details().initial_bounds_in_parent.right(); 229 details().initial_bounds_in_parent.right();
239 } else { 230 } else {
240 *delta_x += details().initial_location_in_parent.x() - 231 *delta_x += details().initial_location_in_parent.x() -
241 details().initial_bounds_in_parent.x(); 232 details().initial_bounds_in_parent.x();
242 } 233 }
243 } 234 }
244 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { 235 if (details().size_change_direction & kBoundsChangeDirection_Vertical) {
245 if (IsBottomEdge(details().window_component)) { 236 if (IsBottomEdge(details().window_component)) {
246 *delta_y += details().initial_location_in_parent.y() - 237 *delta_y += details().initial_location_in_parent.y() -
247 details().initial_bounds_in_parent.bottom(); 238 details().initial_bounds_in_parent.bottom();
248 } else { 239 } else {
249 *delta_y += details().initial_location_in_parent.y() - 240 *delta_y += details().initial_location_in_parent.y() -
250 details().initial_bounds_in_parent.y(); 241 details().initial_bounds_in_parent.y();
251 } 242 }
252 } 243 }
253 } 244 }
254 245
255 gfx::Point WindowResizer::GetOriginForDrag(int delta_x, int delta_y) { 246 gfx::Point WindowResizer::GetOriginForDrag(int delta_x, int delta_y) {
256 gfx::Point origin = details().initial_bounds_in_parent.origin(); 247 gfx::Point origin = details().initial_bounds_in_parent.origin();
257 if (details().bounds_change & kBoundsChange_Repositions) { 248 if (details().bounds_change & kBoundsChange_Repositions) {
258 int pos_change_direction = GetPositionChangeDirectionForWindowComponent( 249 int pos_change_direction = GetPositionChangeDirectionForWindowComponent(
259 details().window_component); 250 details().window_component);
260 if (pos_change_direction & kBoundsChangeDirection_Horizontal) 251 if (pos_change_direction & kBoundsChangeDirection_Horizontal)
(...skipping 20 matching lines...) Expand all
281 int width = details().initial_bounds_in_parent.width(); 272 int width = details().initial_bounds_in_parent.width();
282 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { 273 if (details().size_change_direction & kBoundsChangeDirection_Horizontal) {
283 // Along the right edge, positive delta_x increases the window size. 274 // Along the right edge, positive delta_x increases the window size.
284 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1; 275 int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1;
285 width += x_multiplier * (*delta_x); 276 width += x_multiplier * (*delta_x);
286 277
287 // Ensure we don't shrink past the minimum width and clamp delta_x 278 // Ensure we don't shrink past the minimum width and clamp delta_x
288 // for the window origin computation. 279 // for the window origin computation.
289 if (width < min_width) { 280 if (width < min_width) {
290 width = min_width; 281 width = min_width;
291 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - 282 *delta_x = -x_multiplier *
292 min_width); 283 (details().initial_bounds_in_parent.width() - min_width);
293 } 284 }
294 285
295 // And don't let the window go bigger than the display. 286 // And don't let the window go bigger than the display.
296 int max_width = GetTarget()->GetDisplayNearestWindow().bounds().width(); 287 int max_width = GetTarget()->GetDisplayNearestWindow().bounds().width();
297 gfx::Size max_size = GetTarget()->GetMaximumSize(); 288 gfx::Size max_size = GetTarget()->GetMaximumSize();
298 if (max_size.width() != 0) 289 if (max_size.width() != 0)
299 max_width = std::min(max_width, max_size.width()); 290 max_width = std::min(max_width, max_size.width());
300 if (width > max_width) { 291 if (width > max_width) {
301 width = max_width; 292 width = max_width;
302 *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - 293 *delta_x = -x_multiplier *
303 max_width); 294 (details().initial_bounds_in_parent.width() - max_width);
304 } 295 }
305 } 296 }
306 return width; 297 return width;
307 } 298 }
308 299
309 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) { 300 int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) {
310 int height = details().initial_bounds_in_parent.height(); 301 int height = details().initial_bounds_in_parent.height();
311 if (details().size_change_direction & kBoundsChangeDirection_Vertical) { 302 if (details().size_change_direction & kBoundsChangeDirection_Vertical) {
312 // Along the bottom edge, positive delta_y increases the window size. 303 // Along the bottom edge, positive delta_y increases the window size.
313 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1; 304 int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1;
314 height += y_multiplier * (*delta_y); 305 height += y_multiplier * (*delta_y);
315 306
316 // Ensure we don't shrink past the minimum height and clamp delta_y 307 // Ensure we don't shrink past the minimum height and clamp delta_y
317 // for the window origin computation. 308 // for the window origin computation.
318 if (height < min_height) { 309 if (height < min_height) {
319 height = min_height; 310 height = min_height;
320 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - 311 *delta_y = -y_multiplier *
321 min_height); 312 (details().initial_bounds_in_parent.height() - min_height);
322 } 313 }
323 314
324 // And don't let the window go bigger than the display. 315 // And don't let the window go bigger than the display.
325 int max_height = GetTarget()->GetDisplayNearestWindow().bounds().height(); 316 int max_height = GetTarget()->GetDisplayNearestWindow().bounds().height();
326 gfx::Size max_size = GetTarget()->GetMaximumSize(); 317 gfx::Size max_size = GetTarget()->GetMaximumSize();
327 if (max_size.height() != 0) 318 if (max_size.height() != 0)
328 max_height = std::min(max_height, max_size.height()); 319 max_height = std::min(max_height, max_size.height());
329 if (height > max_height) { 320 if (height > max_height) {
330 height = max_height; 321 height = max_height;
331 *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - 322 *delta_y = -y_multiplier *
332 max_height); 323 (details().initial_bounds_in_parent.height() - max_height);
333 } 324 }
334 } 325 }
335 return height; 326 return height;
336 } 327 }
337 328
338 } // namespace ash 329 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/common/window_resizer.h ('k') | ash/wm/common/window_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698