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

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

Issue 2442503008: Fix editable text 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 var adjustedNode = this.node;
166 if (!adjustedNode) 166 if (!adjustedNode)
167 return null; 167 return null;
168 168
169 // Make no adjustments if we're within editable content.
170 if (adjustedNode.state.editable)
171 return adjustedNode;
172
169 // Selections over line break nodes are broken. 173 // Selections over line break nodes are broken.
170 var parent = adjustedNode.parent; 174 var parent = adjustedNode.parent;
171 var grandparent = parent && parent.parent; 175 var grandparent = parent && parent.parent;
172 if (parent.role == RoleType.lineBreak) { 176 if (parent.role == RoleType.lineBreak) {
173 adjustedNode = grandparent; 177 adjustedNode = grandparent;
174 } else if (grandparent.role == RoleType.lineBreak) { 178 } else if (grandparent.role == RoleType.lineBreak) {
175 adjustedNode = grandparent.parent; 179 adjustedNode = grandparent.parent;
176 } else if (this.index_ == cursors.NODE_INDEX || 180 } else if (this.index_ == cursors.NODE_INDEX ||
177 adjustedNode.role == RoleType.inlineTextBox || 181 adjustedNode.role == RoleType.inlineTextBox ||
178 chrome.automation.NameFromType[adjustedNode.nameFrom] != 'contents') { 182 chrome.automation.NameFromType[adjustedNode.nameFrom] != 'contents') {
(...skipping 11 matching lines...) Expand all
190 /** 194 /**
191 * An index appropriate for making selections. If this cursor has a 195 * An index appropriate for making selections. If this cursor has a
192 * cursors.NODE_INDEX index, the selection index is a node offset e.g. the 196 * cursors.NODE_INDEX index, the selection index is a node offset e.g. the
193 * index in parent. If not, the index is a character offset. 197 * index in parent. If not, the index is a character offset.
194 * @return {number} 198 * @return {number}
195 * @private 199 * @private
196 */ 200 */
197 get selectionIndex_() { 201 get selectionIndex_() {
198 var adjustedIndex = this.index_; 202 var adjustedIndex = this.index_;
199 203
200 // Selecting things under a line break is currently broken. 204 if (!this.node)
201 if (this.node.role == RoleType.inlineTextBox && 205 return -1;
206
207 if (this.node.state.editable) {
208 return this.index_ == cursors.NODE_INDEX ? 0 : this.index_;
209 } else if (this.node.role == RoleType.inlineTextBox &&
210 // Selections under a line break are broken.
202 this.node.parent && this.node.parent.role != RoleType.lineBreak) { 211 this.node.parent && this.node.parent.role != RoleType.lineBreak) {
203 if (adjustedIndex == cursors.NODE_INDEX) 212 if (adjustedIndex == cursors.NODE_INDEX)
204 adjustedIndex = 0; 213 adjustedIndex = 0;
205 214
206 var sibling = this.node.previousSibling; 215 var sibling = this.node.previousSibling;
207 while (sibling) { 216 while (sibling) {
208 adjustedIndex += sibling.name.length; 217 adjustedIndex += sibling.name.length;
209 sibling = sibling.previousSibling; 218 sibling = sibling.previousSibling;
210 } 219 }
211 } else if (this.index_ == cursors.NODE_INDEX || 220 } else if (this.index_ == cursors.NODE_INDEX ||
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 /** 679 /**
671 * Returns whether this range has valid start and end cursors. 680 * Returns whether this range has valid start and end cursors.
672 * @return {boolean} 681 * @return {boolean}
673 */ 682 */
674 isValid: function() { 683 isValid: function() {
675 return this.start.isValid() && this.end.isValid(); 684 return this.start.isValid() && this.end.isValid();
676 } 685 }
677 }; 686 };
678 687
679 }); // goog.scope 688 }); // goog.scope
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698