Commit 0e629123 authored by Xiaodan Zhu's avatar Xiaodan Zhu Committed by Commit Bot

Reverse Scrolling & Touchpad Gestures Consistency.

This CL change the reverse scroll gestures including

 - Swipe up with three fingers to enter overview and down to exit
 overview. In M87, the old gestures also work and a notification shows
 up. In M88, the old gestures fail. In M89, remove notification.

 -For each user, the notification will only show 3 times

 - Swipe right to switch to the next desk and left to switch to the
 previous desk. The old gestures fail immediately.

Bug: 1107183

Change-Id: I815c308c1fee4cf5152227064c5f8fec61f67b06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418015
Commit-Queue: Xiaodan Zhu <zxdan@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809375}
parent 20634318
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "ash/touch/touch_devices_controller.h" #include "ash/touch/touch_devices_controller.h"
#include "ash/wallpaper/wallpaper_controller_impl.h" #include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wm/desks/desks_restore_util.h" #include "ash/wm/desks/desks_restore_util.h"
#include "ash/wm/gestures/wm_gesture_handler.h"
#include "chromeos/components/quick_answers/public/cpp/quick_answers_prefs.h" #include "chromeos/components/quick_answers/public/cpp/quick_answers_prefs.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h" #include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
...@@ -70,6 +71,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) { ...@@ -70,6 +71,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
ShelfController::RegisterProfilePrefs(registry); ShelfController::RegisterProfilePrefs(registry);
TouchDevicesController::RegisterProfilePrefs(registry, for_test); TouchDevicesController::RegisterProfilePrefs(registry, for_test);
tray::VPNListView::RegisterProfilePrefs(registry); tray::VPNListView::RegisterProfilePrefs(registry);
WmGestureHandler::RegisterProfilePrefs(registry);
// Provide prefs registered in the browser for ash_unittests. // Provide prefs registered in the browser for ash_unittests.
if (for_test) { if (for_test) {
......
...@@ -498,6 +498,12 @@ This file contains the strings for ash. ...@@ -498,6 +498,12 @@ This file contains the strings for ash.
<message name="IDS_GESTURE_NOTIFICATION_MESSAGE_LEARN_MORE" desc="The body of the notification to show off new gestures. This notification body links to the help page for the gestures."> <message name="IDS_GESTURE_NOTIFICATION_MESSAGE_LEARN_MORE" desc="The body of the notification to show off new gestures. This notification body links to the help page for the gestures.">
Use gestures to quickly switch between apps and interact with your Chromebook in tablet mode. Use gestures to quickly switch between apps and interact with your Chromebook in tablet mode.
</message> </message>
<message name="IDS_OVERVIEW_REVERSE_GESTURE_NOTIFICATION_TITLE" desc="The title of the notification to change reverse gesture when entering/exiting overview mode">
The Overview touchpad gesture has changed
</message>
<message name="IDS_OVERVIEW_REVERSE_GESTURE_NOTIFICATION_MESSAGE" desc="The body of the notification to change reverse gesture when entering/exiting overview mode">
Swipe up with three fingers to open and down to close the Overview.
</message>
<message name="IDS_UPDATE_NOTIFICATION_MESSAGE_LEARN_MORE" desc="The body of the notification to notify that the user should restart to get system updates. This notification body links to the info page on the update."> <message name="IDS_UPDATE_NOTIFICATION_MESSAGE_LEARN_MORE" desc="The body of the notification to notify that the user should restart to get system updates. This notification body links to the info page on the update.">
Learn more about the latest <ph name="SYSTEM_APP_NAME">$1<ex>Chromium OS</ex></ph> update Learn more about the latest <ph name="SYSTEM_APP_NAME">$1<ex>Chromium OS</ex></ph> update
</message> </message>
......
20bc6189a45f4cd148cfa3bae5f41ed4b9223588
\ No newline at end of file
20bc6189a45f4cd148cfa3bae5f41ed4b9223588
\ No newline at end of file
...@@ -588,6 +588,11 @@ const char kColorModeThemed[] = "cros.system.color_mode_themed"; ...@@ -588,6 +588,11 @@ const char kColorModeThemed[] = "cros.system.color_mode_themed";
const char kAppNotificationBadgingEnabled[] = const char kAppNotificationBadgingEnabled[] =
"ash.app_notification_badging_enabled"; "ash.app_notification_badging_enabled";
// An integer pref that counts how many times the reverse gesture notification
// shows.
const char kReverseGestureNotificationCount[] =
"ash.wm.reverse_gesture_notification_count";
// NOTE: New prefs should start with the "ash." prefix. Existing prefs moved // NOTE: New prefs should start with the "ash." prefix. Existing prefs moved
// into this file should not be renamed, since they may be synced. // into this file should not be renamed, since they may be synced.
......
...@@ -212,6 +212,8 @@ ASH_PUBLIC_EXPORT extern const char kColorModeThemed[]; ...@@ -212,6 +212,8 @@ ASH_PUBLIC_EXPORT extern const char kColorModeThemed[];
ASH_PUBLIC_EXPORT extern const char kAppNotificationBadgingEnabled[]; ASH_PUBLIC_EXPORT extern const char kAppNotificationBadgingEnabled[];
ASH_PUBLIC_EXPORT extern const char kReverseGestureNotificationCount[];
} // namespace prefs } // namespace prefs
} // namespace ash } // namespace ash
......
...@@ -5,19 +5,87 @@ ...@@ -5,19 +5,87 @@
#include "ash/wm/gestures/wm_gesture_handler.h" #include "ash/wm/gestures/wm_gesture_handler.h"
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/notification_utils.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/wm/desks/desks_controller.h" #include "ash/wm/desks/desks_controller.h"
#include "ash/wm/desks/desks_histogram_enums.h" #include "ash/wm/desks/desks_histogram_enums.h"
#include "ash/wm/overview/overview_controller.h" #include "ash/wm/overview/overview_controller.h"
#include "ash/wm/window_cycle_controller.h" #include "ash/wm/window_cycle_controller.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "components/prefs/pref_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/types/event_type.h" #include "ui/events/types/event_type.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_types.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/public/cpp/notifier_id.h"
namespace ash { namespace ash {
namespace { namespace {
constexpr char kOverviewGestureNotificationId[] =
"ash.wm.reverse_overview_gesture";
constexpr int kReverseGestureNotificationShowLimit = 3;
// Is the reverse scrolling for toupad on.
bool IsNaturalScrollOn() {
PrefService* pref =
Shell::Get()->session_controller()->GetActivePrefService();
return pref->GetBoolean(prefs::kTouchpadEnabled) &&
pref->GetBoolean(prefs::kNaturalScroll);
}
// Reverse an offset when the reverse scrolling is on.
float GetOffset(float offset) {
return IsNaturalScrollOn() ? -offset : offset;
}
void ShowOverviewGestureNotification() {
int reverse_gesture_notification_count =
Shell::Get()->session_controller()->GetActivePrefService()->GetInteger(
prefs::kReverseGestureNotificationCount);
if (reverse_gesture_notification_count >=
kReverseGestureNotificationShowLimit) {
return;
}
base::string16 title = l10n_util::GetStringUTF16(
IDS_OVERVIEW_REVERSE_GESTURE_NOTIFICATION_TITLE);
base::string16 message = l10n_util::GetStringUTF16(
IDS_OVERVIEW_REVERSE_GESTURE_NOTIFICATION_MESSAGE);
std::unique_ptr<message_center::Notification> notification =
CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE,
kOverviewGestureNotificationId, title, message, base::string16(),
GURL(),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
kOverviewGestureNotificationId),
message_center::RichNotificationData(), nullptr, gfx::VectorIcon(),
message_center::SystemNotificationWarningLevel::NORMAL);
// Make the notification popup again if it has been in message center.
if (message_center::MessageCenter::Get()->FindVisibleNotificationById(
kOverviewGestureNotificationId)) {
message_center::MessageCenter::Get()->RemoveNotification(
kOverviewGestureNotificationId, false);
}
message_center::MessageCenter::Get()->AddNotification(
std::move(notification));
Shell::Get()->session_controller()->GetActivePrefService()->SetInteger(
prefs::kReverseGestureNotificationCount,
reverse_gesture_notification_count + 1);
}
// The amount the fingers must move in a direction before a continuous gesture // The amount the fingers must move in a direction before a continuous gesture
// animation is started. This is to minimize accidental scrolls. // animation is started. This is to minimize accidental scrolls.
constexpr int kContinuousGestureMoveThresholdDp = 10; constexpr int kContinuousGestureMoveThresholdDp = 10;
...@@ -27,19 +95,40 @@ constexpr int kContinuousGestureMoveThresholdDp = 10; ...@@ -27,19 +95,40 @@ constexpr int kContinuousGestureMoveThresholdDp = 10;
// list is open, close the window cycle list. // list is open, close the window cycle list.
// Returns true if the gesture was handled. // Returns true if the gesture was handled.
bool Handle3FingerVerticalScroll(float scroll_y) { bool Handle3FingerVerticalScroll(float scroll_y) {
if (std::fabs(scroll_y) < WmGestureHandler::kVerticalThresholdDp)
return false;
auto* overview_controller = Shell::Get()->overview_controller(); auto* overview_controller = Shell::Get()->overview_controller();
const bool in_overview = overview_controller->InOverviewSession(); const bool in_overview = overview_controller->InOverviewSession();
if (in_overview) { if (in_overview) {
if (scroll_y > -WmGestureHandler::kVerticalThresholdDp) // If touchpad reverse scroll is off, only swip down can exit overview. If
return false; // touchpad reverse scroll is on, in M87 swip up can also exit overview but
// show notification; in M88, swip up will only show notification; in M89
// the notification is removed.
if (GetOffset(scroll_y) > 0) {
if (!IsNaturalScrollOn()) {
return false;
} else {
ShowOverviewGestureNotification();
}
}
base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview")); base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview"));
if (overview_controller->AcceptSelection()) if (overview_controller->AcceptSelection())
return true; return true;
overview_controller->EndOverview(); overview_controller->EndOverview();
} else { } else {
if (scroll_y < WmGestureHandler::kVerticalThresholdDp) // If touchpad reverse scroll is off, only swip up can enter overview. If
return false; // touchpad reverse scroll is on, in M87 swip down can also enter overview
// but show notification; in M88, swip down will only show notification; in
// M89 the notification is removed.
if (GetOffset(scroll_y) < 0) {
if (!IsNaturalScrollOn()) {
return false;
} else {
ShowOverviewGestureNotification();
}
}
auto* window_cycle_controller = Shell::Get()->window_cycle_controller(); auto* window_cycle_controller = Shell::Get()->window_cycle_controller();
if (window_cycle_controller->IsCycling()) if (window_cycle_controller->IsCycling())
...@@ -58,11 +147,10 @@ bool HandleDesksSwitchHorizontalScroll(float scroll_x) { ...@@ -58,11 +147,10 @@ bool HandleDesksSwitchHorizontalScroll(float scroll_x) {
if (std::fabs(scroll_x) < WmGestureHandler::kHorizontalThresholdDp) if (std::fabs(scroll_x) < WmGestureHandler::kHorizontalThresholdDp)
return false; return false;
// This does not invert if the user changes their touchpad settings // If touchpad reverse scroll is on, the swip direction will invert.
// currently. The scroll works Australian way (scroll left to go to the
// desk on the right and vice versa).
return DesksController::Get()->ActivateAdjacentDesk( return DesksController::Get()->ActivateAdjacentDesk(
/*going_left=*/scroll_x > 0, DesksSwitchSource::kDeskSwitchTouchpad); /*going_left=*/GetOffset(scroll_x) > 0,
DesksSwitchSource::kDeskSwitchTouchpad);
} }
} // namespace } // namespace
...@@ -144,6 +232,11 @@ bool WmGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) { ...@@ -144,6 +232,11 @@ bool WmGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) {
return moved; return moved;
} }
// static
void WmGestureHandler::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(prefs::kReverseGestureNotificationCount, 0);
}
bool WmGestureHandler::EndScroll() { bool WmGestureHandler::EndScroll() {
if (!scroll_data_) if (!scroll_data_)
return false; return false;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/optional.h" #include "base/optional.h"
#include "components/prefs/pref_registry_simple.h"
namespace ui { namespace ui {
class ScrollEvent; class ScrollEvent;
...@@ -35,6 +36,8 @@ class ASH_EXPORT WmGestureHandler { ...@@ -35,6 +36,8 @@ class ASH_EXPORT WmGestureHandler {
// DesksController if |is_enhanced_desk_animations_| is true. // DesksController if |is_enhanced_desk_animations_| is true.
bool ProcessScrollEvent(const ui::ScrollEvent& event); bool ProcessScrollEvent(const ui::ScrollEvent& event);
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
private: private:
// A struct containing the relevant data during a scroll session. // A struct containing the relevant data during a scroll session.
struct ScrollData { struct ScrollData {
......
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