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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 175 |
169 int delta_x = location.x() - details.initial_location_in_parent.x(); | 176 int delta_x = location.x() - details.initial_location_in_parent.x(); |
170 int delta_y = location.y() - details.initial_location_in_parent.y(); | 177 int delta_y = location.y() - details.initial_location_in_parent.y(); |
171 | 178 |
172 // The minimize size constraint may limit how much we change the window | 179 // The minimize size constraint may limit how much we change the window |
173 // position. For example, dragging the left edge to the right should stop | 180 // position. For example, dragging the left edge to the right should stop |
174 // repositioning the window when the minimize size is reached. | 181 // repositioning the window when the minimize size is reached. |
175 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 182 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); |
176 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 183 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
177 | 184 |
| 185 // When we might want to reposition a window which is also restored to its |
| 186 // previous size, to keep the cursor within the dragged window. |
| 187 if (!details.restore_bounds.IsEmpty() && |
| 188 details.bounds_change & kBoundsChange_Repositions) { |
| 189 // However - it is not desirable to change the origin if the window would |
| 190 // be still hit by the cursor. |
| 191 if (details.initial_location_in_parent.x() > |
| 192 details.initial_bounds.x() + details.restore_bounds.width()) |
| 193 origin.set_x(location.x() - details.restore_bounds.width() / 2); |
| 194 } |
| 195 |
178 gfx::Rect new_bounds(origin, size); | 196 gfx::Rect new_bounds(origin, size); |
179 // Update bottom edge to stay in the work area when we are resizing | 197 // Update bottom edge to stay in the work area when we are resizing |
180 // by dragging the bottome edge or corners. | 198 // by dragging the bottome edge or corners. |
181 if (details.window_component == HTBOTTOM || | 199 if (details.window_component == HTBOTTOM || |
182 details.window_component == HTBOTTOMRIGHT || | 200 details.window_component == HTBOTTOMRIGHT || |
183 details.window_component == HTBOTTOMLEFT) { | 201 details.window_component == HTBOTTOMLEFT) { |
184 gfx::Rect work_area = | 202 gfx::Rect work_area = |
185 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | 203 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); |
186 if (new_bounds.bottom() > work_area.bottom()) | 204 if (new_bounds.bottom() > work_area.bottom()) |
187 new_bounds.Inset(0, 0, 0, | 205 new_bounds.Inset(0, 0, 0, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 240 |
223 // static | 241 // static |
224 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, | 242 gfx::Size WindowResizer::GetSizeForDrag(const Details& details, |
225 int* delta_x, | 243 int* delta_x, |
226 int* delta_y) { | 244 int* delta_y) { |
227 gfx::Size size = details.initial_bounds.size(); | 245 gfx::Size size = details.initial_bounds.size(); |
228 if (details.bounds_change & kBoundsChange_Resizes) { | 246 if (details.bounds_change & kBoundsChange_Resizes) { |
229 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); | 247 gfx::Size min_size = details.window->delegate()->GetMinimumSize(); |
230 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), | 248 size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), |
231 GetHeightForDrag(details, min_size.height(), delta_y)); | 249 GetHeightForDrag(details, min_size.height(), delta_y)); |
| 250 } else if (!details.restore_bounds.IsEmpty()) { |
| 251 size = details.restore_bounds.size(); |
232 } | 252 } |
233 return size; | 253 return size; |
234 } | 254 } |
235 | 255 |
236 // static | 256 // static |
237 int WindowResizer::GetWidthForDrag(const Details& details, | 257 int WindowResizer::GetWidthForDrag(const Details& details, |
238 int min_width, | 258 int min_width, |
239 int* delta_x) { | 259 int* delta_x) { |
240 int width = details.initial_bounds.width(); | 260 int width = details.initial_bounds.width(); |
241 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | 261 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height(); | 303 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height(); |
284 if (height > max_height) { | 304 if (height > max_height) { |
285 height = max_height; | 305 height = max_height; |
286 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); | 306 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); |
287 } | 307 } |
288 } | 308 } |
289 return height; | 309 return height; |
290 } | 310 } |
291 | 311 |
292 } // namespace aura | 312 } // namespace aura |
OLD | NEW |