Commit dc6d8e92 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

overview gesture: start drag window only when hotseat has dragged up.

Bug: 997885
Change-Id: I8d4c918b51ff5a2bad566471ca9edb34e680a890
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900279Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713111}
parent f6c57191
...@@ -2164,7 +2164,6 @@ bool ShelfLayoutManager::StartShelfDrag( ...@@ -2164,7 +2164,6 @@ bool ShelfLayoutManager::StartShelfDrag(
: SHELF_AUTO_HIDE_SHOWN; : SHELF_AUTO_HIDE_SHOWN;
MaybeSetupHotseatDrag(event_in_screen); MaybeSetupHotseatDrag(event_in_screen);
MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE);
MaybeStartDragWindowFromShelf(event_in_screen);
// For the hotseat, |drag_amount_| is relative to the top of the shelf. // For the hotseat, |drag_amount_| is relative to the top of the shelf.
// To keep the hotseat from jumping to the top of the shelf on drag, set the // To keep the hotseat from jumping to the top of the shelf on drag, set the
...@@ -2176,6 +2175,9 @@ bool ShelfLayoutManager::StartShelfDrag( ...@@ -2176,6 +2175,9 @@ bool ShelfLayoutManager::StartShelfDrag(
} else { } else {
drag_amount_ = 0.f; drag_amount_ = 0.f;
} }
MaybeStartDragWindowFromShelf(event_in_screen);
return true; return true;
} }
...@@ -2412,43 +2414,61 @@ void ShelfLayoutManager::SendA11yAlertForFullscreenWorkspaceState( ...@@ -2412,43 +2414,61 @@ void ShelfLayoutManager::SendA11yAlertForFullscreenWorkspaceState(
previous_workspace_window_state_ = current_workspace_window_state; previous_workspace_window_state_ = current_workspace_window_state;
} }
void ShelfLayoutManager::MaybeStartDragWindowFromShelf( bool ShelfLayoutManager::MaybeStartDragWindowFromShelf(
const ui::LocatedEvent& event_in_screen) { const ui::LocatedEvent& event_in_screen) {
if (!features::IsDragFromShelfToHomeOrOverviewEnabled()) if (!features::IsDragFromShelfToHomeOrOverviewEnabled())
return; return false;
if (!IsTabletModeEnabled()) if (!IsTabletModeEnabled())
return; return false;
if (drag_status_ != kDragInProgress) if (drag_status_ != kDragInProgress)
return; return false;
// Do not drag on a auto-hide hidden shelf or a hidden shelf. // Do not drag on a auto-hide hidden shelf or a hidden shelf.
if ((visibility_state() == SHELF_AUTO_HIDE && if ((visibility_state() == SHELF_AUTO_HIDE &&
auto_hide_state() == SHELF_AUTO_HIDE_HIDDEN) || auto_hide_state() == SHELF_AUTO_HIDE_HIDDEN) ||
visibility_state() == SHELF_HIDDEN) { visibility_state() == SHELF_HIDDEN) {
return; return false;
} }
// If the start location is above the shelf (e.g., on the extended hotseat), // Do not drag on kShown hotseat (it should be in home screen).
// do not allow the drag. if (hotseat_state() == HotseatState::kShown)
const gfx::Rect shelf_bounds = GetVisibleShelfBounds(); return false;
if (event_in_screen.location().y() < shelf_bounds.y())
return; // If hotseat is hidden when drag starts, do not start drag window if hotseat
// hasn't been fully dragged up.
if (hotseat_state() == HotseatState::kHidden) {
ShelfConfig* shelf_config = ShelfConfig::Get();
const int full_drag_amount =
-(shelf_config->shelf_size() + shelf_config->hotseat_bottom_padding() +
shelf_config->hotseat_size());
if (drag_amount_ > full_drag_amount)
return false;
} else if (hotseat_state() == HotseatState::kExtended) {
// 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_in_screen.location().y() < shelf_bounds.y())
return false;
}
aura::Window* window = aura::Window* window =
GetWindowForDragToHomeOrOverview(event_in_screen.location()); GetWindowForDragToHomeOrOverview(event_in_screen.location());
if (!window) if (!window)
return; return false;
window_drag_controller_ = window_drag_controller_ =
std::make_unique<DragWindowFromShelfController>(window); std::make_unique<DragWindowFromShelfController>(window);
return true;
} }
void ShelfLayoutManager::MaybeUpdateWindowDrag( void ShelfLayoutManager::MaybeUpdateWindowDrag(
const ui::LocatedEvent& event_in_screen, const ui::LocatedEvent& event_in_screen,
float scroll_x, float scroll_x,
float scroll_y) { float scroll_y) {
if (!window_drag_controller_) if (!window_drag_controller_ &&
!MaybeStartDragWindowFromShelf(event_in_screen)) {
return; return;
}
DCHECK_EQ(drag_status_, kDragInProgress); DCHECK_EQ(drag_status_, kDragInProgress);
window_drag_controller_->Drag(event_in_screen.location(), scroll_x, scroll_y); window_drag_controller_->Drag(event_in_screen.location(), scroll_x, scroll_y);
......
...@@ -508,7 +508,7 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver, ...@@ -508,7 +508,7 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
WorkspaceWindowState current_workspace_window_state); WorkspaceWindowState current_workspace_window_state);
// Maybe start/update/end the window drag when swiping up from the shelf. // Maybe start/update/end the window drag when swiping up from the shelf.
void MaybeStartDragWindowFromShelf(const ui::LocatedEvent& event_in_screen); bool MaybeStartDragWindowFromShelf(const ui::LocatedEvent& event_in_screen);
void MaybeUpdateWindowDrag(const ui::LocatedEvent& event_in_screen, void MaybeUpdateWindowDrag(const ui::LocatedEvent& event_in_screen,
float scroll_x, float scroll_x,
float scroll_y); float scroll_y);
......
...@@ -4046,14 +4046,16 @@ class ShelfLayoutManagerWindowDraggingTest : public ShelfLayoutManagerTestBase { ...@@ -4046,14 +4046,16 @@ class ShelfLayoutManagerWindowDraggingTest : public ShelfLayoutManagerTestBase {
TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) { TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) {
const gfx::Rect shelf_widget_bounds = const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen(); GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = ShelfConfig::Get()->hotseat_size(); const int hotseat_size = ShelfConfig::Get()->hotseat_size();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
// Starts the drag from the center of the shelf's bottom. // Starts the drag from the center of the shelf's bottom.
gfx::Point start = shelf_widget_bounds.bottom_center(); gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start); StartScroll(start);
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
// We need at least one window to work with. // We need at least one window to work with.
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
UpdateScroll(-shelf_widget_bounds.height() - hotseat_size);
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
std::unique_ptr<aura::Window> window = std::unique_ptr<aura::Window> window =
...@@ -4061,6 +4063,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) { ...@@ -4061,6 +4063,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) {
wm::ActivateWindow(window.get()); wm::ActivateWindow(window.get());
StartScroll(start); StartScroll(start);
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
DragWindowFromShelfController* window_drag_controller = DragWindowFromShelfController* window_drag_controller =
GetShelfLayoutManager()->window_drag_controller_for_testing(); GetShelfLayoutManager()->window_drag_controller_for_testing();
EXPECT_TRUE(window_drag_controller); EXPECT_TRUE(window_drag_controller);
...@@ -4072,8 +4075,8 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) { ...@@ -4072,8 +4075,8 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) {
// The window needs to be visible to drag up. // The window needs to be visible to drag up.
window->Hide(); window->Hide();
StartScroll(start); StartScroll(start);
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
UpdateScroll(-shelf_widget_bounds.height() - hotseat_size);
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
// In splitview, depends on the drag position, the active dragged window might // In splitview, depends on the drag position, the active dragged window might
...@@ -4085,6 +4088,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) { ...@@ -4085,6 +4088,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) {
split_view_controller->SnapWindow(window.get(), SplitViewController::LEFT); split_view_controller->SnapWindow(window.get(), SplitViewController::LEFT);
split_view_controller->SnapWindow(window2.get(), SplitViewController::RIGHT); split_view_controller->SnapWindow(window2.get(), SplitViewController::RIGHT);
StartScroll(shelf_widget_bounds.bottom_left()); StartScroll(shelf_widget_bounds.bottom_left());
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
window_drag_controller = window_drag_controller =
GetShelfLayoutManager()->window_drag_controller_for_testing(); GetShelfLayoutManager()->window_drag_controller_for_testing();
EXPECT_TRUE(window_drag_controller); EXPECT_TRUE(window_drag_controller);
...@@ -4093,6 +4097,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) { ...@@ -4093,6 +4097,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) {
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
StartScroll(shelf_widget_bounds.bottom_right()); StartScroll(shelf_widget_bounds.bottom_right());
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
window_drag_controller = window_drag_controller =
GetShelfLayoutManager()->window_drag_controller_for_testing(); GetShelfLayoutManager()->window_drag_controller_for_testing();
EXPECT_TRUE(window_drag_controller); EXPECT_TRUE(window_drag_controller);
...@@ -4106,6 +4111,9 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) { ...@@ -4106,6 +4111,9 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) {
TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpInOverview) { TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpInOverview) {
const gfx::Rect shelf_widget_bounds = const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen(); GetShelfWidget()->GetWindowBoundsInScreen();
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();
std::unique_ptr<aura::Window> window1 = std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400)); AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
std::unique_ptr<aura::Window> window2 = std::unique_ptr<aura::Window> window2 =
...@@ -4117,6 +4125,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpInOverview) { ...@@ -4117,6 +4125,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpInOverview) {
overview_controller->StartOverview(); overview_controller->StartOverview();
gfx::Point start = shelf_widget_bounds.bottom_center(); gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start); StartScroll(start);
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
...@@ -4130,6 +4139,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpInOverview) { ...@@ -4130,6 +4139,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpInOverview) {
EXPECT_TRUE(split_view_controller->InSplitViewMode()); EXPECT_TRUE(split_view_controller->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession()); EXPECT_TRUE(overview_controller->InOverviewSession());
StartScroll(shelf_widget_bounds.bottom_right()); StartScroll(shelf_widget_bounds.bottom_right());
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
} }
...@@ -4141,11 +4151,16 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) { ...@@ -4141,11 +4151,16 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) {
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400)); AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get()); wm::ActivateWindow(window.get());
Shelf* shelf = GetPrimaryShelf(); Shelf* shelf = GetPrimaryShelf();
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();
// The window can be dragged on a visible shelf. // The window can be dragged on a visible shelf.
const gfx::Rect shelf_widget_bounds = const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen(); GetShelfWidget()->GetWindowBoundsInScreen();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
StartScroll(shelf_widget_bounds.bottom_center()); StartScroll(shelf_widget_bounds.bottom_center());
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
EXPECT_TRUE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_TRUE(GetShelfLayoutManager()->window_drag_controller_for_testing());
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
...@@ -4159,6 +4174,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) { ...@@ -4159,6 +4174,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) {
gfx::Rect display_bounds = gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
StartScroll(display_bounds.bottom_center()); StartScroll(display_bounds.bottom_center());
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
...@@ -4166,6 +4182,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) { ...@@ -4166,6 +4182,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) {
SwipeUpOnShelf(); SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
StartScroll(display_bounds.bottom_center()); StartScroll(display_bounds.bottom_center());
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
EXPECT_TRUE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_TRUE(GetShelfLayoutManager()->window_drag_controller_for_testing());
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
...@@ -4173,6 +4190,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) { ...@@ -4173,6 +4190,7 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpForHiddenShelf) {
SetState(GetShelfLayoutManager(), SHELF_HIDDEN); SetState(GetShelfLayoutManager(), SHELF_HIDDEN);
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
StartScroll(display_bounds.bottom_center()); StartScroll(display_bounds.bottom_center());
UpdateScroll(-shelf_size - hotseat_size - hotseat_padding_size);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing()); EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
} }
...@@ -4195,6 +4213,33 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpIfDragStartsAboveShelf) { ...@@ -4195,6 +4213,33 @@ TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpIfDragStartsAboveShelf) {
EndScroll(/*is_fling=*/false, 0.f); EndScroll(/*is_fling=*/false, 0.f);
} }
// Tests that the MRU window can only be dragged window after the hotseat is
// fully dragged up if hotseat was hidden before.
TEST_F(ShelfLayoutManagerWindowDraggingTest, StartsDragAfterHotseatIsUp) {
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();
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();
// Starts the drag from the center of the shelf's bottom.
gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
// Continues the drag until the hotseat should have been fully dragged up.
UpdateScroll(-shelf_size);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
UpdateScroll(-hotseat_padding_size);
EXPECT_FALSE(GetShelfLayoutManager()->window_drag_controller_for_testing());
UpdateScroll(-hotseat_size);
EXPECT_TRUE(GetShelfLayoutManager()->window_drag_controller_for_testing());
EndScroll(/*is_fling=*/false, 0.f);
}
class ShelfLayoutManagerKeyboardTest : public AshTestBase { class ShelfLayoutManagerKeyboardTest : public AshTestBase {
public: public:
ShelfLayoutManagerKeyboardTest() = default; ShelfLayoutManagerKeyboardTest() = default;
......
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