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

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

Issue 2153213002: Better work around for Blink selection issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle line breaks. Created 4 years, 5 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 var adjustedIndex = this.index_; 158 var adjustedIndex = this.index_;
159 if (this.node.role == RoleType.inlineTextBox) { 159 if (this.node.role == RoleType.inlineTextBox) {
160 if (adjustedIndex == cursors.NODE_INDEX) 160 if (adjustedIndex == cursors.NODE_INDEX)
161 adjustedIndex = 0; 161 adjustedIndex = 0;
162 162
163 var sibling = this.node.previousSibling; 163 var sibling = this.node.previousSibling;
164 while (sibling) { 164 while (sibling) {
165 adjustedIndex += sibling.name.length; 165 adjustedIndex += sibling.name.length;
166 sibling = sibling.previousSibling; 166 sibling = sibling.previousSibling;
167 } 167 }
168 }
168 169
170 if (this.selectionNode_ && AutomationPredicate.text(this.selectionNode_)) {
169 // Work around Blink's somewhat unexpected offset calculation which 171 // Work around Blink's somewhat unexpected offset calculation which
170 // requires us to consider all previous siblings of the parenting static 172 // requires us to consider all previous siblings of the parenting node of
171 // text. 173 // the static text.
172 var parent = this.node.parent; 174
173 if (parent.role == RoleType.staticText) { 175 var parent = this.selectionNode_.parent;
174 sibling = parent.previousSibling; 176 if (parent) {
175 while (sibling) { 177 // Grab all of the text nodes and accumulate their lengths up to
176 if (sibling.name) 178 // but not including the current static text node.
177 adjustedIndex += sibling.name.length; 179 var texts = [];
178 sibling = sibling.previousSibling; 180 AutomationUtil.findNodePre(parent, Dir.FORWARD, function(node) {
181 if (AutomationPredicate.text(node))
182 texts.push(node);
183 return false;
184 });
185
186 for (var i = 0; i < texts.length; i++) {
187 if (texts[i] == this.selectionNode_)
188 break;
189
190 adjustedIndex += texts[i].name.length;
179 } 191 }
180 } 192 }
181 } else if (this.index_ == cursors.NODE_INDEX) { 193 } else if (this.index_ == cursors.NODE_INDEX) {
182 if (this.index_ == cursors.NODE_INDEX) { 194 if (this.index_ == cursors.NODE_INDEX) {
183 // Translate the index into a selection on the parent. 195 // Translate the index into a selection on the parent.
184 if (this.node.parent) 196 if (this.node.parent)
185 adjustedIndex = this.node.indexInParent; 197 adjustedIndex = this.node.indexInParent;
186 } 198 }
187 } 199 }
188 return adjustedIndex; 200 return adjustedIndex;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 /** 593 /**
582 * Select the text contained within this range. 594 * Select the text contained within this range.
583 */ 595 */
584 select: function() { 596 select: function() {
585 var startNode = this.start.selectionNode_; 597 var startNode = this.start.selectionNode_;
586 var endNode = this.end.selectionNode_; 598 var endNode = this.end.selectionNode_;
587 599
588 if (!startNode || !endNode) 600 if (!startNode || !endNode)
589 return; 601 return;
590 602
591 // Find the most common root. 603 // Only allow selections inside of the same web tree.
592 var uniqueAncestors = AutomationUtil.getUniqueAncestors(startNode, endNode); 604 if (startNode.root &&
593 var mcr = startNode.root; 605 startNode.root.role == RoleType.rootWebArea &&
594 if (uniqueAncestors) { 606 startNode.root === endNode.root) {
595 var common = uniqueAncestors.pop().parent;
596 if (common)
597 mcr = common.root;
598 }
599
600 if (!mcr || mcr.role == RoleType.desktop)
601 return;
602
603 if (mcr === startNode.root && mcr === endNode.root) {
604 var startIndex = this.start.selectionIndex_; 607 var startIndex = this.start.selectionIndex_;
605 608
606 // We want to adjust to select the entire node for node offsets; 609 // We want to adjust to select the entire node for node offsets;
607 // otherwise, use the plain character offset. 610 // otherwise, use the plain character offset.
608 var endIndex = this.end.index == cursors.NODE_INDEX ? 611 var endIndex = this.end.index == cursors.NODE_INDEX ?
609 this.end.selectionIndex_ + 1 : this.end.selectionIndex_; 612 this.end.selectionIndex_ + 1 : this.end.selectionIndex_;
610 613
611 chrome.automation.setDocumentSelection( 614 chrome.automation.setDocumentSelection(
612 { anchorObject: startNode, 615 { anchorObject: startNode,
613 anchorOffset: startIndex, 616 anchorOffset: startIndex,
(...skipping 16 matching lines...) Expand all
630 /** 633 /**
631 * Returns whether this range has valid start and end cursors. 634 * Returns whether this range has valid start and end cursors.
632 * @return {boolean} 635 * @return {boolean}
633 */ 636 */
634 isValid: function() { 637 isValid: function() {
635 return this.start.isValid() && this.end.isValid(); 638 return this.start.isValid() && this.end.isValid();
636 } 639 }
637 }; 640 };
638 641
639 }); // goog.scope 642 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698