diff options
author | varkha@chromium.org <varkha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 21:41:26 +0000 |
---|---|---|
committer | varkha@chromium.org <varkha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 21:41:26 +0000 |
commit | c35e7ec8e0b3d525f27f5a52864c61768698954f (patch) | |
tree | 3a39891959a74851ad3a889267ba60a6ebf68585 /ash/wm/window_resizer.cc | |
parent | 863f0ef77be6de51154a5b490577440f4795befd (diff) | |
download | chromium_src-c35e7ec8e0b3d525f27f5a52864c61768698954f.zip chromium_src-c35e7ec8e0b3d525f27f5a52864c61768698954f.tar.gz chromium_src-c35e7ec8e0b3d525f27f5a52864c61768698954f.tar.bz2 |
Removes individual instances of Details structure in WindowResizer subclasses and adds DragDetails to WindowState. It is possible to access the current WindowResizer during the drag via window_state->drag_details()->window_resizer.
Simplifies construction of WindowResizer chain by creating DragDetails once at a point where creation of the resizer chain is imminent (after all checks that would return empty WindowResizer object are made).
Keeps track of whether currently dragged window is a panel attached to the shelf and if so prevents it from indicating that it can be docked (and from getting docked).
BUG=310931
Review URL: https://codereview.chromium.org/121153003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/window_resizer.cc')
-rw-r--r-- | ash/wm/window_resizer.cc | 282 |
1 files changed, 104 insertions, 178 deletions
diff --git a/ash/wm/window_resizer.cc b/ash/wm/window_resizer.cc index 372ce48..2631cc6 100644 --- a/ash/wm/window_resizer.cc +++ b/ash/wm/window_resizer.cc @@ -25,60 +25,6 @@ namespace ash { namespace { -int GetPositionChangeDirectionForWindowComponent(int window_component) { - int pos_change_direction = WindowResizer::kBoundsChangeDirection_None; - switch (window_component) { - case HTTOPLEFT: - case HTBOTTOMRIGHT: - case HTGROWBOX: - case HTCAPTION: - pos_change_direction |= - WindowResizer::kBoundsChangeDirection_Horizontal | - WindowResizer::kBoundsChangeDirection_Vertical; - break; - case HTTOP: - case HTTOPRIGHT: - case HTBOTTOM: - pos_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical; - break; - case HTBOTTOMLEFT: - case HTRIGHT: - case HTLEFT: - pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal; - break; - default: - break; - } - return pos_change_direction; -} - -int GetSizeChangeDirectionForWindowComponent(int window_component) { - int size_change_direction = WindowResizer::kBoundsChangeDirection_None; - switch (window_component) { - case HTTOPLEFT: - case HTTOPRIGHT: - case HTBOTTOMLEFT: - case HTBOTTOMRIGHT: - case HTGROWBOX: - case HTCAPTION: - size_change_direction |= - WindowResizer::kBoundsChangeDirection_Horizontal | - WindowResizer::kBoundsChangeDirection_Vertical; - break; - case HTTOP: - case HTBOTTOM: - size_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical; - break; - case HTRIGHT: - case HTLEFT: - size_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal; - break; - default: - break; - } - return size_change_direction; -} - // Returns true for resize components along the right edge, where a drag in // positive x will make the window larger. bool IsRightEdge(int window_component) { @@ -104,45 +50,12 @@ const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; // static const int WindowResizer::kBoundsChangeDirection_Vertical = 2; -WindowResizer::Details::Details() - : window(NULL), - window_state(NULL), - window_component(HTNOWHERE), - bounds_change(0), - position_change_direction(0), - size_change_direction(0), - is_resizable(false), - source(aura::client::WINDOW_MOVE_SOURCE_MOUSE) { -} - -WindowResizer::Details::Details(aura::Window* window, - const gfx::Point& location, - int window_component, - aura::client::WindowMoveSource source) - : window(window), - window_state(wm::GetWindowState(window)), - initial_bounds_in_parent(window->bounds()), - restore_bounds(gfx::Rect()), - initial_location_in_parent(location), - initial_opacity(window->layer()->opacity()), - window_component(window_component), - bounds_change(GetBoundsChangeForWindowComponent(window_component)), - position_change_direction( - GetPositionChangeDirectionForWindowComponent(window_component)), - size_change_direction( - GetSizeChangeDirectionForWindowComponent(window_component)), - is_resizable(bounds_change != kBoundsChangeDirection_None), - source(source) { - if (window_state->IsNormalShowState() && - window_state->HasRestoreBounds() && - window_component == HTCAPTION) - restore_bounds = window_state->GetRestoreBoundsInScreen(); +WindowResizer::WindowResizer() { } -WindowResizer::Details::~Details() { -} - -WindowResizer::WindowResizer() { +WindowResizer::WindowResizer(wm::WindowState* window_state) + : window_state_(window_state) { + DCHECK(window_state_->drag_details()); } WindowResizer::~WindowResizer() { @@ -175,44 +88,71 @@ int WindowResizer::GetBoundsChangeForWindowComponent(int component) { return bounds_change; } -// static +//static +int WindowResizer::GetPositionChangeDirectionForWindowComponent( + int window_component) { + int pos_change_direction = WindowResizer::kBoundsChangeDirection_None; + switch (window_component) { + case HTTOPLEFT: + case HTBOTTOMRIGHT: + case HTGROWBOX: + case HTCAPTION: + pos_change_direction |= + WindowResizer::kBoundsChangeDirection_Horizontal | + WindowResizer::kBoundsChangeDirection_Vertical; + break; + case HTTOP: + case HTTOPRIGHT: + case HTBOTTOM: + pos_change_direction |= WindowResizer::kBoundsChangeDirection_Vertical; + break; + case HTBOTTOMLEFT: + case HTRIGHT: + case HTLEFT: + pos_change_direction |= WindowResizer::kBoundsChangeDirection_Horizontal; + break; + default: + break; + } + return pos_change_direction; +} + gfx::Rect WindowResizer::CalculateBoundsForDrag( - const Details& details, const gfx::Point& passed_location) { - if (!details.is_resizable) - return details.initial_bounds_in_parent; + if (!details().is_resizable) + return details().initial_bounds_in_parent; gfx::Point location = passed_location; - int delta_x = location.x() - details.initial_location_in_parent.x(); - int delta_y = location.y() - details.initial_location_in_parent.y(); + int delta_x = location.x() - details().initial_location_in_parent.x(); + int delta_y = location.y() - details().initial_location_in_parent.y(); - AdjustDeltaForTouchResize(details, &delta_x, &delta_y); + AdjustDeltaForTouchResize(&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. - gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); - gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); + gfx::Size size = GetSizeForDrag(&delta_x, &delta_y); + gfx::Point origin = GetOriginForDrag(delta_x, delta_y); gfx::Rect new_bounds(origin, size); // Sizing has to keep the result on the screen. Note that this correction // has to come first since it might have an impact on the origin as well as // on the size. - if (details.bounds_change & kBoundsChange_Resizes) { + if (details().bounds_change & kBoundsChange_Resizes) { gfx::Rect work_area = - Shell::GetScreen()->GetDisplayNearestWindow(details.window).work_area(); + Shell::GetScreen()->GetDisplayNearestWindow(GetTarget()).work_area(); aura::Window* dock_container = Shell::GetContainer( - details.window->GetRootWindow(), + GetTarget()->GetRootWindow(), internal::kShellWindowId_DockedContainer); internal::DockedWindowLayoutManager* dock_layout = static_cast<internal::DockedWindowLayoutManager*>( dock_container->layout_manager()); work_area.Union(dock_layout->docked_bounds()); - work_area = ScreenAsh::ConvertRectFromScreen(details.window->parent(), + work_area = ScreenAsh::ConvertRectFromScreen(GetTarget()->parent(), work_area); - if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { - if (IsRightEdge(details.window_component) && + if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { + if (IsRightEdge(details().window_component) && new_bounds.right() < work_area.x() + kMinimumOnScreenArea) { int delta = work_area.x() + kMinimumOnScreenArea - new_bounds.right(); new_bounds.set_width(new_bounds.width() + delta); @@ -223,16 +163,16 @@ gfx::Rect WindowResizer::CalculateBoundsForDrag( new_bounds.set_width(width); } } - if (details.size_change_direction & kBoundsChangeDirection_Vertical) { - if (!IsBottomEdge(details.window_component) && + if (details().size_change_direction & kBoundsChangeDirection_Vertical) { + if (!IsBottomEdge(details().window_component) && new_bounds.y() > work_area.bottom() - kMinimumOnScreenArea) { int height = new_bounds.bottom() - work_area.bottom() + kMinimumOnScreenArea; new_bounds.set_y(work_area.bottom() - kMinimumOnScreenArea); new_bounds.set_height(height); - } else if (details.window_component == HTBOTTOM || - details.window_component == HTBOTTOMRIGHT || - details.window_component == HTBOTTOMLEFT) { + } else if (details().window_component == HTBOTTOM || + details().window_component == HTBOTTOMRIGHT || + details().window_component == HTBOTTOMLEFT) { // Update bottom edge to stay in the work area when we are resizing // by dragging the bottom edge or corners. if (new_bounds.bottom() > work_area.bottom()) @@ -240,7 +180,7 @@ gfx::Rect WindowResizer::CalculateBoundsForDrag( new_bounds.bottom() - work_area.bottom()); } } - if (details.bounds_change & kBoundsChange_Repositions && + if (details().bounds_change & kBoundsChange_Repositions && new_bounds.y() < 0) { int delta = new_bounds.y(); new_bounds.set_y(0); @@ -248,21 +188,22 @@ gfx::Rect WindowResizer::CalculateBoundsForDrag( } } - if (details.bounds_change & kBoundsChange_Repositions) { + if (details().bounds_change & kBoundsChange_Repositions) { // When we might want to reposition a window which is also restored to its // previous size, to keep the cursor within the dragged window. - if (!details.restore_bounds.IsEmpty()) { + if (!details().restore_bounds.IsEmpty()) { // However - it is not desirable to change the origin if the window would // be still hit by the cursor. - if (details.initial_location_in_parent.x() > - details.initial_bounds_in_parent.x() + details.restore_bounds.width()) - new_bounds.set_x(location.x() - details.restore_bounds.width() / 2); + if (details().initial_location_in_parent.x() > + details().initial_bounds_in_parent.x() + + details().restore_bounds.width()) + new_bounds.set_x(location.x() - details().restore_bounds.width() / 2); } // Make sure that |new_bounds| doesn't leave any of the displays. Note that // the |work_area| above isn't good for this check since it is the work area // for the current display but the window can move to a different one. - aura::Window* parent = details.window->parent(); + aura::Window* parent = GetTarget()->parent(); gfx::Point passed_location_in_screen(passed_location); wm::ConvertPointToScreen(parent, &passed_location_in_screen); gfx::Rect near_passed_location(passed_location_in_screen, gfx::Size()); @@ -304,42 +245,36 @@ bool WindowResizer::IsBottomEdge(int window_component) { window_component == HTGROWBOX; } -// static -void WindowResizer::AdjustDeltaForTouchResize(const Details& details, - int* delta_x, - int* delta_y) { - if (details.source != aura::client::WINDOW_MOVE_SOURCE_TOUCH || - !(details.bounds_change & kBoundsChange_Resizes)) +void WindowResizer::AdjustDeltaForTouchResize(int* delta_x, int* delta_y) { + if (details().source != aura::client::WINDOW_MOVE_SOURCE_TOUCH || + !(details().bounds_change & kBoundsChange_Resizes)) return; - if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { - if (IsRightEdge(details.window_component)) { - *delta_x += details.initial_location_in_parent.x() - - details.initial_bounds_in_parent.right(); + if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { + if (IsRightEdge(details().window_component)) { + *delta_x += details().initial_location_in_parent.x() - + details().initial_bounds_in_parent.right(); } else { - *delta_x += details.initial_location_in_parent.x() - - details.initial_bounds_in_parent.x(); + *delta_x += details().initial_location_in_parent.x() - + details().initial_bounds_in_parent.x(); } } - if (details.size_change_direction & kBoundsChangeDirection_Vertical) { - if (IsBottomEdge(details.window_component)) { - *delta_y += details.initial_location_in_parent.y() - - details.initial_bounds_in_parent.bottom(); + if (details().size_change_direction & kBoundsChangeDirection_Vertical) { + if (IsBottomEdge(details().window_component)) { + *delta_y += details().initial_location_in_parent.y() - + details().initial_bounds_in_parent.bottom(); } else { - *delta_y += details.initial_location_in_parent.y() - - details.initial_bounds_in_parent.y(); + *delta_y += details().initial_location_in_parent.y() - + details().initial_bounds_in_parent.y(); } } } -// static -gfx::Point WindowResizer::GetOriginForDrag(const Details& details, - int delta_x, - int delta_y) { - gfx::Point origin = details.initial_bounds_in_parent.origin(); - if (details.bounds_change & kBoundsChange_Repositions) { - int pos_change_direction = - GetPositionChangeDirectionForWindowComponent(details.window_component); +gfx::Point WindowResizer::GetOriginForDrag(int delta_x, int delta_y) { + gfx::Point origin = details().initial_bounds_in_parent.origin(); + if (details().bounds_change & kBoundsChange_Repositions) { + int pos_change_direction = GetPositionChangeDirectionForWindowComponent( + details().window_component); if (pos_change_direction & kBoundsChangeDirection_Horizontal) origin.Offset(delta_x, 0); if (pos_change_direction & kBoundsChangeDirection_Vertical) @@ -348,85 +283,76 @@ gfx::Point WindowResizer::GetOriginForDrag(const Details& details, return origin; } -// static -gfx::Size WindowResizer::GetSizeForDrag(const Details& details, - int* delta_x, - int* delta_y) { - gfx::Size size = details.initial_bounds_in_parent.size(); - if (details.bounds_change & kBoundsChange_Resizes) { - gfx::Size min_size = details.window->delegate()->GetMinimumSize(); - size.SetSize(GetWidthForDrag(details, min_size.width(), delta_x), - GetHeightForDrag(details, min_size.height(), delta_y)); - } else if (!details.restore_bounds.IsEmpty()) { - size = details.restore_bounds.size(); +gfx::Size WindowResizer::GetSizeForDrag(int* delta_x, int* delta_y) { + gfx::Size size = details().initial_bounds_in_parent.size(); + if (details().bounds_change & kBoundsChange_Resizes) { + gfx::Size min_size = GetTarget()->delegate()->GetMinimumSize(); + size.SetSize(GetWidthForDrag(min_size.width(), delta_x), + GetHeightForDrag(min_size.height(), delta_y)); + } else if (!details().restore_bounds.IsEmpty()) { + size = details().restore_bounds.size(); } return size; } -// static -int WindowResizer::GetWidthForDrag(const Details& details, - int min_width, - int* delta_x) { - int width = details.initial_bounds_in_parent.width(); - if (details.size_change_direction & kBoundsChangeDirection_Horizontal) { +int WindowResizer::GetWidthForDrag(int min_width, int* delta_x) { + int width = details().initial_bounds_in_parent.width(); + if (details().size_change_direction & kBoundsChangeDirection_Horizontal) { // Along the right edge, positive delta_x increases the window size. - int x_multiplier = IsRightEdge(details.window_component) ? 1 : -1; + int x_multiplier = IsRightEdge(details().window_component) ? 1 : -1; width += x_multiplier * (*delta_x); // Ensure we don't shrink past the minimum width and clamp delta_x // for the window origin computation. if (width < min_width) { width = min_width; - *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - + *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - min_width); } // And don't let the window go bigger than the display. int max_width = Shell::GetScreen()->GetDisplayNearestWindow( - details.window).bounds().width(); - gfx::Size max_size = details.window->delegate()->GetMaximumSize(); + GetTarget()).bounds().width(); + gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize(); if (max_size.width() != 0) max_width = std::min(max_width, max_size.width()); if (width > max_width) { width = max_width; - *delta_x = -x_multiplier * (details.initial_bounds_in_parent.width() - + *delta_x = -x_multiplier * (details().initial_bounds_in_parent.width() - max_width); } } return width; } -// static -int WindowResizer::GetHeightForDrag(const Details& details, - int min_height, - int* delta_y) { - int height = details.initial_bounds_in_parent.height(); - if (details.size_change_direction & kBoundsChangeDirection_Vertical) { +int WindowResizer::GetHeightForDrag(int min_height, int* delta_y) { + int height = details().initial_bounds_in_parent.height(); + if (details().size_change_direction & kBoundsChangeDirection_Vertical) { // Along the bottom edge, positive delta_y increases the window size. - int y_multiplier = IsBottomEdge(details.window_component) ? 1 : -1; + int y_multiplier = IsBottomEdge(details().window_component) ? 1 : -1; height += y_multiplier * (*delta_y); // Ensure we don't shrink past the minimum height and clamp delta_y // for the window origin computation. if (height < min_height) { height = min_height; - *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - + *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - min_height); } // And don't let the window go bigger than the display. int max_height = Shell::GetScreen()->GetDisplayNearestWindow( - details.window).bounds().height(); - gfx::Size max_size = details.window->delegate()->GetMaximumSize(); + GetTarget()).bounds().height(); + gfx::Size max_size = GetTarget()->delegate()->GetMaximumSize(); if (max_size.height() != 0) max_height = std::min(max_height, max_size.height()); if (height > max_height) { height = max_height; - *delta_y = -y_multiplier * (details.initial_bounds_in_parent.height() - + *delta_y = -y_multiplier * (details().initial_bounds_in_parent.height() - max_height); } } return height; } -} // namespace aura +} // namespace ash |