Commit 56e39c64 authored by wnwen's avatar wnwen Committed by Commit bot

Clear restore bounds for user resize/drag actions.

When the window is not snapped, user resizes should always clear restore
bounds. This allows user initiated resizes to not be unexpectedly
ignored.

BUG=405563
TEST=WorkspaceWindowResizerTest.RestoreClearedOnResize

Review URL: https://codereview.chromium.org/477823003

Cr-Commit-Position: refs/heads/master@{#292228}
parent 2eb7fbb5
......@@ -162,7 +162,10 @@ void WorkspaceLayoutManager::OnKeyboardBoundsChanging(
SetChildBounds(window, gfx::Rect(origin, window_bounds.size()));
}
} else if (window_state->HasRestoreBounds()) {
// Keyboard hidden, restore original bounds if they exist.
// Keyboard hidden, restore original bounds if they exist. If the user has
// resized or dragged the window in the meantime, WorkspaceWindowResizer
// will have cleared the restore bounds and this code will not accidentally
// override user intent.
window_state->SetAndClearRestoreBounds();
}
}
......
......@@ -443,23 +443,31 @@ void WorkspaceWindowResizer::CompleteDrag() {
}
}
if (!snapped && window_state()->IsSnapped()) {
// Keep the window snapped if the user resizes the window such that the
// window has valid bounds for a snapped window. Always unsnap the window
// if the user dragged the window via the caption area because doing this is
// slightly less confusing.
if (details().window_component == HTCAPTION ||
!AreBoundsValidSnappedBounds(window_state()->GetStateType(),
GetTarget()->bounds())) {
// Set the window to WINDOW_STATE_TYPE_NORMAL but keep the
// window at the bounds that the user has moved/resized the
// window to. ClearRestoreBounds() is used instead of
// SaveCurrentBoundsForRestore() because most of the restore
// logic is skipped because we are still in the middle of a
// drag. TODO(pkotwicz): Fix this and use
// SaveCurrentBoundsForRestore().
if (!snapped) {
if (window_state()->IsSnapped()) {
// Keep the window snapped if the user resizes the window such that the
// window has valid bounds for a snapped window. Always unsnap the window
// if the user dragged the window via the caption area because doing this
// is slightly less confusing.
if (details().window_component == HTCAPTION ||
!AreBoundsValidSnappedBounds(window_state()->GetStateType(),
GetTarget()->bounds())) {
// Set the window to WINDOW_STATE_TYPE_NORMAL but keep the
// window at the bounds that the user has moved/resized the
// window to. ClearRestoreBounds() is used instead of
// SaveCurrentBoundsForRestore() because most of the restore
// logic is skipped because we are still in the middle of a
// drag. TODO(pkotwicz): Fix this and use
// SaveCurrentBoundsForRestore().
window_state()->ClearRestoreBounds();
window_state()->Restore();
}
} else if (!dock_layout_->is_dragged_window_docked()) {
// The window was not snapped and is not snapped. This is a user
// resize/drag and so the current bounds should be maintained, clearing
// any prior restore bounds. When the window is docked the restore bound
// must be kept so the docked state can be reverted properly.
window_state()->ClearRestoreBounds();
window_state()->Restore();
}
}
}
......
......@@ -1181,6 +1181,22 @@ TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
}
// Verifies that a dragged, non-snapped window will clear restore bounds.
TEST_F(WorkspaceWindowResizerTest, RestoreClearedOnResize) {
window_->SetBounds(gfx::Rect(10, 10, 100, 100));
wm::WindowState* window_state = wm::GetWindowState(window_.get());
window_state->SetRestoreBoundsInScreen(gfx::Rect(50, 50, 50, 50));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMRIGHT));
ASSERT_TRUE(resizer.get());
// Drag the window to new position by adding (20, 30) to original point,
// the original restore bound should be cleared.
resizer->Drag(CalculateDragPoint(*resizer, 20, 30), 0);
resizer->CompleteDrag();
EXPECT_EQ("10,10 120x130", window_->bounds().ToString());
EXPECT_FALSE(window_state->HasRestoreBounds());
}
// Verifies that a dragged window will restore to its pre-maximized size.
TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) {
window_->SetBounds(gfx::Rect(0, 0, 1000, 1000));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment