Chromium Code Reviews| Index: ash/wm/window_resizer.cc |
| diff --git a/ash/wm/window_resizer.cc b/ash/wm/window_resizer.cc |
| index 3773d0735099072ee932d1ffc915df274181a16b..60ebcfe09c0ab7b30237eb4d332889669f39a692 100644 |
| --- a/ash/wm/window_resizer.cc |
| +++ b/ash/wm/window_resizer.cc |
| @@ -4,6 +4,8 @@ |
| #include "ash/wm/window_resizer.h" |
| +#include <cmath> |
| + |
| #include "ash/screen_ash.h" |
| #include "ash/shell.h" |
| #include "ash/wm/property_util.h" |
| @@ -107,7 +109,8 @@ WindowResizer::Details::Details() |
| bounds_change(0), |
| position_change_direction(0), |
| size_change_direction(0), |
| - is_resizable(false) { |
| + is_resizable(false), |
| + is_touch(false) { |
| } |
| WindowResizer::Details::Details(aura::Window* window, |
| @@ -124,7 +127,9 @@ WindowResizer::Details::Details(aura::Window* window, |
| GetPositionChangeDirectionForWindowComponent(window_component)), |
| size_change_direction( |
| GetSizeChangeDirectionForWindowComponent(window_component)), |
| - is_resizable(bounds_change != kBoundsChangeDirection_None) { |
| + is_resizable(bounds_change != kBoundsChangeDirection_None), |
| + is_touch(window->GetRootWindow()->current_event()->type() == |
| + 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.
|
| if (wm::IsWindowNormal(window) && |
| GetRestoreBoundsInScreen(window) && |
| window_component == HTCAPTION) |
| @@ -181,6 +186,9 @@ gfx::Rect WindowResizer::CalculateBoundsForDrag( |
| int delta_x = location.x() - details.initial_location_in_parent.x(); |
| int delta_y = location.y() - details.initial_location_in_parent.y(); |
| + // Adjust values of |delta_x| and |delta_y| for touch resizes. |
| + AdjustDeltas(details, &delta_x, &delta_y); |
| + |
| // The minimize size constraint may limit how much we change the window |
| // position. For example, dragging the left edge to the right should stop |
| // repositioning the window when the minimize size is reached. |
| @@ -265,6 +273,48 @@ gfx::Rect WindowResizer::CalculateBoundsForDrag( |
| } |
| // static |
| +void WindowResizer::AdjustDeltas(const Details& details, |
| + int* delta_x, |
| + int* delta_y) { |
| + 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.
|
| + if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { |
| + if (IsRightEdge(details.window_component) && *delta_x > 0) { |
| + int display_width = Shell::GetScreen()->GetDisplayNearestWindow( |
| + details.window).bounds().width(); |
| + int right = details.initial_bounds_in_parent.right(); |
| + float window_distance = display_width - right; |
| + float touch_distance = display_width - |
| + details.initial_location_in_parent.x(); |
| + *delta_x = static_cast<int>( |
| + ceil(*delta_x * window_distance / touch_distance)); |
| + } else if (!IsRightEdge(details.window_component) && *delta_x < 0) { |
| + float window_distance = details.initial_bounds_in_parent.x(); |
| + float touch_distance = details.initial_location_in_parent.x(); |
| + *delta_x = static_cast<int>( |
| + ceil(*delta_x * window_distance / touch_distance)); |
| + } |
| + } |
| + if (details.size_change_direction & kBoundsChangeDirection_Vertical) { |
| + if (IsBottomEdge(details.window_component) && *delta_y > 0) { |
| + int display_height = Shell::GetScreen()->GetDisplayNearestWindow( |
| + details.window).bounds().height(); |
| + int bottom = details.initial_bounds_in_parent.bottom(); |
| + float window_distance = display_height - bottom; |
| + float touch_distance = display_height - |
| + details.initial_location_in_parent.y(); |
| + *delta_y = static_cast<int>( |
| + ceil(*delta_y * window_distance / touch_distance)); |
| + } else if (!IsBottomEdge(details.window_component) && *delta_y < 0) { |
| + float window_distance = details.initial_bounds_in_parent.y(); |
| + float touch_distance = details.initial_location_in_parent.y(); |
| + *delta_y = static_cast<int>( |
| + ceil(*delta_y * window_distance / touch_distance)); |
| + } |
| + } |
| + } |
| +} |
| + |
| +// static |
| bool WindowResizer::IsBottomEdge(int window_component) { |
| return window_component == HTBOTTOMLEFT || |
| window_component == HTBOTTOM || |