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

Desks: Prepare Virtual Desks Gestures for launch

This CL makes the following changes:
- Tab scrubbing will always use 3-finger gestures.
- 4-finger horizontal swipes will switch desks only if
  the flag "--enable-virtual-desks-gestures" is enabled.
- 3-finger horizontal swipes while in Overview will always
  move the highlighter.

This CL is meant to be merged back to M-79.
A follow-up CL will remove the "--enable-virtual-desks-gestures"
flag entirely on M-80, so that virtual desks gestures will always
be enabled going forward.

BUG=1005340
TEST=Tested manually on device, updated existing tests.

Change-Id: I1316e150556a4f2ede79b41dab8ddc3402d39370
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902232
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713262}
parent 7facefc7
...@@ -98,8 +98,7 @@ ASH_PUBLIC_EXPORT extern const base::Feature kViewsLogin; ...@@ -98,8 +98,7 @@ ASH_PUBLIC_EXPORT extern const base::Feature kViewsLogin;
// Enables the Virtual Desks feature. // Enables the Virtual Desks feature.
ASH_PUBLIC_EXPORT extern const base::Feature kVirtualDesks; ASH_PUBLIC_EXPORT extern const base::Feature kVirtualDesks;
// Enables the touchpad 3-finger gestures to switch desks. It also changes tab // Enables the touchpad 4-finger gestures to switch desks.
// scrubbing as well as overview highlight to use 4-finger gestures.
// This flag is only effective if the Virtual Desks feature is enabled (see // This flag is only effective if the Virtual Desks feature is enabled (see
// `kVirtualDesks`). // `kVirtualDesks`).
ASH_PUBLIC_EXPORT extern const base::Feature kVirtualDesksGestures; ASH_PUBLIC_EXPORT extern const base::Feature kVirtualDesksGestures;
......
...@@ -47,7 +47,7 @@ bool Handle3FingerVerticalScroll(float scroll_y) { ...@@ -47,7 +47,7 @@ bool Handle3FingerVerticalScroll(float scroll_y) {
return true; return true;
} }
// Handles horizontal 3-finger scroll by switching desks if possible. // Handles horizontal 4-finger scroll by switching desks if possible.
// Returns true if the gesture was handled. // Returns true if the gesture was handled.
bool HandleDesksSwitchHorizontalScroll(float scroll_x) { bool HandleDesksSwitchHorizontalScroll(float scroll_x) {
DCHECK(CanHandleVirtualDesksGestures()); DCHECK(CanHandleVirtualDesksGestures());
...@@ -126,18 +126,17 @@ bool WmGestureHandler::EndScroll() { ...@@ -126,18 +126,17 @@ bool WmGestureHandler::EndScroll() {
if (std::fabs(scroll_x) < std::fabs(scroll_y)) if (std::fabs(scroll_x) < std::fabs(scroll_y))
return Handle3FingerVerticalScroll(scroll_y); return Handle3FingerVerticalScroll(scroll_y);
if (can_handle_desks_gestures_) return MoveOverviewSelection(finger_count, scroll_x, scroll_y);
return HandleDesksSwitchHorizontalScroll(scroll_x);
} }
return MoveOverviewSelection(finger_count, scroll_x, scroll_y); return finger_count == 4 && can_handle_desks_gestures_ &&
HandleDesksSwitchHorizontalScroll(scroll_x);
} }
bool WmGestureHandler::MoveOverviewSelection(int finger_count, bool WmGestureHandler::MoveOverviewSelection(int finger_count,
float scroll_x, float scroll_x,
float scroll_y) { float scroll_y) {
const int required_finger_count = can_handle_desks_gestures_ ? 4 : 3; if (finger_count != 3)
if (finger_count != required_finger_count)
return false; return false;
auto* overview_controller = Shell::Get()->overview_controller(); auto* overview_controller = Shell::Get()->overview_controller();
......
...@@ -23,6 +23,9 @@ namespace ash { ...@@ -23,6 +23,9 @@ namespace ash {
namespace { namespace {
constexpr int kNumFingersForHighlight = 3;
constexpr int kNumFingersForDesksSwitch = 4;
bool InOverviewSession() { bool InOverviewSession() {
return Shell::Get()->overview_controller()->InOverviewSession(); return Shell::Get()->overview_controller()->InOverviewSession();
} }
...@@ -32,10 +35,6 @@ bool CanHandleVirtualDesksGestures() { ...@@ -32,10 +35,6 @@ bool CanHandleVirtualDesksGestures() {
features::IsVirtualDesksGesturesEnabled(); features::IsVirtualDesksGesturesEnabled();
} }
int GetNumFingersForHighlight() {
return CanHandleVirtualDesksGestures() ? 4 : 3;
}
const aura::Window* GetHighlightedWindow() { const aura::Window* GetHighlightedWindow() {
return InOverviewSession() ? GetOverviewHighlightedWindow() : nullptr; return InOverviewSession() ? GetOverviewHighlightedWindow() : nullptr;
} }
...@@ -72,7 +71,7 @@ class WmGestureHandlerTest : public AshTestBase, ...@@ -72,7 +71,7 @@ class WmGestureHandlerTest : public AshTestBase,
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, /*fingers=*/3); Scroll(x_offset, 0, kNumFingersForDesksSwitch);
waiter.Wait(); waiter.Wait();
} }
...@@ -123,7 +122,7 @@ TEST_P(WmGestureHandlerTest, HorizontalScrollInOverview) { ...@@ -123,7 +122,7 @@ TEST_P(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, GetNumFingersForHighlight()); Scroll(x_offset, y_offset, kNumFingersForHighlight);
} while (!GetHighlightedWindow()); } while (!GetHighlightedWindow());
}; };
...@@ -154,10 +153,10 @@ TEST_P(WmGestureHandlerTest, HorizontalScrollInOverview) { ...@@ -154,10 +153,10 @@ TEST_P(WmGestureHandlerTest, HorizontalScrollInOverview) {
// Tests that a mostly horizontal scroll does not trigger overview. // Tests that a mostly horizontal scroll does not trigger overview.
TEST_P(WmGestureHandlerTest, HorizontalScrolls) { TEST_P(WmGestureHandlerTest, HorizontalScrolls) {
const float long_scroll = 2 * WmGestureHandler::kVerticalThresholdDp; const float long_scroll = 2 * WmGestureHandler::kVerticalThresholdDp;
Scroll(long_scroll + 100, -long_scroll, GetNumFingersForHighlight()); Scroll(long_scroll + 100, -long_scroll, kNumFingersForHighlight);
EXPECT_FALSE(InOverviewSession()); EXPECT_FALSE(InOverviewSession());
Scroll(-long_scroll - 100, -long_scroll, GetNumFingersForHighlight()); Scroll(-long_scroll - 100, -long_scroll, kNumFingersForHighlight);
EXPECT_FALSE(InOverviewSession()); EXPECT_FALSE(InOverviewSession());
} }
...@@ -209,7 +208,7 @@ TEST_P(DesksGestureHandlerTest, HorizontalScrolls) { ...@@ -209,7 +208,7 @@ TEST_P(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, 3); Scroll(long_scroll, 0.f, kNumFingersForDesksSwitch);
EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk()); EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk());
} }
...@@ -224,16 +223,17 @@ TEST_P(DesksGestureHandlerTest, NoDeskChanges) { ...@@ -224,16 +223,17 @@ TEST_P(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, 3); Scroll(short_scroll, 0.f, kNumFingersForDesksSwitch);
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, 3); Scroll(long_scroll, long_scroll + 10.f, kNumFingersForDesksSwitch);
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, 3); Scroll(0.f, WmGestureHandler::kVerticalThresholdDp,
kNumFingersForDesksSwitch);
EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk()); EXPECT_EQ(desk_controller->desks()[0].get(), desk_controller->active_desk());
} }
...@@ -248,7 +248,7 @@ TEST_P(DesksGestureHandlerTest, NoDoubleDeskChange) { ...@@ -248,7 +248,7 @@ TEST_P(DesksGestureHandlerTest, NoDoubleDeskChange) {
const float long_scroll = WmGestureHandler::kHorizontalThresholdDp * 3; const float long_scroll = WmGestureHandler::kHorizontalThresholdDp * 3;
DeskSwitchAnimationWaiter waiter; DeskSwitchAnimationWaiter waiter;
Scroll(-long_scroll, 0, 3); Scroll(-long_scroll, 0, kNumFingersForDesksSwitch);
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());
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <algorithm> #include <algorithm>
#include "ash/public/cpp/ash_features.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -26,17 +25,6 @@ ...@@ -26,17 +25,6 @@
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h" #include "ui/events/gesture_detection/gesture_configuration.h"
namespace {
int GetRequiredNumberOfFingers() {
return ash::features::IsVirtualDesksEnabled() &&
ash::features::IsVirtualDesksGesturesEnabled()
? 4
: 3;
}
} // namespace
// static // static
TabScrubber* TabScrubber::GetInstance() { TabScrubber* TabScrubber::GetInstance() {
static TabScrubber* instance = nullptr; static TabScrubber* instance = nullptr;
...@@ -79,8 +67,7 @@ bool TabScrubber::IsActivationPending() { ...@@ -79,8 +67,7 @@ bool TabScrubber::IsActivationPending() {
return activate_timer_.IsRunning(); return activate_timer_.IsRunning();
} }
TabScrubber::TabScrubber() TabScrubber::TabScrubber() {
: required_finger_count_(GetRequiredNumberOfFingers()) {
// TODO(mash): Add window server API to observe swipe gestures. Observing // TODO(mash): Add window server API to observe swipe gestures. Observing
// gestures on browser windows is not sufficient, as this feature works when // gestures on browser windows is not sufficient, as this feature works when
// the cursor is over the shelf, desktop, etc. https://crbug.com/796366 // the cursor is over the shelf, desktop, etc. https://crbug.com/796366
...@@ -100,7 +87,7 @@ void TabScrubber::OnScrollEvent(ui::ScrollEvent* event) { ...@@ -100,7 +87,7 @@ void TabScrubber::OnScrollEvent(ui::ScrollEvent* event) {
return; return;
} }
if (event->finger_count() != required_finger_count_) if (event->finger_count() != 3)
return; return;
Browser* browser = GetActiveBrowser(); Browser* browser = GetActiveBrowser();
......
...@@ -76,9 +76,6 @@ class TabScrubber : public ui::EventHandler, ...@@ -76,9 +76,6 @@ class TabScrubber : public ui::EventHandler,
void UpdateHighlightedTab(Tab* new_tab, int new_index); void UpdateHighlightedTab(Tab* new_tab, int new_index);
// The required number of fingers to perform tab scrubbing, which can be
// affected by some Virtual Desks flags.
const int required_finger_count_;
// Are we currently scrubbing?. // Are we currently scrubbing?.
bool scrubbing_ = false; bool scrubbing_ = false;
// The last browser we used for scrubbing, NULL if |scrubbing_| is false and // The last browser we used for scrubbing, NULL if |scrubbing_| is false and
......
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