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/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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 | 95 |
94 // static | 96 // static |
95 const int WindowResizer::kBoundsChangeDirection_None = 0; | 97 const int WindowResizer::kBoundsChangeDirection_None = 0; |
96 // static | 98 // static |
97 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; | 99 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; |
98 // static | 100 // static |
99 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; | 101 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; |
100 | 102 |
101 WindowResizer::Details::Details() | 103 WindowResizer::Details::Details() |
102 : window(NULL), | 104 : window(NULL), |
105 restore_bounds(gfx::Rect()), | |
sky
2012/09/07 02:43:30
not necessary.
Mr4D (OOO till 08-26)
2012/09/08 01:17:41
Done.
| |
103 window_component(HTNOWHERE), | 106 window_component(HTNOWHERE), |
104 bounds_change(0), | 107 bounds_change(0), |
105 position_change_direction(0), | 108 position_change_direction(0), |
106 size_change_direction(0), | 109 size_change_direction(0), |
107 is_resizable(false) { | 110 is_resizable(false) { |
108 } | 111 } |
109 | 112 |
110 WindowResizer::Details::Details(aura::Window* window, | 113 WindowResizer::Details::Details(aura::Window* window, |
111 const gfx::Point& location, | 114 const gfx::Point& location, |
112 int window_component) | 115 int window_component) |
113 : window(window), | 116 : window(window), |
114 initial_bounds(window->bounds()), | 117 initial_bounds(window->bounds()), |
118 restore_bounds(gfx::Rect()), | |
115 initial_location_in_parent(location), | 119 initial_location_in_parent(location), |
116 initial_opacity(window->layer()->opacity()), | 120 initial_opacity(window->layer()->opacity()), |
117 window_component(window_component), | 121 window_component(window_component), |
118 bounds_change(GetBoundsChangeForWindowComponent(window_component)), | 122 bounds_change(GetBoundsChangeForWindowComponent(window_component)), |
119 position_change_direction( | 123 position_change_direction( |
120 GetPositionChangeDirectionForWindowComponent(window_component)), | 124 GetPositionChangeDirectionForWindowComponent(window_component)), |
121 size_change_direction( | 125 size_change_direction( |
122 GetSizeChangeDirectionForWindowComponent(window_component)), | 126 GetSizeChangeDirectionForWindowComponent(window_component)), |
123 is_resizable(bounds_change != kBoundsChangeDirection_None) { | 127 is_resizable(bounds_change != kBoundsChangeDirection_None) { |
128 if (wm::IsWindowNormal(window) && | |
129 GetRestoreBoundsInScreen(window) && | |
130 window_component == HTCAPTION) | |
131 restore_bounds = *GetRestoreBoundsInScreen(window); | |
124 } | 132 } |
125 | 133 |
126 WindowResizer::Details::~Details() { | 134 WindowResizer::Details::~Details() { |
127 } | 135 } |
128 | 136 |
129 WindowResizer::WindowResizer() { | 137 WindowResizer::WindowResizer() { |
130 } | 138 } |
131 | 139 |
132 WindowResizer::~WindowResizer() { | 140 WindowResizer::~WindowResizer() { |
133 } | 141 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 | 199 |
192 int delta_x = location.x() - details.initial_location_in_parent.x(); | 200 int delta_x = location.x() - details.initial_location_in_parent.x(); |
193 int delta_y = location.y() - details.initial_location_in_parent.y(); | 201 int delta_y = location.y() - details.initial_location_in_parent.y(); |
194 | 202 |
195 // The minimize size constraint may limit how much we change the window | 203 // 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 | 204 // position. For example, dragging the left edge to the right should stop |
197 // repositioning the window when the minimize size is reached. | 205 // repositioning the window when the minimize size is reached. |
198 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y, grid_size); | 206 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y, grid_size); |
199 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 207 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
200 | 208 |
209 // When we reposition a window which is also restored to its previous size, | |
210 // we center the window around the cursor. | |
211 if (!details.restore_bounds.IsEmpty() && | |
212 details.bounds_change & kBoundsChange_Repositions) | |
213 origin.set_x(location.x() - details.restore_bounds.width() / 2); | |
sky
2012/09/07 15:46:15
One more comment here. Centering is going to be eq
Mr4D (OOO till 08-26)
2012/09/07 16:45:33
I tried it actually this way and I found it this w
| |
214 | |
201 gfx::Rect new_bounds(origin, size); | 215 gfx::Rect new_bounds(origin, size); |
202 // Update bottom edge to stay in the work area when we are resizing | 216 // Update bottom edge to stay in the work area when we are resizing |
203 // by dragging the bottome edge or corners. | 217 // by dragging the bottome edge or corners. |
204 if (details.window_component == HTBOTTOM || | 218 if (details.window_component == HTBOTTOM || |
205 details.window_component == HTBOTTOMRIGHT || | 219 details.window_component == HTBOTTOMRIGHT || |
206 details.window_component == HTBOTTOMLEFT) { | 220 details.window_component == HTBOTTOMLEFT) { |
207 gfx::Rect work_area = | 221 gfx::Rect work_area = |
208 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | 222 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); |
209 if (new_bounds.bottom() > work_area.bottom()) | 223 if (new_bounds.bottom() > work_area.bottom()) |
210 new_bounds.Inset(0, 0, 0, | 224 new_bounds.Inset(0, 0, 0, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 int grid_size) { | 274 int grid_size) { |
261 gfx::Size size = details.initial_bounds.size(); | 275 gfx::Size size = details.initial_bounds.size(); |
262 if (details.bounds_change & kBoundsChange_Resizes) { | 276 if (details.bounds_change & kBoundsChange_Resizes) { |
263 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); | 277 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); |
264 min_size.set_width(AlignToGridRoundUp(min_size.width(), grid_size)); | 278 min_size.set_width(AlignToGridRoundUp(min_size.width(), grid_size)); |
265 min_size.set_height(AlignToGridRoundUp(min_size.height(), grid_size)); | 279 min_size.set_height(AlignToGridRoundUp(min_size.height(), grid_size)); |
266 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x, | 280 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x, |
267 grid_size), | 281 grid_size), |
268 GetHeightForDrag(details, min_size.height(), delta_y, | 282 GetHeightForDrag(details, min_size.height(), delta_y, |
269 grid_size)); | 283 grid_size)); |
284 } else { | |
sky
2012/09/07 02:43:30
else if
Mr4D (OOO till 08-26)
2012/09/08 01:17:41
Done.
| |
285 if (!details.restore_bounds.IsEmpty()) | |
286 size = details.restore_bounds.size(); | |
270 } | 287 } |
271 return size; | 288 return size; |
272 } | 289 } |
273 | 290 |
274 // static | 291 // static |
275 int WindowResizer::GetWidthForDrag(const Details& details, | 292 int WindowResizer::GetWidthForDrag(const Details& details, |
276 int min_width, | 293 int min_width, |
277 int* delta_x, | 294 int* delta_x, |
278 int grid_size) { | 295 int grid_size) { |
279 int width = details.initial_bounds.width(); | 296 int width = details.initial_bounds.width(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height(); | 350 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height(); |
334 if (height > max_height) { | 351 if (height > max_height) { |
335 height = max_height; | 352 height = max_height; |
336 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); | 353 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); |
337 } | 354 } |
338 } | 355 } |
339 return height; | 356 return height; |
340 } | 357 } |
341 | 358 |
342 } // namespace aura | 359 } // namespace aura |
OLD | NEW |