[keyboard-alt]: Add buttons to notifications
Screenshot: http://screen/BLtA6Hoz2ZwugfF Bug: b/279503977 Change-Id: I3654532306c8a53e276b508b90ee7ddc6b2c8763 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4761193 Commit-Queue: Michael Checo <michaelcheco@google.com> Reviewed-by: David Padlipsky <dpad@google.com> Cr-Commit-Position: refs/heads/main@{#1181641}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
acecd0f681
commit
457c0e7e8f
@ -7051,6 +7051,12 @@ To shut down the device, press and hold the power button on the device again.
|
||||
<message name="IDS_ASH_DEVICE_SETTINGS_NOTIFICATIONS_RIGHT_CLICK_DISABLED_TITLE" desc="Title for the notification shown when the right-click shortcut is disabled.">
|
||||
Keyboard shortcut is off
|
||||
</message>
|
||||
<message name="IDS_ASH_DEVICE_SETTINGS_EDIT_SHORTCUT_BUTTON" desc="Button shown for device settings notifications which links to the settings app.">
|
||||
Edit shortcut
|
||||
</message>
|
||||
<message name="IDS_ASH_DEVICE_SETTINGS_LEARN_MORE_BUTTON" desc="Button shown for device settings notifications which opens an article with helpful information related to the notification.">
|
||||
Learn more
|
||||
</message>
|
||||
</messages>
|
||||
</release>
|
||||
</grit>
|
||||
|
@ -0,0 +1 @@
|
||||
7343ac9bc3dac6a95432f781a78c1dcca9165035
|
@ -0,0 +1 @@
|
||||
7343ac9bc3dac6a95432f781a78c1dcca9165035
|
@ -170,7 +170,7 @@ bool IsActiveUserSession() {
|
||||
|
||||
// If the user has reached the settings page through the notification, do
|
||||
// not show any more new notifications.
|
||||
void StopShowingNotification(const char* pref_name) {
|
||||
void PreventNotificationFromShowingAgain(const char* pref_name) {
|
||||
Shell::Get()->session_controller()->GetActivePrefService()->SetInteger(
|
||||
pref_name, 0);
|
||||
}
|
||||
@ -274,6 +274,19 @@ std::string GetSixPackNotificationId(ui::KeyboardCode key_code, int device_id) {
|
||||
return notification_id + kDelimiter + base::NumberToString(device_id);
|
||||
}
|
||||
|
||||
void RemoveNotification(const std::string& notification_id) {
|
||||
message_center::MessageCenter::Get()->RemoveNotification(notification_id,
|
||||
/*by_user=*/true);
|
||||
}
|
||||
|
||||
void ShowRemapKeysSubpage(int device_id) {
|
||||
Shell::Get()->system_tray_model()->client()->ShowRemapKeysSubpage(device_id);
|
||||
}
|
||||
|
||||
void ShowTouchpadSettings() {
|
||||
Shell::Get()->system_tray_model()->client()->ShowTouchpadSettings();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
InputDeviceSettingsNotificationController::
|
||||
@ -333,21 +346,10 @@ void InputDeviceSettingsNotificationController::
|
||||
|
||||
prefs->SetInteger(prefs::kRemapToRightClickNotificationsRemaining,
|
||||
num_notifications_remaining - 1);
|
||||
auto on_click_handler =
|
||||
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
|
||||
base::BindRepeating([]() {
|
||||
if (!Shell::Get()->session_controller()->IsUserSessionBlocked()) {
|
||||
Shell::Get()
|
||||
->system_tray_model()
|
||||
->client()
|
||||
->ShowTouchpadSettings();
|
||||
StopShowingNotification(
|
||||
prefs::kRemapToRightClickNotificationsRemaining);
|
||||
}
|
||||
}));
|
||||
const auto notification_id =
|
||||
GetRightClickNotificationId(blocked_modifier, active_modifier);
|
||||
auto notification = CreateSystemNotificationPtr(
|
||||
message_center::NOTIFICATION_TYPE_SIMPLE,
|
||||
GetRightClickNotificationId(blocked_modifier, active_modifier),
|
||||
message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
|
||||
GetRightClickRewriteNotificationTitle(active_modifier),
|
||||
GetRightClickRewriteNotificationMessage(blocked_modifier,
|
||||
active_modifier),
|
||||
@ -355,12 +357,66 @@ void InputDeviceSettingsNotificationController::
|
||||
message_center::NotifierId(
|
||||
message_center::NotifierType::SYSTEM_COMPONENT, kNotifierId,
|
||||
NotificationCatalogName::kEventRewriterDeprecation),
|
||||
message_center::RichNotificationData(), std::move(on_click_handler),
|
||||
message_center::RichNotificationData(),
|
||||
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
|
||||
base::BindRepeating(&InputDeviceSettingsNotificationController::
|
||||
HandleRightClickNotificationClicked,
|
||||
weak_ptr_factory_.GetWeakPtr(), notification_id)),
|
||||
kNotificationKeyboardIcon,
|
||||
message_center::SystemNotificationWarningLevel::NORMAL);
|
||||
message_center_->AddNotification(std::move(notification));
|
||||
}
|
||||
|
||||
void InputDeviceSettingsNotificationController::
|
||||
HandleSixPackNotificationClicked(int device_id,
|
||||
const char* pref_name,
|
||||
const std::string& notification_id,
|
||||
absl::optional<int> button_index) {
|
||||
// Clicked on body.
|
||||
if (!button_index) {
|
||||
ShowRemapKeysSubpage(device_id);
|
||||
RemoveNotification(notification_id);
|
||||
PreventNotificationFromShowingAgain(pref_name);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (*button_index) {
|
||||
case NotificationButtonIndex::BUTTON_EDIT_SHORTCUT:
|
||||
ShowRemapKeysSubpage(device_id);
|
||||
break;
|
||||
case NotificationButtonIndex::BUTTON_LEARN_MORE:
|
||||
// TODO(b/279503977): Add link to learn more page.
|
||||
break;
|
||||
}
|
||||
PreventNotificationFromShowingAgain(pref_name);
|
||||
RemoveNotification(notification_id);
|
||||
}
|
||||
|
||||
void InputDeviceSettingsNotificationController::
|
||||
HandleRightClickNotificationClicked(const std::string& notification_id,
|
||||
absl::optional<int> button_index) {
|
||||
// Clicked on body.
|
||||
if (!button_index) {
|
||||
ShowTouchpadSettings();
|
||||
PreventNotificationFromShowingAgain(
|
||||
prefs::kRemapToRightClickNotificationsRemaining);
|
||||
RemoveNotification(notification_id);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (*button_index) {
|
||||
case NotificationButtonIndex::BUTTON_EDIT_SHORTCUT:
|
||||
ShowTouchpadSettings();
|
||||
break;
|
||||
case NotificationButtonIndex::BUTTON_LEARN_MORE:
|
||||
// TODO(b/279503977): Add link to learn more page.
|
||||
break;
|
||||
}
|
||||
PreventNotificationFromShowingAgain(
|
||||
prefs::kRemapToRightClickNotificationsRemaining);
|
||||
RemoveNotification(notification_id);
|
||||
}
|
||||
|
||||
// TODO(b/279503977): Use `blocked_modifier` and `active_modifier` to display
|
||||
// the notification message once strings are finalized.
|
||||
void InputDeviceSettingsNotificationController::
|
||||
@ -387,20 +443,14 @@ void InputDeviceSettingsNotificationController::
|
||||
}
|
||||
prefs->SetInteger(pref, num_notifications_remaining - 1);
|
||||
|
||||
auto on_click_handler =
|
||||
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
|
||||
base::BindRepeating(
|
||||
[](int device_id, const char* pref_name) {
|
||||
Shell::Get()
|
||||
->system_tray_model()
|
||||
->client()
|
||||
->ShowRemapKeysSubpage(device_id);
|
||||
StopShowingNotification(pref_name);
|
||||
},
|
||||
device_id, pref));
|
||||
const auto notification_id = GetSixPackNotificationId(key_code, device_id);
|
||||
message_center::RichNotificationData rich_notification_data;
|
||||
rich_notification_data.buttons.emplace_back(
|
||||
l10n_util::GetStringUTF16(IDS_ASH_DEVICE_SETTINGS_EDIT_SHORTCUT_BUTTON));
|
||||
rich_notification_data.buttons.emplace_back(
|
||||
l10n_util::GetStringUTF16(IDS_ASH_DEVICE_SETTINGS_LEARN_MORE_BUTTON));
|
||||
auto notification = CreateSystemNotificationPtr(
|
||||
message_center::NOTIFICATION_TYPE_SIMPLE,
|
||||
GetSixPackNotificationId(key_code, device_id),
|
||||
message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
|
||||
l10n_util::GetStringUTF16(IDS_ASH_SETTINGS_SHORTCUT_NOTIFICATION_TITLE),
|
||||
GetSixPackNotificationMessage(key_code, blocked_modifier,
|
||||
active_modifier),
|
||||
@ -408,7 +458,12 @@ void InputDeviceSettingsNotificationController::
|
||||
message_center::NotifierId(
|
||||
message_center::NotifierType::SYSTEM_COMPONENT, kNotifierId,
|
||||
NotificationCatalogName::kEventRewriterDeprecation),
|
||||
message_center::RichNotificationData(), std::move(on_click_handler),
|
||||
rich_notification_data,
|
||||
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
|
||||
base::BindRepeating(&InputDeviceSettingsNotificationController::
|
||||
HandleSixPackNotificationClicked,
|
||||
weak_ptr_factory_.GetWeakPtr(), device_id, pref,
|
||||
notification_id)),
|
||||
kNotificationKeyboardIcon,
|
||||
message_center::SystemNotificationWarningLevel::NORMAL);
|
||||
message_center_->AddNotification(std::move(notification));
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "ash/ash_export.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "ui/events/ash/mojom/simulate_right_click_modifier.mojom-shared.h"
|
||||
#include "ui/events/ash/mojom/six_pack_shortcut_modifier.mojom-shared.h"
|
||||
#include "ui/events/keycodes/keyboard_codes_posix.h"
|
||||
@ -19,6 +20,12 @@ class MessageCenter;
|
||||
|
||||
namespace ash {
|
||||
|
||||
// The notification button index.
|
||||
enum NotificationButtonIndex {
|
||||
BUTTON_EDIT_SHORTCUT = 0,
|
||||
BUTTON_LEARN_MORE,
|
||||
};
|
||||
|
||||
// Manages showing notifications for Six Pack/right-click event rewrites.
|
||||
// Notifications are shown when the user's setting is inconsistent with
|
||||
// the matched modifier key or the setting is disabled.
|
||||
@ -54,8 +61,18 @@ class ASH_EXPORT InputDeviceSettingsNotificationController {
|
||||
int device_id);
|
||||
|
||||
private:
|
||||
void HandleRightClickNotificationClicked(const std::string& notification_id,
|
||||
absl::optional<int> button_index);
|
||||
|
||||
void HandleSixPackNotificationClicked(int device_id,
|
||||
const char* pref_name,
|
||||
const std::string& notification_id,
|
||||
absl::optional<int> button_index);
|
||||
// MessageCenter for adding notifications.
|
||||
const raw_ptr<message_center::MessageCenter, ExperimentalAsh> message_center_;
|
||||
|
||||
base::WeakPtrFactory<InputDeviceSettingsNotificationController>
|
||||
weak_ptr_factory_{this};
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "ash/system/input_device_settings/input_device_settings_notification_controller.h"
|
||||
|
||||
#include "ash/constants/ash_pref_names.h"
|
||||
#include "ash/public/cpp/test/test_system_tray_client.h"
|
||||
#include "ash/shell.h"
|
||||
#include "ash/test/ash_test_base.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -37,6 +38,14 @@ class TestMessageCenter : public message_center::FakeMessageCenter {
|
||||
CHECK(notification);
|
||||
notification->delegate()->Click(absl::nullopt, absl::nullopt);
|
||||
}
|
||||
|
||||
void ClickOnNotificationButton(const std::string& id,
|
||||
int button_index) override {
|
||||
message_center::Notification* notification =
|
||||
FindVisibleNotificationById(id);
|
||||
CHECK(notification);
|
||||
notification->delegate()->Click(button_index, absl::nullopt);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@ -212,6 +221,31 @@ TEST_F(InputDeviceSettingsNotificationControllerTest,
|
||||
prefs::kRemapToRightClickNotificationsRemaining));
|
||||
}
|
||||
|
||||
// TODO(b/279503977): Add test that verifies behavior of clicking on the
|
||||
// "Learn more" button.
|
||||
TEST_F(InputDeviceSettingsNotificationControllerTest,
|
||||
ShowTouchpadSettingsOnRightClickNotificationClick) {
|
||||
controller()->NotifyRightClickRewriteBlockedBySetting(
|
||||
ui::mojom::SimulateRightClickModifier::kAlt,
|
||||
ui::mojom::SimulateRightClickModifier::kSearch);
|
||||
message_center()->ClickOnNotificationButton(
|
||||
"alt_right_click_rewrite_blocked_by_setting",
|
||||
NotificationButtonIndex::BUTTON_EDIT_SHORTCUT);
|
||||
EXPECT_EQ(GetSystemTrayClient()->show_touchpad_settings_count(), 1);
|
||||
}
|
||||
|
||||
TEST_F(InputDeviceSettingsNotificationControllerTest,
|
||||
ShowRemapKeysSettingsOnSixPackNotificationClick) {
|
||||
controller()->NotifySixPackRewriteBlockedBySetting(
|
||||
ui::VKEY_DELETE, ui::mojom::SixPackShortcutModifier::kAlt,
|
||||
ui::mojom::SixPackShortcutModifier::kSearch,
|
||||
/*device_id=*/1);
|
||||
message_center()->ClickOnNotificationButton(
|
||||
"delete_six_pack_rewrite_blocked_by_setting_1",
|
||||
NotificationButtonIndex::BUTTON_EDIT_SHORTCUT);
|
||||
EXPECT_EQ(GetSystemTrayClient()->show_remap_keys_subpage_count(), 1);
|
||||
}
|
||||
|
||||
TEST_F(InputDeviceSettingsNotificationControllerTest,
|
||||
NotifySixPackRewriteBlockedBySetting) {
|
||||
size_t expected_notification_count = 1;
|
||||
|
Reference in New Issue
Block a user