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

Side by Side Diff: ui/accessibility/ax_range.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_position.h ('k') | 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 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_RANGE_H_ 5 #ifndef UI_ACCESSIBILITY_AX_RANGE_H_
6 #define UI_ACCESSIBILITY_AX_RANGE_H_ 6 #define UI_ACCESSIBILITY_AX_RANGE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 if (focus) { 33 if (focus) {
34 focus_ = std::move(focus); 34 focus_ = std::move(focus);
35 } else { 35 } else {
36 focus = AXPositionType::CreateNullPosition(); 36 focus = AXPositionType::CreateNullPosition();
37 } 37 }
38 } 38 }
39 39
40 AXRange(const AXRange& other) = delete; 40 AXRange(const AXRange& other) = delete;
41 41
42 AXRange(const AXRange&& other) : AXRange() { 42 AXRange(AXRange&& other) : AXRange() {
43 anchor_.swap(other.anchor_); 43 anchor_.swap(other.anchor_);
44 focus_.swap(other.focus_); 44 focus_.swap(other.focus_);
45 } 45 }
46 46
47 AXRange& operator=(const AXRange& other) = delete; 47 AXRange& operator=(const AXRange& other) = delete;
48 48
49 AXRange& operator=(const AXRange&& other) { 49 AXRange& operator=(const AXRange&& other) {
50 if (this != other) { 50 if (this != other) {
51 anchor_ = AXPositionType::CreateNullPosition(); 51 anchor_ = AXPositionType::CreateNullPosition();
52 focus_ = AXPositionType::CreateNullPosition(); 52 focus_ = AXPositionType::CreateNullPosition();
(...skipping 18 matching lines...) Expand all
71 AXPositionType* focus() const { 71 AXPositionType* focus() const {
72 DCHECK(focus_); 72 DCHECK(focus_);
73 return focus_.get(); 73 return focus_.get();
74 } 74 }
75 75
76 base::string16 GetText() const { 76 base::string16 GetText() const {
77 base::string16 text; 77 base::string16 text;
78 if (IsNull()) 78 if (IsNull())
79 return text; 79 return text;
80 80
81 std::unique_ptr<AXPositionType> first, second; 81 std::unique_ptr<AXPositionType> start, end;
82 if (*anchor_ <= *focus_) { 82 if (*anchor_ < *focus_) {
83 first = anchor_->AsLeafTextPosition(); 83 start = anchor_->AsLeafTextPosition();
84 second = focus_->AsLeafTextPosition(); 84 end = focus_->AsLeafTextPosition();
85 } else { 85 } else {
86 first = focus_->AsLeafTextPosition(); 86 start = focus_->AsLeafTextPosition();
87 second = anchor_->AsLeafTextPosition(); 87 end = anchor_->AsLeafTextPosition();
88 } 88 }
89 89
90 int start_offset = start->text_offset();
91 DCHECK_GE(start_offset, 0);
92 int end_offset = end->text_offset();
93 DCHECK_GE(end_offset, 0);
94
90 do { 95 do {
91 text += first->GetInnerText(); 96 text += start->GetInnerText();
92 first = first->CreateNextTextAnchorPosition(); 97 start = start->CreateNextTextAnchorPosition();
93 } while (*first <= *second); 98 } while (!start->IsNullPosition() && *start <= *end);
94 99
95 return text; 100 if (static_cast<size_t>(start_offset) > text.length())
101 return base::string16();
102
103 text = text.substr(start_offset, base::string16::npos);
104 size_t text_length = text.length() - end->GetInnerText().length() +
105 static_cast<size_t>(end_offset);
106 return text.substr(0, text_length);
96 } 107 }
97 108
98 private: 109 private:
99 std::unique_ptr<AXPositionType> anchor_; 110 std::unique_ptr<AXPositionType> anchor_;
100 std::unique_ptr<AXPositionType> focus_; 111 std::unique_ptr<AXPositionType> focus_;
101 }; 112 };
102 113
103 } // namespace ui 114 } // namespace ui
104 115
105 #endif // UI_ACCESSIBILITY_AX_RANGE_H_ 116 #endif // UI_ACCESSIBILITY_AX_RANGE_H_
OLDNEW
« no previous file with comments | « ui/accessibility/ax_position.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698