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

Unified Diff: Source/web/WebAXObject.cpp

Issue 1185343003: Implements the ability to get and set the caret position and the current selection from anywhere in… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed retrieving the selection in text controls. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/web/WebAXObject.cpp
diff --git a/Source/web/WebAXObject.cpp b/Source/web/WebAXObject.cpp
index ef98b5b69d6631c1ed86e7f07808f5f7b3f09631..f4862408fbbbc960656cd9779b6cc95c77d85313 100644
--- a/Source/web/WebAXObject.cpp
+++ b/Source/web/WebAXObject.cpp
@@ -816,12 +816,44 @@ WebAXRole WebAXObject::role() const
return static_cast<WebAXRole>(m_private->roleValue());
}
+void WebAXObject::selection(WebAXObject& anchorObject, int& anchorOffset,
+ WebAXObject& focusObject, int& focusOffset) const
+{
+ if (isDetached()) {
+ anchorObject = WebAXObject();
+ anchorOffset = -1;
+ focusObject = WebAXObject();
+ focusOffset = -1;
+ return;
+ }
+
+ AXObject::AXRange axSelection = m_private->selection();
+ anchorObject = WebAXObject(axSelection.anchorObject);
+ anchorOffset = axSelection.anchorOffset;
+ focusObject = WebAXObject(axSelection.focusObject);
+ focusOffset = axSelection.focusOffset;
+ return;
+}
+
+void WebAXObject::setSelection(const WebAXObject& anchorObject, int anchorOffset,
+ const WebAXObject& focusObject, int focusOffset) const
+{
+ if (isDetached())
+ return;
+
+ AXObject::AXRange axSelection(anchorObject, anchorOffset,
+ focusObject, focusOffset);
+ m_private->setSelection(axSelection);
+ return;
+}
+
unsigned WebAXObject::selectionEnd() const
{
if (isDetached())
return 0;
- return m_private->selectedTextRange().start + m_private->selectedTextRange().length;
+ AXObject::AXRange axSelection = m_private->selectionUnderObject();
+ return axSelection.focusOffset;
}
unsigned WebAXObject::selectionStart() const
@@ -829,7 +861,8 @@ unsigned WebAXObject::selectionStart() const
if (isDetached())
return 0;
- return m_private->selectedTextRange().start;
+ AXObject::AXRange axSelection = m_private->selectionUnderObject();
+ return axSelection.anchorOffset;
}
unsigned WebAXObject::selectionEndLineNumber() const
@@ -867,7 +900,7 @@ void WebAXObject::setSelectedTextRange(int selectionStart, int selectionEnd) con
if (isDetached())
return;
- m_private->setSelectedTextRange(AXObject::PlainTextRange(selectionStart, selectionEnd - selectionStart));
+ m_private->setSelection(AXObject::AXRange(selectionStart, selectionEnd));
}
void WebAXObject::setValue(WebString value) const
@@ -1489,17 +1522,19 @@ void WebAXObject::wordBoundaries(WebVector<int>& starts, WebVector<int>& ends) c
if (isDetached())
return;
- Vector<AXObject::PlainTextRange> words;
- m_private->wordBoundaries(words);
+ Vector<AXObject::AXRange> wordBoundaries;
+ m_private->wordBoundaries(wordBoundaries);
- WebVector<int> startsWebVector(words.size());
- WebVector<int> endsWebVector(words.size());
- for (size_t i = 0; i < words.size(); i++) {
- startsWebVector[i] = words[i].start;
- endsWebVector[i] = words[i].start + words[i].length;
+ WebVector<int> wordStartOffsets(wordBoundaries.size());
+ WebVector<int> wordEndOffsets(wordBoundaries.size());
+ for (size_t i = 0; i < wordBoundaries.size(); ++i) {
+ ASSERT(wordBoundaries[i].isSimple());
+ wordStartOffsets[i] = wordBoundaries[i].anchorOffset;
+ wordEndOffsets[i] = wordBoundaries[i].focusOffset;
}
- starts.swap(startsWebVector);
- ends.swap(endsWebVector);
+
+ starts.swap(wordStartOffsets);
+ ends.swap(wordEndOffsets);
}
bool WebAXObject::isScrollableContainer() const

Powered by Google App Engine
This is Rietveld 408576698