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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include <atlbase.h> 5 #include <atlbase.h>
6 #include <atlcom.h> 6 #include <atlcom.h>
7 #include <limits.h> 7 #include <limits.h>
8 #include <oleacc.h> 8 #include <oleacc.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 847
848 STDMETHODIMP AXPlatformNodeWin::get_offsetAtPoint( 848 STDMETHODIMP AXPlatformNodeWin::get_offsetAtPoint(
849 LONG x, LONG y, enum IA2CoordinateType coord_type, LONG* offset) { 849 LONG x, LONG y, enum IA2CoordinateType coord_type, LONG* offset) {
850 COM_OBJECT_VALIDATE_1_ARG(offset); 850 COM_OBJECT_VALIDATE_1_ARG(offset);
851 // We don't support this method, but we have to return something 851 // We don't support this method, but we have to return something
852 // rather than E_NOTIMPL or screen readers will complain. 852 // rather than E_NOTIMPL or screen readers will complain.
853 *offset = 0; 853 *offset = 0;
854 return S_OK; 854 return S_OK;
855 } 855 }
856 856
857 STDMETHODIMP AXPlatformNodeWin::addSelection(LONG start_offset,
858 LONG end_offset) {
859 // We only support one selection.
860 return setSelection(0, start_offset, end_offset);
861 }
862
863 STDMETHODIMP AXPlatformNodeWin::removeSelection(LONG selection_index) {
864 if (selection_index != 0)
865 return E_INVALIDARG;
866 // Simply collapse the selection to the position of the caret if a caret is
867 // visible, otherwise set the selection to 0.
868 return setCaretOffset(GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END));
869 }
870
871 STDMETHODIMP AXPlatformNodeWin::setCaretOffset(LONG offset) {
872 return setSelection(0, offset, offset);
873 }
874
875 STDMETHODIMP AXPlatformNodeWin::setSelection(LONG selection_index,
876 LONG start_offset,
877 LONG end_offset) {
878 if (selection_index != 0)
879 return E_INVALIDARG;
880
881 HandleSpecialTextOffset(&start_offset);
882 HandleSpecialTextOffset(&end_offset);
883 if (start_offset < 0 ||
884 start_offset > static_cast<LONG>(TextForIAccessibleText().length())) {
885 return E_INVALIDARG;
886 }
887 if (end_offset < 0 ||
888 end_offset > static_cast<LONG>(TextForIAccessibleText().length())) {
889 return E_INVALIDARG;
890 }
891
892 SetTextSelection(static_cast<int>(start_offset),
893 static_cast<int>(end_offset));
894 return S_OK;
895 }
896
857 // 897 //
858 // IAccessibleText methods not implemented. 898 // IAccessibleText methods not implemented.
859 // 899 //
860 900
861 STDMETHODIMP AXPlatformNodeWin::get_newText(IA2TextSegment* new_text) { 901 STDMETHODIMP AXPlatformNodeWin::get_newText(IA2TextSegment* new_text) {
862 return E_NOTIMPL; 902 return E_NOTIMPL;
863 } 903 }
864 STDMETHODIMP AXPlatformNodeWin::get_oldText(IA2TextSegment* old_text) { 904 STDMETHODIMP AXPlatformNodeWin::get_oldText(IA2TextSegment* old_text) {
865 return E_NOTIMPL; 905 return E_NOTIMPL;
866 } 906 }
867 STDMETHODIMP AXPlatformNodeWin::addSelection(LONG start_offset,
868 LONG end_offset) {
869 return E_NOTIMPL;
870 }
871 STDMETHODIMP AXPlatformNodeWin::get_attributes(LONG offset,
872 LONG* start_offset,
873 LONG* end_offset,
874 BSTR* text_attributes) {
875 return E_NOTIMPL;
876 }
877 STDMETHODIMP AXPlatformNodeWin::get_characterExtents( 907 STDMETHODIMP AXPlatformNodeWin::get_characterExtents(
878 LONG offset, 908 LONG offset,
879 enum IA2CoordinateType coord_type, 909 enum IA2CoordinateType coord_type,
880 LONG* x, 910 LONG* x,
881 LONG* y, 911 LONG* y,
882 LONG* width, 912 LONG* width,
883 LONG* height) { 913 LONG* height) {
884 return E_NOTIMPL; 914 return E_NOTIMPL;
885 } 915 }
886 STDMETHODIMP AXPlatformNodeWin::removeSelection(LONG selection_index) {
887 return E_NOTIMPL;
888 }
889 STDMETHODIMP AXPlatformNodeWin::setCaretOffset(LONG offset) {
890 return E_NOTIMPL;
891 }
892 STDMETHODIMP AXPlatformNodeWin::setSelection(LONG selection_index,
893 LONG start_offset,
894 LONG end_offset) {
895 return E_NOTIMPL;
896 }
897 STDMETHODIMP AXPlatformNodeWin::scrollSubstringTo( 916 STDMETHODIMP AXPlatformNodeWin::scrollSubstringTo(
898 LONG start_index, 917 LONG start_index,
899 LONG end_index, 918 LONG end_index,
900 enum IA2ScrollType scroll_type) { 919 enum IA2ScrollType scroll_type) {
901 return E_NOTIMPL; 920 return E_NOTIMPL;
902 } 921 }
903 STDMETHODIMP AXPlatformNodeWin::scrollSubstringToPoint( 922 STDMETHODIMP AXPlatformNodeWin::scrollSubstringToPoint(
904 LONG start_index, 923 LONG start_index,
905 LONG end_index, 924 LONG end_index,
906 enum IA2CoordinateType coordinate_type, 925 enum IA2CoordinateType coordinate_type,
907 LONG x, 926 LONG x,
908 LONG y) { 927 LONG y) {
909 return E_NOTIMPL; 928 return E_NOTIMPL;
910 } 929 }
930 STDMETHODIMP AXPlatformNodeWin::get_attributes(LONG offset,
931 LONG* start_offset,
932 LONG* end_offset,
933 BSTR* text_attributes) {
934 return E_NOTIMPL;
935 }
911 936
912 // 937 //
913 // IServiceProvider implementation. 938 // IServiceProvider implementation.
914 // 939 //
915 940
916 STDMETHODIMP AXPlatformNodeWin::QueryService( 941 STDMETHODIMP AXPlatformNodeWin::QueryService(
917 REFGUID guidService, REFIID riid, void** object) { 942 REFGUID guidService, REFIID riid, void** object) {
918 COM_OBJECT_VALIDATE_1_ARG(object); 943 COM_OBJECT_VALIDATE_1_ARG(object);
919 944
920 if (riid == IID_IAccessible2) { 945 if (riid == IID_IAccessible2) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 } 1149 }
1125 1150
1126 void AXPlatformNodeWin::RemoveAlertTarget() { 1151 void AXPlatformNodeWin::RemoveAlertTarget() {
1127 if (g_alert_targets.Get().find(this) != g_alert_targets.Get().end()) 1152 if (g_alert_targets.Get().find(this) != g_alert_targets.Get().end())
1128 g_alert_targets.Get().erase(this); 1153 g_alert_targets.Get().erase(this);
1129 } 1154 }
1130 1155
1131 base::string16 AXPlatformNodeWin::TextForIAccessibleText() { 1156 base::string16 AXPlatformNodeWin::TextForIAccessibleText() {
1132 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) 1157 if (GetData().role == ui::AX_ROLE_TEXT_FIELD)
1133 return GetString16Attribute(ui::AX_ATTR_VALUE); 1158 return GetString16Attribute(ui::AX_ATTR_VALUE);
1134 else 1159 return GetString16Attribute(ui::AX_ATTR_NAME);
1135 return GetString16Attribute(ui::AX_ATTR_NAME);
1136 } 1160 }
1137 1161
1138 void AXPlatformNodeWin::HandleSpecialTextOffset( 1162 void AXPlatformNodeWin::HandleSpecialTextOffset(LONG* offset) {
1139 const base::string16& text, LONG* offset) {
1140 if (*offset == IA2_TEXT_OFFSET_LENGTH) { 1163 if (*offset == IA2_TEXT_OFFSET_LENGTH) {
1141 *offset = static_cast<LONG>(text.size()); 1164 *offset = static_cast<LONG>(TextForIAccessibleText().length());
1142 } else if (*offset == IA2_TEXT_OFFSET_CARET) { 1165 } else if (*offset == IA2_TEXT_OFFSET_CARET) {
1143 get_caretOffset(offset); 1166 get_caretOffset(offset);
1144 } 1167 }
1145 } 1168 }
1146 1169
1147 ui::TextBoundaryType AXPlatformNodeWin::IA2TextBoundaryToTextBoundary( 1170 ui::TextBoundaryType AXPlatformNodeWin::IA2TextBoundaryToTextBoundary(
1148 IA2TextBoundaryType ia2_boundary) { 1171 IA2TextBoundaryType ia2_boundary) {
1149 switch(ia2_boundary) { 1172 switch(ia2_boundary) {
1150 case IA2_TEXT_BOUNDARY_CHAR: return ui::CHAR_BOUNDARY; 1173 case IA2_TEXT_BOUNDARY_CHAR: return ui::CHAR_BOUNDARY;
1151 case IA2_TEXT_BOUNDARY_WORD: return ui::WORD_BOUNDARY; 1174 case IA2_TEXT_BOUNDARY_WORD: return ui::WORD_BOUNDARY;
1152 case IA2_TEXT_BOUNDARY_LINE: return ui::LINE_BOUNDARY; 1175 case IA2_TEXT_BOUNDARY_LINE: return ui::LINE_BOUNDARY;
1153 case IA2_TEXT_BOUNDARY_SENTENCE: return ui::SENTENCE_BOUNDARY; 1176 case IA2_TEXT_BOUNDARY_SENTENCE: return ui::SENTENCE_BOUNDARY;
1154 case IA2_TEXT_BOUNDARY_PARAGRAPH: return ui::PARAGRAPH_BOUNDARY; 1177 case IA2_TEXT_BOUNDARY_PARAGRAPH: return ui::PARAGRAPH_BOUNDARY;
1155 case IA2_TEXT_BOUNDARY_ALL: return ui::ALL_BOUNDARY; 1178 case IA2_TEXT_BOUNDARY_ALL: return ui::ALL_BOUNDARY;
1156 default: 1179 default:
1157 NOTREACHED(); 1180 NOTREACHED();
1158 return ui::CHAR_BOUNDARY; 1181 return ui::CHAR_BOUNDARY;
1159 } 1182 }
1160 } 1183 }
1161 1184
1162 LONG AXPlatformNodeWin::FindBoundary( 1185 LONG AXPlatformNodeWin::FindBoundary(
1163 const base::string16& text, 1186 const base::string16& text,
1164 IA2TextBoundaryType ia2_boundary, 1187 IA2TextBoundaryType ia2_boundary,
1165 LONG start_offset, 1188 LONG start_offset,
1166 ui::TextBoundaryDirection direction) { 1189 ui::TextBoundaryDirection direction) {
1167 HandleSpecialTextOffset(text, &start_offset); 1190 HandleSpecialTextOffset(&start_offset);
1168 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary); 1191 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary);
1169 std::vector<int32_t> line_breaks; 1192 std::vector<int32_t> line_breaks;
1170 return static_cast<LONG>(ui::FindAccessibleTextBoundary( 1193 return static_cast<LONG>(ui::FindAccessibleTextBoundary(
1171 text, line_breaks, boundary, start_offset, direction, 1194 text, line_breaks, boundary, start_offset, direction,
1172 AX_TEXT_AFFINITY_DOWNSTREAM)); 1195 AX_TEXT_AFFINITY_DOWNSTREAM));
1173 } 1196 }
1174 1197
1175 } // namespace ui 1198 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698