Skip to content

Commit

Permalink
cros: Prevent a window drag towards bottom of screen moving shelf
Browse files Browse the repository at this point in the history
This shouldn't move the shelf or hotseat.

Bug: 1025080
Change-Id: I70f48b99e96ca590890706edc84b623509bb561d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919629
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: Manu Cornet <manucornet@chromium.org>
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716423}
  • Loading branch information
Alex Newcomer authored and Commit Bot committed Nov 19, 2019
1 parent 6e2348f commit 3512959
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
16 changes: 13 additions & 3 deletions ash/shelf/shelf_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1748,8 +1748,13 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
if (move_shelf_with_hotseat) {
// Do not allow the shelf to be dragged more than |shelf_size| from the
// bottom of the display.
const int shelf_y = std::max(available_bounds.bottom() - shelf_size,
static_cast<int>(baseline + translate));
int shelf_y = std::max(available_bounds.bottom() - shelf_size,
static_cast<int>(baseline + translate));
// Window drags only happen after the hotseat has been dragged up to its
// full height. After the drag moves a window, do not allow the drag to
// move the hotseat down.
if (IsWindowDragInProgress())
shelf_y = available_bounds.bottom() - shelf_size;
target_bounds_.shelf_bounds.set_y(shelf_y);
}

Expand All @@ -1769,6 +1774,11 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
-hotseat_extended_y,
static_cast<int>((use_hotseat_baseline ? hotseat_baseline : 0) +
translate));
// Window drags only happen after the hotseat has been dragged up to its
// full height. After the drag moves a window, do not allow the drag to move
// the hotseat down.
if (IsWindowDragInProgress())
hotseat_y = -hotseat_extended_y;
target_bounds_.hotseat_bounds_in_shelf.set_y(hotseat_y);
return;
}
Expand Down Expand Up @@ -2630,7 +2640,7 @@ void ShelfLayoutManager::MaybeCancelWindowDrag() {
window_drag_controller_->CancelDrag();
}

bool ShelfLayoutManager::IsWindowDragInProgress() {
bool ShelfLayoutManager::IsWindowDragInProgress() const {
return window_drag_controller_ && window_drag_controller_->drag_started();
}

Expand Down
2 changes: 1 addition & 1 deletion ash/shelf/shelf_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
base::Optional<DragWindowFromShelfController::ShelfWindowDragResult>
MaybeEndWindowDrag(const ui::LocatedEvent& event_in_screen);
void MaybeCancelWindowDrag();
bool IsWindowDragInProgress();
bool IsWindowDragInProgress() const;

// True when inside UpdateBoundsAndOpacity() method. Used to prevent calling
// UpdateBoundsAndOpacity() again from SetChildBounds().
Expand Down
58 changes: 58 additions & 0 deletions ash/shelf/shelf_layout_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4872,6 +4872,64 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DISABLED_NoOpForHiddenShelf) {
EndScroll(/*is_fling=*/false, 0.f);
}

// Tests that dragging below the hotseat after dragging the MRU up results in
// the hotseat not moving from its extended position.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
DragBelowHotseatDoesNotMoveHotseat) {
// Go to in-app shelf, then drag the hotseat up until it is extended, this
// will start a window drag.
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start);
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = ShelfConfig::Get()->hotseat_size();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
const int hotseat_y =
GetShelfWidget()->hotseat_widget()->GetWindowBoundsInScreen().y();

// Drag down, the hotseat should not move because it was extended when the
// window drag began.
UpdateScroll(10);

EXPECT_EQ(hotseat_y,
GetShelfWidget()->hotseat_widget()->GetWindowBoundsInScreen().y());
EndScroll(/*is_fling=*/false, 0.f);
}

// Tests that dragging below the hotseat after dragging the MRU up results in
// the hotseat not moving from its extended position with an autohidden shelf.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
DragBelowHotseatDoesNotMoveHotseatAutoHiddenShelf) {
// Extend the hotseat, then start dragging the window.
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
SwipeUpOnShelf();
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start);
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = ShelfConfig::Get()->hotseat_size();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
const int hotseat_y =
GetShelfWidget()->hotseat_widget()->GetWindowBoundsInScreen().y();

// Drag down, the hotseat should not move because it was extended when the
// window drag began.
UpdateScroll(10);

EXPECT_EQ(hotseat_y,
GetShelfWidget()->hotseat_widget()->GetWindowBoundsInScreen().y());
EndScroll(/*is_fling=*/false, 0.f);
}

TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpIfDragStartsAboveShelf) {
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
Expand Down

0 comments on commit 3512959

Please sign in to comment.