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) {
break;
default:
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.
......@@ -667,12 +710,6 @@ CommandHandler.onCommand = function(command) {
return false;
}
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':
(new PanelCommand(PanelCommandType.OPEN_MENUS, 'role_heading')).send();
return false;
......@@ -915,40 +952,6 @@ CommandHandler.onCommand = function(command) {
}
CommandHandler.onCommand(command);
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': {
const node = ChromeVoxState.instance.currentRange.start.node;
const optSubs = [];
......@@ -1050,9 +1053,6 @@ CommandHandler.onCommand = function(command) {
.go();
}
return false;
case 'resetTextToSpeechSettings':
ChromeVox.tts.resetTextToSpeechSettings();
return false;
case 'toggleAnnotationsWidget': {
if (!UserAnnotationHandler.instance.enabled) {
return false;
......
......@@ -38,8 +38,7 @@ GestureCommandHandler.getEnabled = function() {
* @private
*/
GestureCommandHandler.onAccessibilityGesture_ = function(gesture) {
if (!GestureCommandHandler.enabled_ ||
!ChromeVoxState.instance.currentRange) {
if (!GestureCommandHandler.enabled_) {
return;
}
......@@ -53,14 +52,17 @@ GestureCommandHandler.onAccessibilityGesture_ = function(gesture) {
Output.forceModeForNextSpeechUtterance(QueueMode.FLUSH);
// Map gestures to arrow keys while within menus.
const range = ChromeVoxState.instance.currentRange;
if (commandData.menuKeyOverride && range.start && range.start.node &&
range.start.node.role == RoleType.MENU_ITEM &&
(range.start.node.root.docUrl.indexOf(chrome.extension.getURL('')) == 0 ||
range.start.node.root.role == RoleType.DESKTOP)) {
const key = commandData.keyOverride;
BackgroundKeyboardHandler.sendKeyPress(key.keyCode, key.modifiers);
return;
if (ChromeVoxState.instance.currentRange) {
const range = ChromeVoxState.instance.currentRange;
if (commandData.menuKeyOverride && range.start && range.start.node &&
range.start.node.role == RoleType.MENU_ITEM &&
(range.start.node.root.docUrl.indexOf(chrome.extension.getURL('')) ==
0 ||
range.start.node.root.role == RoleType.DESKTOP)) {
const key = commandData.keyOverride;
BackgroundKeyboardHandler.sendKeyPress(key.keyCode, key.modifiers);
return;
}
}
const textEditHandler = DesktopAutomationHandler.instance.textEditHandler;
......
......@@ -476,7 +476,8 @@ Panel = class {
{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) {
const menuTitle = roleListMenuMapping[i].menuTitle;
const predicate = roleListMenuMapping[i].predicate;
......@@ -487,7 +488,7 @@ Panel = class {
Panel.addNodeMenu(menuTitle, node, predicate, async);
}
if (node.standardActions) {
if (node && node.standardActions) {
for (let i = 0; i < node.standardActions.length; i++) {
const standardAction = node.standardActions[i];
const actionMsg = Panel.ACTION_TO_MSG_ID[standardAction];
......@@ -502,7 +503,7 @@ Panel = class {
}
}
if (node.customActions) {
if (node && node.customActions) {
for (let i = 0; i < node.customActions.length; i++) {
const customAction = node.customActions[i];
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