Commit e929f5ad authored by Xiaodan Zhu's avatar Xiaodan Zhu Committed by Commit Bot

Add system toast for reverse gesture changes

This CL add system toast for reverse scrolling gesture changes.

 - If the user perform wrong gestures twice, a system toast will show up
 to indicate the right gestures.

 - If the toast shows at the fist time, it will disappear until the user
 perform the right gesture. Otherwise, it will shows for 2500ms.

Bug: 1107183

Change-Id: I1fd3fb9f0c898ca15cae2de87df6e89c7b62aecc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417242
Commit-Queue: Xiaodan Zhu <zxdan@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809431}
parent 9016b6b0
...@@ -504,6 +504,12 @@ This file contains the strings for ash. ...@@ -504,6 +504,12 @@ This file contains the strings for ash.
<message name="IDS_OVERVIEW_REVERSE_GESTURE_NOTIFICATION_MESSAGE" desc="The body of the notification to change reverse gesture when entering/exiting overview mode"> <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. Swipe up with three fingers to open and down to close the Overview.
</message> </message>
<message name="IDS_CHANGE_NEXT_DESK_REVERSE_GESTURE" desc="The toast of changing reverse gesture to switch to the next desk.">
The touchpad gesture to switch to the next desk has changed. Swipe right with four fingers to switch to the next desk.
</message>
<message name="IDS_CHANGE_LAST_DESK_REVERSE_GESTURE" desc="The toast of changing reverse gesture to switch to the previous desk.">
The touchpad gesture to switch to the previous desk has changed. Swipe left with four fingers to switch to the previous desk.
</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>
......
254d8fc1e4d13f9775cfd6e2f35585b44fb6df67
\ No newline at end of file
a720949921534c6d1314ded4f45b77329bfe7320
\ No newline at end of file
...@@ -7,14 +7,17 @@ ...@@ -7,14 +7,17 @@
#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/ash_pref_names.h"
#include "ash/public/cpp/notification_utils.h" #include "ash/public/cpp/notification_utils.h"
#include "ash/public/cpp/toast_data.h"
#include "ash/session/session_controller_impl.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/strings/grit/ash_strings.h"
#include "ash/system/toast/toast_manager_impl.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 "base/time/time.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -33,6 +36,16 @@ constexpr char kOverviewGestureNotificationId[] = ...@@ -33,6 +36,16 @@ constexpr char kOverviewGestureNotificationId[] =
"ash.wm.reverse_overview_gesture"; "ash.wm.reverse_overview_gesture";
constexpr int kReverseGestureNotificationShowLimit = 3; constexpr int kReverseGestureNotificationShowLimit = 3;
constexpr char kSwitchNextDeskToastId[] = "ash.wm.reverse_next_desk_toast";
constexpr char kSwitchLastDeskToastId[] = "ash.wm.reverse_last_desk_toast";
constexpr base::TimeDelta kToastDurationMs =
base::TimeDelta::FromMilliseconds(2500);
// Check if the user used the wrong gestures.
bool gDidWrongNextDeskGesture = false;
bool gDidWrongLastDeskGesture = false;
// Is the reverse scrolling for toupad on. // Is the reverse scrolling for toupad on.
bool IsNaturalScrollOn() { bool IsNaturalScrollOn() {
PrefService* pref = PrefService* pref =
...@@ -86,6 +99,12 @@ void ShowOverviewGestureNotification() { ...@@ -86,6 +99,12 @@ void ShowOverviewGestureNotification() {
reverse_gesture_notification_count + 1); reverse_gesture_notification_count + 1);
} }
void ShowReverseGestureToast(const char* toast_id, int message_id) {
Shell::Get()->toast_manager()->Show(
ToastData(toast_id, l10n_util::GetStringUTF16(message_id),
kToastDurationMs.InMilliseconds(), base::nullopt));
}
// 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;
...@@ -106,11 +125,10 @@ bool Handle3FingerVerticalScroll(float scroll_y) { ...@@ -106,11 +125,10 @@ bool Handle3FingerVerticalScroll(float scroll_y) {
// show notification; in M88, swip up will only show notification; in M89 // show notification; in M88, swip up will only show notification; in M89
// the notification is removed. // the notification is removed.
if (GetOffset(scroll_y) > 0) { if (GetOffset(scroll_y) > 0) {
if (!IsNaturalScrollOn()) { if (!IsNaturalScrollOn())
return false; return false;
} else { else
ShowOverviewGestureNotification(); ShowOverviewGestureNotification();
}
} }
base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview")); base::RecordAction(base::UserMetricsAction("Touchpad_Gesture_Overview"));
...@@ -123,11 +141,10 @@ bool Handle3FingerVerticalScroll(float scroll_y) { ...@@ -123,11 +141,10 @@ bool Handle3FingerVerticalScroll(float scroll_y) {
// but show notification; in M88, swip down will only show notification; in // but show notification; in M88, swip down will only show notification; in
// M89 the notification is removed. // M89 the notification is removed.
if (GetOffset(scroll_y) < 0) { if (GetOffset(scroll_y) < 0) {
if (!IsNaturalScrollOn()) { if (!IsNaturalScrollOn())
return false; return false;
} else { else
ShowOverviewGestureNotification(); ShowOverviewGestureNotification();
}
} }
auto* window_cycle_controller = Shell::Get()->window_cycle_controller(); auto* window_cycle_controller = Shell::Get()->window_cycle_controller();
...@@ -147,6 +164,32 @@ bool HandleDesksSwitchHorizontalScroll(float scroll_x) { ...@@ -147,6 +164,32 @@ bool HandleDesksSwitchHorizontalScroll(float scroll_x) {
if (std::fabs(scroll_x) < WmGestureHandler::kHorizontalThresholdDp) if (std::fabs(scroll_x) < WmGestureHandler::kHorizontalThresholdDp)
return false; return false;
if (IsNaturalScrollOn()) {
if (GetOffset(scroll_x) < 0 && !DesksController::Get()->GetNextDesk() &&
DesksController::Get()->GetPreviousDesk()) {
if (!gDidWrongLastDeskGesture) {
gDidWrongLastDeskGesture = true;
} else {
ShowReverseGestureToast(kSwitchLastDeskToastId,
IDS_CHANGE_LAST_DESK_REVERSE_GESTURE);
}
} else if (GetOffset(scroll_x) > 0 &&
!DesksController::Get()->GetPreviousDesk() &&
DesksController::Get()->GetNextDesk()) {
if (!gDidWrongNextDeskGesture) {
gDidWrongNextDeskGesture = true;
} else {
ShowReverseGestureToast(kSwitchNextDeskToastId,
IDS_CHANGE_NEXT_DESK_REVERSE_GESTURE);
}
} else {
gDidWrongNextDeskGesture = false;
gDidWrongLastDeskGesture = false;
Shell::Get()->toast_manager()->Cancel(kSwitchNextDeskToastId);
Shell::Get()->toast_manager()->Cancel(kSwitchLastDeskToastId);
}
}
// If touchpad reverse scroll is on, the swip direction will invert. // If touchpad reverse scroll is on, the swip direction will invert.
return DesksController::Get()->ActivateAdjacentDesk( return DesksController::Get()->ActivateAdjacentDesk(
/*going_left=*/GetOffset(scroll_x) > 0, /*going_left=*/GetOffset(scroll_x) > 0,
......
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