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" | 9 #include "ash/wm/property_util.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 window_component(HTNOWHERE), | 107 window_component(HTNOWHERE), |
108 bounds_change(0), | 108 bounds_change(0), |
109 position_change_direction(0), | 109 position_change_direction(0), |
110 size_change_direction(0), | 110 size_change_direction(0), |
111 is_resizable(false) { | 111 is_resizable(false) { |
112 } | 112 } |
113 | 113 |
114 WindowResizer::Details::Details(aura::Window* window, | 114 WindowResizer::Details::Details(aura::Window* window, |
115 const gfx::Point& location, | 115 const gfx::Point& location, |
116 int window_component) | 116 int window_component) |
117 : window(window), | 117 : window(window), |
118 initial_bounds(window->bounds()), | 118 initial_bounds_in_parent(window->bounds()), |
119 restore_bounds(gfx::Rect()), | 119 initial_bounds(window->GetBoundsInScreen()), |
120 initial_location_in_parent(location), | 120 restore_bounds(gfx::Rect()), |
121 initial_opacity(window->layer()->opacity()), | 121 initial_location_in_parent(location), |
122 window_component(window_component), | 122 initial_opacity(window->layer()->opacity()), |
123 bounds_change(GetBoundsChangeForWindowComponent(window_component)), | 123 window_component(window_component), |
124 position_change_direction( | 124 bounds_change(GetBoundsChangeForWindowComponent(window_component)), |
125 GetPositionChangeDirectionForWindowComponent(window_component)), | 125 position_change_direction( |
126 size_change_direction( | 126 GetPositionChangeDirectionForWindowComponent(window_component)), |
127 GetSizeChangeDirectionForWindowComponent(window_component)), | 127 size_change_direction( |
128 is_resizable(bounds_change != kBoundsChangeDirection_None) { | 128 GetSizeChangeDirectionForWindowComponent(window_component)), |
| 129 is_resizable(bounds_change != kBoundsChangeDirection_None) { |
129 if (wm::IsWindowNormal(window) && | 130 if (wm::IsWindowNormal(window) && |
130 GetRestoreBoundsInScreen(window) && | 131 GetRestoreBoundsInScreen(window) && |
131 window_component == HTCAPTION) | 132 window_component == HTCAPTION) |
132 restore_bounds = *GetRestoreBoundsInScreen(window); | 133 restore_bounds = *GetRestoreBoundsInScreen(window); |
133 } | 134 } |
134 | 135 |
135 WindowResizer::Details::~Details() { | 136 WindowResizer::Details::~Details() { |
136 } | 137 } |
137 | 138 |
138 WindowResizer::WindowResizer() { | 139 WindowResizer::WindowResizer() { |
(...skipping 27 matching lines...) Expand all Loading... |
166 break; | 167 break; |
167 } | 168 } |
168 return bounds_change; | 169 return bounds_change; |
169 } | 170 } |
170 | 171 |
171 // static | 172 // static |
172 gfx::Rect WindowResizer::CalculateBoundsForDrag( | 173 gfx::Rect WindowResizer::CalculateBoundsForDrag( |
173 const Details& details, | 174 const Details& details, |
174 const gfx::Point& passed_location) { | 175 const gfx::Point& passed_location) { |
175 if (!details.is_resizable) | 176 if (!details.is_resizable) |
176 return details.initial_bounds; | 177 return details.initial_bounds_in_parent; |
177 | 178 |
178 gfx::Point location = passed_location; | 179 gfx::Point location = passed_location; |
179 gfx::Rect work_area = | 180 gfx::Rect work_area = |
180 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | 181 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); |
181 | 182 |
182 int delta_x = location.x() - details.initial_location_in_parent.x(); | 183 int delta_x = location.x() - details.initial_location_in_parent.x(); |
183 int delta_y = location.y() - details.initial_location_in_parent.y(); | 184 int delta_y = location.y() - details.initial_location_in_parent.y(); |
184 | 185 |
185 // The minimize size constraint may limit how much we change the window | 186 // The minimize size constraint may limit how much we change the window |
186 // position. For example, dragging the left edge to the right should stop | 187 // position. For example, dragging the left edge to the right should stop |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 231 } |
231 } | 232 } |
232 | 233 |
233 if (details.bounds_change & kBoundsChange_Repositions) { | 234 if (details.bounds_change & kBoundsChange_Repositions) { |
234 // When we might want to reposition a window which is also restored to its | 235 // When we might want to reposition a window which is also restored to its |
235 // previous size, to keep the cursor within the dragged window. | 236 // previous size, to keep the cursor within the dragged window. |
236 if (!details.restore_bounds.IsEmpty()) { | 237 if (!details.restore_bounds.IsEmpty()) { |
237 // However - it is not desirable to change the origin if the window would | 238 // However - it is not desirable to change the origin if the window would |
238 // be still hit by the cursor. | 239 // be still hit by the cursor. |
239 if (details.initial_location_in_parent.x() > | 240 if (details.initial_location_in_parent.x() > |
240 details.initial_bounds.x() + details.restore_bounds.width()) | 241 details.initial_bounds_in_parent.x() + details.restore_bounds.width()) |
241 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); | 242 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); |
242 } | 243 } |
243 | 244 |
244 // Make sure that |new_bounds| doesn't leave any of the displays. Note that | 245 // Make sure that |new_bounds| doesn't leave any of the displays. Note that |
245 // the |work_area| above isn't good for this check since it is the work area | 246 // the |work_area| above isn't good for this check since it is the work area |
246 // for the current display but the window can move to a different one. | 247 // for the current display but the window can move to a different one. |
247 aura::Window* parent = details.window->parent(); | 248 aura::Window* parent = details.window->parent(); |
248 gfx::Rect new_bounds_in_screen = | 249 gfx::Rect new_bounds_in_screen = |
249 ScreenAsh::ConvertRectToScreen(parent, new_bounds); | 250 ScreenAsh::ConvertRectToScreen(parent, new_bounds); |
250 const gfx::Display& display = | 251 const gfx::Display& display = |
(...skipping 19 matching lines...) Expand all Loading... |
270 return window_component == HTBOTTOMLEFT || | 271 return window_component == HTBOTTOMLEFT || |
271 window_component == HTBOTTOM || | 272 window_component == HTBOTTOM || |
272 window_component == HTBOTTOMRIGHT || | 273 window_component == HTBOTTOMRIGHT || |
273 window_component == HTGROWBOX; | 274 window_component == HTGROWBOX; |
274 } | 275 } |
275 | 276 |
276 // static | 277 // static |
277 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, | 278 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, |
278 int delta_x, | 279 int delta_x, |
279 int delta_y) { | 280 int delta_y) { |
280 gfx::Point origin = details.initial_bounds.origin(); | 281 gfx::Point origin = details.initial_bounds_in_parent.origin(); |
281 if (details.bounds_change & kBoundsChange_Repositions) { | 282 if (details.bounds_change & kBoundsChange_Repositions) { |
282 int pos_change_direction = | 283 int pos_change_direction = |
283 GetPositionChangeDirectionForWindowComponent(details.window_component); | 284 GetPositionChangeDirectionForWindowComponent(details.window_component); |
284 if (pos_change_direction & kBoundsChangeDirection_Horizontal) | 285 if (pos_change_direction & kBoundsChangeDirection_Horizontal) |
285 origin.Offset(delta_x, 0); | 286 origin.Offset(delta_x, 0); |
286 if (pos_change_direction & kBoundsChangeDirection_Vertical) | 287 if (pos_change_direction & kBoundsChangeDirection_Vertical) |
287 origin.Offset(0, delta_y); | 288 origin.Offset(0, delta_y); |
288 } | 289 } |
289 return origin; | 290 return origin; |
290 } | 291 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 details.window).bounds().height(); | 355 details.window).bounds().height(); |
355 if (height > max_height) { | 356 if (height > max_height) { |
356 height = max_height; | 357 height = max_height; |
357 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); | 358 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); |
358 } | 359 } |
359 } | 360 } |
360 return height; | 361 return height; |
361 } | 362 } |
362 | 363 |
363 } // namespace aura | 364 } // namespace aura |
OLD | NEW |