Commit 45a22b64 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Makes more commands available when ChromeVox has no range

RELNOTES: Some ChromeVox commands can now be used when there's no focus e.g. speaking the battery status or opening the ChromeVox menus.
Change-Id: Ia997e6c201ae870af11af3f66a118aa1a4aa14fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147792Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758582}
parent 7b09715b
...@@ -278,6 +278,49 @@ CommandHandler.onCommand = function(command) { ...@@ -278,6 +278,49 @@ CommandHandler.onCommand = function(command) {
break; break;
default: default:
break; break;
case 'toggleKeyboardHelp':
(new PanelCommand(PanelCommandType.OPEN_MENUS)).send();
return false;
case 'showPanelMenuMostRecent':
(new PanelCommand(PanelCommandType.OPEN_MENUS_MOST_RECENT)).send();
return false;
case 'nextGranularity':
case 'previousGranularity': {
const backwards = command == 'previousGranularity';
let gran = GestureCommandHandler.granularity;
const next = backwards ?
(--gran >= 0 ? gran : GestureGranularity.COUNT - 1) :
++gran % GestureGranularity.COUNT;
GestureCommandHandler.granularity =
/** @type {GestureGranularity} */ (next);
let announce = '';
switch (GestureCommandHandler.granularity) {
case GestureGranularity.CHARACTER:
announce = Msgs.getMsg('character_granularity');
break;
case GestureGranularity.WORD:
announce = Msgs.getMsg('word_granularity');
break;
case GestureGranularity.LINE:
announce = Msgs.getMsg('line_granularity');
break;
}
ChromeVox.tts.speak(announce, QueueMode.FLUSH);
}
return false;
case 'announceBatteryDescription':
chrome.accessibilityPrivate.getBatteryDescription(function(
batteryDescription) {
new Output()
.withString(batteryDescription)
.withQueueMode(QueueMode.FLUSH)
.go();
});
break;
case 'resetTextToSpeechSettings':
ChromeVox.tts.resetTextToSpeechSettings();
return false;
} }
// Require a current range. // Require a current range.
...@@ -667,12 +710,6 @@ CommandHandler.onCommand = function(command) { ...@@ -667,12 +710,6 @@ CommandHandler.onCommand = function(command) {
return false; return false;
} }
break; break;
case 'toggleKeyboardHelp':
(new PanelCommand(PanelCommandType.OPEN_MENUS)).send();
return false;
case 'showPanelMenuMostRecent':
(new PanelCommand(PanelCommandType.OPEN_MENUS_MOST_RECENT)).send();
return false;
case 'showHeadingsList': case 'showHeadingsList':
(new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_heading')).send(); (new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_heading')).send();
return false; return false;
...@@ -915,40 +952,6 @@ CommandHandler.onCommand = function(command) { ...@@ -915,40 +952,6 @@ CommandHandler.onCommand = function(command) {
} }
CommandHandler.onCommand(command); CommandHandler.onCommand(command);
return false; return false;
case 'nextGranularity':
case 'previousGranularity': {
const backwards = command == 'previousGranularity';
let gran = GestureCommandHandler.granularity;
const next = backwards ?
(--gran >= 0 ? gran : GestureGranularity.COUNT - 1) :
++gran % GestureGranularity.COUNT;
GestureCommandHandler.granularity =
/** @type {GestureGranularity} */ (next);
let announce = '';
switch (GestureCommandHandler.granularity) {
case GestureGranularity.CHARACTER:
announce = Msgs.getMsg('character_granularity');
break;
case GestureGranularity.WORD:
announce = Msgs.getMsg('word_granularity');
break;
case GestureGranularity.LINE:
announce = Msgs.getMsg('line_granularity');
break;
}
ChromeVox.tts.speak(announce, QueueMode.FLUSH);
}
return false;
case 'announceBatteryDescription':
chrome.accessibilityPrivate.getBatteryDescription(function(
batteryDescription) {
new Output()
.withString(batteryDescription)
.withQueueMode(QueueMode.FLUSH)
.go();
});
break;
case 'announceRichTextDescription': { case 'announceRichTextDescription': {
const node = ChromeVoxState.instance.currentRange.start.node; const node = ChromeVoxState.instance.currentRange.start.node;
const optSubs = []; const optSubs = [];
...@@ -1050,9 +1053,6 @@ CommandHandler.onCommand = function(command) { ...@@ -1050,9 +1053,6 @@ CommandHandler.onCommand = function(command) {
.go(); .go();
} }
return false; return false;
case 'resetTextToSpeechSettings':
ChromeVox.tts.resetTextToSpeechSettings();
return false;
case 'toggleAnnotationsWidget': { case 'toggleAnnotationsWidget': {
if (!UserAnnotationHandler.instance.enabled) { if (!UserAnnotationHandler.instance.enabled) {
return false; return false;
......
...@@ -38,8 +38,7 @@ GestureCommandHandler.getEnabled = function() { ...@@ -38,8 +38,7 @@ GestureCommandHandler.getEnabled = function() {
* @private * @private
*/ */
GestureCommandHandler.onAccessibilityGesture_ = function(gesture) { GestureCommandHandler.onAccessibilityGesture_ = function(gesture) {
if (!GestureCommandHandler.enabled_ || if (!GestureCommandHandler.enabled_) {
!ChromeVoxState.instance.currentRange) {
return; return;
} }
...@@ -53,14 +52,17 @@ GestureCommandHandler.onAccessibilityGesture_ = function(gesture) { ...@@ -53,14 +52,17 @@ GestureCommandHandler.onAccessibilityGesture_ = function(gesture) {
Output.forceModeForNextSpeechUtterance(QueueMode.FLUSH); Output.forceModeForNextSpeechUtterance(QueueMode.FLUSH);
// Map gestures to arrow keys while within menus. // Map gestures to arrow keys while within menus.
const range = ChromeVoxState.instance.currentRange; if (ChromeVoxState.instance.currentRange) {
if (commandData.menuKeyOverride && range.start && range.start.node && const range = ChromeVoxState.instance.currentRange;
range.start.node.role == RoleType.MENU_ITEM && if (commandData.menuKeyOverride && range.start && range.start.node &&
(range.start.node.root.docUrl.indexOf(chrome.extension.getURL('')) == 0 || range.start.node.role == RoleType.MENU_ITEM &&
range.start.node.root.role == RoleType.DESKTOP)) { (range.start.node.root.docUrl.indexOf(chrome.extension.getURL('')) ==
const key = commandData.keyOverride; 0 ||
BackgroundKeyboardHandler.sendKeyPress(key.keyCode, key.modifiers); range.start.node.root.role == RoleType.DESKTOP)) {
return; const key = commandData.keyOverride;
BackgroundKeyboardHandler.sendKeyPress(key.keyCode, key.modifiers);
return;
}
} }
const textEditHandler = DesktopAutomationHandler.instance.textEditHandler; const textEditHandler = DesktopAutomationHandler.instance.textEditHandler;
......
...@@ -476,7 +476,8 @@ Panel = class { ...@@ -476,7 +476,8 @@ Panel = class {
{menuTitle: 'role_table', predicate: AutomationPredicate.table} {menuTitle: 'role_table', predicate: AutomationPredicate.table}
]; ];
const node = bkgnd.ChromeVoxState.instance.getCurrentRange().start.node; const range = bkgnd.ChromeVoxState.instance.getCurrentRange();
const node = range ? range.start.node : null;
for (let i = 0; i < roleListMenuMapping.length; ++i) { for (let i = 0; i < roleListMenuMapping.length; ++i) {
const menuTitle = roleListMenuMapping[i].menuTitle; const menuTitle = roleListMenuMapping[i].menuTitle;
const predicate = roleListMenuMapping[i].predicate; const predicate = roleListMenuMapping[i].predicate;
...@@ -487,7 +488,7 @@ Panel = class { ...@@ -487,7 +488,7 @@ Panel = class {
Panel.addNodeMenu(menuTitle, node, predicate, async); Panel.addNodeMenu(menuTitle, node, predicate, async);
} }
if (node.standardActions) { if (node && node.standardActions) {
for (let i = 0; i < node.standardActions.length; i++) { for (let i = 0; i < node.standardActions.length; i++) {
const standardAction = node.standardActions[i]; const standardAction = node.standardActions[i];
const actionMsg = Panel.ACTION_TO_MSG_ID[standardAction]; const actionMsg = Panel.ACTION_TO_MSG_ID[standardAction];
...@@ -502,7 +503,7 @@ Panel = class { ...@@ -502,7 +503,7 @@ Panel = class {
} }
} }
if (node.customActions) { if (node && node.customActions) {
for (let i = 0; i < node.customActions.length; i++) { for (let i = 0; i < node.customActions.length; i++) {
const customAction = node.customActions[i]; const customAction = node.customActions[i];
actionsMenu.addMenuItem( actionsMenu.addMenuItem(
......
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