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

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

Issue 2385343002: Make ChromeVox use child-index based offsets again for selection. (Closed)
Patch Set: Created 4 years, 2 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 074cbdac315723cea6103eacd38debeb5420d18d..b10a19275d750d363830741673365bd6fa6f9e24 100644
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
@@ -162,13 +162,21 @@ cursors.Cursor.prototype = {
* @private
*/
get selectionNode_() {
+ var adjustedNode = this.node;
if (!this.node)
return null;
- if (this.node.role == RoleType.inlineTextBox)
- return this.node.parent;
-
- return this.node;
+ // Selections over line break nodes are broken.
+ var parent = adjustedNode.parent;
+ var grandparent = parent && parent.parent;
+ if (parent.role == RoleType.lineBreak)
+ adjustedNode = grandparent;
+ else if (grandparent.role == RoleType.lineBreak)
+ adjustedNode = grandparent.parent;
+ else
+ adjustedNode = parent;
+
+ return adjustedNode;
},
/**
@@ -180,7 +188,10 @@ cursors.Cursor.prototype = {
*/
get selectionIndex_() {
var adjustedIndex = this.index_;
- if (this.node.role == RoleType.inlineTextBox) {
+
+ // Selecting things under a line break is currently broken.
+ if (this.node.role == RoleType.inlineTextBox &&
+ this.node.parent && this.node.parent.role != RoleType.lineBreak) {
if (adjustedIndex == cursors.NODE_INDEX)
adjustedIndex = 0;
@@ -189,10 +200,13 @@ cursors.Cursor.prototype = {
adjustedIndex += sibling.name.length;
sibling = sibling.previousSibling;
}
- } else if (this.index_ == cursors.NODE_INDEX) {
- // Indicies of this kind are buggy. Set it to 0 (different than the DOM
- // index in parent convention).
- adjustedIndex = 0;
+ } else {
+ // The selected node could have been adjusted upwards in the tree.
+ var childOfSelection = this.node;
+ do {
+ adjustedIndex = childOfSelection.indexInParent;
+ childOfSelection = childOfSelection.parent;
+ } while (childOfSelection && childOfSelection != this.selectionNode_);
}
return adjustedIndex;
},
@@ -617,8 +631,8 @@ cursors.Range.prototype = {
// 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_;
+ var endIndex = endNode.role == RoleType.staticText ?
+ this.end.selectionIndex_ : this.end.selectionIndex_ + 1;
chrome.automation.setDocumentSelection(
{ anchorObject: startNode,

Powered by Google App Engine
This is Rietveld 408576698