Commit ed9e7a03 authored by Sara Kato's avatar Sara Kato Committed by Commit Bot

Add sticky notifications for docked and fullscreen magnifier.

Bug: 853104
Change-Id: I6b6a0e0436e7c3753e09f9071110bf36c10be1a1
Tests: 
ash: ash_unittests:AcceleratorControllerTest.TestDialogCancel
ash: ash_unittests:AcceleratorControllerTest.TestToggleHighContrast
ash: ash_unittests:MagnifiersAcceleratorsTester.TestToggleFullscreenMagnifier
ash: ash_unittests:MagnifiersAcceleratorsTester.TestToggleDockedMagnifier
Reviewed-on: https://chromium-review.googlesource.com/1102217
Commit-Queue: Sara Kato <sarakato@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570340}
parent dc839a42
...@@ -96,6 +96,10 @@ const char kNotifierAccelerator[] = "ash.accelerator-controller"; ...@@ -96,6 +96,10 @@ const char kNotifierAccelerator[] = "ash.accelerator-controller";
const char kHighContrastToggleAccelNotificationId[] = const char kHighContrastToggleAccelNotificationId[] =
"chrome://settings/accessibility/highcontrast"; "chrome://settings/accessibility/highcontrast";
const char kDockedMagnifierToggleAccelNotificationId[] =
"chrome://settings/accessibility/dockedmagnifier";
const char kFullscreenMagnifierToggleAccelNotificationId[] =
"chrome://settings/accessibility/fullscreenmagnifier";
namespace { namespace {
...@@ -805,6 +809,42 @@ bool CanHandleToggleDockedMagnifier() { ...@@ -805,6 +809,42 @@ bool CanHandleToggleDockedMagnifier() {
return features::IsDockedMagnifierEnabled(); return features::IsDockedMagnifierEnabled();
} }
void CreateAndShowStickyNotification(const int title_id,
const int message_id,
const std::string& notification_id) {
std::unique_ptr<Notification> notification =
Notification::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
l10n_util::GetStringUTF16(title_id),
l10n_util::GetStringUTF16(message_id), gfx::Image(),
base::string16() /* display source */, GURL(),
message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT,
kNotifierAccelerator),
message_center::RichNotificationData(), nullptr,
kNotificationAccessibilityIcon,
SystemNotificationWarningLevel::NORMAL);
notification->set_priority(message_center::SYSTEM_PRIORITY);
message_center::MessageCenter::Get()->AddNotification(
std::move(notification));
}
void RemoveStickyNotitification(const std::string& notification_id) {
message_center::MessageCenter::Get()->RemoveNotification(notification_id,
false /* by_user */);
}
void SetDockedMagnifierEnabled(bool enabled) {
if (enabled) {
CreateAndShowStickyNotification(IDS_DOCKED_MAGNIFIER_ACCEL_TITLE,
IDS_DOCKED_MAGNIFIER_ACCEL_MSG,
kDockedMagnifierToggleAccelNotificationId);
} else {
RemoveStickyNotitification(kDockedMagnifierToggleAccelNotificationId);
}
Shell::Get()->docked_magnifier_controller()->SetEnabled(enabled);
}
void HandleToggleDockedMagnifier() { void HandleToggleDockedMagnifier() {
DCHECK(features::IsDockedMagnifierEnabled()); DCHECK(features::IsDockedMagnifierEnabled());
base::RecordAction(UserMetricsAction("Accel_Toggle_Docked_Magnifier")); base::RecordAction(UserMetricsAction("Accel_Toggle_Docked_Magnifier"));
...@@ -824,41 +864,34 @@ void HandleToggleDockedMagnifier() { ...@@ -824,41 +864,34 @@ void HandleToggleDockedMagnifier() {
Shell::Get() Shell::Get()
->accessibility_controller() ->accessibility_controller()
->SetDockedMagnifierAcceleratorDialogAccepted(); ->SetDockedMagnifierAcceleratorDialogAccepted();
Shell::Get()->docked_magnifier_controller()->SetEnabled(true); SetDockedMagnifierEnabled(true);
})); }));
} else { } else {
docked_magnifier_controller->SetEnabled(!current_enabled); SetDockedMagnifierEnabled(!current_enabled);
}
}
void SetFullscreenMagnifierEnabled(bool enabled) {
if (enabled) {
CreateAndShowStickyNotification(
IDS_FULLSCREEN_MAGNIFIER_ACCEL_TITLE,
IDS_FULLSCREEN_MAGNIFIER_ACCEL_MSG,
kFullscreenMagnifierToggleAccelNotificationId);
} else {
RemoveStickyNotitification(kFullscreenMagnifierToggleAccelNotificationId);
} }
Shell::Get()->magnification_controller()->SetEnabled(enabled);
} }
void SetHighContrastEnabled(bool enabled) { void SetHighContrastEnabled(bool enabled) {
if (enabled) { if (enabled) {
// Show a notification so the user knows that this accelerator toggled CreateAndShowStickyNotification(IDS_HIGH_CONTRAST_ACCEL_TITLE,
// high contrast mode, and that they can press it again to toggle back. IDS_HIGH_CONTRAST_ACCEL_MSG,
// The message center automatically only shows this once per session. kHighContrastToggleAccelNotificationId);
std::unique_ptr<Notification> notification =
Notification::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE,
kHighContrastToggleAccelNotificationId,
l10n_util::GetStringUTF16(IDS_HIGH_CONTRAST_ACCEL_TITLE),
l10n_util::GetStringUTF16(IDS_HIGH_CONTRAST_ACCEL_MSG),
gfx::Image(), base::string16() /* display source */, GURL(),
message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT,
kNotifierAccelerator),
message_center::RichNotificationData(), nullptr,
kNotificationAccessibilityIcon,
SystemNotificationWarningLevel::NORMAL);
notification->set_priority(message_center::SYSTEM_PRIORITY);
message_center::MessageCenter::Get()->AddNotification(
std::move(notification));
} else { } else {
message_center::MessageCenter::Get()->RemoveNotification( RemoveStickyNotitification(kHighContrastToggleAccelNotificationId);
kHighContrastToggleAccelNotificationId, false /* by_user */);
} }
AccessibilityController* controller = Shell::Get()->accessibility_controller()->SetHighContrastEnabled(enabled);
Shell::Get()->accessibility_controller();
controller->SetHighContrastEnabled(enabled);
} }
void HandleToggleHighContrast() { void HandleToggleHighContrast() {
...@@ -912,10 +945,10 @@ void HandleToggleFullscreenMagnifier() { ...@@ -912,10 +945,10 @@ void HandleToggleFullscreenMagnifier() {
Shell::Get() Shell::Get()
->accessibility_controller() ->accessibility_controller()
->SetScreenMagnifierAcceleratorDialogAccepted(); ->SetScreenMagnifierAcceleratorDialogAccepted();
Shell::Get()->magnification_controller()->SetEnabled(true); SetFullscreenMagnifierEnabled(true);
})); }));
} else { } else {
controller->SetEnabled(!current_enabled); SetFullscreenMagnifierEnabled(!current_enabled);
} }
} }
......
...@@ -34,8 +34,10 @@ namespace ash { ...@@ -34,8 +34,10 @@ namespace ash {
struct AcceleratorData; struct AcceleratorData;
class ExitWarningHandler; class ExitWarningHandler;
// Identifier for the high contrast toggle accelerator notification. // Identifiers for toggling accelerator notifications.
ASH_EXPORT extern const char kHighContrastToggleAccelNotificationId[]; ASH_EXPORT extern const char kHighContrastToggleAccelNotificationId[];
ASH_EXPORT extern const char kDockedMagnifierToggleAccelNotificationId[];
ASH_EXPORT extern const char kFullscreenMagnifierToggleAccelNotificationId[];
// AcceleratorController provides functions for registering or unregistering // AcceleratorController provides functions for registering or unregistering
// global keyboard accelerators, which are handled earlier than any windows. It // global keyboard accelerators, which are handled earlier than any windows. It
......
...@@ -183,6 +183,16 @@ class AcceleratorControllerTest : public AshTestBase { ...@@ -183,6 +183,16 @@ class AcceleratorControllerTest : public AshTestBase {
kHighContrastToggleAccelNotificationId); kHighContrastToggleAccelNotificationId);
} }
bool ContainsDockedMagnifierNotification() const {
return nullptr != message_center()->FindVisibleNotificationById(
kDockedMagnifierToggleAccelNotificationId);
}
bool ContainsFullscreenMagnifierNotification() const {
return nullptr != message_center()->FindVisibleNotificationById(
kFullscreenMagnifierToggleAccelNotificationId);
}
bool IsConfirmationDialogOpen() { bool IsConfirmationDialogOpen() {
return !!(GetController()->confirmation_dialog_for_testing()); return !!(GetController()->confirmation_dialog_for_testing());
} }
...@@ -1420,6 +1430,7 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleFullscreenMagnifier) { ...@@ -1420,6 +1430,7 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleFullscreenMagnifier) {
EXPECT_FALSE(IsConfirmationDialogOpen()); EXPECT_FALSE(IsConfirmationDialogOpen());
EXPECT_FALSE(docked_magnifier_controller()->GetEnabled()); EXPECT_FALSE(docked_magnifier_controller()->GetEnabled());
EXPECT_TRUE(fullscreen_magnifier_controller()->IsEnabled()); EXPECT_TRUE(fullscreen_magnifier_controller()->IsEnabled());
EXPECT_TRUE(ContainsFullscreenMagnifierNotification());
EXPECT_TRUE(ProcessInController(fullscreen_magnifier_accelerator)); EXPECT_TRUE(ProcessInController(fullscreen_magnifier_accelerator));
EXPECT_FALSE(docked_magnifier_controller()->GetEnabled()); EXPECT_FALSE(docked_magnifier_controller()->GetEnabled());
...@@ -1427,6 +1438,7 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleFullscreenMagnifier) { ...@@ -1427,6 +1438,7 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleFullscreenMagnifier) {
EXPECT_TRUE(accessibility_controller EXPECT_TRUE(accessibility_controller
->HasScreenMagnifierAcceleratorDialogBeenAccepted()); ->HasScreenMagnifierAcceleratorDialogBeenAccepted());
EXPECT_FALSE(IsConfirmationDialogOpen()); EXPECT_FALSE(IsConfirmationDialogOpen());
EXPECT_FALSE(ContainsFullscreenMagnifierNotification());
// Dialog will not be shown the second time the accelerator is used. // Dialog will not be shown the second time the accelerator is used.
EXPECT_TRUE(ProcessInController(fullscreen_magnifier_accelerator)); EXPECT_TRUE(ProcessInController(fullscreen_magnifier_accelerator));
...@@ -1435,6 +1447,9 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleFullscreenMagnifier) { ...@@ -1435,6 +1447,9 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleFullscreenMagnifier) {
->HasScreenMagnifierAcceleratorDialogBeenAccepted()); ->HasScreenMagnifierAcceleratorDialogBeenAccepted());
EXPECT_FALSE(docked_magnifier_controller()->GetEnabled()); EXPECT_FALSE(docked_magnifier_controller()->GetEnabled());
EXPECT_TRUE(fullscreen_magnifier_controller()->IsEnabled()); EXPECT_TRUE(fullscreen_magnifier_controller()->IsEnabled());
EXPECT_TRUE(ContainsFullscreenMagnifierNotification());
RemoveAllNotifications();
} }
TEST_F(MagnifiersAcceleratorsTester, TestToggleDockedMagnifier) { TEST_F(MagnifiersAcceleratorsTester, TestToggleDockedMagnifier) {
...@@ -1455,6 +1470,7 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleDockedMagnifier) { ...@@ -1455,6 +1470,7 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleDockedMagnifier) {
EXPECT_FALSE(IsConfirmationDialogOpen()); EXPECT_FALSE(IsConfirmationDialogOpen());
EXPECT_TRUE(docked_magnifier_controller()->GetEnabled()); EXPECT_TRUE(docked_magnifier_controller()->GetEnabled());
EXPECT_FALSE(fullscreen_magnifier_controller()->IsEnabled()); EXPECT_FALSE(fullscreen_magnifier_controller()->IsEnabled());
EXPECT_TRUE(ContainsDockedMagnifierNotification());
EXPECT_TRUE(ProcessInController(docked_magnifier_accelerator)); EXPECT_TRUE(ProcessInController(docked_magnifier_accelerator));
EXPECT_FALSE(docked_magnifier_controller()->GetEnabled()); EXPECT_FALSE(docked_magnifier_controller()->GetEnabled());
...@@ -1462,12 +1478,16 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleDockedMagnifier) { ...@@ -1462,12 +1478,16 @@ TEST_F(MagnifiersAcceleratorsTester, TestToggleDockedMagnifier) {
EXPECT_TRUE(accessibility_controller EXPECT_TRUE(accessibility_controller
->HasDockedMagnifierAcceleratorDialogBeenAccepted()); ->HasDockedMagnifierAcceleratorDialogBeenAccepted());
EXPECT_FALSE(IsConfirmationDialogOpen()); EXPECT_FALSE(IsConfirmationDialogOpen());
EXPECT_FALSE(ContainsDockedMagnifierNotification());
// Dialog will not be shown the second time accelerator is used. // Dialog will not be shown the second time accelerator is used.
EXPECT_TRUE(ProcessInController(docked_magnifier_accelerator)); EXPECT_TRUE(ProcessInController(docked_magnifier_accelerator));
EXPECT_FALSE(IsConfirmationDialogOpen()); EXPECT_FALSE(IsConfirmationDialogOpen());
EXPECT_TRUE(docked_magnifier_controller()->GetEnabled()); EXPECT_TRUE(docked_magnifier_controller()->GetEnabled());
EXPECT_FALSE(fullscreen_magnifier_controller()->IsEnabled()); EXPECT_FALSE(fullscreen_magnifier_controller()->IsEnabled());
EXPECT_TRUE(ContainsDockedMagnifierNotification());
RemoveAllNotifications();
} }
} // namespace ash } // namespace ash
...@@ -1293,14 +1293,34 @@ This file contains the strings for ash. ...@@ -1293,14 +1293,34 @@ This file contains the strings for ash.
<!-- Notification that an accelerator was pressed, so the user knows how to toggle it back --> <!-- Notification that an accelerator was pressed, so the user knows how to toggle it back -->
<message name="IDS_HIGH_CONTRAST_ACCEL_TITLE" <message name="IDS_HIGH_CONTRAST_ACCEL_TITLE"
desc="Notification title to tell users that they just pressed the Search+Shift+H shortcut to toggle High Contrast Mode, and that pressing it again will toggle it off."> desc="Notification title to tell users that they just pressed the Ctrl+Search+H shortcut to toggle High Contrast Mode, and that pressing it again will toggle it off.">
High Contrast Mode High Contrast Mode
</message> </message>
<message name="IDS_HIGH_CONTRAST_ACCEL_MSG" <message name="IDS_HIGH_CONTRAST_ACCEL_MSG"
desc="Notification message to tell users that they just pressed the Search+Shift+H shortcut to toggle High Contrast Mode, and that pressing it again will toggle it off."> desc="Notification message to tell users that they just pressed the Ctrl+Search+H shortcut to toggle High Contrast Mode, and that pressing it again will toggle it off.">
High Contrast Mode enabled. Press Ctrl+Search+H again to toggle it off. High Contrast Mode enabled. Press Ctrl+Search+H again to toggle it off.
</message> </message>
<!-- Notification that an accelerator was pressed, so the user knows how to toggle it back -->
<message name="IDS_DOCKED_MAGNIFIER_ACCEL_TITLE"
desc="Notification title to tell users that they just pressed the Ctrl+Search+D shortcut to toggle Docked Magnifier, and that pressing it again will toggle it off.">
Docked Magnifier
</message>
<message name="IDS_DOCKED_MAGNIFIER_ACCEL_MSG"
desc="Notification message to tell users that they just pressed the Ctrl+Search+D shortcut to toggle Docked Magnifier, and that pressing it again will toggle it off.">
Docked Magnifier enabled. Press Ctrl+Search+D again to toggle it off.
</message>
<!-- Notification that an accelerator was pressed, so the user knows how to toggle it back -->
<message name="IDS_FULLSCREEN_MAGNIFIER_ACCEL_TITLE"
desc="Notification title to tell users that they just pressed the Ctrl+Search+M shortcut to toggle Fullscreen Magnifier, and that pressing it again will toggle it off.">
Fullscreen Magnifier
</message>
<message name="IDS_FULLSCREEN_MAGNIFIER_ACCEL_MSG"
desc="Notification message to tell users that they just pressed the Ctrl+Search+M shortcut to toggle Fullscreen Magnifier, and that pressing it again will toggle it off.">
Fullscreen Magnifier enabled. Press Ctrl+Search+M again to toggle it off.
</message>
<!-- Tray scale strings --> <!-- Tray scale strings -->
<message name="IDS_ASH_STATUS_TRAY_SCALE" desc="The label used in scale setting detailed page of ash tray popup."> <message name="IDS_ASH_STATUS_TRAY_SCALE" desc="The label used in scale setting detailed page of ash tray popup.">
Display scale settings Display scale settings
......
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