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..9f77cbe2d3432125d88495dcc81a7f82df83c2f4 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,8 @@ 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()->IsGestureEvent()) { |
| if (wm::IsWindowNormal(window) && |
| GetRestoreBoundsInScreen(window) && |
| window_component == HTCAPTION) |
| @@ -181,6 +185,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. |
| + AdjustDeltaForTouch(details, &delta_x, &delta_y); |
|
sadrul
2013/05/29 04:01:51
My suggestion was to make AdjustDeltaForTouch more
|
| + |
| // 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 +272,49 @@ gfx::Rect WindowResizer::CalculateBoundsForDrag( |
| } |
| // static |
| +void WindowResizer::AdjustDeltaForTouch(const Details& details, |
| + int* delta_x, |
| + int* delta_y) { |
| + if (!details.is_touch || !(details.bounds_change & kBoundsChange_Resizes)) |
| + return; |
| + |
| + 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 || |