| OLD | NEW |
| 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 Loading... |
| 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 if (SetTextSelection(static_cast<int>(start_offset), |
| 893 static_cast<int>(end_offset))) { |
| 894 return S_OK; |
| 895 } |
| 896 return E_FAIL; |
| 897 } |
| 898 |
| 857 // | 899 // |
| 858 // IAccessibleText methods not implemented. | 900 // IAccessibleText methods not implemented. |
| 859 // | 901 // |
| 860 | 902 |
| 861 STDMETHODIMP AXPlatformNodeWin::get_newText(IA2TextSegment* new_text) { | 903 STDMETHODIMP AXPlatformNodeWin::get_newText(IA2TextSegment* new_text) { |
| 862 return E_NOTIMPL; | 904 return E_NOTIMPL; |
| 863 } | 905 } |
| 864 STDMETHODIMP AXPlatformNodeWin::get_oldText(IA2TextSegment* old_text) { | 906 STDMETHODIMP AXPlatformNodeWin::get_oldText(IA2TextSegment* old_text) { |
| 865 return E_NOTIMPL; | 907 return E_NOTIMPL; |
| 866 } | 908 } |
| 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( | 909 STDMETHODIMP AXPlatformNodeWin::get_characterExtents( |
| 878 LONG offset, | 910 LONG offset, |
| 879 enum IA2CoordinateType coord_type, | 911 enum IA2CoordinateType coord_type, |
| 880 LONG* x, | 912 LONG* x, |
| 881 LONG* y, | 913 LONG* y, |
| 882 LONG* width, | 914 LONG* width, |
| 883 LONG* height) { | 915 LONG* height) { |
| 884 return E_NOTIMPL; | 916 return E_NOTIMPL; |
| 885 } | 917 } |
| 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( | 918 STDMETHODIMP AXPlatformNodeWin::scrollSubstringTo( |
| 898 LONG start_index, | 919 LONG start_index, |
| 899 LONG end_index, | 920 LONG end_index, |
| 900 enum IA2ScrollType scroll_type) { | 921 enum IA2ScrollType scroll_type) { |
| 901 return E_NOTIMPL; | 922 return E_NOTIMPL; |
| 902 } | 923 } |
| 903 STDMETHODIMP AXPlatformNodeWin::scrollSubstringToPoint( | 924 STDMETHODIMP AXPlatformNodeWin::scrollSubstringToPoint( |
| 904 LONG start_index, | 925 LONG start_index, |
| 905 LONG end_index, | 926 LONG end_index, |
| 906 enum IA2CoordinateType coordinate_type, | 927 enum IA2CoordinateType coordinate_type, |
| 907 LONG x, | 928 LONG x, |
| 908 LONG y) { | 929 LONG y) { |
| 909 return E_NOTIMPL; | 930 return E_NOTIMPL; |
| 910 } | 931 } |
| 932 STDMETHODIMP AXPlatformNodeWin::get_attributes(LONG offset, |
| 933 LONG* start_offset, |
| 934 LONG* end_offset, |
| 935 BSTR* text_attributes) { |
| 936 return E_NOTIMPL; |
| 937 } |
| 911 | 938 |
| 912 // | 939 // |
| 913 // IServiceProvider implementation. | 940 // IServiceProvider implementation. |
| 914 // | 941 // |
| 915 | 942 |
| 916 STDMETHODIMP AXPlatformNodeWin::QueryService( | 943 STDMETHODIMP AXPlatformNodeWin::QueryService( |
| 917 REFGUID guidService, REFIID riid, void** object) { | 944 REFGUID guidService, REFIID riid, void** object) { |
| 918 COM_OBJECT_VALIDATE_1_ARG(object); | 945 COM_OBJECT_VALIDATE_1_ARG(object); |
| 919 | 946 |
| 920 if (riid == IID_IAccessible2) { | 947 if (riid == IID_IAccessible2) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 } | 1151 } |
| 1125 | 1152 |
| 1126 void AXPlatformNodeWin::RemoveAlertTarget() { | 1153 void AXPlatformNodeWin::RemoveAlertTarget() { |
| 1127 if (g_alert_targets.Get().find(this) != g_alert_targets.Get().end()) | 1154 if (g_alert_targets.Get().find(this) != g_alert_targets.Get().end()) |
| 1128 g_alert_targets.Get().erase(this); | 1155 g_alert_targets.Get().erase(this); |
| 1129 } | 1156 } |
| 1130 | 1157 |
| 1131 base::string16 AXPlatformNodeWin::TextForIAccessibleText() { | 1158 base::string16 AXPlatformNodeWin::TextForIAccessibleText() { |
| 1132 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) | 1159 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) |
| 1133 return GetString16Attribute(ui::AX_ATTR_VALUE); | 1160 return GetString16Attribute(ui::AX_ATTR_VALUE); |
| 1134 else | 1161 return GetString16Attribute(ui::AX_ATTR_NAME); |
| 1135 return GetString16Attribute(ui::AX_ATTR_NAME); | |
| 1136 } | 1162 } |
| 1137 | 1163 |
| 1138 void AXPlatformNodeWin::HandleSpecialTextOffset( | 1164 void AXPlatformNodeWin::HandleSpecialTextOffset(LONG* offset) { |
| 1139 const base::string16& text, LONG* offset) { | |
| 1140 if (*offset == IA2_TEXT_OFFSET_LENGTH) { | 1165 if (*offset == IA2_TEXT_OFFSET_LENGTH) { |
| 1141 *offset = static_cast<LONG>(text.size()); | 1166 *offset = static_cast<LONG>(TextForIAccessibleText().length()); |
| 1142 } else if (*offset == IA2_TEXT_OFFSET_CARET) { | 1167 } else if (*offset == IA2_TEXT_OFFSET_CARET) { |
| 1143 get_caretOffset(offset); | 1168 get_caretOffset(offset); |
| 1144 } | 1169 } |
| 1145 } | 1170 } |
| 1146 | 1171 |
| 1147 ui::TextBoundaryType AXPlatformNodeWin::IA2TextBoundaryToTextBoundary( | 1172 ui::TextBoundaryType AXPlatformNodeWin::IA2TextBoundaryToTextBoundary( |
| 1148 IA2TextBoundaryType ia2_boundary) { | 1173 IA2TextBoundaryType ia2_boundary) { |
| 1149 switch(ia2_boundary) { | 1174 switch(ia2_boundary) { |
| 1150 case IA2_TEXT_BOUNDARY_CHAR: return ui::CHAR_BOUNDARY; | 1175 case IA2_TEXT_BOUNDARY_CHAR: return ui::CHAR_BOUNDARY; |
| 1151 case IA2_TEXT_BOUNDARY_WORD: return ui::WORD_BOUNDARY; | 1176 case IA2_TEXT_BOUNDARY_WORD: return ui::WORD_BOUNDARY; |
| 1152 case IA2_TEXT_BOUNDARY_LINE: return ui::LINE_BOUNDARY; | 1177 case IA2_TEXT_BOUNDARY_LINE: return ui::LINE_BOUNDARY; |
| 1153 case IA2_TEXT_BOUNDARY_SENTENCE: return ui::SENTENCE_BOUNDARY; | 1178 case IA2_TEXT_BOUNDARY_SENTENCE: return ui::SENTENCE_BOUNDARY; |
| 1154 case IA2_TEXT_BOUNDARY_PARAGRAPH: return ui::PARAGRAPH_BOUNDARY; | 1179 case IA2_TEXT_BOUNDARY_PARAGRAPH: return ui::PARAGRAPH_BOUNDARY; |
| 1155 case IA2_TEXT_BOUNDARY_ALL: return ui::ALL_BOUNDARY; | 1180 case IA2_TEXT_BOUNDARY_ALL: return ui::ALL_BOUNDARY; |
| 1156 default: | 1181 default: |
| 1157 NOTREACHED(); | 1182 NOTREACHED(); |
| 1158 return ui::CHAR_BOUNDARY; | 1183 return ui::CHAR_BOUNDARY; |
| 1159 } | 1184 } |
| 1160 } | 1185 } |
| 1161 | 1186 |
| 1162 LONG AXPlatformNodeWin::FindBoundary( | 1187 LONG AXPlatformNodeWin::FindBoundary( |
| 1163 const base::string16& text, | 1188 const base::string16& text, |
| 1164 IA2TextBoundaryType ia2_boundary, | 1189 IA2TextBoundaryType ia2_boundary, |
| 1165 LONG start_offset, | 1190 LONG start_offset, |
| 1166 ui::TextBoundaryDirection direction) { | 1191 ui::TextBoundaryDirection direction) { |
| 1167 HandleSpecialTextOffset(text, &start_offset); | 1192 HandleSpecialTextOffset(&start_offset); |
| 1168 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary); | 1193 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary); |
| 1169 std::vector<int32_t> line_breaks; | 1194 std::vector<int32_t> line_breaks; |
| 1170 return static_cast<LONG>(ui::FindAccessibleTextBoundary( | 1195 return static_cast<LONG>(ui::FindAccessibleTextBoundary( |
| 1171 text, line_breaks, boundary, start_offset, direction, | 1196 text, line_breaks, boundary, start_offset, direction, |
| 1172 AX_TEXT_AFFINITY_DOWNSTREAM)); | 1197 AX_TEXT_AFFINITY_DOWNSTREAM)); |
| 1173 } | 1198 } |
| 1174 | 1199 |
| 1175 } // namespace ui | 1200 } // namespace ui |
| OLD | NEW |