Commit e19ef20a authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

Switch Access: Ensure user can cancel when deactivating switch access.

This change ensures that switch access is in a stable state if the user
cancels when disabling it. Previously, pressing cancel
triggered a buggy re-initialization of switch access that resulted in
disabed switches. This change simply turns switch access off before
re-activating it to ensure it's in a stable state. Though we do turn
switch access off, then on again, the end result for the user is that
switch access stays on.

Bug: 1115126
AX-Relnotes: N/A

Change-Id: I57c37e02122f137f64c38e57aff3009678aec2b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354622
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarAnastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#797927}
parent e2151716
...@@ -1807,18 +1807,18 @@ void AccessibilityControllerImpl:: ...@@ -1807,18 +1807,18 @@ void AccessibilityControllerImpl::
void AccessibilityControllerImpl::SwitchAccessDisableDialogClosed( void AccessibilityControllerImpl::SwitchAccessDisableDialogClosed(
bool disable_dialog_accepted) { bool disable_dialog_accepted) {
switch_access_disable_dialog_showing_ = false; switch_access_disable_dialog_showing_ = false;
// Always deactivate switch access. Turning switch access off ensures it is
// re-activated correctly.
// The pref was already disabled, but we left switch access on so the user
// could interact with the dialog.
DeactivateSwitchAccess();
if (disable_dialog_accepted) { if (disable_dialog_accepted) {
// The pref was already disabled, but we left switch access on until they
// accepted the dialog.
if (client_)
client_->OnSwitchAccessDisabled();
switch_access_bubble_controller_.reset();
switch_access_event_handler_.reset();
NotifyAccessibilityStatusChanged(); NotifyAccessibilityStatusChanged();
} else { } else {
// Reset the preference (which was already set to false) to match the // Reset the preference (which was already set to false). Doing so turns
// behavior of keeping Switch Access enabled. // switch access back on.
switch_access().SetEnabled(true); skip_switch_access_notification_ = true;
SetSwitchAccessEnabled(true);
} }
} }
...@@ -1846,6 +1846,27 @@ void AccessibilityControllerImpl::MaybeCreateSwitchAccessEventHandler() { ...@@ -1846,6 +1846,27 @@ void AccessibilityControllerImpl::MaybeCreateSwitchAccessEventHandler() {
UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kPrevious); UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kPrevious);
} }
void AccessibilityControllerImpl::ActivateSwitchAccess() {
switch_access_bubble_controller_ =
std::make_unique<SwitchAccessMenuBubbleController>();
MaybeCreateSwitchAccessEventHandler();
if (::switches::IsSwitchAccessPointScanningEnabled())
StartPointScanning();
if (skip_switch_access_notification_) {
skip_switch_access_notification_ = false;
return;
}
ShowAccessibilityNotification(A11yNotificationType::kSwitchAccessEnabled);
}
void AccessibilityControllerImpl::DeactivateSwitchAccess() {
if (client_)
client_->OnSwitchAccessDisabled();
switch_access_bubble_controller_.reset();
switch_access_event_handler_.reset();
}
void AccessibilityControllerImpl::UpdateShortcutsEnabledFromPref() { void AccessibilityControllerImpl::UpdateShortcutsEnabledFromPref() {
DCHECK(active_user_prefs_); DCHECK(active_user_prefs_);
const bool enabled = const bool enabled =
...@@ -1988,16 +2009,7 @@ void AccessibilityControllerImpl::UpdateFeatureFromPref(FeatureType feature) { ...@@ -1988,16 +2009,7 @@ void AccessibilityControllerImpl::UpdateFeatureFromPref(FeatureType feature) {
// user accepts the dialog. // user accepts the dialog.
return; return;
} else { } else {
switch_access_bubble_controller_ = ActivateSwitchAccess();
std::make_unique<SwitchAccessMenuBubbleController>();
MaybeCreateSwitchAccessEventHandler();
if (::switches::IsSwitchAccessPointScanningEnabled()) {
StartPointScanning();
}
ShowAccessibilityNotification(
A11yNotificationType::kSwitchAccessEnabled);
} }
break; break;
case FeatureType::kVirtualKeyboard: case FeatureType::kVirtualKeyboard:
......
...@@ -456,6 +456,8 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController, ...@@ -456,6 +456,8 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
void SwitchAccessDisableDialogClosed(bool disable_dialog_accepted); void SwitchAccessDisableDialogClosed(bool disable_dialog_accepted);
void MaybeCreateSelectToSpeakEventHandler(); void MaybeCreateSelectToSpeakEventHandler();
void MaybeCreateSwitchAccessEventHandler(); void MaybeCreateSwitchAccessEventHandler();
void ActivateSwitchAccess();
void DeactivateSwitchAccess();
// Client interface in chrome browser. // Client interface in chrome browser.
AccessibilityControllerClient* client_ = nullptr; AccessibilityControllerClient* client_ = nullptr;
...@@ -484,6 +486,7 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController, ...@@ -484,6 +486,7 @@ class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
nullptr; nullptr;
bool no_switch_access_disable_confirmation_dialog_for_testing_ = false; bool no_switch_access_disable_confirmation_dialog_for_testing_ = false;
bool switch_access_disable_dialog_showing_ = false; bool switch_access_disable_dialog_showing_ = false;
bool skip_switch_access_notification_ = false;
// Used to control the highlights of caret, cursor and focus. // Used to control the highlights of caret, cursor and focus.
std::unique_ptr<AccessibilityHighlightController> std::unique_ptr<AccessibilityHighlightController>
......
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