summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorwnwen <wnwen@chromium.org>2014-08-27 14:29:02 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-27 21:30:17 +0000
commit56e39c64d4538396ce669727ae1dd0c462478f74 (patch)
treec6dff0825290bc8fca9dadf5d7bace2f5b37aa89 /ash
parent2eb7fbb502958e0a5d34e1a0c43f998419117217 (diff)
downloadchromium_src-56e39c64d4538396ce669727ae1dd0c462478f74.zip
chromium_src-56e39c64d4538396ce669727ae1dd0c462478f74.tar.gz
chromium_src-56e39c64d4538396ce669727ae1dd0c462478f74.tar.bz2
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}
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/workspace/workspace_layout_manager.cc5
-rw-r--r--ash/wm/workspace/workspace_window_resizer.cc40
-rw-r--r--ash/wm/workspace/workspace_window_resizer_unittest.cc16
3 files changed, 44 insertions, 17 deletions
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc
index ceffce9..63c4aed 100644
--- a/ash/wm/workspace/workspace_layout_manager.cc
+++ b/ash/wm/workspace/workspace_layout_manager.cc
@@ -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();
}
}
diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc
index 395c2ad..7611071 100644
--- a/ash/wm/workspace/workspace_window_resizer.cc
+++ b/ash/wm/workspace/workspace_window_resizer.cc
@@ -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();
}
}
}
diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc
index 49af2b7..9b10e16 100644
--- a/ash/wm/workspace/workspace_window_resizer_unittest.cc
+++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc
@@ -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));