Commit ca6a0568 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Cache virtual keyboard open state for auto-scan

Instead of re-calculating whether the virtual keyboard is open every
time auto-scan changes, cache the value and explicitly set it when the
keyboard is entered or exited.

Bug: None
Change-Id: Ia86a95f6552df4f919d6e583829f5d3f15077cb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829767Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#702892}
parent fdcb4def
......@@ -34,6 +34,12 @@ class AutoScanManager {
* @private {number}
*/
this.keyboardScanTime_ = SCAN_TIME_NOT_INITIALIZED;
/**
* Whether the current node is within the virtual keyboard.
* @private {boolean}
*/
this.inKeyboard_ = false;
}
/** Finishes setup of auto scan manager once Prefs are loaded. */
......@@ -72,10 +78,8 @@ class AutoScanManager {
* @param {boolean} enabled
*/
setEnabled(enabled) {
if (this.isRunning())
this.stop_();
if (enabled)
this.start_();
if (this.isRunning()) this.stop_();
if (enabled) this.start_();
}
/**
......@@ -96,6 +100,15 @@ class AutoScanManager {
*/
setKeyboardScanTime(scanTime) {
this.keyboardScanTime_ = scanTime;
if (this.inKeyboard_) this.restartIfRunning();
}
/**
* Sets whether the keyboard scan time is used.
* @param {boolean} inKeyboard
*/
setInKeyboard(inKeyboard) {
this.inKeyboard_ = inKeyboard;
}
/**
......@@ -116,17 +129,13 @@ class AutoScanManager {
* @private
*/
start_() {
if (this.defaultScanTime_ === SCAN_TIME_NOT_INITIALIZED)
return;
if (this.defaultScanTime_ === SCAN_TIME_NOT_INITIALIZED) return;
let currentScanTime = this.defaultScanTime_;
if (this.switchAccess_.improvedTextInputEnabled()) {
if (this.switchAccess_.inVirtualKeyboard()) {
if (this.keyboardScanTime_ !== SCAN_TIME_NOT_INITIALIZED) {
currentScanTime = this.keyboardScanTime_;
}
}
if (this.switchAccess_.improvedTextInputEnabled() && this.inKeyboard_ &&
this.keyboardScanTime_ !== SCAN_TIME_NOT_INITIALIZED) {
currentScanTime = this.keyboardScanTime_;
}
this.intervalID_ = window.setInterval(
......
......@@ -437,15 +437,6 @@ class NavigationManager {
this.focusRingManager.setFocusNodes(this.node_, this.scope_);
}
/**
* Checks if the current scope is in the virtual keyboard.
* @return {boolean}
* @public
*/
inVirtualKeyboard() {
return this.textInputManager_.inVirtualKeyboard(this.scope_);
}
/**
* Puts focus on the virtual keyboard, if the current node is a text input.
* TODO(946190): Handle the case where the user has not enabled the onscreen
......@@ -455,6 +446,8 @@ class NavigationManager {
if (!this.textInputManager_.enterKeyboard(this.node_))
return;
this.switchAccess_.setInKeyboard(true);
chrome.accessibilityPrivate.setVirtualKeyboardVisible(
true /* is_visible */);
this.setScope_(this.textInputManager_.getKeyboard(this.desktop_));
......@@ -481,6 +474,7 @@ class NavigationManager {
this.textInputManager_.returnToTextFocus();
chrome.accessibilityPrivate.setVirtualKeyboardVisible(
false /* isVisible */);
this.switchAccess_.setInKeyboard(false);
return true;
}
......
......@@ -117,25 +117,11 @@ class SwitchAccess {
this.navigationManager_.selectCurrentNode();
}
/**
* Check if the current node is in the virtual keyboard.
* @return {boolean}
* @override
* @public
*/
inVirtualKeyboard() {
if (this.navigationManager_) {
return this.navigationManager_.inVirtualKeyboard();
}
return false;
}
/**
* Returns whether or not the feature flag
* for improved text input is enabled.
* @return {boolean}
* @override
* @public
*/
improvedTextInputEnabled() {
return this.enableImprovedTextInput_;
......@@ -144,12 +130,20 @@ class SwitchAccess {
/**
* Restarts auto-scan if it is enabled.
* @override
* @public
*/
restartAutoScan() {
this.autoScanManager_.restartIfRunning();
}
/**
* Sets whether the current node is in the virtual keyboard.
* @param {boolean} inKeyboard
* @override
*/
setInKeyboard(inKeyboard) {
this.autoScanManager_.setInKeyboard(inKeyboard);
}
/**
* Handle a change in user preferences.
* @override
......
......@@ -33,10 +33,11 @@ class SwitchAccessInterface {
restartAutoScan() {}
/**
* Check if the current node is in the virtual keyboard.
* @return {boolean}
* Sets whether the current node is in the virtual keyboard.
* @param {boolean} inKeyboard
*/
inVirtualKeyboard() {}
setInKeyboard(inKeyboard) {}
/**
* Check whether or not the feature flag
......
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