Commit c7ea5964 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Improve pass through mode in ChromeVox

In particular, this change makes it so we precisely pass through only the next sequence of key downs/ups that follow the pass through shortcut (Search+Shift+Esc).
Previously, we would only partially pass through the shortcut after the Search+Shift+Esc command.

Test: browser_tests --gtest_filter=ChromeVox*.*
Change-Id: Ic9d41d35bd5cce47eb3151bdba6b435f385d56e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2104449Reviewed-by: default avatarSara Kato <sarakato@chromium.org>
Commit-Queue: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750813}
parent 8190f935
...@@ -15,14 +15,35 @@ goog.require('Output'); ...@@ -15,14 +15,35 @@ goog.require('Output');
goog.require('ChromeVoxKbHandler'); goog.require('ChromeVoxKbHandler');
goog.require('ChromeVoxPrefs'); goog.require('ChromeVoxPrefs');
/**
* @enum {string}
* Internal pass through mode state (see usage below).
* @private
*/
const KeyboardPassThroughState_ = {
// No pass through is in progress.
NO_PASS_THROUGH: 'no_pass_through',
// The pass through shortcut command has been pressed (keydowns), waiting for
// user to release (keyups) all the shortcut keys.
PENDING_PASS_THROUGH_SHORTCUT_KEYUPS: 'pending_pass_through_keyups',
// The pass through shortcut command has been pressed and released, waiting
// for the user to press/release a shortcut to be passed through.
PENDING_SHORTCUT_KEYUPS: 'pending_shortcut_keyups'
};
BackgroundKeyboardHandler = class { BackgroundKeyboardHandler = class {
constructor() { constructor() {
/** @type {number} @private */ /** @private {!KeyboardPassThroughState_} */
this.passThroughKeyUpCount_ = 0; this.passThroughState_ = KeyboardPassThroughState_.NO_PASS_THROUGH;
/** @type {Set} @private */ /** @type {Set} @private */
this.eatenKeyDowns_ = new Set(); this.eatenKeyDowns_ = new Set();
/** @private {Set} */
this.passedThroughKeyDowns_ = new Set();
document.addEventListener('keydown', this.onKeyDown.bind(this), false); document.addEventListener('keydown', this.onKeyDown.bind(this), false);
document.addEventListener('keyup', this.onKeyUp.bind(this), false); document.addEventListener('keyup', this.onKeyUp.bind(this), false);
...@@ -40,7 +61,17 @@ BackgroundKeyboardHandler = class { ...@@ -40,7 +61,17 @@ BackgroundKeyboardHandler = class {
onKeyDown(evt) { onKeyDown(evt) {
EventSourceState.set(EventSourceType.STANDARD_KEYBOARD); EventSourceState.set(EventSourceType.STANDARD_KEYBOARD);
evt.stickyMode = ChromeVox.isStickyModeOn(); evt.stickyMode = ChromeVox.isStickyModeOn();
// If somehow the user gets into a state where there are dangling key downs
// don't get a key up, clear the eaten key downs. This is detected by a set
// list of modifier flags.
if (!evt.altKey && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey) {
this.eatenKeyDowns_.clear();
this.passedThroughKeyDowns_.clear();
}
if (ChromeVox.passThroughMode) { if (ChromeVox.passThroughMode) {
this.passedThroughKeyDowns_.add(evt.keyCode);
return false; return false;
} }
...@@ -56,6 +87,10 @@ BackgroundKeyboardHandler = class { ...@@ -56,6 +87,10 @@ BackgroundKeyboardHandler = class {
// ChromeVox has no range. // ChromeVox has no range.
(ChromeVoxState.instance.currentRange && (ChromeVoxState.instance.currentRange &&
(evt.metaKey || evt.keyCode == 91))) { (evt.metaKey || evt.keyCode == 91))) {
if (ChromeVox.passThroughMode) {
this.passThroughState_ =
KeyboardPassThroughState_.PENDING_PASS_THROUGH_SHORTCUT_KEYUPS;
}
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); evt.stopPropagation();
this.eatenKeyDowns_.add(evt.keyCode); this.eatenKeyDowns_.add(evt.keyCode);
...@@ -70,23 +105,32 @@ BackgroundKeyboardHandler = class { ...@@ -70,23 +105,32 @@ BackgroundKeyboardHandler = class {
* SpokenFeedbackEventRewriterDelegate::HandleKeyboardEvent. * SpokenFeedbackEventRewriterDelegate::HandleKeyboardEvent.
*/ */
onKeyUp(evt) { onKeyUp(evt) {
// Reset pass through mode once a keyup (not involving the pass through
// key) is seen. The pass through command involves three keys.
if (ChromeVox.passThroughMode) {
if (this.passThroughKeyUpCount_ >= 3) {
ChromeVox.passThroughMode = false;
this.passThroughKeyUpCount_ = 0;
} else {
this.passThroughKeyUpCount_++;
}
}
if (this.eatenKeyDowns_.has(evt.keyCode)) { if (this.eatenKeyDowns_.has(evt.keyCode)) {
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); evt.stopPropagation();
this.eatenKeyDowns_.delete(evt.keyCode); this.eatenKeyDowns_.delete(evt.keyCode);
} }
if (ChromeVox.passThroughMode) {
this.passedThroughKeyDowns_.delete(evt.keyCode);
if (this.passThroughState_ ==
KeyboardPassThroughState_.PENDING_PASS_THROUGH_SHORTCUT_KEYUPS &&
this.eatenKeyDowns_.size == 0) {
// All keys of the pass through shortcut command have been released.
// Ready to pass through the next shortcut.
this.passThroughState_ =
KeyboardPassThroughState_.PENDING_SHORTCUT_KEYUPS;
} else if (
this.passThroughState_ ==
KeyboardPassThroughState_.PENDING_SHORTCUT_KEYUPS &&
this.passedThroughKeyDowns_.size == 0) {
// All keys of the passed through shortcut have been released. Ready to
// go back to normal processing (aka no pass through).
ChromeVox.passThroughMode = false;
this.passThroughState_ = KeyboardPassThroughState_.NO_PASS_THROUGH;
}
}
return false; return false;
} }
......
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