Commit 164d31bc authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

ChromeVox UserActionMonitor: Don't block Ctrl+Alt+Z

This change allows a user to turn ChromeVox off, even if
UserActionMonitor is active. This is useful in the tutorial, where some
lessons block ChromeVox execution.

This change also fixes a closure error in tts_background.js.

Bug: 1126135
Change-Id: I583c572dd5017e373022aa6614086dc839e1c9b1
AX-Relnotes: N/A
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412631
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807656}
parent c0e18346
...@@ -73,6 +73,7 @@ PanelCommandType = { ...@@ -73,6 +73,7 @@ PanelCommandType = {
CLEAR_SPEECH: 'clear_speech', CLEAR_SPEECH: 'clear_speech',
ADD_NORMAL_SPEECH: 'add_normal_speech', ADD_NORMAL_SPEECH: 'add_normal_speech',
ADD_ANNOTATION_SPEECH: 'add_annotation_speech', ADD_ANNOTATION_SPEECH: 'add_annotation_speech',
CLOSE_CHROMEVOX: 'close_chromevox',
UPDATE_BRAILLE: 'update_braille', UPDATE_BRAILLE: 'update_braille',
OPEN_ANNOTATIONS_UI: 'open_annotations_ui', OPEN_ANNOTATIONS_UI: 'open_annotations_ui',
OPEN_MENUS: 'open_menus', OPEN_MENUS: 'open_menus',
......
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
goog.provide('UserActionMonitor'); goog.provide('UserActionMonitor');
goog.require('KeyCode');
goog.require('KeySequence'); goog.require('KeySequence');
goog.require('Output'); goog.require('Output');
goog.require('PanelCommand');
goog.require('PanelCommandType');
/** /**
* The types of actions we want to monitor. * The types of actions we want to monitor.
...@@ -65,6 +68,12 @@ UserActionMonitor = class { ...@@ -65,6 +68,12 @@ UserActionMonitor = class {
* @return {boolean} * @return {boolean}
*/ */
onKeySequence(actualSequence) { onKeySequence(actualSequence) {
if (actualSequence.equals(
UserActionMonitor.CLOSE_CHROMEVOX_KEY_SEQUENCE_)) {
UserActionMonitor.closeChromeVox_();
return true;
}
const expectedAction = this.getExpectedAction_(); const expectedAction = this.getExpectedAction_();
if (expectedAction.type !== ActionType.KEY_SEQUENCE) { if (expectedAction.type !== ActionType.KEY_SEQUENCE) {
return false; return false;
...@@ -126,8 +135,21 @@ UserActionMonitor = class { ...@@ -126,8 +135,21 @@ UserActionMonitor = class {
throw new Error('UserActionMonitor: actionIndex_ is invalid.'); throw new Error('UserActionMonitor: actionIndex_ is invalid.');
} }
/** @private */
static closeChromeVox_() {
(new PanelCommand(PanelCommandType.CLOSE_CHROMEVOX)).send();
}
}; };
/**
* The key sequence used to close ChromeVox.
* @const {!KeySequence}
* @private
*/
UserActionMonitor.CLOSE_CHROMEVOX_KEY_SEQUENCE_ = KeySequence.deserialize(
{keys: {keyCode: [KeyCode.Z], ctrlKey: [true], altKey: [true]}});
/** /**
* Defines an object that is used to create a UserActionMonitor.Action. * Defines an object that is used to create a UserActionMonitor.Action.
* @typedef {{ * @typedef {{
......
...@@ -407,3 +407,37 @@ TEST_F('ChromeVoxUserActionMonitorTest', 'BlockCommands', function() { ...@@ -407,3 +407,37 @@ TEST_F('ChromeVoxUserActionMonitorTest', 'BlockCommands', function() {
.replay(); .replay();
}); });
}); });
// Tests that a user can close ChromeVox (Ctrl + Alt + Z) when UserActionMonitor
// is active.
TEST_F('ChromeVoxUserActionMonitorTest', 'CloseChromeVox', function() {
this.runWithLoadedTree(this.simpleDoc, function() {
const keyboardHandler = new BackgroundKeyboardHandler();
let finished = false;
let closed = false;
const actions =
[{type: 'key_sequence', value: {'keys': {'keyCode': [KeyCode.A]}}}];
const onFinished = () => finished = true;
ChromeVoxState.instance.createUserActionMonitor(actions, onFinished);
// Swap in the below function so we don't actually close ChromeVox.
UserActionMonitor.closeChromeVox_ = () => {
closed = true;
};
assertFalse(closed);
assertFalse(finished);
keyboardHandler.onKeyDown(
this.createMockKeyDownEvent(KeyCode.CONTROL, {ctrlKey: true}));
assertFalse(closed);
assertFalse(finished);
keyboardHandler.onKeyDown(this.createMockKeyDownEvent(
KeyCode.ALT, {ctrlKey: true, altKey: true}));
assertFalse(closed);
assertFalse(finished);
keyboardHandler.onKeyDown(
this.createMockKeyDownEvent(KeyCode.Z, {ctrlKey: true, altKey: true}));
assertTrue(closed);
// |finished| remains false since we didn't press the expected key sequence.
assertFalse(finished);
});
});
...@@ -737,7 +737,7 @@ TtsBackground = class extends ChromeTtsBase { ...@@ -737,7 +737,7 @@ TtsBackground = class extends ChromeTtsBase {
} }
// Only pronounce phonetic hints when explicitly requested. // Only pronounce phonetic hints when explicitly requested.
if (!properties.phoneticCharacters) { if (!properties['phoneticCharacters']) {
return; return;
} }
......
...@@ -291,6 +291,9 @@ Panel = class { ...@@ -291,6 +291,9 @@ Panel = class {
Panel.openAnnotationsUI(command.data); Panel.openAnnotationsUI(command.data);
} }
break; break;
case PanelCommandType.CLOSE_CHROMEVOX:
Panel.onClose();
break;
} }
} }
......
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