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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Classes related to cursors that point to and select parts of 6 * @fileoverview Classes related to cursors that point to and select parts of
7 * the automation tree. 7 * the automation tree.
8 */ 8 */
9 9
10 goog.provide('cursors.Cursor'); 10 goog.provide('cursors.Cursor');
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return this.index_; 155 return this.index_;
156 }, 156 },
157 157
158 158
159 /** 159 /**
160 * A node appropriate for making selections. 160 * A node appropriate for making selections.
161 * @return {AutomationNode} 161 * @return {AutomationNode}
162 * @private 162 * @private
163 */ 163 */
164 get selectionNode_() { 164 get selectionNode_() {
165 var adjustedNode = this.node;
165 if (!this.node) 166 if (!this.node)
166 return null; 167 return null;
167 168
168 if (this.node.role == RoleType.inlineTextBox) 169 // Selections over line break nodes are broken.
169 return this.node.parent; 170 var parent = adjustedNode.parent;
171 var grandparent = parent && parent.parent;
172 if (parent.role == RoleType.lineBreak)
173 adjustedNode = grandparent;
174 else if (grandparent.role == RoleType.lineBreak)
175 adjustedNode = grandparent.parent;
176 else
177 adjustedNode = parent;
170 178
171 return this.node; 179 return adjustedNode;
172 }, 180 },
173 181
174 /** 182 /**
175 * An index appropriate for making selections. If this cursor has a 183 * An index appropriate for making selections. If this cursor has a
176 * cursors.NODE_INDEX index, the selection index is a node offset e.g. the 184 * cursors.NODE_INDEX index, the selection index is a node offset e.g. the
177 * index in parent. If not, the index is a character offset. 185 * index in parent. If not, the index is a character offset.
178 * @return {number} 186 * @return {number}
179 * @private 187 * @private
180 */ 188 */
181 get selectionIndex_() { 189 get selectionIndex_() {
182 var adjustedIndex = this.index_; 190 var adjustedIndex = this.index_;
183 if (this.node.role == RoleType.inlineTextBox) { 191
192 // Selecting things under a line break is currently broken.
193 if (this.node.role == RoleType.inlineTextBox &&
194 this.node.parent && this.node.parent.role != RoleType.lineBreak) {
184 if (adjustedIndex == cursors.NODE_INDEX) 195 if (adjustedIndex == cursors.NODE_INDEX)
185 adjustedIndex = 0; 196 adjustedIndex = 0;
186 197
187 var sibling = this.node.previousSibling; 198 var sibling = this.node.previousSibling;
188 while (sibling) { 199 while (sibling) {
189 adjustedIndex += sibling.name.length; 200 adjustedIndex += sibling.name.length;
190 sibling = sibling.previousSibling; 201 sibling = sibling.previousSibling;
191 } 202 }
192 } else if (this.index_ == cursors.NODE_INDEX) { 203 } else {
193 // Indicies of this kind are buggy. Set it to 0 (different than the DOM 204 // The selected node could have been adjusted upwards in the tree.
194 // index in parent convention). 205 var childOfSelection = this.node;
195 adjustedIndex = 0; 206 do {
207 adjustedIndex = childOfSelection.indexInParent;
208 childOfSelection = childOfSelection.parent;
209 } while (childOfSelection && childOfSelection != this.selectionNode_);
196 } 210 }
197 return adjustedIndex; 211 return adjustedIndex;
198 }, 212 },
199 213
200 /** 214 /**
201 * Gets the accessible text of the node associated with this cursor. 215 * Gets the accessible text of the node associated with this cursor.
202 * 216 *
203 * @param {!AutomationNode=} opt_node Use this node rather than this cursor's 217 * @param {!AutomationNode=} opt_node Use this node rather than this cursor's
204 * node. 218 * node.
205 * @return {string} 219 * @return {string}
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 if (!startNode || !endNode) 624 if (!startNode || !endNode)
611 return; 625 return;
612 626
613 // Only allow selections within the same web tree. 627 // Only allow selections within the same web tree.
614 if (startNode.root && 628 if (startNode.root &&
615 startNode.root.role == RoleType.rootWebArea && 629 startNode.root.role == RoleType.rootWebArea &&
616 startNode.root == endNode.root) { 630 startNode.root == endNode.root) {
617 // We want to adjust to select the entire node for node offsets; 631 // We want to adjust to select the entire node for node offsets;
618 // otherwise, use the plain character offset. 632 // otherwise, use the plain character offset.
619 var startIndex = this.start.selectionIndex_; 633 var startIndex = this.start.selectionIndex_;
620 var endIndex = this.end.index == cursors.NODE_INDEX ? 634 var endIndex = endNode.role == RoleType.staticText ?
621 this.end.selectionIndex_ + 1 : this.end.selectionIndex_; 635 this.end.selectionIndex_ : this.end.selectionIndex_ + 1;
622 636
623 chrome.automation.setDocumentSelection( 637 chrome.automation.setDocumentSelection(
624 { anchorObject: startNode, 638 { anchorObject: startNode,
625 anchorOffset: startIndex, 639 anchorOffset: startIndex,
626 focusObject: endNode, 640 focusObject: endNode,
627 focusOffset: endIndex } 641 focusOffset: endIndex }
628 ); 642 );
629 } 643 }
630 }, 644 },
631 645
(...skipping 10 matching lines...) Expand all
642 /** 656 /**
643 * Returns whether this range has valid start and end cursors. 657 * Returns whether this range has valid start and end cursors.
644 * @return {boolean} 658 * @return {boolean}
645 */ 659 */
646 isValid: function() { 660 isValid: function() {
647 return this.start.isValid() && this.end.isValid(); 661 return this.start.isValid() && this.end.isValid();
648 } 662 }
649 }; 663 };
650 664
651 }); // goog.scope 665 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698