| 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) { |
| 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) { |
| 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 } else if (details.window_component == HTBOTTOM || |
| 215 details.window_component == HTBOTTOMRIGHT || |
| 216 details.window_component == HTBOTTOMLEFT) { |
| 217 // Update bottom edge to stay in the work area when we are resizing |
| 218 // by dragging the bottom edge or corners. |
| 219 if (new_bounds.bottom() > work_area.bottom()) |
| 220 new_bounds.Inset(0, 0, 0, |
| 221 new_bounds.bottom() - work_area.bottom()); |
| 222 } |
| 223 } |
| 224 if (details.bounds_change & kBoundsChange_Repositions && |
| 225 new_bounds.y() < 0) { |
| 226 int delta = new_bounds.y(); |
| 227 new_bounds.set_y(0); |
| 228 new_bounds.set_height(new_bounds.height() + delta); |
| 229 } |
| 194 } | 230 } |
| 195 | 231 |
| 196 gfx::Rect new_bounds(origin, size); | 232 if (details.bounds_change & kBoundsChange_Repositions) { |
| 197 // Update bottom edge to stay in the work area when we are resizing | 233 // When we might want to reposition a window which is also restored to its |
| 198 // by dragging the bottome edge or corners. | 234 // previous size, to keep the cursor within the dragged window. |
| 199 if (details.window_component == HTBOTTOM || | 235 if (!details.restore_bounds.IsEmpty()) { |
| 200 details.window_component == HTBOTTOMRIGHT || | 236 // However - it is not desirable to change the origin if the window would |
| 201 details.window_component == HTBOTTOMLEFT) { | 237 // be still hit by the cursor. |
| 202 gfx::Rect work_area = | 238 if (details.initial_location_in_parent.x() > |
| 203 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | 239 details.initial_bounds.x() + details.restore_bounds.width()) |
| 204 if (new_bounds.bottom() > work_area.bottom()) | 240 new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); |
| 205 new_bounds.Inset(0, 0, 0, | 241 } |
| 206 new_bounds.bottom() - work_area.bottom()); | 242 // Make sure that the x origin does not leave the screen. Note that y is |
| 243 // taken care of next. |
| 244 new_bounds.set_x( |
| 245 std::max(work_area.x() - new_bounds.width() + kMinimumOnScreenArea, |
| 246 std::min(work_area.right() - kMinimumOnScreenArea, |
| 247 new_bounds.x()))); |
| 207 } | 248 } |
| 208 if (details.bounds_change & kBoundsChange_Resizes && | 249 |
| 209 details.bounds_change & kBoundsChange_Repositions && new_bounds.y() < 0) { | |
| 210 int delta = new_bounds.y(); | |
| 211 new_bounds.set_y(0); | |
| 212 new_bounds.set_height(new_bounds.height() + delta); | |
| 213 } | |
| 214 return new_bounds; | 250 return new_bounds; |
| 215 } | 251 } |
| 216 | 252 |
| 217 // static | 253 // static |
| 218 bool WindowResizer::IsBottomEdge(int window_component) { | 254 bool WindowResizer::IsBottomEdge(int window_component) { |
| 219 return window_component == HTBOTTOMLEFT || | 255 return window_component == HTBOTTOMLEFT || |
| 220 window_component == HTBOTTOM || | 256 window_component == HTBOTTOM || |
| 221 window_component == HTBOTTOMRIGHT || | 257 window_component == HTBOTTOMRIGHT || |
| 222 window_component == HTGROWBOX; | 258 window_component == HTGROWBOX; |
| 223 } | 259 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 details.window).bounds().height(); | 339 details.window).bounds().height(); |
| 304 if (height > max_height) { | 340 if (height > max_height) { |
| 305 height = max_height; | 341 height = max_height; |
| 306 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); | 342 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); |
| 307 } | 343 } |
| 308 } | 344 } |
| 309 return height; | 345 return height; |
| 310 } | 346 } |
| 311 | 347 |
| 312 } // namespace aura | 348 } // namespace aura |
| OLD | NEW |