Commit a27403ed authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Simplify how shelf prevents window drag start on downward swipe

The current logic avoids calls to MaybeStartDragWindowFromShelf until
the first shelf drag update, so it can detect the scroll direction
before starting window drag, and then use the scroll value to detect the
initial scroll position. Simpler approach would be to pass the
scroll start gesture's scroll hint in StartGestureDrag.

Additionally, this cl further restricts when window drag can start with
extended hotseat. The window drag will only be allowed if the gesture
started on the shelf (e.g. gesture that starts on hotseat, goes down,
and then up again should not start window drag).

BUG=1043243

Change-Id: I9c70ab4670646e1be27970f37b0e7bcc3f2fc224
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008618Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733801}
parent fde4c690
...@@ -2148,7 +2148,10 @@ bool ShelfLayoutManager::StartGestureDrag( ...@@ -2148,7 +2148,10 @@ bool ShelfLayoutManager::StartGestureDrag(
if (Shell::Get()->app_list_controller()->IsVisible()) if (Shell::Get()->app_list_controller()->IsVisible())
return true; return true;
return StartShelfDrag(gesture_in_screen); return StartShelfDrag(
gesture_in_screen,
gfx::Vector2dF(gesture_in_screen.details().scroll_x_hint(),
scroll_y_hint));
} }
void ShelfLayoutManager::UpdateGestureDrag( void ShelfLayoutManager::UpdateGestureDrag(
...@@ -2183,7 +2186,10 @@ void ShelfLayoutManager::AttemptToDragByMouse( ...@@ -2183,7 +2186,10 @@ void ShelfLayoutManager::AttemptToDragByMouse(
void ShelfLayoutManager::StartMouseDrag(const ui::MouseEvent& mouse_in_screen) { void ShelfLayoutManager::StartMouseDrag(const ui::MouseEvent& mouse_in_screen) {
float scroll_y_hint = mouse_in_screen.y() - last_mouse_drag_position_.y(); float scroll_y_hint = mouse_in_screen.y() - last_mouse_drag_position_.y();
if (!StartAppListDrag(mouse_in_screen, scroll_y_hint)) if (!StartAppListDrag(mouse_in_screen, scroll_y_hint))
StartShelfDrag(mouse_in_screen); StartShelfDrag(
mouse_in_screen,
gfx::Vector2dF(mouse_in_screen.x() - last_mouse_drag_position_.x(),
scroll_y_hint));
} }
void ShelfLayoutManager::UpdateMouseDrag( void ShelfLayoutManager::UpdateMouseDrag(
...@@ -2304,8 +2310,8 @@ bool ShelfLayoutManager::StartAppListDrag( ...@@ -2304,8 +2310,8 @@ bool ShelfLayoutManager::StartAppListDrag(
return true; return true;
} }
bool ShelfLayoutManager::StartShelfDrag( bool ShelfLayoutManager::StartShelfDrag(const ui::LocatedEvent& event_in_screen,
const ui::LocatedEvent& event_in_screen) { const gfx::Vector2dF& scroll_hint) {
// Disable the shelf dragging if the fullscreen app list is opened. // Disable the shelf dragging if the fullscreen app list is opened.
if (Shell::Get()->app_list_controller()->IsVisible() && if (Shell::Get()->app_list_controller()->IsVisible() &&
!IsTabletModeEnabled()) !IsTabletModeEnabled())
...@@ -2343,6 +2349,13 @@ bool ShelfLayoutManager::StartShelfDrag( ...@@ -2343,6 +2349,13 @@ bool ShelfLayoutManager::StartShelfDrag(
drag_amount_ = 0.f; drag_amount_ = 0.f;
} }
// If the start location is above the shelf (e.g., on the extended hotseat),
// do not allow window drag when the hotseat is extended.
const gfx::Rect shelf_bounds = GetVisibleShelfBounds();
allow_window_drag_on_extended_hotseat_ =
event_in_screen.location_f().y() >= shelf_bounds.y();
MaybeStartDragWindowFromShelf(event_in_screen, scroll_hint);
return true; return true;
} }
...@@ -2653,8 +2666,6 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf( ...@@ -2653,8 +2666,6 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf(
if (hotseat_state() == HotseatState::kShown) if (hotseat_state() == HotseatState::kShown)
return false; return false;
gfx::PointF event_start_location = event_in_screen.location_f();
// If hotseat is hidden when drag starts, do not start drag window if hotseat // If hotseat is hidden when drag starts, do not start drag window if hotseat
// hasn't been fully dragged up. // hasn't been fully dragged up.
if (hotseat_state() == HotseatState::kHidden) { if (hotseat_state() == HotseatState::kHidden) {
...@@ -2665,16 +2676,9 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf( ...@@ -2665,16 +2676,9 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf(
if (drag_amount_ > full_drag_amount) if (drag_amount_ > full_drag_amount)
return false; return false;
} else if (hotseat_state() == HotseatState::kExtended) { } else if (hotseat_state() == HotseatState::kExtended) {
// Window drag will not start until it's determined that the gesture is if (!allow_window_drag_on_extended_hotseat_)
// going up. The effective starting position will thus be the previous event
// location.
event_start_location -= scroll;
// If the start location is above the shelf (e.g., on the extended hotseat),
// do not allow the drag.
const gfx::Rect shelf_bounds = GetVisibleShelfBounds();
if (event_start_location.y() < shelf_bounds.y())
return false; return false;
// Do not start drag if it's a downward update event. // Do not start drag if it's a downward update event.
if (scroll.y() >= 0) if (scroll.y() >= 0)
return false; return false;
...@@ -2693,15 +2697,7 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf( ...@@ -2693,15 +2697,7 @@ bool ShelfLayoutManager::MaybeStartDragWindowFromShelf(
return false; return false;
window_drag_controller_ = std::make_unique<DragWindowFromShelfController>( window_drag_controller_ = std::make_unique<DragWindowFromShelfController>(
window, event_start_location, hotseat_state()); window, event_in_screen.location_f(), hotseat_state());
// In extended state, the effective start location is the previous event, so
// send additional drag event, so the controller doesn't skip the current
// drag location.
if (hotseat_state() == HotseatState::kExtended) {
window_drag_controller_->Drag(event_in_screen.location_f(), scroll.x(),
scroll.y());
}
return true; return true;
} }
......
...@@ -502,7 +502,8 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -502,7 +502,8 @@ class ASH_EXPORT ShelfLayoutManager
bool IsDragAllowed() const; bool IsDragAllowed() const;
bool StartAppListDrag(const ui::LocatedEvent& event_in_screen, bool StartAppListDrag(const ui::LocatedEvent& event_in_screen,
float scroll_y_hint); float scroll_y_hint);
bool StartShelfDrag(const ui::LocatedEvent& event_in_screen); bool StartShelfDrag(const ui::LocatedEvent& event_in_screen,
const gfx::Vector2dF& scroll_hint);
// Sets the Hotseat up to be dragged, if applicable. // Sets the Hotseat up to be dragged, if applicable.
void MaybeSetupHotseatDrag(const ui::LocatedEvent& event_in_screen); void MaybeSetupHotseatDrag(const ui::LocatedEvent& event_in_screen);
void UpdateDrag(const ui::LocatedEvent& event_in_screen, void UpdateDrag(const ui::LocatedEvent& event_in_screen,
...@@ -692,6 +693,11 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -692,6 +693,11 @@ class ASH_EXPORT ShelfLayoutManager
// if the overview session is active. // if the overview session is active.
bool allow_fling_from_overview_to_home_ = false; bool allow_fling_from_overview_to_home_ = false;
// Indicates whether shelf drag gesture can start window drag from shelf to
// overview or home when hotseat is in extended state (the window drag will
// only be allowed if drag started within shelf bounds).
bool allow_window_drag_on_extended_hotseat_ = false;
// Tracks whether the shelf is currently dimmed for inactivity. // Tracks whether the shelf is currently dimmed for inactivity.
bool dimmed_for_inactivity_ = false; bool dimmed_for_inactivity_ = false;
......
...@@ -5454,6 +5454,46 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpIfDragStartsAboveShelf) { ...@@ -5454,6 +5454,46 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpIfDragStartsAboveShelf) {
EXPECT_FALSE(IsWindowDragInProgress()); EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity()); EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
}
// Test that gesture that starts within hotseat bounds, goes down to shelf, and
// start moving up does not start window drag (as upward swipe from hotseat does
// not start window drag either).
TEST_F(ShelfLayoutManagerWindowDraggingTest,
NoOpIfDragSTartsAboveShelfAndMovesToShelf) {
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
gfx::Rect hotseat_bounds =
GetShelfWidget()->hotseat_widget()->GetWindowBoundsInScreen();
StartScroll(hotseat_bounds.CenterPoint());
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
const gfx::Vector2d vector_from_hotseat_to_shelf_center =
hotseat_bounds.CenterPoint() -
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
UpdateScroll(vector_from_hotseat_to_shelf_center.y());
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(-vector_from_hotseat_to_shelf_center.y());
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
} }
// Tests that the MRU window can only be dragged window after the hotseat is // Tests that the MRU window can only be dragged window after the hotseat is
......
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