Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5710)

Unified Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
index b3e95556bf0f20b6d1b6711937e99fc645581992..7142a0e773bb4b22448e356ac01491c95241af20 100644
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
@@ -88,12 +88,13 @@ cursors.Cursor = function(node, index) {
node = nextNode;
index = 0;
}
- } else if (node.role == RoleType.GENERIC_CONTAINER &&
- node.state.richlyEditable &&
- (node.firstChild && (node.firstChild.role == RoleType.LINE_BREAK ||
- node.firstChild.role == RoleType.STATIC_TEXT))) {
+ } else if (
+ node.role == RoleType.GENERIC_CONTAINER && node.state.richlyEditable &&
+ (node.firstChild &&
+ (node.firstChild.role == RoleType.LINE_BREAK ||
+ node.firstChild.role == RoleType.STATIC_TEXT))) {
// Re-interpret this case as pointing to the text under the div.
- node = node.find({ role: RoleType.INLINE_TEXT_BOX }) || node;
+ node = node.find({role: RoleType.INLINE_TEXT_BOX}) || node;
}
/** @type {number} @private */
@@ -126,8 +127,7 @@ cursors.Cursor.prototype = {
* @return {boolean}
*/
equals: function(rhs) {
- return this.node === rhs.node &&
- this.index === rhs.index;
+ return this.node === rhs.node && this.index === rhs.index;
},
/**
@@ -142,11 +142,13 @@ cursors.Cursor.prototype = {
// node.
var lNode = this.node;
var rNode = rhs.node;
- while (lNode && (lNode.role == RoleType.INLINE_TEXT_BOX ||
- lNode.role == RoleType.STATIC_TEXT))
+ while (lNode &&
+ (lNode.role == RoleType.INLINE_TEXT_BOX ||
+ lNode.role == RoleType.STATIC_TEXT))
lNode = lNode.parent;
- while (rNode && (rNode.role == RoleType.INLINE_TEXT_BOX ||
- rNode.role == RoleType.STATIC_TEXT))
+ while (rNode &&
+ (rNode.role == RoleType.INLINE_TEXT_BOX ||
+ rNode.role == RoleType.STATIC_TEXT))
rNode = rNode.parent;
// Ignore indicies for now.
@@ -216,7 +218,8 @@ cursors.Cursor.prototype = {
adjustedNode = grandparent;
} else if (grandparent && grandparent.role == RoleType.LINE_BREAK) {
adjustedNode = grandparent.parent;
- } else if (this.index_ == cursors.NODE_INDEX ||
+ } else if (
+ this.index_ == cursors.NODE_INDEX ||
adjustedNode.role == RoleType.INLINE_TEXT_BOX ||
adjustedNode.nameFrom != chrome.automation.NameFromType.CONTENTS) {
// A node offset or unselectable character offset.
@@ -245,8 +248,9 @@ cursors.Cursor.prototype = {
if (this.node.state.editable) {
return this.index_ == cursors.NODE_INDEX ? 0 : this.index_;
- } else if (this.node.role == RoleType.INLINE_TEXT_BOX &&
- // Selections under a line break are broken.
+ } else if (
+ this.node.role == RoleType.INLINE_TEXT_BOX &&
+ // Selections under a line break are broken.
this.node.parent && this.node.parent.role != RoleType.LINE_BREAK) {
if (adjustedIndex == cursors.NODE_INDEX)
adjustedIndex = 0;
@@ -256,7 +260,8 @@ cursors.Cursor.prototype = {
adjustedIndex += sibling.name.length;
sibling = sibling.previousSibling;
}
- } else if (this.index_ == cursors.NODE_INDEX ||
+ } else if (
+ this.index_ == cursors.NODE_INDEX ||
this.node.nameFrom != chrome.automation.NameFromType.CONTENTS) {
// A node offset or unselectable character offset.
@@ -312,8 +317,8 @@ cursors.Cursor.prototype = {
newNode, dir, AutomationPredicate.leafWithText);
if (newNode) {
var newText = AutomationUtil.getText(newNode);
- newIndex =
- dir == Dir.FORWARD ? 0 :
+ newIndex = dir == Dir.FORWARD ?
+ 0 :
StringUtil.previousCodePointOffset(newText, newText.length);
newIndex = Math.max(newIndex, 0);
} else {
@@ -323,10 +328,10 @@ cursors.Cursor.prototype = {
break;
case Unit.WORD:
if (newNode.role != RoleType.INLINE_TEXT_BOX) {
- newNode = AutomationUtil.findNextNode(newNode,
- Dir.FORWARD,
- AutomationPredicate.inlineTextBox,
- {skipInitialSubtree: false}) || newNode;
+ newNode = AutomationUtil.findNextNode(
+ newNode, Dir.FORWARD, AutomationPredicate.inlineTextBox,
+ {skipInitialSubtree: false}) ||
+ newNode;
}
switch (movement) {
case Movement.BOUND:
@@ -365,8 +370,8 @@ cursors.Cursor.prototype = {
if (dir == Dir.BACKWARD && newIndex != 0) {
newIndex = 0;
} else {
- newNode = AutomationUtil.findNextNode(newNode, dir,
- AutomationPredicate.leaf);
+ newNode = AutomationUtil.findNextNode(
+ newNode, dir, AutomationPredicate.leaf);
if (newNode) {
newIndex = 0;
if (dir == Dir.BACKWARD &&
@@ -391,10 +396,10 @@ cursors.Cursor.prototype = {
newIndex = dir == Dir.FORWARD ? this.getText().length - 1 : 0;
break;
case Movement.DIRECTIONAL:
- var pred = unit == Unit.TEXT ?
- AutomationPredicate.leaf : AutomationPredicate.object;
- newNode = AutomationUtil.findNextNode(newNode, dir, pred) ||
- originalNode;
+ var pred = unit == Unit.TEXT ? AutomationPredicate.leaf :
+ AutomationPredicate.object;
+ newNode =
+ AutomationUtil.findNextNode(newNode, dir, pred) || originalNode;
newIndex = cursors.NODE_INDEX;
break;
}
@@ -406,8 +411,8 @@ cursors.Cursor.prototype = {
switch (movement) {
case Movement.BOUND:
- newNode = AutomationUtil.findNodeUntil(newNode, dir,
- AutomationPredicate.linebreak, true);
+ newNode = AutomationUtil.findNodeUntil(
+ newNode, dir, AutomationPredicate.linebreak, true);
newNode = newNode || originalNode;
newIndex =
dir == Dir.FORWARD ? AutomationUtil.getText(newNode).length : 0;
@@ -416,8 +421,8 @@ cursors.Cursor.prototype = {
newNode = AutomationUtil.findNodeUntil(
newNode, dir, AutomationPredicate.linebreak);
break;
- }
- break;
+ }
+ break;
default:
throw Error('Unrecognized unit: ' + unit);
}
@@ -450,7 +455,8 @@ cursors.Cursor.prototype = {
newIndex = newIndex - length;
}
break;
- } else if (newNode.role != RoleType.INLINE_TEXT_BOX &&
+ } else if (
+ newNode.role != RoleType.INLINE_TEXT_BOX &&
newNode.children[newIndex]) {
// Valid node offset.
newNode = newNode.children[newIndex];
@@ -506,8 +512,7 @@ cursors.WrappingCursor.prototype = {
return this;
// Regular movement.
- if (!AutomationPredicate.root(this.node) ||
- dir == Dir.FORWARD ||
+ if (!AutomationPredicate.root(this.node) || dir == Dir.FORWARD ||
movement == Movement.BOUND)
result = cursors.Cursor.prototype.move.call(this, unit, movement, dir);
@@ -523,8 +528,8 @@ cursors.WrappingCursor.prototype = {
// For 2, place range on the root (if not already there). If at root,
// try to descend to the first leaf-like object.
if (movement == Movement.DIRECTIONAL && result.equals(this)) {
- var pred = unit == Unit.NODE ?
- AutomationPredicate.object : AutomationPredicate.leaf;
+ var pred = unit == Unit.NODE ? AutomationPredicate.object :
+ AutomationPredicate.leaf;
var endpoint = this.node;
if (!endpoint)
return this;
@@ -539,11 +544,9 @@ cursors.WrappingCursor.prototype = {
// Case 2: backward (sync downwards to a leaf), if already on the root.
if (dir == Dir.BACKWARD && endpoint == this.node) {
playEarcon = true;
- endpoint = AutomationUtil.findNodePre(endpoint,
- dir,
- function(n) {
- return pred(n) && !AutomationPredicate.shouldIgnoreNode(n);
- }) || endpoint;
+ endpoint = AutomationUtil.findNodePre(endpoint, dir, function(n) {
+ return pred(n) && !AutomationPredicate.shouldIgnoreNode(n);
+ }) || endpoint;
}
if (playEarcon)
@@ -580,7 +583,7 @@ cursors.Range.fromNode = function(node) {
return new cursors.Range(cursor, cursor);
};
- /**
+/**
* Given |rangeA| and |rangeB| in order, determine which |Dir|
* relates them.
* @param {!cursors.Range} rangeA
@@ -591,8 +594,8 @@ cursors.Range.getDirection = function(rangeA, rangeB) {
if (!rangeA || !rangeB)
return Dir.FORWARD;
- if (!rangeA.start.node || !rangeA.end.node ||
- !rangeB.start.node || !rangeB.end.node)
+ if (!rangeA.start.node || !rangeA.end.node || !rangeB.start.node ||
+ !rangeB.end.node)
return Dir.FORWARD;
// They are the same range.
@@ -601,11 +604,9 @@ cursors.Range.getDirection = function(rangeA, rangeB) {
return Dir.FORWARD;
var testDirA =
- AutomationUtil.getDirection(
- rangeA.start.node, rangeB.end.node);
+ AutomationUtil.getDirection(rangeA.start.node, rangeB.end.node);
var testDirB =
- AutomationUtil.getDirection(
- rangeB.start.node, rangeA.end.node);
+ AutomationUtil.getDirection(rangeB.start.node, rangeA.end.node);
// The two ranges are either partly overlapping or non overlapping.
if (testDirA == Dir.FORWARD && testDirB == Dir.BACKWARD)
@@ -624,8 +625,7 @@ cursors.Range.prototype = {
* @return {boolean}
*/
equals: function(rhs) {
- return this.start_.equals(rhs.start) &&
- this.end_.equals(rhs.end);
+ return this.start_.equals(rhs.start) && this.end_.equals(rhs.end);
},
/**
@@ -668,8 +668,7 @@ cursors.Range.prototype = {
* @return {boolean}
*/
isSubNode: function() {
- return this.start.node === this.end.node &&
- this.start.index > -1 &&
+ return this.start.node === this.end.node && this.start.index > -1 &&
this.end.index > -1;
},
@@ -679,8 +678,7 @@ cursors.Range.prototype = {
* @return {boolean?}
*/
isInlineText: function() {
- return this.start.node &&
- this.end.node &&
+ return this.start.node && this.end.node &&
this.start.node.role == this.end.node.role &&
this.start.node.role == RoleType.INLINE_TEXT_BOX;
},
@@ -733,32 +731,32 @@ cursors.Range.prototype = {
return;
// Only allow selections within the same web tree.
- if (startNode.root &&
- startNode.root.role == RoleType.ROOT_WEB_AREA &&
+ if (startNode.root && startNode.root.role == RoleType.ROOT_WEB_AREA &&
startNode.root == endNode.root) {
// We want to adjust to select the entire node for node offsets;
// otherwise, use the plain character offset.
var startIndex = this.start.selectionIndex_;
var endIndex = this.end.index_ == cursors.NODE_INDEX ?
- this.end.selectionIndex_ + 1 : this.end.selectionIndex_;
-
- chrome.automation.setDocumentSelection(
- { anchorObject: startNode,
- anchorOffset: startIndex,
- focusObject: endNode,
- focusOffset: endIndex }
- );
+ this.end.selectionIndex_ + 1 :
+ this.end.selectionIndex_;
+
+ chrome.automation.setDocumentSelection({
+ anchorObject: startNode,
+ anchorOffset: startIndex,
+ focusObject: endNode,
+ focusOffset: endIndex
+ });
}
},
/**
* Returns true if this range has either cursor end on web content.
* @return {boolean}
- */
+ */
isWebRange: function() {
return this.isValid() &&
(this.start.node.root.role != RoleType.DESKTOP ||
- this.end.node.root.role != RoleType.DESKTOP);
+ this.end.node.root.role != RoleType.DESKTOP);
},
/**

Powered by Google App Engine
This is Rietveld 408576698