Commit 7b50ccd7 authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Virtual Desks and Overview swipes finger count changes

- Tab scrubbing: change to use 4-finger gestures.
- Desk switch: change to use 3-finger  gestures.
- Overview selection: change to use 4-finger gestures.

BUG=995911
TEST=Manually, modify existing tests.

Change-Id: I867f3c0033647cc15998e6ef3bce02ac43c2ae7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764832Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689540}
parent d49abde0
...@@ -14,6 +14,49 @@ ...@@ -14,6 +14,49 @@
namespace ash { namespace ash {
namespace {
// Handles vertical 3-finger scroll gesture by entering overview on scrolling
// up, and exiting it on scrolling down.
// Returns true if the gesture was handled.
bool Handle3FingerVerticalScroll(float scroll_y) {
auto* overview_controller = Shell::Get()->overview_controller();
const bool in_overview = overview_controller->InOverviewSession();
if (in_overview) {
if (scroll_y < WmGestureHandler::kVerticalThresholdDp)
return false;
base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview"));
if (overview_controller->AcceptSelection())
return true;
overview_controller->EndOverview();
} else {
if (scroll_y > -WmGestureHandler::kVerticalThresholdDp)
return false;
base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview"));
overview_controller->StartOverview();
}
return true;
}
// Handles horizontal 3-finger scroll by switching desks if possible.
// Returns true if the gesture was handled.
bool Handle3FingerHorizontalScroll(float scroll_x) {
if (std::fabs(scroll_x) < WmGestureHandler::kHorizontalThresholdDp)
return false;
// This does not invert if the user changes their touchpad settings
// currently. The scroll works Australian way (scroll left to go to the
// desk on the right and vice versa).
DesksController::Get()->ActivateAdjacentDesk(
/*going_left=*/scroll_x > 0, DesksSwitchSource::kDeskSwitchTouchpad);
return true;
}
} // namespace
WmGestureHandler::WmGestureHandler() = default; WmGestureHandler::WmGestureHandler() = default;
WmGestureHandler::~WmGestureHandler() = default; WmGestureHandler::~WmGestureHandler() = default;
...@@ -70,56 +113,22 @@ bool WmGestureHandler::EndScroll() { ...@@ -70,56 +113,22 @@ bool WmGestureHandler::EndScroll() {
if (finger_count == 0) if (finger_count == 0)
return false; return false;
// Horizontal 4-finger scroll switches desks if possible. if (finger_count == 3) {
if (finger_count == 4) {
if (std::fabs(scroll_x) < std::fabs(scroll_y)) if (std::fabs(scroll_x) < std::fabs(scroll_y))
return false; return Handle3FingerVerticalScroll(scroll_y);
if (std::fabs(scroll_x) < kHorizontalThresholdDp)
return false;
// This does not invert if the user changes their touchpad settings return Handle3FingerHorizontalScroll(scroll_x);
// currently. The scroll works Australian way (scroll left to go to the
// desk on the right and vice versa).
DesksController::Get()->ActivateAdjacentDesk(
/*going_left=*/scroll_x > 0, DesksSwitchSource::kDeskSwitchTouchpad);
return true;
} }
DCHECK_EQ(3, finger_count); DCHECK_EQ(4, finger_count);
// Horizontal 3-finger scroll moves selection when already in overview mode. // Horizontal 4-finger scroll moves selection when already in overview mode.
if (MoveOverviewSelection(finger_count, scroll_x, scroll_y)) return MoveOverviewSelection(finger_count, scroll_x, scroll_y);
return true;
if (std::fabs(scroll_x) >= std::fabs(scroll_y))
return false;
auto* overview_controller = Shell::Get()->overview_controller();
const bool in_overview = overview_controller->InOverviewSession();
// Use vertical 3-finger scroll gesture up to enter overview, down to exit.
if (in_overview) {
if (scroll_y < 0 || scroll_y < kVerticalThresholdDp)
return false;
base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview"));
if (overview_controller->AcceptSelection())
return true;
overview_controller->EndOverview();
} else {
if (scroll_y > 0 || scroll_y > -kVerticalThresholdDp)
return false;
base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview"));
overview_controller->StartOverview();
}
return true;
} }
bool WmGestureHandler::MoveOverviewSelection(int finger_count, bool WmGestureHandler::MoveOverviewSelection(int finger_count,
float scroll_x, float scroll_x,
float scroll_y) { float scroll_y) {
if (finger_count != 3) if (finger_count != 4)
return false; return false;
auto* overview_controller = Shell::Get()->overview_controller(); auto* overview_controller = Shell::Get()->overview_controller();
......
...@@ -68,7 +68,7 @@ TEST_F(WmGestureHandlerTest, VerticalScrolls) { ...@@ -68,7 +68,7 @@ TEST_F(WmGestureHandlerTest, VerticalScrolls) {
EXPECT_FALSE(InOverviewSession()); EXPECT_FALSE(InOverviewSession());
} }
// Tests three finger horizontal scroll gesture to move selection left or right. // Tests four finger horizontal scroll gesture to move selection left or right.
TEST_F(WmGestureHandlerTest, HorizontalScrollInOverview) { TEST_F(WmGestureHandlerTest, HorizontalScrollInOverview) {
const gfx::Rect bounds(0, 0, 400, 400); const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1 = CreateTestWindow(bounds); std::unique_ptr<aura::Window> window1 = CreateTestWindow(bounds);
...@@ -88,7 +88,7 @@ TEST_F(WmGestureHandlerTest, HorizontalScrollInOverview) { ...@@ -88,7 +88,7 @@ TEST_F(WmGestureHandlerTest, HorizontalScrollInOverview) {
auto scroll_until_window_highlighted = [this](float x_offset, auto scroll_until_window_highlighted = [this](float x_offset,
float y_offset) { float y_offset) {
do { do {
Scroll(x_offset, y_offset, /*num_fingers=*/3); Scroll(x_offset, y_offset, /*num_fingers=*/4);
} while (!GetHighlightedWindow()); } while (!GetHighlightedWindow());
}; };
...@@ -99,15 +99,16 @@ TEST_F(WmGestureHandlerTest, HorizontalScrollInOverview) { ...@@ -99,15 +99,16 @@ TEST_F(WmGestureHandlerTest, HorizontalScrollInOverview) {
scroll_until_window_highlighted(horizontal_scroll * 3, 0); scroll_until_window_highlighted(horizontal_scroll * 3, 0);
EXPECT_TRUE(InOverviewSession()); EXPECT_TRUE(InOverviewSession());
// Short scroll left (3 fingers) moves selection to the third window. // Short scroll left (4 fingers) moves selection to the third window.
scroll_until_window_highlighted(-horizontal_scroll, 0); scroll_until_window_highlighted(-horizontal_scroll, 0);
EXPECT_TRUE(InOverviewSession()); EXPECT_TRUE(InOverviewSession());
// Short scroll left (3 fingers) moves selection to the second window. // Short scroll left (4 fingers) moves selection to the second window.
scroll_until_window_highlighted(-horizontal_scroll, 0); scroll_until_window_highlighted(-horizontal_scroll, 0);
EXPECT_TRUE(InOverviewSession()); EXPECT_TRUE(InOverviewSession());
// Swiping down exits and selects the currently-highlighted window. // Swiping down (3 fingers) exits and selects the currently-highlighted
// window.
Scroll(0, vertical_scroll, 3); Scroll(0, vertical_scroll, 3);
EXPECT_FALSE(InOverviewSession()); EXPECT_FALSE(InOverviewSession());
...@@ -166,7 +167,7 @@ class DesksGestureHandlerTest : public WmGestureHandlerTest { ...@@ -166,7 +167,7 @@ class DesksGestureHandlerTest : public WmGestureHandlerTest {
DeskSwitchAnimationWaiter waiter; DeskSwitchAnimationWaiter waiter;
const float x_offset = const float x_offset =
(scroll_left ? -1 : 1) * WmGestureHandler::kHorizontalThresholdDp; (scroll_left ? -1 : 1) * WmGestureHandler::kHorizontalThresholdDp;
Scroll(x_offset, 0, 4); Scroll(x_offset, 0, 3);
waiter.Wait(); waiter.Wait();
} }
...@@ -176,7 +177,7 @@ class DesksGestureHandlerTest : public WmGestureHandlerTest { ...@@ -176,7 +177,7 @@ class DesksGestureHandlerTest : public WmGestureHandlerTest {
DISALLOW_COPY_AND_ASSIGN(DesksGestureHandlerTest); DISALLOW_COPY_AND_ASSIGN(DesksGestureHandlerTest);
}; };
// Tests that a four-finger scroll will switch desks as expected. // Tests that a three-finger horizontal scroll will switch desks as expected.
TEST_F(DesksGestureHandlerTest, HorizontalScrolls) { TEST_F(DesksGestureHandlerTest, HorizontalScrolls) {
auto* desk_controller = DesksController::Get(); auto* desk_controller = DesksController::Get();
desk_controller->NewDesk(DesksCreationRemovalSource::kButton); desk_controller->NewDesk(DesksCreationRemovalSource::kButton);
...@@ -194,7 +195,7 @@ TEST_F(DesksGestureHandlerTest, HorizontalScrolls) { ...@@ -194,7 +195,7 @@ TEST_F(DesksGestureHandlerTest, HorizontalScrolls) {
// Tests that since there is no previous desk, we remain on the same desk when // Tests that since there is no previous desk, we remain on the same desk when
// scrolling right. // scrolling right.
const float long_scroll = WmGestureHandler::kHorizontalThresholdDp; const float long_scroll = WmGestureHandler::kHorizontalThresholdDp;
Scroll(long_scroll, 0.f, 4); Scroll(long_scroll, 0.f, 3);
EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk()); EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk());
} }
...@@ -209,16 +210,16 @@ TEST_F(DesksGestureHandlerTest, NoDeskChanges) { ...@@ -209,16 +210,16 @@ TEST_F(DesksGestureHandlerTest, NoDeskChanges) {
const float short_scroll = WmGestureHandler::kHorizontalThresholdDp - 10.f; const float short_scroll = WmGestureHandler::kHorizontalThresholdDp - 10.f;
const float long_scroll = WmGestureHandler::kHorizontalThresholdDp; const float long_scroll = WmGestureHandler::kHorizontalThresholdDp;
// Tests that a short horizontal scroll does not switch desks. // Tests that a short horizontal scroll does not switch desks.
Scroll(short_scroll, 0.f, 4); Scroll(short_scroll, 0.f, 3);
EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk()); EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk());
// Tests that a scroll that meets the horizontal requirements, but is mostly // Tests that a scroll that meets the horizontal requirements, but is mostly
// vertical does not switch desks. // vertical does not switch desks.
Scroll(long_scroll, long_scroll + 10.f, 4); Scroll(long_scroll, long_scroll + 10.f, 3);
EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk()); EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk());
// Tests that a vertical scroll does not switch desks. // Tests that a vertical scroll does not switch desks.
Scroll(0.f, WmGestureHandler::kVerticalThresholdDp, 4); Scroll(0.f, WmGestureHandler::kVerticalThresholdDp, 3);
EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk()); EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk());
} }
...@@ -233,7 +234,7 @@ TEST_F(DesksGestureHandlerTest, NoDoubleDeskChange) { ...@@ -233,7 +234,7 @@ TEST_F(DesksGestureHandlerTest, NoDoubleDeskChange) {
const float long_scroll = WmGestureHandler::kHorizontalThresholdDp * 3; const float long_scroll = WmGestureHandler::kHorizontalThresholdDp * 3;
DeskSwitchAnimationWaiter waiter; DeskSwitchAnimationWaiter waiter;
Scroll(-long_scroll, 0, 4); Scroll(-long_scroll, 0, 3);
waiter.Wait(); waiter.Wait();
EXPECT_EQ(desk_controller->desks()[1].get(), desk_controller->active_desk()); EXPECT_EQ(desk_controller->desks()[1].get(), desk_controller->active_desk());
} }
......
...@@ -94,7 +94,7 @@ void TabScrubber::OnScrollEvent(ui::ScrollEvent* event) { ...@@ -94,7 +94,7 @@ void TabScrubber::OnScrollEvent(ui::ScrollEvent* event) {
return; return;
} }
if (event->finger_count() != 3) if (event->finger_count() != 4)
return; return;
Browser* browser = GetActiveBrowser(); Browser* browser = GetActiveBrowser();
......
...@@ -23,7 +23,7 @@ namespace gfx { ...@@ -23,7 +23,7 @@ namespace gfx {
class Point; class Point;
} }
// Class to enable quick tab switching via horizontal 3 finger swipes. // Class to enable quick tab switching via horizontal 4 finger swipes.
class TabScrubber : public ui::EventHandler, class TabScrubber : public ui::EventHandler,
public BrowserListObserver, public BrowserListObserver,
public TabStripObserver { public TabStripObserver {
......
...@@ -152,7 +152,7 @@ class TabScrubberTest : public InProcessBrowserTest, ...@@ -152,7 +152,7 @@ class TabScrubberTest : public InProcessBrowserTest,
GetStartX(browser, active_index, direction); GetStartX(browser, active_index, direction);
ui::ScrollEvent scroll_event(ui::ET_SCROLL, gfx::Point(0, 0), ui::ScrollEvent scroll_event(ui::ET_SCROLL, gfx::Point(0, 0),
ui::EventTimeForNow(), 0, offset, 0, offset, 0, ui::EventTimeForNow(), 0, offset, 0, offset, 0,
3); 4);
event_generator->Dispatch(&scroll_event); event_generator->Dispatch(&scroll_event);
} }
...@@ -242,8 +242,8 @@ class TabScrubberTest : public InProcessBrowserTest, ...@@ -242,8 +242,8 @@ class TabScrubberTest : public InProcessBrowserTest,
// forces the TabScrubber to complete any pending activation. // forces the TabScrubber to complete any pending activation.
class ScrollGenerator { class ScrollGenerator {
public: public:
// TabScrubber reacts to three-finger scrolls. // TabScrubber reacts to four-finger scrolls.
static const int kNumFingers = 3; static const int kNumFingers = 4;
explicit ScrollGenerator(ui::test::EventGenerator* event_generator) explicit ScrollGenerator(ui::test::EventGenerator* event_generator)
: event_generator_(event_generator) { : event_generator_(event_generator) {
......
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