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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/accessibility/ax_position.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/accessibility/ax_range.h
diff --git a/ui/accessibility/ax_range.h b/ui/accessibility/ax_range.h
index 7235c0623d4ead598c4826ed8e3f2c7526c6ef1b..914f350d3a74d292ccaa90ca4531dc0c6c3739c5 100644
--- a/ui/accessibility/ax_range.h
+++ b/ui/accessibility/ax_range.h
@@ -39,7 +39,7 @@ class AXRange {
AXRange(const AXRange& other) = delete;
- AXRange(const AXRange&& other) : AXRange() {
+ AXRange(AXRange&& other) : AXRange() {
anchor_.swap(other.anchor_);
focus_.swap(other.focus_);
}
@@ -78,21 +78,32 @@ class AXRange {
if (IsNull())
return text;
- std::unique_ptr<AXPositionType> first, second;
- if (*anchor_ <= *focus_) {
- first = anchor_->AsLeafTextPosition();
- second = focus_->AsLeafTextPosition();
+ std::unique_ptr<AXPositionType> start, end;
+ if (*anchor_ < *focus_) {
+ start = anchor_->AsLeafTextPosition();
+ end = focus_->AsLeafTextPosition();
} else {
- first = focus_->AsLeafTextPosition();
- second = anchor_->AsLeafTextPosition();
+ start = focus_->AsLeafTextPosition();
+ end = anchor_->AsLeafTextPosition();
}
+ int start_offset = start->text_offset();
+ DCHECK_GE(start_offset, 0);
+ int end_offset = end->text_offset();
+ DCHECK_GE(end_offset, 0);
+
do {
- text += first->GetInnerText();
- first = first->CreateNextTextAnchorPosition();
- } while (*first <= *second);
+ text += start->GetInnerText();
+ start = start->CreateNextTextAnchorPosition();
+ } while (!start->IsNullPosition() && *start <= *end);
+
+ if (static_cast<size_t>(start_offset) > text.length())
+ return base::string16();
- return text;
+ text = text.substr(start_offset, base::string16::npos);
+ size_t text_length = text.length() - end->GetInnerText().length() +
+ static_cast<size_t>(end_offset);
+ return text.substr(0, text_length);
}
private:
« 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