Commit 686dd212 authored by Katie D's avatar Katie D Committed by Commit Bot

Refactor an InputHandler from SelectToSpeak.

The SelectToSpeak class is messy and should be refactored to separate
the input handling, state logic, and output handling. This is the first
part of that refactor.

Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: If53dc7f85b223641e82533c82ab89aa50719d198
Reviewed-on: https://chromium-review.googlesource.com/1136842
Commit-Queue: Katie Dektar <katie@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575800}
parent b4e6da64
...@@ -34,6 +34,7 @@ run_jsbundler("select_to_speak_copied_files") { ...@@ -34,6 +34,7 @@ run_jsbundler("select_to_speak_copied_files") {
"checked.png", "checked.png",
"closure_shim.js", "closure_shim.js",
"earcons/null_selection.ogg", "earcons/null_selection.ogg",
"input_handler.js",
"node_utils.js", "node_utils.js",
"options.css", "options.css",
"options.html", "options.html",
...@@ -169,6 +170,7 @@ js_type_check("closure_compile") { ...@@ -169,6 +170,7 @@ js_type_check("closure_compile") {
":../chromevox/cvox2/background/constants", ":../chromevox/cvox2/background/constants",
":../chromevox/cvox2/background/tree_walker", ":../chromevox/cvox2/background/tree_walker",
":closure_shim", ":closure_shim",
":input_handler",
":node_utils", ":node_utils",
":paragraph_utils", ":paragraph_utils",
":rect_utils", ":rect_utils",
...@@ -182,6 +184,7 @@ js_library("select_to_speak") { ...@@ -182,6 +184,7 @@ js_library("select_to_speak") {
deps = [ deps = [
":../chromevox/cvox2/background/automation_util", ":../chromevox/cvox2/background/automation_util",
":../chromevox/cvox2/background/constants", ":../chromevox/cvox2/background/constants",
":input_handler",
":node_utils", ":node_utils",
":paragraph_utils", ":paragraph_utils",
":rect_utils", ":rect_utils",
...@@ -238,6 +241,12 @@ js_library("paragraph_utils") { ...@@ -238,6 +241,12 @@ js_library("paragraph_utils") {
] ]
} }
js_library("input_handler") {
deps = [
":rect_utils",
]
}
js_library("rect_utils") { js_library("rect_utils") {
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"automation_predicate.js", "automation_predicate.js",
"tree_walker.js", "tree_walker.js",
"automation_util.js", "automation_util.js",
"input_handler.js",
"node_utils.js", "node_utils.js",
"paragraph_utils.js", "paragraph_utils.js",
"word_utils.js", "word_utils.js",
......
...@@ -31,7 +31,7 @@ SelectToSpeakKeystrokeSelectionTest.prototype = { ...@@ -31,7 +31,7 @@ SelectToSpeakKeystrokeSelectionTest.prototype = {
{keyCode: SelectToSpeak.SEARCH_KEY_CODE}); {keyCode: SelectToSpeak.SEARCH_KEY_CODE});
selectToSpeak.fireMockKeyDownEvent( selectToSpeak.fireMockKeyDownEvent(
{keyCode: SelectToSpeak.READ_SELECTION_KEY_CODE}); {keyCode: SelectToSpeak.READ_SELECTION_KEY_CODE});
assertTrue(selectToSpeak.isSelectionKeyDown_); assertTrue(selectToSpeak.inputHandler_.isSelectionKeyDown_);
selectToSpeak.fireMockKeyUpEvent( selectToSpeak.fireMockKeyUpEvent(
{keyCode: SelectToSpeak.READ_SELECTION_KEY_CODE}); {keyCode: SelectToSpeak.READ_SELECTION_KEY_CODE});
selectToSpeak.fireMockKeyUpEvent( selectToSpeak.fireMockKeyUpEvent(
...@@ -51,7 +51,8 @@ SelectToSpeakKeystrokeSelectionTest.prototype = { ...@@ -51,7 +51,8 @@ SelectToSpeakKeystrokeSelectionTest.prototype = {
* @param {string} expected The expected string that will be read, ignoring * @param {string} expected The expected string that will be read, ignoring
* extra whitespace, after this selection is triggered. * extra whitespace, after this selection is triggered.
*/ */
testSimpleTextAtKeystroke: function(text, anchorOffset, focusOffset, expected) { testSimpleTextAtKeystroke: function(text, anchorOffset, focusOffset,
expected) {
this.testReadTextAtKeystroke('<p>' + text + '</p>', this.testReadTextAtKeystroke('<p>' + text + '</p>',
function(desktop) { function(desktop) {
// Set the document selection. This will fire the changed event // Set the document selection. This will fire the changed event
...@@ -245,8 +246,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', ...@@ -245,8 +246,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest',
// Using JS to do the selection instead of Automation, so that we can // Using JS to do the selection instead of Automation, so that we can
// ensure this is stable against changes in chrome.automation. // ensure this is stable against changes in chrome.automation.
let selectionCode = let selectionCode =
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(body, 1);' + 'range.setStart(body, 1);' +
'range.setEnd(body, 2);'; 'range.setEnd(body, 2);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<img id="one" src="pipe.jpg" alt="one"/>' + '<img id="one" src="pipe.jpg" alt="one"/>' +
...@@ -263,8 +264,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', ...@@ -263,8 +264,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest',
TEST_F('SelectToSpeakKeystrokeSelectionTest', TEST_F('SelectToSpeakKeystrokeSelectionTest',
'HandlesMultipleImagesCorrectlyWithJS2', function() { 'HandlesMultipleImagesCorrectlyWithJS2', function() {
let selectionCode = let selectionCode =
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(body, 1);' + 'range.setStart(body, 1);' +
'range.setEnd(body, 3);'; 'range.setEnd(body, 3);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<img id="one" src="pipe.jpg" alt="one"/>' + '<img id="one" src="pipe.jpg" alt="one"/>' +
...@@ -282,8 +283,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextFieldFullySelected', ...@@ -282,8 +283,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextFieldFullySelected',
function() { function() {
let selectionCode = let selectionCode =
'let p = document.getElementsByTagName("p")[0];' + 'let p = document.getElementsByTagName("p")[0];' +
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(p, 0);' + 'range.setStart(p, 0);' +
'range.setEnd(body, 2);'; 'range.setEnd(body, 2);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<p>paragraph</p>' + '<p>paragraph</p>' +
...@@ -301,8 +302,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextFieldFullySelected', ...@@ -301,8 +302,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextFieldFullySelected',
TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TwoTextFieldsFullySelected', TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TwoTextFieldsFullySelected',
function() { function() {
let selectionCode = let selectionCode =
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(body, 0);' + 'range.setStart(body, 0);' +
'range.setEnd(body, 2);'; 'range.setEnd(body, 2);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<input type="text" value="one"></input><textarea cols="5">two three</textarea>'), '<input type="text" value="one"></input><textarea cols="5">two three</textarea>'),
...@@ -325,8 +326,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextInputPartiallySelected', ...@@ -325,8 +326,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextInputPartiallySelected',
'let input = document.getElementById("input");' + 'let input = document.getElementById("input");' +
'input.focus();' + 'input.focus();' +
'input.setSelectionRange(5, 10);' + 'input.setSelectionRange(5, 10);' +
'}' + '}' +
'</script>' + '</script>' +
'<body onload="doSelection()">' + '<body onload="doSelection()">' +
'<input id="input" type="text" value="text field"></input>' + '<input id="input" type="text" value="text field"></input>' +
'</body>'; '</body>';
...@@ -347,8 +348,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextAreaPartiallySelected', ...@@ -347,8 +348,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextAreaPartiallySelected',
'let input = document.getElementById("input");' + 'let input = document.getElementById("input");' +
'input.focus();' + 'input.focus();' +
'input.setSelectionRange(6, 17);' + 'input.setSelectionRange(6, 17);' +
'}' + '}' +
'</script>' + '</script>' +
'<body onload="doSelection()">' + '<body onload="doSelection()">' +
'<textarea id="input" type="text" cols="10">first line second line</textarea>' + '<textarea id="input" type="text" cols="10">first line second line</textarea>' +
'</body>'; '</body>';
...@@ -364,8 +365,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextAreaPartiallySelected', ...@@ -364,8 +365,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'TextAreaPartiallySelected',
TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBr', TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBr',
function() { function() {
let selectionCode = let selectionCode =
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(body, 0);' + 'range.setStart(body, 0);' +
'range.setEnd(body, 3);'; 'range.setEnd(body, 3);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'Test<br/><br/>Unread'), function() { 'Test<br/><br/>Unread'), function() {
...@@ -381,8 +382,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBrComplex', ...@@ -381,8 +382,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBrComplex',
function() { function() {
let selectionCode = let selectionCode =
'let p = document.getElementsByTagName("p")[0];' + 'let p = document.getElementsByTagName("p")[0];' +
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(p, 0);' + 'range.setStart(p, 0);' +
'range.setEnd(body, 2);'; 'range.setEnd(body, 2);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<p>Some text</p><br/><br/>Unread'), function() { '<p>Some text</p><br/><br/>Unread'), function() {
...@@ -401,8 +402,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBrAfterText', ...@@ -401,8 +402,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBrAfterText',
// the further off it got. // the further off it got.
let selectionCode = let selectionCode =
'let p = document.getElementsByTagName("p")[0];' + 'let p = document.getElementsByTagName("p")[0];' +
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(p, 1);' + 'range.setStart(p, 1);' +
'range.setEnd(body, 2);'; 'range.setEnd(body, 2);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<p>Unread</p><p>Some text</p><br/>Unread'), function() { '<p>Unread</p><p>Some text</p><br/>Unread'), function() {
...@@ -417,8 +418,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBrAfterText', ...@@ -417,8 +418,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextWithBrAfterText',
TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextAreaAndBrs', TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextAreaAndBrs',
function() { function() {
let selectionCode = let selectionCode =
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(body, 1);' + 'range.setStart(body, 1);' +
'range.setEnd(body, 4);'; 'range.setEnd(body, 4);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<br/><br/><textarea>Some text</textarea><br/><br/>Unread'), '<br/><br/><textarea>Some text</textarea><br/><br/>Unread'),
...@@ -434,8 +435,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextAreaAndBrs', ...@@ -434,8 +435,8 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', 'HandlesTextAreaAndBrs',
TEST_F('SelectToSpeakKeystrokeSelectionTest', 'textFieldWithComboBoxSimple', TEST_F('SelectToSpeakKeystrokeSelectionTest', 'textFieldWithComboBoxSimple',
function() { function() {
let selectionCode = let selectionCode =
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(body, 0);' + 'range.setStart(body, 0);' +
'range.setEnd(body, 1);'; 'range.setEnd(body, 1);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'<input list="list" value="one"></label><datalist id="list">' + '<input list="list" value="one"></label><datalist id="list">' +
...@@ -460,11 +461,11 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', ...@@ -460,11 +461,11 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest',
'selection.removeAllRanges();' + 'selection.removeAllRanges();' +
'let p1 = document.getElementsByTagName("p")[0];' + 'let p1 = document.getElementsByTagName("p")[0];' +
'let p2 = document.getElementsByTagName("p")[1];' + 'let p2 = document.getElementsByTagName("p")[1];' +
'range.setStart(p1.firstChild, 1);' + 'range.setStart(p1.firstChild, 1);' +
'range.setEnd(p2.firstChild, 3);' + 'range.setEnd(p2.firstChild, 3);' +
'selection.addRange(range);' + 'selection.addRange(range);' +
'}' + '}' +
'</script>' + '</script>' +
'<body onload="doSelection()">' + '<body onload="doSelection()">' +
'<div id="input" contenteditable><p>a b c</p><p>d e f</p></div>' + '<div id="input" contenteditable><p>a b c</p><p>d e f</p></div>' +
'</body>'; '</body>';
...@@ -483,7 +484,7 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest', ...@@ -483,7 +484,7 @@ TEST_F('SelectToSpeakKeystrokeSelectionTest',
'contentEditableExternallySelected', function() { 'contentEditableExternallySelected', function() {
let selectionCode = let selectionCode =
'let body = document.getElementsByTagName("body")[0];' + 'let body = document.getElementsByTagName("body")[0];' +
'range.setStart(body, 1);' + 'range.setStart(body, 1);' +
'range.setEnd(body, 2);'; 'range.setEnd(body, 2);';
this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode, this.runWithLoadedTree(this.generateHtmlWithSelection(selectionCode,
'Unread <div id="input" contenteditable><p>a b c</p><p>d e f</p></div>' + 'Unread <div id="input" contenteditable><p>a b c</p><p>d e f</p></div>' +
......
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