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

Unified Diff: ui/accessibility/platform/ax_platform_node_win.cc

Issue 2679313003: Implemented IA2::setSelection and related methods on text fields in Views. (Closed)
Patch Set: Made |SetTextSelection| return a value. Created 3 years, 10 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: ui/accessibility/platform/ax_platform_node_win.cc
diff --git a/ui/accessibility/platform/ax_platform_node_win.cc b/ui/accessibility/platform/ax_platform_node_win.cc
index 5028f2da5bf7526ba6e212b92696f5ae60536f52..428222ef6664e2b97b1c54e7eac3e35e82c884b8 100644
--- a/ui/accessibility/platform/ax_platform_node_win.cc
+++ b/ui/accessibility/platform/ax_platform_node_win.cc
@@ -854,6 +854,48 @@ STDMETHODIMP AXPlatformNodeWin::get_offsetAtPoint(
return S_OK;
}
+STDMETHODIMP AXPlatformNodeWin::addSelection(LONG start_offset,
+ LONG end_offset) {
+ // We only support one selection.
+ return setSelection(0, start_offset, end_offset);
+}
+
+STDMETHODIMP AXPlatformNodeWin::removeSelection(LONG selection_index) {
+ if (selection_index != 0)
+ return E_INVALIDARG;
+ // Simply collapse the selection to the position of the caret if a caret is
+ // visible, otherwise set the selection to 0.
+ return setCaretOffset(GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END));
+}
+
+STDMETHODIMP AXPlatformNodeWin::setCaretOffset(LONG offset) {
+ return setSelection(0, offset, offset);
+}
+
+STDMETHODIMP AXPlatformNodeWin::setSelection(LONG selection_index,
+ LONG start_offset,
+ LONG end_offset) {
+ if (selection_index != 0)
+ return E_INVALIDARG;
+
+ HandleSpecialTextOffset(&start_offset);
+ HandleSpecialTextOffset(&end_offset);
+ if (start_offset < 0 ||
+ start_offset > static_cast<LONG>(TextForIAccessibleText().length())) {
+ return E_INVALIDARG;
+ }
+ if (end_offset < 0 ||
+ end_offset > static_cast<LONG>(TextForIAccessibleText().length())) {
+ return E_INVALIDARG;
+ }
+
+ if (SetTextSelection(static_cast<int>(start_offset),
+ static_cast<int>(end_offset))) {
+ return S_OK;
+ }
+ return E_FAIL;
+}
+
//
// IAccessibleText methods not implemented.
//
@@ -864,16 +906,6 @@ STDMETHODIMP AXPlatformNodeWin::get_newText(IA2TextSegment* new_text) {
STDMETHODIMP AXPlatformNodeWin::get_oldText(IA2TextSegment* old_text) {
return E_NOTIMPL;
}
-STDMETHODIMP AXPlatformNodeWin::addSelection(LONG start_offset,
- LONG end_offset) {
- return E_NOTIMPL;
-}
-STDMETHODIMP AXPlatformNodeWin::get_attributes(LONG offset,
- LONG* start_offset,
- LONG* end_offset,
- BSTR* text_attributes) {
- return E_NOTIMPL;
-}
STDMETHODIMP AXPlatformNodeWin::get_characterExtents(
LONG offset,
enum IA2CoordinateType coord_type,
@@ -883,17 +915,6 @@ STDMETHODIMP AXPlatformNodeWin::get_characterExtents(
LONG* height) {
return E_NOTIMPL;
}
-STDMETHODIMP AXPlatformNodeWin::removeSelection(LONG selection_index) {
- return E_NOTIMPL;
-}
-STDMETHODIMP AXPlatformNodeWin::setCaretOffset(LONG offset) {
- return E_NOTIMPL;
-}
-STDMETHODIMP AXPlatformNodeWin::setSelection(LONG selection_index,
- LONG start_offset,
- LONG end_offset) {
- return E_NOTIMPL;
-}
STDMETHODIMP AXPlatformNodeWin::scrollSubstringTo(
LONG start_index,
LONG end_index,
@@ -908,6 +929,12 @@ STDMETHODIMP AXPlatformNodeWin::scrollSubstringToPoint(
LONG y) {
return E_NOTIMPL;
}
+STDMETHODIMP AXPlatformNodeWin::get_attributes(LONG offset,
+ LONG* start_offset,
+ LONG* end_offset,
+ BSTR* text_attributes) {
+ return E_NOTIMPL;
+}
//
// IServiceProvider implementation.
@@ -1131,14 +1158,12 @@ void AXPlatformNodeWin::RemoveAlertTarget() {
base::string16 AXPlatformNodeWin::TextForIAccessibleText() {
if (GetData().role == ui::AX_ROLE_TEXT_FIELD)
return GetString16Attribute(ui::AX_ATTR_VALUE);
- else
- return GetString16Attribute(ui::AX_ATTR_NAME);
+ return GetString16Attribute(ui::AX_ATTR_NAME);
}
-void AXPlatformNodeWin::HandleSpecialTextOffset(
- const base::string16& text, LONG* offset) {
+void AXPlatformNodeWin::HandleSpecialTextOffset(LONG* offset) {
if (*offset == IA2_TEXT_OFFSET_LENGTH) {
- *offset = static_cast<LONG>(text.size());
+ *offset = static_cast<LONG>(TextForIAccessibleText().length());
} else if (*offset == IA2_TEXT_OFFSET_CARET) {
get_caretOffset(offset);
}
@@ -1164,7 +1189,7 @@ LONG AXPlatformNodeWin::FindBoundary(
IA2TextBoundaryType ia2_boundary,
LONG start_offset,
ui::TextBoundaryDirection direction) {
- HandleSpecialTextOffset(text, &start_offset);
+ HandleSpecialTextOffset(&start_offset);
ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary);
std::vector<int32_t> line_breaks;
return static_cast<LONG>(ui::FindAccessibleTextBoundary(

Powered by Google App Engine
This is Rietveld 408576698