Chromium Code Reviews| 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 <cmath> | |
| 8 | |
| 7 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
| 8 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 9 #include "ash/wm/property_util.h" | 11 #include "ash/wm/property_util.h" |
| 10 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_delegate.h" | 16 #include "ui/aura/window_delegate.h" |
| 15 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 16 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; | 102 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; |
| 101 // static | 103 // static |
| 102 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; | 104 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; |
| 103 | 105 |
| 104 WindowResizer::Details::Details() | 106 WindowResizer::Details::Details() |
| 105 : window(NULL), | 107 : window(NULL), |
| 106 window_component(HTNOWHERE), | 108 window_component(HTNOWHERE), |
| 107 bounds_change(0), | 109 bounds_change(0), |
| 108 position_change_direction(0), | 110 position_change_direction(0), |
| 109 size_change_direction(0), | 111 size_change_direction(0), |
| 110 is_resizable(false) { | 112 is_resizable(false), |
| 113 is_touch(false) { | |
| 111 } | 114 } |
| 112 | 115 |
| 113 WindowResizer::Details::Details(aura::Window* window, | 116 WindowResizer::Details::Details(aura::Window* window, |
| 114 const gfx::Point& location, | 117 const gfx::Point& location, |
| 115 int window_component) | 118 int window_component) |
| 116 : window(window), | 119 : window(window), |
| 117 initial_bounds_in_parent(window->bounds()), | 120 initial_bounds_in_parent(window->bounds()), |
| 118 restore_bounds(gfx::Rect()), | 121 restore_bounds(gfx::Rect()), |
| 119 initial_location_in_parent(location), | 122 initial_location_in_parent(location), |
| 120 initial_opacity(window->layer()->opacity()), | 123 initial_opacity(window->layer()->opacity()), |
| 121 window_component(window_component), | 124 window_component(window_component), |
| 122 bounds_change(GetBoundsChangeForWindowComponent(window_component)), | 125 bounds_change(GetBoundsChangeForWindowComponent(window_component)), |
| 123 position_change_direction( | 126 position_change_direction( |
| 124 GetPositionChangeDirectionForWindowComponent(window_component)), | 127 GetPositionChangeDirectionForWindowComponent(window_component)), |
| 125 size_change_direction( | 128 size_change_direction( |
| 126 GetSizeChangeDirectionForWindowComponent(window_component)), | 129 GetSizeChangeDirectionForWindowComponent(window_component)), |
| 127 is_resizable(bounds_change != kBoundsChangeDirection_None) { | 130 is_resizable(bounds_change != kBoundsChangeDirection_None), |
| 131 is_touch(window->GetRootWindow()->current_event()->type() == | |
| 132 ui::ET_GESTURE_SCROLL_BEGIN) { | |
|
sadrul
2013/05/08 17:10:56
Should this check current_event()->IsGestureEvent(
mohsen
2013/05/28 23:27:39
Done.
| |
| 128 if (wm::IsWindowNormal(window) && | 133 if (wm::IsWindowNormal(window) && |
| 129 GetRestoreBoundsInScreen(window) && | 134 GetRestoreBoundsInScreen(window) && |
| 130 window_component == HTCAPTION) | 135 window_component == HTCAPTION) |
| 131 restore_bounds = *GetRestoreBoundsInScreen(window); | 136 restore_bounds = *GetRestoreBoundsInScreen(window); |
| 132 } | 137 } |
| 133 | 138 |
| 134 WindowResizer::Details::~Details() { | 139 WindowResizer::Details::~Details() { |
| 135 } | 140 } |
| 136 | 141 |
| 137 WindowResizer::WindowResizer() { | 142 WindowResizer::WindowResizer() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 if (!details.is_resizable) | 179 if (!details.is_resizable) |
| 175 return details.initial_bounds_in_parent; | 180 return details.initial_bounds_in_parent; |
| 176 | 181 |
| 177 gfx::Point location = passed_location; | 182 gfx::Point location = passed_location; |
| 178 gfx::Rect work_area = | 183 gfx::Rect work_area = |
| 179 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); | 184 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window); |
| 180 | 185 |
| 181 int delta_x = location.x() - details.initial_location_in_parent.x(); | 186 int delta_x = location.x() - details.initial_location_in_parent.x(); |
| 182 int delta_y = location.y() - details.initial_location_in_parent.y(); | 187 int delta_y = location.y() - details.initial_location_in_parent.y(); |
| 183 | 188 |
| 189 // Adjust values of |delta_x| and |delta_y| for touch resizes. | |
| 190 AdjustDeltas(details, &delta_x, &delta_y); | |
| 191 | |
| 184 // The minimize size constraint may limit how much we change the window | 192 // The minimize size constraint may limit how much we change the window |
| 185 // position. For example, dragging the left edge to the right should stop | 193 // position. For example, dragging the left edge to the right should stop |
| 186 // repositioning the window when the minimize size is reached. | 194 // repositioning the window when the minimize size is reached. |
| 187 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); | 195 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); |
| 188 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); | 196 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); |
| 189 gfx::Rect new_bounds(origin, size); | 197 gfx::Rect new_bounds(origin, size); |
| 190 | 198 |
| 191 // Sizing has to keep the result on the screen. Note that this correction | 199 // Sizing has to keep the result on the screen. Note that this correction |
| 192 // has to come first since it might have an impact on the origin as well as | 200 // has to come first since it might have an impact on the origin as well as |
| 193 // on the size. | 201 // on the size. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 new_bounds_in_screen.x()))); | 266 new_bounds_in_screen.x()))); |
| 259 new_bounds = | 267 new_bounds = |
| 260 ScreenAsh::ConvertRectFromScreen(parent, new_bounds_in_screen); | 268 ScreenAsh::ConvertRectFromScreen(parent, new_bounds_in_screen); |
| 261 } | 269 } |
| 262 } | 270 } |
| 263 | 271 |
| 264 return new_bounds; | 272 return new_bounds; |
| 265 } | 273 } |
| 266 | 274 |
| 267 // static | 275 // static |
| 276 void WindowResizer::AdjustDeltas(const Details& details, | |
| 277 int* delta_x, | |
| 278 int* delta_y) { | |
| 279 if (details.is_touch && (details.bounds_change & kBoundsChange_Resizes)) { | |
|
sadrul
2013/05/08 17:10:56
Return early instead of nesting too deep.
mohsen
2013/05/28 23:27:39
Done.
| |
| 280 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { | |
| 281 if (IsRightEdge(details.window_component) && *delta_x > 0) { | |
| 282 int display_width = Shell::GetScreen()->GetDisplayNearestWindow( | |
| 283 details.window).bounds().width(); | |
| 284 int right = details.initial_bounds_in_parent.right(); | |
| 285 float window_distance = display_width - right; | |
| 286 float touch_distance = display_width - | |
| 287 details.initial_location_in_parent.x(); | |
| 288 *delta_x = static_cast<int>( | |
| 289 ceil(*delta_x * window_distance / touch_distance)); | |
| 290 } else if (!IsRightEdge(details.window_component) && *delta_x < 0) { | |
| 291 float window_distance = details.initial_bounds_in_parent.x(); | |
| 292 float touch_distance = details.initial_location_in_parent.x(); | |
| 293 *delta_x = static_cast<int>( | |
| 294 ceil(*delta_x * window_distance / touch_distance)); | |
| 295 } | |
| 296 } | |
| 297 if (details.size_change_direction & kBoundsChangeDirection_Vertical) { | |
| 298 if (IsBottomEdge(details.window_component) && *delta_y > 0) { | |
| 299 int display_height = Shell::GetScreen()->GetDisplayNearestWindow( | |
| 300 details.window).bounds().height(); | |
| 301 int bottom = details.initial_bounds_in_parent.bottom(); | |
| 302 float window_distance = display_height - bottom; | |
| 303 float touch_distance = display_height - | |
| 304 details.initial_location_in_parent.y(); | |
| 305 *delta_y = static_cast<int>( | |
| 306 ceil(*delta_y * window_distance / touch_distance)); | |
| 307 } else if (!IsBottomEdge(details.window_component) && *delta_y < 0) { | |
| 308 float window_distance = details.initial_bounds_in_parent.y(); | |
| 309 float touch_distance = details.initial_location_in_parent.y(); | |
| 310 *delta_y = static_cast<int>( | |
| 311 ceil(*delta_y * window_distance / touch_distance)); | |
| 312 } | |
| 313 } | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 // static | |
| 268 bool WindowResizer::IsBottomEdge(int window_component) { | 318 bool WindowResizer::IsBottomEdge(int window_component) { |
| 269 return window_component == HTBOTTOMLEFT || | 319 return window_component == HTBOTTOMLEFT || |
| 270 window_component == HTBOTTOM || | 320 window_component == HTBOTTOM || |
| 271 window_component == HTBOTTOMRIGHT || | 321 window_component == HTBOTTOMRIGHT || |
| 272 window_component == HTGROWBOX; | 322 window_component == HTGROWBOX; |
| 273 } | 323 } |
| 274 | 324 |
| 275 // static | 325 // static |
| 276 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, | 326 gfx::Point WindowResizer::GetOriginForDrag(const Details& details, |
| 277 int delta_x, | 327 int delta_x, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 if (height > max_height) { | 413 if (height > max_height) { |
| 364 height = max_height; | 414 height = max_height; |
| 365 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - | 415 *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - |
| 366 max_height); | 416 max_height); |
| 367 } | 417 } |
| 368 } | 418 } |
| 369 return height; | 419 return height; |
| 370 } | 420 } |
| 371 | 421 |
| 372 } // namespace aura | 422 } // namespace aura |
| OLD | NEW |