Commit 3338706b authored by Sara Kato's avatar Sara Kato Committed by Commit Bot

Add dialog for screen rotation shortcut.

Screen rotation may be triggered using Ctrl + Shift + Reload (F5).
The screen will be rotated if the user presses "Continue".

UI Strings for ash_strings are still in review.

TEST: Manual
Bug: 881929
Change-Id: Ie6c067f164b0a0d6f4d68f0d29360d7166937e70
Reviewed-on: https://chromium-review.googlesource.com/c/1272556Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarSatoru Takabayashi <satorux@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarYuki Awano <yawano@chromium.org>
Commit-Queue: Sara Kato <sarakato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602934}
parent b15f94ee
......@@ -348,12 +348,7 @@ display::Display::Rotation GetNextRotation(display::Display::Rotation current) {
return display::Display::ROTATE_0;
}
// Rotates the screen.
void HandleRotateScreen() {
if (Shell::Get()->display_manager()->IsInUnifiedMode())
return;
base::RecordAction(UserMetricsAction("Accel_Rotate_Screen"));
void RotateScreen() {
gfx::Point point = display::Screen::GetScreen()->GetCursorScreenPoint();
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestPoint(point);
......@@ -364,6 +359,31 @@ void HandleRotateScreen() {
display::Display::RotationSource::USER);
}
// Rotates the screen.
void HandleRotateScreen() {
if (Shell::Get()->display_manager()->IsInUnifiedMode())
return;
base::RecordAction(UserMetricsAction("Accel_Rotate_Screen"));
const bool dialog_ever_accepted =
Shell::Get()
->accessibility_controller()
->HasDisplayRotationAcceleratorDialogBeenAccepted();
if (!dialog_ever_accepted) {
Shell::Get()->accelerator_controller()->MaybeShowConfirmationDialog(
IDS_ASH_ROTATE_SCREEN_TITLE, IDS_ASH_ROTATE_SCREEN_BODY,
base::BindOnce([]() {
RotateScreen();
Shell::Get()
->accessibility_controller()
->SetDisplayRotationAcceleratorDialogBeenAccepted();
}));
} else {
RotateScreen();
}
}
void HandleRestoreTab() {
base::RecordAction(UserMetricsAction("Accel_Restore_Tab"));
Shell::Get()->new_window_controller()->RestoreTab();
......
......@@ -512,14 +512,45 @@ TEST_F(AcceleratorControllerTest, RotateScreen) {
display::Display::Rotation initial_rotation =
GetActiveDisplayRotation(display.id());
ui::test::EventGenerator* generator = GetEventGenerator();
AccessibilityController* accessibility_controller =
Shell::Get()->accessibility_controller();
EXPECT_FALSE(accessibility_controller
->HasDisplayRotationAcceleratorDialogBeenAccepted());
generator->PressKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
generator->ReleaseKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
display::Display::Rotation new_rotation =
// Dialog should be open.
EXPECT_TRUE(IsConfirmationDialogOpen());
// Cancel on the dialog should have no effect.
CancelConfirmationDialog();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(accessibility_controller
->HasDisplayRotationAcceleratorDialogBeenAccepted());
display::Display::Rotation rotation_after_cancel =
GetActiveDisplayRotation(display.id());
// Screen rotation should not have been triggered.
EXPECT_EQ(initial_rotation, rotation_after_cancel);
// Use short cut again.
generator->PressKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
generator->ReleaseKey(ui::VKEY_BROWSER_REFRESH,
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
EXPECT_TRUE(IsConfirmationDialogOpen());
AcceptConfirmationDialog();
base::RunLoop().RunUntilIdle();
// Dialog should be closed.
EXPECT_FALSE(IsConfirmationDialogOpen());
EXPECT_TRUE(accessibility_controller
->HasDisplayRotationAcceleratorDialogBeenAccepted());
display::Display::Rotation rotation_after_accept =
GetActiveDisplayRotation(display.id());
// |new_rotation| is determined by the AcceleratorController.
EXPECT_NE(initial_rotation, new_rotation);
EXPECT_NE(initial_rotation, rotation_after_accept);
}
TEST_F(AcceleratorControllerTest, AutoRepeat) {
......
......@@ -87,6 +87,7 @@ constexpr const char* const kCopiedOnSigninAccessibilityPrefs[]{
prefs::kScreenMagnifierAcceleratorDialogHasBeenAccepted,
prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted,
prefs::kDictationAcceleratorDialogHasBeenAccepted,
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted,
};
// Returns true if |pref_service| is the one used for the signin screen.
......@@ -295,6 +296,8 @@ void AccessibilityController::RegisterProfilePrefs(PrefRegistrySimple* registry,
prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kDictationAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted, false);
return;
}
......@@ -327,6 +330,8 @@ void AccessibilityController::RegisterProfilePrefs(PrefRegistrySimple* registry,
prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted);
registry->RegisterForeignPref(
prefs::kDictationAcceleratorDialogHasBeenAccepted);
registry->RegisterForeignPref(
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted);
}
void AccessibilityController::SetHighContrastAcceleratorDialogAccepted() {
......@@ -367,6 +372,22 @@ void AccessibilityController::SetDockedMagnifierAcceleratorDialogAccepted() {
active_user_prefs_->CommitPendingWrite();
}
bool AccessibilityController::HasDisplayRotationAcceleratorDialogBeenAccepted()
const {
return active_user_prefs_ &&
active_user_prefs_->GetBoolean(
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted);
}
void AccessibilityController::
SetDisplayRotationAcceleratorDialogBeenAccepted() {
if (!active_user_prefs_)
return;
active_user_prefs_->SetBoolean(
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted, true);
active_user_prefs_->CommitPendingWrite();
}
bool AccessibilityController::HasDockedMagnifierAcceleratorDialogBeenAccepted()
const {
return active_user_prefs_ &&
......
......@@ -65,6 +65,8 @@ class ASH_EXPORT AccessibilityController
bool HasDockedMagnifierAcceleratorDialogBeenAccepted() const;
void SetDictationAcceleratorDialogAccepted();
bool HasDictationAcceleratorDialogBeenAccepted() const;
void SetDisplayRotationAcceleratorDialogBeenAccepted();
bool HasDisplayRotationAcceleratorDialogBeenAccepted() const;
void SetAutoclickEnabled(bool enabled);
bool IsAutoclickEnabled() const;
......
......@@ -1284,6 +1284,12 @@ This file contains the strings for ash.
<message name="IDS_ASH_SCREEN_MAGNIFIER_BODY" desc="The text for the screen magnifier dialog.">
You pressed the shortcut for the full-screen magnifier. Do you want to turn it on?
</message>
<message name="IDS_ASH_ROTATE_SCREEN_TITLE" desc="Dialog title for when the screen has been rotated.">
Rotate Screen
</message>
<message name="IDS_ASH_ROTATE_SCREEN_BODY" desc="The text for the screen rotation dialog.">
You pressed the shortcut for screen rotation. Do you want to rotate the screen?
</message>
<message name="IDS_ASH_CONTINUE_BUTTON" desc="The text for continue button on accessibility confirmation dialogs.">
Continue
</message>
......
......@@ -99,6 +99,10 @@ const char kScreenMagnifierAcceleratorDialogHasBeenAccepted[] =
// ever been shown.
const char kDictationAcceleratorDialogHasBeenAccepted[] =
"settings.a11y.dictation_accelerator_dialog_has_been_accepted";
// A boolean pref which indicates whether the display rotation confirmation
// dialog has ever been shown.
const char kDisplayRotationAcceleratorDialogHasBeenAccepted[] =
"settings.a11y.display_rotation_accelerator_dialog_has_been_accepted";
// A dictionary pref that stores the mixed mirror mode parameters.
const char kDisplayMixedMirrorModeParams[] =
......
......@@ -43,6 +43,8 @@ ASH_PUBLIC_EXPORT extern const char
kScreenMagnifierAcceleratorDialogHasBeenAccepted[];
ASH_PUBLIC_EXPORT extern const char
kDictationAcceleratorDialogHasBeenAccepted[];
ASH_PUBLIC_EXPORT extern const char
kDisplayRotationAcceleratorDialogHasBeenAccepted[];
ASH_PUBLIC_EXPORT extern const char kDisplayMixedMirrorModeParams[];
ASH_PUBLIC_EXPORT extern const char kDisplayPowerState[];
......
......@@ -254,6 +254,9 @@ void Preferences::RegisterProfilePrefs(
registry->RegisterBooleanPref(
ash::prefs::kDictationAcceleratorDialogHasBeenAccepted, false,
PrefRegistry::PUBLIC);
registry->RegisterBooleanPref(
ash::prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted, false,
PrefRegistry::PUBLIC);
registry->RegisterBooleanPref(
ash::prefs::kAccessibilityScreenMagnifierEnabled, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF | PrefRegistry::PUBLIC);
......
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