Commit eb58a0e1 authored by David Tseng's avatar David Tseng Committed by Chromium LUCI CQ

Reland "Refactor intent usage in ChromeVox"

This is a reland of 39716b26

Original change's description:
> Refactor intent usage in ChromeVox
>
> This is a purely refactoring change to set up ChromeVox to use all
> possible intents. IntentHandler, the newly introduced class, will
> cleanly process all intents, along with whatever computed metadata is
> needed (e.g. EditableLine).
>
> R=akihiroota@chromium.org, nektar@chromium.org
>
> AX-Relnotes: n/a
> Test: existing browser_tests --gtest_filter=ChromeVoxEditing*.*
> Change-Id: I74d9454794fc6a40075bbf56fb0037b607c2b974
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2594240
> Commit-Queue: David Tseng <dtseng@chromium.org>
> Reviewed-by: Akihiro Ota <akihiroota@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#838241}
TBR=akihiroota@chromium.org, nektar@chromium.org, dtseng@chromium.org

Change-Id: I4fa306dc747cd623cdbb38f11c8ace144730af57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601639
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarLan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839027}
parent 22326118
......@@ -48,7 +48,9 @@ chromevox_modules = [
"background/desktop_automation_handler.js",
"background/download_handler.js",
"background/earcon_engine.js",
"background/editing.js",
"background/editing/editable_line.js",
"background/editing/editing.js",
"background/editing/intent_handler.js",
"background/event_source.js",
"background/find_handler.js",
"background/focus_automation_handler.js",
......@@ -450,7 +452,7 @@ if (is_chromeos_ash) {
"background/color_test.js",
"background/cursors_test.js",
"background/download_handler_test.js",
"background/editing_test.js",
"background/editing/editing_test.js",
"background/keyboard_handler_test.js",
"background/live_regions_test.js",
"background/locale_output_helper_test.js",
......
......@@ -267,7 +267,8 @@ TEST_F(
`
<div role="textbox" contenteditable>
<p style="font-size:20px; font-family:times">
<b style="color:#ff0000">Move</b> <i>through</i> <u style="font-family:georgia">text</u>
<b style="color:#ff0000">Move</b>
<i>through</i> <u style="font-family:georgia">text</u>
by <strike style="font-size:12px; color:#0000ff">character</strike>
<a href="#">test</a>!
</p>
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Handles automation intents for speech feedback.
*/
goog.provide('IntentHandler');
goog.require('editing.EditableLine');
goog.scope(function() {
const AutomationIntent = chrome.automation.AutomationIntent;
const IntentCommandType = chrome.automation.IntentCommandType;
const IntentTextBoundaryType = chrome.automation.IntentTextBoundaryType;
/**
* A stateless class that turns intents into speech.
*/
IntentHandler = class {
/**
* Called when intents are received from an AutomationEvent.
* @param {!Array<AutomationIntent>} intents
* @param {!editing.EditableLine} cur The current line.
* @param {editing.EditableLine} prev The previous line.
* @return {boolean} Whether intents are handled.
*/
static onIntents(intents, cur, prev) {
if (intents.length === 0) {
return false;
}
// Currently, discard all other intents once one is handled.
for (let i = 0; i < intents.length; i++) {
if (IntentHandler.onIntent(intents[i], cur, prev)) {
return true;
}
}
return false;
}
/**
* Called when an intent is received.
* @param {!AutomationIntent} intent
* @param {!editing.EditableLine} cur The current line.
* @param {editing.EditableLine} prev The previous line.
* @return {boolean} Whether the intent was handled.
*/
static onIntent(intent, cur, prev) {
switch (intent.command) {
case IntentCommandType.MOVE_SELECTION:
return IntentHandler.onMoveSelection(intent, cur, prev);
// TODO: implement support.
case IntentCommandType.CLEAR_SELECTION:
case IntentCommandType.DELETE:
case IntentCommandType.DICTATE:
case IntentCommandType.EXTEND_SELECTION:
case IntentCommandType.FORMAT:
case IntentCommandType.HISTORY:
case IntentCommandType.INSERT:
case IntentCommandType.MARKER:
case IntentCommandType.SET_SELECTION:
break;
}
return false;
}
/**
* Called when the text selection moves.
* @param {!AutomationIntent} intent A move selection
* intent.
* @param {!editing.EditableLine} cur The current line.
* @param {editing.EditableLine} prev The previous line.
* @return {boolean} Whether the intent was handled.
*/
static onMoveSelection(intent, cur, prev) {
switch (intent.textBoundary) {
case IntentTextBoundaryType.CHARACTER:
// Read character to the right of the cursor. It is assumed to be a new
// line if empty.
// TODO: detect when this is the end of the document; read "end of text"
// if so.
ChromeVox.tts.speak(
cur.text.substring(cur.startOffset, cur.startOffset + 1) || '\n',
QueueMode.CATEGORY_FLUSH);
return true;
case IntentTextBoundaryType.LINE_END:
case IntentTextBoundaryType.LINE_START:
case IntentTextBoundaryType.LINE_START_OR_END:
cur.speakLine(prev);
return true;
// TODO: implement support.
case IntentTextBoundaryType.FORMAT:
case IntentTextBoundaryType.OBJECT:
case IntentTextBoundaryType.PAGE_END:
case IntentTextBoundaryType.PAGE_START:
case IntentTextBoundaryType.PAGE_START_OR_END:
case IntentTextBoundaryType.PARAGRAPH_END:
case IntentTextBoundaryType.PARAGRAPH_START:
case IntentTextBoundaryType.PARAGRAPH_START_OR_END:
case IntentTextBoundaryType.SENTENCE_END:
case IntentTextBoundaryType.SENTENCE_START:
case IntentTextBoundaryType.SENTENCE_START_OR_END:
case IntentTextBoundaryType.WEB_PAGE:
case IntentTextBoundaryType.WORD_END:
case IntentTextBoundaryType.WORD_START:
case IntentTextBoundaryType.WORD_START_OR_END:
break;
}
return false;
}
};
}); // goog.scope
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