Commit 099889e8 authored by plundblad's avatar plundblad Committed by Commit bot

Refactorings to reduce dependencies in ChromeVox 2.

Mainly, this breaks out braille span classes and the EditableTextBase
class into their own files.  This removes lots of dependencies on code that
should only run in the content script in ChromeVox classic from the
ChromeVox next background script.

BUG=

Review URL: https://codereview.chromium.org/889593002

Cr-Commit-Position: refs/heads/master@{#313895}
parent b64a083c
......@@ -133,9 +133,8 @@ cvox.BrailleInputHandler.prototype.init = function() {
* spans.
*/
cvox.BrailleInputHandler.prototype.onDisplayContentChanged = function(text) {
var valueSpan = text.getSpanInstanceOf(cvox.BrailleUtil.ValueSpan);
var selectionSpan = text.getSpanInstanceOf(
cvox.BrailleUtil.ValueSelectionSpan);
var valueSpan = text.getSpanInstanceOf(cvox.ValueSpan);
var selectionSpan = text.getSpanInstanceOf(cvox.ValueSelectionSpan);
if (!(valueSpan && selectionSpan)) {
return;
}
......
......@@ -391,7 +391,6 @@ CvoxBrailleInputHandlerUnitTest.prototype = {
closureModuleDeps: [
'cvox.BrailleInputHandler',
'cvox.BrailleUtil',
'cvox.Spannable',
],
/**
......
......@@ -9,9 +9,10 @@
goog.provide('cvox.ExpandingBrailleTranslator');
goog.require('cvox.BrailleUtil');
goog.require('cvox.LibLouis');
goog.require('cvox.Spannable');
goog.require('cvox.ValueSelectionSpan');
goog.require('cvox.ValueSpan');
/**
......@@ -48,7 +49,7 @@ cvox.ExpandingBrailleTranslator =
/**
* What expansion to apply to the part of the translated string marked by the
* {@code cvox.BrailleUtil.ValueSpan} spannable.
* {@code cvox.ValueSpan} spannable.
* @enum {number}
*/
cvox.ExpandingBrailleTranslator.ExpansionType = {
......@@ -200,7 +201,7 @@ cvox.ExpandingBrailleTranslator.prototype.findExpandRanges_ = function(
var result = [];
if (this.uncontractedTranslator_ &&
expansionType != cvox.ExpandingBrailleTranslator.ExpansionType.NONE) {
var value = text.getSpanInstanceOf(cvox.BrailleUtil.ValueSpan);
var value = text.getSpanInstanceOf(cvox.ValueSpan);
if (value) {
// The below type casts are valid because the ranges must be valid when
// the span is known to exist.
......@@ -234,8 +235,7 @@ cvox.ExpandingBrailleTranslator.prototype.findExpandRanges_ = function(
*/
cvox.ExpandingBrailleTranslator.prototype.addRangesForSelection_ = function(
text, valueStart, valueEnd, outRanges) {
var selection = text.getSpanInstanceOf(
cvox.BrailleUtil.ValueSelectionSpan);
var selection = text.getSpanInstanceOf(cvox.ValueSelectionSpan);
if (!selection) {
return;
}
......
......@@ -18,10 +18,11 @@ CvoxExpandingBrailleTranslatorUnitTest.prototype = {
/** @override */
closureModuleDeps: [
'cvox.BrailleUtil',
'cvox.ExpandingBrailleTranslator',
'cvox.LibLouis',
'cvox.Spannable',
'cvox.ValueSelectionSpan',
'cvox.ValueSpan',
]
};
......@@ -73,8 +74,8 @@ function assertArrayBufferMatches(expected, actual) {
TEST_F('CvoxExpandingBrailleTranslatorUnitTest', 'TranslationError',
function() {
var text = new cvox.Spannable('error ok', new cvox.BrailleUtil.ValueSpan());
text.setSpan(new cvox.BrailleUtil.ValueSelectionSpan, 0, 0);
var text = new cvox.Spannable('error ok', new cvox.ValueSpan());
text.setSpan(new cvox.ValueSelectionSpan, 0, 0);
var contractedTranslator = new FakeTranslator('c');
// Translator that always results in an error.
var uncontractedTranslator = {
......@@ -199,11 +200,10 @@ function runTranslationTestVariants(testCase, contracted, valueExpansion) {
function createText(text, opt_selectionStart, opt_selectionEnd) {
var result = new cvox.Spannable(text);
result.setSpan(
new cvox.BrailleUtil.ValueSpan, 0, text.length);
result.setSpan(new cvox.ValueSpan, 0, text.length);
if (goog.isDef(opt_selectionStart)) {
result.setSpan(
new cvox.BrailleUtil.ValueSelectionSpan,
new cvox.ValueSelectionSpan,
opt_selectionStart,
goog.isDef(opt_selectionEnd) ? opt_selectionEnd : opt_selectionStart);
}
......
// Copyright 2015 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 Objects used in spannables as annotations for ARIA values
* and selections.
*/
goog.provide('cvox.ValueSelectionSpan');
goog.provide('cvox.ValueSpan');
goog.require('cvox.Spannable');
/**
* Attached to the value region of a braille spannable.
* @param {number} offset The offset of the span into the value.
* @constructor
*/
cvox.ValueSpan = function(offset) {
/**
* The offset of the span into the value.
* @type {number}
*/
this.offset = offset;
};
/**
* Creates a value span from a json serializable object.
* @param {!Object} obj The json serializable object to convert.
* @return {!cvox.ValueSpan} The value span.
*/
cvox.ValueSpan.fromJson = function(obj) {
return new cvox.ValueSpan(obj.offset);
};
/**
* Converts this object to a json serializable object.
* @return {!Object} The JSON representation.
*/
cvox.ValueSpan.prototype.toJson = function() {
return this;
};
cvox.Spannable.registerSerializableSpan(
cvox.ValueSpan,
'cvox.ValueSpan',
cvox.ValueSpan.fromJson,
cvox.ValueSpan.prototype.toJson);
/**
* Attached to the selected text within a value.
* @constructor
*/
cvox.ValueSelectionSpan = function() {
};
cvox.Spannable.registerStatelessSerializableSpan(
cvox.ValueSelectionSpan,
'cvox.ValueSelectionSpan');
......@@ -12,6 +12,7 @@ goog.provide('cvox.TabsApiHandler');
goog.require('cvox.AbstractEarcons');
goog.require('cvox.AbstractTts');
goog.require('cvox.BrailleInterface');
goog.require('cvox.ChromeVox');
goog.require('cvox.NavBraille');
......
......@@ -8,15 +8,16 @@
goog.provide('cvox.BrailleUtil');
goog.provide('cvox.BrailleUtil.ValueSelectionSpan');
goog.provide('cvox.BrailleUtil.ValueSpan');
goog.require('cvox.ChromeVox');
goog.require('cvox.DomUtil');
goog.require('cvox.EditableTextAreaShadow');
goog.require('cvox.Focuser');
goog.require('cvox.NavBraille');
goog.require('cvox.NodeStateUtil');
goog.require('cvox.Spannable');
goog.require('cvox.ValueSelectionSpan');
goog.require('cvox.ValueSpan');
/**
......@@ -80,59 +81,6 @@ cvox.BrailleUtil.TEMPLATE = {
};
/**
* Attached to the value region of a braille spannable.
* @param {number} offset The offset of the span into the value.
* @constructor
*/
cvox.BrailleUtil.ValueSpan = function(offset) {
/**
* The offset of the span into the value.
* @type {number}
*/
this.offset = offset;
};
/**
* Creates a value span from a json serializable object.
* @param {!Object} obj The json serializable object to convert.
* @return {!cvox.BrailleUtil.ValueSpan} The value span.
*/
cvox.BrailleUtil.ValueSpan.fromJson = function(obj) {
return new cvox.BrailleUtil.ValueSpan(obj.offset);
};
/**
* Converts this object to a json serializable object.
* @return {!Object} The JSON representation.
*/
cvox.BrailleUtil.ValueSpan.prototype.toJson = function() {
return this;
};
cvox.Spannable.registerSerializableSpan(
cvox.BrailleUtil.ValueSpan,
'cvox.BrailleUtil.ValueSpan',
cvox.BrailleUtil.ValueSpan.fromJson,
cvox.BrailleUtil.ValueSpan.prototype.toJson);
/**
* Attached to the selected text within a value.
* @constructor
*/
cvox.BrailleUtil.ValueSelectionSpan = function() {
};
cvox.Spannable.registerStatelessSerializableSpan(
cvox.BrailleUtil.ValueSelectionSpan,
'cvox.BrailleUtil.ValueSelectionSpan');
/**
* Gets the braille name for a node.
* See DomUtil for a more precise definition of 'name'.
......@@ -220,8 +168,8 @@ cvox.BrailleUtil.getContainer = function(prev, node) {
/**
* Gets the braille value of a node. A cvox.BrailleUtil.ValueSpan will be
* attached, along with (possibly) a cvox.BrailleUtil.ValueSelectionSpan.
* Gets the braille value of a node. A {@code cvox.ValueSpan} will be
* attached, along with (possibly) a {@code cvox.ValueSelectionSpan}.
* @param {Node} node The node.
* @return {!cvox.Spannable} The value spannable.
*/
......@@ -229,7 +177,7 @@ cvox.BrailleUtil.getValue = function(node) {
if (!node) {
return new cvox.Spannable();
}
var valueSpan = new cvox.BrailleUtil.ValueSpan(0 /* offset */);
var valueSpan = new cvox.ValueSpan(0 /* offset */);
if (cvox.DomUtil.isInputTypeText(node)) {
var value = node.value;
if (node.type === 'password') {
......@@ -242,7 +190,7 @@ cvox.BrailleUtil.getValue = function(node) {
node.selectionStart, 0, spannable.getLength());
var selectionEnd = cvox.BrailleUtil.clamp_(
node.selectionEnd, 0, spannable.getLength());
spannable.setSpan(new cvox.BrailleUtil.ValueSelectionSpan(),
spannable.setSpan(new cvox.ValueSelectionSpan(),
Math.min(selectionStart, selectionEnd),
Math.max(selectionStart, selectionEnd));
}
......@@ -261,7 +209,7 @@ cvox.BrailleUtil.getValue = function(node) {
node.selectionStart - lineStart, 0, spannable.getLength());
var selectionEnd = cvox.BrailleUtil.clamp_(
node.selectionEnd - lineStart, 0, spannable.getLength());
spannable.setSpan(new cvox.BrailleUtil.ValueSelectionSpan(),
spannable.setSpan(new cvox.ValueSelectionSpan(),
Math.min(selectionStart, selectionEnd),
Math.max(selectionStart, selectionEnd));
}
......@@ -333,7 +281,7 @@ cvox.BrailleUtil.getTemplated = function(prev, node, opt_override) {
if (!component.toString() && template[i + 1] == ' ' &&
(!(component instanceof cvox.Spannable) ||
!/**@type {cvox.Spannable}*/(component).getSpanInstanceOf(
cvox.BrailleUtil.ValueSelectionSpan))) {
cvox.ValueSelectionSpan))) {
i++;
}
}
......@@ -343,8 +291,8 @@ cvox.BrailleUtil.getTemplated = function(prev, node, opt_override) {
/**
* Creates a braille value from a string and, optionally, a selection range.
* A cvox.BrailleUtil.ValueSpan will be
* attached, along with a cvox.BrailleUtil.ValueSelectionSpan if applicable.
* A {@code cvox.ValueSpan} will be attached, along with a
* {@code cvox.ValueSelectionSpan} if applicable.
* @param {string} text The text to display as the value.
* @param {number=} opt_selStart Selection start.
* @param {number=} opt_selEnd Selection end if different from selection start.
......@@ -354,7 +302,7 @@ cvox.BrailleUtil.getTemplated = function(prev, node, opt_override) {
cvox.BrailleUtil.createValue = function(text, opt_selStart, opt_selEnd,
opt_textOffset) {
var spannable = new cvox.Spannable(
text, new cvox.BrailleUtil.ValueSpan(opt_textOffset || 0));
text, new cvox.ValueSpan(opt_textOffset || 0));
if (goog.isDef(opt_selStart)) {
opt_selEnd = goog.isDef(opt_selEnd) ? opt_selEnd : opt_selStart;
// TODO(plundblad): This looses the distinction between the selection
......@@ -366,8 +314,7 @@ cvox.BrailleUtil.createValue = function(text, opt_selStart, opt_selEnd,
opt_selEnd = temp;
}
spannable.setSpan(new cvox.BrailleUtil.ValueSelectionSpan(),
opt_selStart, opt_selEnd);
spannable.setSpan(new cvox.ValueSelectionSpan(), opt_selStart, opt_selEnd);
}
return spannable;
};
......@@ -395,7 +342,7 @@ cvox.BrailleUtil.click = function(braille, opt_displayPosition) {
node instanceof HTMLTextAreaElement)) {
var valueSpan = spans.filter(
function(s) {
return s instanceof cvox.BrailleUtil.ValueSpan;
return s instanceof cvox.ValueSpan;
})[0];
if (valueSpan) {
if (document.activeElement !== node) {
......
......@@ -389,32 +389,32 @@ TEST_F('CvoxBrailleUtilUnitTest', 'CreateValue', function() {
// Value without a selection.
s = cvox.BrailleUtil.createValue('value');
assertEquals('value', s.toString());
assertUndefined(s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan));
valueSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSpan);
assertUndefined(s.getSpanInstanceOf(cvox.ValueSelectionSpan));
valueSpan = s.getSpanInstanceOf(cvox.ValueSpan);
assertEquals(0, s.getSpanStart(valueSpan));
assertEquals(s.getLength(), s.getSpanEnd(valueSpan));
// Value with a carret at the start of the text.
s = cvox.BrailleUtil.createValue('value', 0);
selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
selectionSpan = s.getSpanInstanceOf(cvox.ValueSelectionSpan);
assertEquals(0, s.getSpanStart(selectionSpan));
assertEquals(0, s.getSpanEnd(selectionSpan));
// Value with a carret inside the text.
s = cvox.BrailleUtil.createValue('value', 1);
selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
selectionSpan = s.getSpanInstanceOf(cvox.ValueSelectionSpan);
assertEquals(1, s.getSpanStart(selectionSpan));
assertEquals(1, s.getSpanEnd(selectionSpan));
// Value with a carret at the end of the text.
s = cvox.BrailleUtil.createValue('value', 5);
selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
selectionSpan = s.getSpanInstanceOf(cvox.ValueSelectionSpan);
assertEquals(5, s.getSpanStart(selectionSpan));
assertEquals(5, s.getSpanEnd(selectionSpan));
// All of the value selected selected with reversed start and end.
s = cvox.BrailleUtil.createValue('value', 5, 0);
selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
selectionSpan = s.getSpanInstanceOf(cvox.ValueSelectionSpan);
assertEquals(0, s.getSpanStart(selectionSpan));
assertEquals(5, s.getSpanEnd(selectionSpan));
});
......@@ -95,6 +95,7 @@ CvoxEditableTextUnitTest.prototype = {
/** @override */
closureModuleDeps: [
'cvox.ChromeVoxEditableElement',
'cvox.ChromeVoxEditableHTMLInput',
'cvox.ChromeVoxEditableTextBase',
'cvox.ChromeVoxEventWatcher',
......@@ -275,7 +276,7 @@ TEST_F('CvoxEditableTextUnitTest', 'Selection', function() {
TEST_F('CvoxEditableTextUnitTest', 'MultiLineText', function() {
var str = 'This string\nspans\nfive lines.\n \n';
var tts = new TestTts();
var obj = new cvox.ChromeVoxEditableTextBase(str, 0, 0, false, tts);
var obj = new cvox.ChromeVoxEditableElement(null, str, 0, 0, false, tts);
obj.multiline = true;
obj.getLineIndex = function(index) {
if (index >= 33) {
......
......@@ -18,15 +18,6 @@ goog.require('cursors.Cursor');
goog.require('cvox.ChromeVoxEditableTextBase');
goog.require('cvox.TabsApiHandler');
// Define types here due to editable_text.js's implicit dependency with
// ChromeVoxEventWatcher.
/** @type {Object} */
cvox.ChromeVoxEventWatcher;
/** @type {function(boolean)} */
cvox.ChromeVoxEventWatcher.handleTextChanged;
/** @type {function()} */
cvox.ChromeVoxEventWatcher.setUpTextHandler;
goog.scope(function() {
var AutomationNode = chrome.automation.AutomationNode;
var Dir = AutomationUtil.Dir;
......
......@@ -13,9 +13,9 @@ goog.require('AutomationUtil.Dir');
goog.require('cursors.Cursor');
goog.require('cursors.Range');
goog.require('cursors.Unit');
goog.require('cvox.BrailleUtil.ValueSelectionSpan');
goog.require('cvox.BrailleUtil.ValueSpan');
goog.require('cvox.Spannable');
goog.require('cvox.ValueSelectionSpan');
goog.require('cvox.ValueSpan');
goog.scope(function() {
var Dir = AutomationUtil.Dir;
......@@ -338,9 +338,9 @@ Output.prototype = {
} else {
startIndex = valueStart + selSpan.startIndex;
endIndex = valueStart + selSpan.endIndex;
this.brailleBuffer_.setSpan(new cvox.BrailleUtil.ValueSpan(valueStart),
this.brailleBuffer_.setSpan(new cvox.ValueSpan(valueStart),
valueStart, valueEnd);
this.brailleBuffer_.setSpan(new cvox.BrailleUtil.ValueSelectionSpan(),
this.brailleBuffer_.setSpan(new cvox.ValueSelectionSpan(),
startIndex, endIndex);
}
}
......
......@@ -24,9 +24,10 @@ CvoxBrailleIntegrationUnitTest.prototype = {
'cvox.BrailleBackground',
'cvox.BrailleInputHandler',
'cvox.BrailleKeyCommand',
'cvox.BrailleUtil',
'cvox.ChromeBraille',
'cvox.ExpandingBrailleTranslator',
'cvox.ValueSelectionSpan',
'cvox.ValueSpan',
],
/** @override */
......@@ -146,8 +147,8 @@ TEST_F('CvoxBrailleIntegrationUnitTest', 'Write', function() {
});
TEST_F('CvoxBrailleIntegrationUnitTest', 'WriteWithSpans', function() {
var selectionSpan = new cvox.BrailleUtil.ValueSelectionSpan();
var valueSpan = new cvox.BrailleUtil.ValueSpan(20);
var selectionSpan = new cvox.ValueSelectionSpan();
var valueSpan = new cvox.ValueSpan(20);
var toSend = cvox.NavBraille.fromText(
new cvox.Spannable('Hello', valueSpan));
toSend.text.setSpan(selectionSpan, 0, 0);
......
......@@ -214,8 +214,7 @@ cvox.LayoutLineWalker.prototype.extend_ = function(start) {
cvox.LayoutLineWalker.prototype.appendBraille_ = function(
prevSel, sel, cur, braille) {
var item = this.subWalker_.getBraille(prevSel, cur).text;
var valueSelectionSpan = item.getSpanInstanceOf(
cvox.BrailleUtil.ValueSelectionSpan);
var valueSelectionSpan = item.getSpanInstanceOf(cvox.ValueSelectionSpan);
if (braille.text.getLength() > 0) {
braille.text.append(cvox.BrailleUtil.ITEM_SEPARATOR);
......
......@@ -10,6 +10,7 @@
goog.provide('cvox.StructuralLineWalker');
goog.require('cvox.AbstractSelectionWalker');
goog.require('cvox.BrailleUtil');
goog.require('cvox.TraverseContent');
/**
......
......@@ -17,7 +17,6 @@ CvoxStructuralLineWalkerUnitTest.prototype = {
/** @override */
closureModuleDeps: [
'cvox.BrailleUtil',
'cvox.StructuralLineWalker',
'cvox.TestMsgs',
],
......
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