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" |
11 #include "ash/wm/workspace/workspace_layout_manager2.h" | |
11 #include "ui/aura/client/aura_constants.h" | 12 #include "ui/aura/client/aura_constants.h" |
12 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
14 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
15 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
16 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
17 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 break; | 163 break; |
163 default: | 164 default: |
164 break; | 165 break; |
165 } | 166 } |
166 return bounds_change; | 167 return bounds_change; |
167 } | 168 } |
168 | 169 |
169 // static | 170 // static |
170 gfx::Rect WindowResizer::CalculateBoundsForDrag( | 171 gfx::Rect WindowResizer::CalculateBoundsForDrag( |
171 const Details& details, | 172 const Details& details, |
172 const gfx::Point& location) { | 173 const gfx::Point& passed_location) { |
173 if (!details.is_resizable) | 174 if (!details.is_resizable) |
174 return details.initial_bounds; | 175 return details.initial_bounds; |
175 | 176 |
177 gfx::Point location = passed_location; | |
178 gfx::Rect work_area = | |
179 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | |
180 | |
176 int delta_x = location.x() - details.initial_location_in_parent.x(); | 181 int delta_x = location.x() - details.initial_location_in_parent.x(); |
177 int delta_y = location.y() - details.initial_location_in_parent.y(); | 182 int delta_y = location.y() - details.initial_location_in_parent.y(); |
178 | 183 |
179 // The minimize size constraint may limit how much we change the window | 184 // The minimize size constraint may limit how much we change the window |
180 // position. For example, dragging the left edge to the right should stop | 185 // position. For example, dragging the left edge to the right should stop |
181 // repositioning the window when the minimize size is reached. | 186 // repositioning the window when the minimize size is reached. |
182 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 187 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); |
183 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 188 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
189 gfx::Rect new_bounds(origin, size); | |
184 | 190 |
185 // When we might want to reposition a window which is also restored to its | 191 // Sizing has to keep the result on the screen. Note that this correction |
186 // previous size, to keep the cursor within the dragged window. | 192 // has to come first since it might have an impact on the origin as well as |
187 if (!details.restore_bounds.IsEmpty() && | 193 // on the size. |
188 details.bounds_change & kBoundsChange_Repositions) { | 194 if (details.bounds_change & kBoundsChange_Resizes) { |
sky
2012/10/16 22:57:46
This code is logically similar to that of 245-250,
Mr4D (OOO till 08-26)
2012/10/17 00:05:17
The thing is that a resize operation can change si
| |
189 // However - it is not desirable to change the origin if the window would | 195 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { |
190 // be still hit by the cursor. | 196 if (IsRightEdge(details.window_component) && |
191 if (details.initial_location_in_parent.x() > | 197 new_bounds.right() < work_area.x() + kMinimumOnScreenArea) { |
192 details.initial_bounds.x() + details.restore_bounds.width()) | 198 int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right(); |
193 origin.set_x(location.x() - details.restore_bounds.width() / 2); | 199 new_bounds.set_width(new_bounds.width() + delta); |
200 } else if (new_bounds.x() > work_area.right() - kMinimumOnScreenArea) { | |
201 int width = new_bounds.right() - work_area.right() + | |
202 kMinimumOnScreenArea; | |
203 new_bounds.set_x(work_area.right() - kMinimumOnScreenArea); | |
204 new_bounds.set_width(width); | |
205 } | |
206 } | |
207 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { | |
sky
2012/10/16 22:57:46
Similarly should we fold 237-244 into this?
Mr4D (OOO till 08-26)
2012/10/17 00:05:17
Done.
| |
208 if (!IsBottomEdge(details.window_component) && | |
209 new_bounds.y() > work_area.bottom() - kMinimumOnScreenArea) { | |
210 int height = new_bounds.bottom() - work_area.bottom() + | |
211 kMinimumOnScreenArea; | |
212 new_bounds.set_y(work_area.bottom() - kMinimumOnScreenArea); | |
213 new_bounds.set_height(height); | |
214 } | |
215 } | |
194 } | 216 } |
195 | 217 |
196 gfx::Rect new_bounds(origin, size); | 218 if (details.bounds_change & kBoundsChange_Repositions) { |
219 // When we might want to reposition a window which is also restored to its | |
220 // previous size, to keep the cursor within the dragged window. | |
221 if (!details.restore_bounds.IsEmpty()) { | |
222 // However - it is not desirable to change the origin if the window would | |
223 // be still hit by the cursor. | |
224 if (details.initial_location_in_parent.x() > | |
225 details.initial_bounds.x() + details.restore_bounds.width()) | |
226 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); | |
227 } | |
228 // Make sure that the x origin does not leave the screen. Note that y is | |
229 // taken care of next. | |
230 new_bounds.set_x( | |
231 std::max(work_area.x() - new_bounds.width() + kMinimumOnScreenArea, | |
232 std::min(work_area.right() - kMinimumOnScreenArea, | |
233 new_bounds.x()))); | |
234 } | |
235 | |
197 // Update bottom edge to stay in the work area when we are resizing | 236 // Update bottom edge to stay in the work area when we are resizing |
198 // by dragging the bottome edge or corners. | 237 // by dragging the bottom edge or corners. |
199 if (details.window_component == HTBOTTOM || | 238 if (details.window_component == HTBOTTOM || |
200 details.window_component == HTBOTTOMRIGHT || | 239 details.window_component == HTBOTTOMRIGHT || |
201 details.window_component == HTBOTTOMLEFT) { | 240 details.window_component == HTBOTTOMLEFT) { |
202 gfx::Rect work_area = | |
203 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | |
204 if (new_bounds.bottom() > work_area.bottom()) | 241 if (new_bounds.bottom() > work_area.bottom()) |
205 new_bounds.Inset(0, 0, 0, | 242 new_bounds.Inset(0, 0, 0, |
206 new_bounds.bottom() - work_area.bottom()); | 243 new_bounds.bottom() - work_area.bottom()); |
207 } | 244 } |
208 if (details.bounds_change & kBoundsChange_Resizes && | 245 if (details.bounds_change & kBoundsChange_Resizes && |
209 details.bounds_change & kBoundsChange_Repositions && new_bounds.y() < 0) { | 246 details.bounds_change & kBoundsChange_Repositions && new_bounds.y() < 0) { |
210 int delta = new_bounds.y(); | 247 int delta = new_bounds.y(); |
211 new_bounds.set_y(0); | 248 new_bounds.set_y(0); |
212 new_bounds.set_height(new_bounds.height() + delta); | 249 new_bounds.set_height(new_bounds.height() + delta); |
213 } | 250 } |
251 | |
214 return new_bounds; | 252 return new_bounds; |
215 } | 253 } |
216 | 254 |
217 // static | 255 // static |
218 bool WindowResizer::IsBottomEdge(int window_component) { | 256 bool WindowResizer::IsBottomEdge(int window_component) { |
219 return window_component == HTBOTTOMLEFT || | 257 return window_component == HTBOTTOMLEFT || |
220 window_component == HTBOTTOM || | 258 window_component == HTBOTTOM || |
221 window_component == HTBOTTOMRIGHT || | 259 window_component == HTBOTTOMRIGHT || |
222 window_component == HTGROWBOX; | 260 window_component == HTGROWBOX; |
223 } | 261 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 details.window).bounds().height(); | 341 details.window).bounds().height(); |
304 if (height > max_height) { | 342 if (height > max_height) { |
305 height = max_height; | 343 height = max_height; |
306 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); | 344 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); |
307 } | 345 } |
308 } | 346 } |
309 return height; | 347 return height; |
310 } | 348 } |
311 | 349 |
312 } // namespace aura | 350 } // namespace aura |
OLD | NEW |