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

Side by Side Diff: ui/accessibility/ax_position.h

Issue 2565833002: Uses |AXPosition| to enable navigation by character, word and line in content editables on the Mac. (Closed)
Patch Set: Fixed some boundary errors. Created 4 years 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 | « ui/accessibility/ax_node_position_unittest.cc ('k') | ui/accessibility/ax_range.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef UI_ACCESSIBILITY_AX_POSITION_H_ 5 #ifndef UI_ACCESSIBILITY_AX_POSITION_H_
6 #define UI_ACCESSIBILITY_AX_POSITION_H_ 6 #define UI_ACCESSIBILITY_AX_POSITION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 " anchor_id=" + base::IntToString(anchor_id_) + " text_offset=" + 143 " anchor_id=" + base::IntToString(anchor_id_) + " text_offset=" +
144 str_text_offset + " affinity=" + 144 str_text_offset + " affinity=" +
145 ui::ToString(static_cast<AXTextAffinity>(affinity_)); 145 ui::ToString(static_cast<AXTextAffinity>(affinity_));
146 } 146 }
147 } 147 }
148 148
149 if (!IsTextPosition() || text_offset() > MaxTextOffset()) 149 if (!IsTextPosition() || text_offset() > MaxTextOffset())
150 return str; 150 return str;
151 151
152 std::string text = base::UTF16ToUTF8(GetInnerText()); 152 std::string text = base::UTF16ToUTF8(GetInnerText());
153 DCHECK(!text.empty()); 153 DCHECK_GE(text_offset_, 0);
154 DCHECK_LE(text_offset_, static_cast<int>(text.length()));
154 std::string annotated_text; 155 std::string annotated_text;
155 if (text_offset() == MaxTextOffset()) { 156 if (text_offset() == MaxTextOffset()) {
156 annotated_text = text + "<>"; 157 annotated_text = text + "<>";
157 } else { 158 } else {
158 annotated_text = text.substr(0, text_offset()) + "<" + 159 annotated_text = text.substr(0, text_offset()) + "<" +
159 text[text_offset()] + ">" + 160 text[text_offset()] + ">" +
160 text.substr(text_offset() + 1); 161 text.substr(text_offset() + 1);
161 } 162 }
162 163
163 return str + " annotated_text=" + annotated_text; 164 return str + " annotated_text=" + annotated_text;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 AXPositionInstance AsTreePosition() const { 262 AXPositionInstance AsTreePosition() const {
262 if (IsNullPosition() || IsTreePosition()) 263 if (IsNullPosition() || IsTreePosition())
263 return Clone(); 264 return Clone();
264 265
265 AXPositionInstance copy = Clone(); 266 AXPositionInstance copy = Clone();
266 DCHECK(copy); 267 DCHECK(copy);
267 DCHECK_NE(copy->text_offset_, INVALID_OFFSET); 268 DCHECK_NE(copy->text_offset_, INVALID_OFFSET);
268 // If the anchor node has no text inside it then the child index should be 269 // If the anchor node has no text inside it then the child index should be
269 // set to |BEFORE_TEXT|, hence the check for the text's length. 270 // set to |BEFORE_TEXT|, hence the check for the text's length.
270 if (copy->MaxTextOffset() > 0 && 271 if (copy->MaxTextOffset() > 0 &&
271 copy->text_offset_ == copy->MaxTextOffset()) { 272 copy->text_offset_ >= copy->MaxTextOffset()) {
272 copy->child_index_ = copy->AnchorChildCount(); 273 copy->child_index_ = copy->AnchorChildCount();
273 } else { 274 } else {
274 DCHECK_GE(copy->text_offset_, 0); 275 DCHECK_GE(copy->text_offset_, 0);
275 DCHECK_LT(copy->text_offset_, copy->MaxTextOffset());
276 copy->child_index_ = BEFORE_TEXT; 276 copy->child_index_ = BEFORE_TEXT;
277 277
278 int current_offset = 0; 278 int current_offset = 0;
279 for (int i = 0; i < copy->AnchorChildCount(); ++i) { 279 for (int i = 0; i < copy->AnchorChildCount(); ++i) {
280 AXPositionInstance child = copy->CreateChildPositionAt(i); 280 AXPositionInstance child = copy->CreateChildPositionAt(i);
281 DCHECK(child); 281 DCHECK(child);
282 if (copy->text_offset_ >= current_offset && 282 if (copy->text_offset_ >= current_offset &&
283 copy->text_offset_ < (current_offset + child->MaxTextOffset())) { 283 copy->text_offset_ < (current_offset + child->MaxTextOffset())) {
284 copy->child_index_ = i; 284 copy->child_index_ = i;
285 break; 285 break;
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 1135
1136 template <class AXPositionType, class AXNodeType> 1136 template <class AXPositionType, class AXNodeType>
1137 bool operator>=(const AXPosition<AXPositionType, AXNodeType>& first, 1137 bool operator>=(const AXPosition<AXPositionType, AXNodeType>& first,
1138 const AXPosition<AXPositionType, AXNodeType>& second) { 1138 const AXPosition<AXPositionType, AXNodeType>& second) {
1139 return first == second || first > second; 1139 return first == second || first > second;
1140 } 1140 }
1141 1141
1142 } // namespace ui 1142 } // namespace ui
1143 1143
1144 #endif // UI_ACCESSIBILITY_AX_POSITION_H_ 1144 #endif // UI_ACCESSIBILITY_AX_POSITION_H_
OLDNEW
« no previous file with comments | « ui/accessibility/ax_node_position_unittest.cc ('k') | ui/accessibility/ax_range.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698