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;
// Enables the Virtual Desks feature.
ASH_PUBLIC_EXPORT extern const base::Feature kVirtualDesks;
// Enables the touchpad 3-finger gestures to switch desks. It also changes tab
// scrubbing as well as overview highlight to use 4-finger gestures.
// Enables the touchpad 4-finger gestures to switch desks.
// This flag is only effective if the Virtual Desks feature is enabled (see
// `kVirtualDesks`).
ASH_PUBLIC_EXPORT extern const base::Feature kVirtualDesksGestures;
......
......@@ -47,7 +47,7 @@ bool Handle3FingerVerticalScroll(float scroll_y) {
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.
bool HandleDesksSwitchHorizontalScroll(float scroll_x) {
DCHECK(CanHandleVirtualDesksGestures());
......@@ -126,18 +126,17 @@ bool WmGestureHandler::EndScroll() {
if (std::fabs(scroll_x) < std::fabs(scroll_y))
return Handle3FingerVerticalScroll(scroll_y);
if (can_handle_desks_gestures_)
return HandleDesksSwitchHorizontalScroll(scroll_x);
return MoveOverviewSelection(finger_count, scroll_x, scroll_y);
}
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,
float scroll_x,
float scroll_y) {
const int required_finger_count = can_handle_desks_gestures_ ? 4 : 3;
if (finger_count != required_finger_count)
if (finger_count != 3)
return false;
auto* overview_controller = Shell::Get()->overview_controller();
......
......@@ -23,6 +23,9 @@ namespace ash {
namespace {
constexpr int kNumFingersForHighlight = 3;
constexpr int kNumFingersForDesksSwitch = 4;
bool InOverviewSession() {
return Shell::Get()->overview_controller()->InOverviewSession();
}
......@@ -32,10 +35,6 @@ bool CanHandleVirtualDesksGestures() {
features::IsVirtualDesksGesturesEnabled();
}
int GetNumFingersForHighlight() {
return CanHandleVirtualDesksGestures() ? 4 : 3;
}
const aura::Window* GetHighlightedWindow() {
return InOverviewSession() ? GetOverviewHighlightedWindow() : nullptr;
}
......@@ -72,7 +71,7 @@ class WmGestureHandlerTest : public AshTestBase,
DeskSwitchAnimationWaiter waiter;
const float x_offset =
(scroll_left ? -1 : 1) * WmGestureHandler::kHorizontalThresholdDp;
Scroll(x_offset, 0, /*fingers=*/3);
Scroll(x_offset, 0, kNumFingersForDesksSwitch);
waiter.Wait();
}
......@@ -123,7 +122,7 @@ TEST_P(WmGestureHandlerTest, HorizontalScrollInOverview) {
auto scroll_until_window_highlighted = [this](float x_offset,
float y_offset) {
do {
Scroll(x_offset, y_offset, GetNumFingersForHighlight());
Scroll(x_offset, y_offset, kNumFingersForHighlight);
} while (!GetHighlightedWindow());
};
......@@ -154,10 +153,10 @@ TEST_P(WmGestureHandlerTest, HorizontalScrollInOverview) {
// Tests that a mostly horizontal scroll does not trigger overview.
TEST_P(WmGestureHandlerTest, HorizontalScrolls) {
const float long_scroll = 2 * WmGestureHandler::kVerticalThresholdDp;
Scroll(long_scroll + 100, -long_scroll, GetNumFingersForHighlight());
Scroll(long_scroll + 100, -long_scroll, kNumFingersForHighlight);
EXPECT_FALSE(InOverviewSession());
Scroll(-long_scroll - 100, -long_scroll, GetNumFingersForHighlight());
Scroll(-long_scroll - 100, -long_scroll, kNumFingersForHighlight);
EXPECT_FALSE(InOverviewSession());
}
......@@ -209,7 +208,7 @@ TEST_P(DesksGestureHandlerTest, HorizontalScrolls) {
// Tests that since there is no previous desk, we remain on the same desk when
// scrolling right.
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());
}
......@@ -224,16 +223,17 @@ TEST_P(DesksGestureHandlerTest, NoDeskChanges) {
const float short_scroll = WmGestureHandler::kHorizontalThresholdDp - 10.f;
const float long_scroll = WmGestureHandler::kHorizontalThresholdDp;
// 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());
// Tests that a scroll that meets the horizontal requirements, but is mostly
// 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());
// 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());
}
......@@ -248,7 +248,7 @@ TEST_P(DesksGestureHandlerTest, NoDoubleDeskChange) {
const float long_scroll = WmGestureHandler::kHorizontalThresholdDp * 3;
DeskSwitchAnimationWaiter waiter;
Scroll(-long_scroll, 0, 3);
Scroll(-long_scroll, 0, kNumFingersForDesksSwitch);
waiter.Wait();
EXPECT_EQ(desk_controller->desks()[1].get(), desk_controller->active_desk());
}
......
......@@ -8,7 +8,6 @@
#include <algorithm>
#include "ash/public/cpp/ash_features.h"
#include "ash/shell.h"
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
......@@ -26,17 +25,6 @@
#include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
namespace {
int GetRequiredNumberOfFingers() {
return ash::features::IsVirtualDesksEnabled() &&
ash::features::IsVirtualDesksGesturesEnabled()
? 4
: 3;
}
} // namespace
// static
TabScrubber* TabScrubber::GetInstance() {
static TabScrubber* instance = nullptr;
......@@ -79,8 +67,7 @@ bool TabScrubber::IsActivationPending() {
return activate_timer_.IsRunning();
}
TabScrubber::TabScrubber()
: required_finger_count_(GetRequiredNumberOfFingers()) {
TabScrubber::TabScrubber() {
// TODO(mash): Add window server API to observe swipe gestures. Observing
// gestures on browser windows is not sufficient, as this feature works when
// the cursor is over the shelf, desktop, etc. https://crbug.com/796366
......@@ -100,7 +87,7 @@ void TabScrubber::OnScrollEvent(ui::ScrollEvent* event) {
return;
}
if (event->finger_count() != required_finger_count_)
if (event->finger_count() != 3)
return;
Browser* browser = GetActiveBrowser();
......
......@@ -76,9 +76,6 @@ class TabScrubber : public ui::EventHandler,
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?.
bool scrubbing_ = false;
// 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