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
3 // found in the LICENSE file.
5 #ifndef UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_WIN_H_
6 #define UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_WIN_H_
12 #include "third_party/iaccessible2/ia2_api_all.h"
13 #include "ui/accessibility/platform/ax_platform_node_base.h"
17 class __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
19 : public CComObjectRootEx
<CComMultiThreadModel
>,
20 public IDispatchImpl
<IAccessible2_2
, &IID_IAccessible2
,
21 &LIBID_IAccessible2Lib
>,
22 public IAccessibleText
,
23 public IServiceProvider
,
24 public AXPlatformNodeBase
{
26 BEGIN_COM_MAP(AXPlatformNodeWin
)
27 COM_INTERFACE_ENTRY2(IDispatch
, IAccessible2_2
)
28 COM_INTERFACE_ENTRY(AXPlatformNodeWin
)
29 COM_INTERFACE_ENTRY(IAccessible
)
30 COM_INTERFACE_ENTRY(IAccessible2
)
31 COM_INTERFACE_ENTRY(IAccessible2_2
)
32 COM_INTERFACE_ENTRY(IAccessibleText
)
33 COM_INTERFACE_ENTRY(IServiceProvider
)
36 ~AXPlatformNodeWin() override
;
38 // AXPlatformNode overrides.
39 void Destroy() override
;
40 gfx::NativeViewAccessible
GetNativeViewAccessible() override
;
41 void NotifyAccessibilityEvent(ui::AXEvent event_type
) override
;
43 // AXPlatformNodeBase overrides.
44 int GetIndexInParent() override
;
47 // IAccessible methods.
50 // Retrieves the child element or child object at a given point on the screen.
51 STDMETHODIMP
accHitTest(LONG x_left
, LONG y_top
, VARIANT
* child
) override
;
53 // Performs the object's default action.
54 STDMETHODIMP
accDoDefaultAction(VARIANT var_id
) override
;
56 // Retrieves the specified object's current screen location.
57 STDMETHODIMP
accLocation(LONG
* x_left
,
61 VARIANT var_id
) override
;
63 // Traverses to another UI element and retrieves the object.
64 STDMETHODIMP
accNavigate(LONG nav_dir
, VARIANT start
, VARIANT
* end
) override
;
66 // Retrieves an IDispatch interface pointer for the specified child.
67 STDMETHODIMP
get_accChild(VARIANT var_child
, IDispatch
** disp_child
) override
;
69 // Retrieves the number of accessible children.
70 STDMETHODIMP
get_accChildCount(LONG
* child_count
) override
;
72 // Retrieves a string that describes the object's default action.
73 STDMETHODIMP
get_accDefaultAction(VARIANT var_id
,
74 BSTR
* default_action
) override
;
76 // Retrieves the tooltip description.
77 STDMETHODIMP
get_accDescription(VARIANT var_id
, BSTR
* desc
) override
;
79 // Retrieves the object that has the keyboard focus.
80 STDMETHODIMP
get_accFocus(VARIANT
* focus_child
) override
;
82 // Retrieves the specified object's shortcut.
83 STDMETHODIMP
get_accKeyboardShortcut(VARIANT var_id
,
84 BSTR
* access_key
) override
;
86 // Retrieves the name of the specified object.
87 STDMETHODIMP
get_accName(VARIANT var_id
, BSTR
* name
) override
;
89 // Retrieves the IDispatch interface of the object's parent.
90 STDMETHODIMP
get_accParent(IDispatch
** disp_parent
) override
;
92 // Retrieves information describing the role of the specified object.
93 STDMETHODIMP
get_accRole(VARIANT var_id
, VARIANT
* role
) override
;
95 // Retrieves the current state of the specified object.
96 STDMETHODIMP
get_accState(VARIANT var_id
, VARIANT
* state
) override
;
98 // Gets the help string for the specified object.
99 STDMETHODIMP
get_accHelp(VARIANT var_id
, BSTR
* help
) override
;
101 // Retrieve or set the string value associated with the specified object.
102 // Setting the value is not typically used by screen readers, but it's
103 // used frequently by automation software.
104 STDMETHODIMP
get_accValue(VARIANT var_id
, BSTR
* value
) override
;
105 STDMETHODIMP
put_accValue(VARIANT var_id
, BSTR new_value
) override
;
107 // IAccessible methods not implemented.
108 STDMETHODIMP
get_accSelection(VARIANT
* selected
) override
;
109 STDMETHODIMP
accSelect(LONG flags_sel
, VARIANT var_id
) override
;
110 STDMETHODIMP
get_accHelpTopic(BSTR
* help_file
,
112 LONG
* topic_id
) override
;
113 STDMETHODIMP
put_accName(VARIANT var_id
, BSTR put_name
) override
;
116 // IAccessible2 methods.
119 STDMETHODIMP
role(LONG
* role
) override
;
121 STDMETHODIMP
get_states(AccessibleStates
* states
) override
;
123 STDMETHODIMP
get_uniqueID(LONG
* unique_id
) override
;
125 STDMETHODIMP
get_windowHandle(HWND
* window_handle
) override
;
127 STDMETHODIMP
get_relationTargetsOfType(BSTR type
,
130 long* n_targets
) override
;
132 STDMETHODIMP
get_attributes(BSTR
* attributes
) override
;
134 STDMETHODIMP
get_indexInParent(LONG
* index_in_parent
) override
;
137 // IAccessible2 methods not implemented.
140 STDMETHODIMP
get_attribute(BSTR name
, VARIANT
* attribute
) override
{
143 STDMETHODIMP
get_extendedRole(BSTR
* extended_role
) override
{
146 STDMETHODIMP
get_nRelations(LONG
* n_relations
) override
{ return E_NOTIMPL
; }
147 STDMETHODIMP
get_relation(LONG relation_index
,
148 IAccessibleRelation
** relation
) override
{
151 STDMETHODIMP
get_relations(LONG max_relations
,
152 IAccessibleRelation
** relations
,
153 LONG
* n_relations
) override
{
156 STDMETHODIMP
scrollTo(enum IA2ScrollType scroll_type
) override
{
159 STDMETHODIMP
scrollToPoint(enum IA2CoordinateType coordinate_type
,
164 STDMETHODIMP
get_groupPosition(LONG
* group_level
,
165 LONG
* similar_items_in_group
,
166 LONG
* position_in_group
) override
{
169 STDMETHODIMP
get_localizedExtendedRole(
170 BSTR
* localized_extended_role
) override
{
173 STDMETHODIMP
get_nExtendedStates(LONG
* n_extended_states
) override
{
176 STDMETHODIMP
get_extendedStates(LONG max_extended_states
,
177 BSTR
** extended_states
,
178 LONG
* n_extended_states
) override
{
181 STDMETHODIMP
get_localizedExtendedStates(
182 LONG max_localized_extended_states
,
183 BSTR
** localized_extended_states
,
184 LONG
* n_localized_extended_states
) override
{
187 STDMETHODIMP
get_locale(IA2Locale
* locale
) override
{ return E_NOTIMPL
; }
188 STDMETHODIMP
get_accessibleWithCaret(IUnknown
** accessible
,
189 long* caret_offset
) override
{
194 // IAccessibleText methods.
197 STDMETHODIMP
get_nCharacters(LONG
* n_characters
) override
;
199 STDMETHODIMP
get_caretOffset(LONG
* offset
) override
;
201 STDMETHODIMP
get_nSelections(LONG
* n_selections
) override
;
203 STDMETHODIMP
get_selection(LONG selection_index
,
205 LONG
* end_offset
) override
;
207 STDMETHODIMP
get_text(LONG start_offset
,
209 BSTR
* text
) override
;
211 STDMETHODIMP
get_textAtOffset(LONG offset
,
212 enum IA2TextBoundaryType boundary_type
,
215 BSTR
* text
) override
;
217 STDMETHODIMP
get_textBeforeOffset(LONG offset
,
218 enum IA2TextBoundaryType boundary_type
,
221 BSTR
* text
) override
;
223 STDMETHODIMP
get_textAfterOffset(LONG offset
,
224 enum IA2TextBoundaryType boundary_type
,
227 BSTR
* text
) override
;
229 STDMETHODIMP
get_offsetAtPoint(LONG x
,
231 enum IA2CoordinateType coord_type
,
232 LONG
* offset
) override
;
235 // IAccessibleText methods not implemented.
238 STDMETHODIMP
get_newText(IA2TextSegment
* new_text
) override
{
241 STDMETHODIMP
get_oldText(IA2TextSegment
* old_text
) override
{
244 STDMETHODIMP
addSelection(LONG start_offset
, LONG end_offset
) override
{
247 STDMETHODIMP
get_attributes(LONG offset
,
250 BSTR
* text_attributes
) override
{
253 STDMETHODIMP
get_characterExtents(LONG offset
,
254 enum IA2CoordinateType coord_type
,
258 LONG
* height
) override
{
261 STDMETHODIMP
removeSelection(LONG selection_index
) override
{
264 STDMETHODIMP
setCaretOffset(LONG offset
) override
{ return E_NOTIMPL
; }
265 STDMETHODIMP
setSelection(LONG selection_index
,
267 LONG end_offset
) override
{
270 STDMETHODIMP
scrollSubstringTo(LONG start_index
,
272 enum IA2ScrollType scroll_type
) override
{
275 STDMETHODIMP
scrollSubstringToPoint(LONG start_index
,
277 enum IA2CoordinateType coordinate_type
,
284 // IServiceProvider methods.
287 STDMETHODIMP
QueryService(REFGUID guidService
,
289 void** object
) override
;
295 bool IsValidId(const VARIANT
& child
) const;
298 int MSAAEvent(ui::AXEvent event
);
300 HRESULT
GetStringAttributeAsBstr(
301 ui::AXStringAttribute attribute
,
302 BSTR
* value_bstr
) const;
304 void AddAlertTarget();
305 void RemoveAlertTarget();
307 // Return the text to use for IAccessibleText.
308 base::string16
TextForIAccessibleText();
310 // If offset is a member of IA2TextSpecialOffsets this function updates the
311 // value of offset and returns, otherwise offset remains unchanged.
312 void HandleSpecialTextOffset(const base::string16
& text
, LONG
* offset
);
314 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType.
315 ui::TextBoundaryType
IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type
);
317 // Search forwards (direction == 1) or backwards (direction == -1)
318 // from the given offset until the given boundary is found, and
319 // return the offset of that boundary.
320 LONG
FindBoundary(const base::string16
& text
,
321 IA2TextBoundaryType ia2_boundary
,
323 ui::TextBoundaryDirection direction
);
325 // A windows-specific unique ID for this object. It's returned in
326 // IAccessible2::get_uniqueID, but more importantly it's used for
327 // firing events. On Windows, we fire events on the nearest parent HWND
328 // and pass the unique ID as the child id parameter. When the client
329 // wants to retrieve the object the event was fired on, it calls
330 // get_accChild and passes the child ID. We use negative IDs for the unique
331 // ID so we can distinguish a request for an arbitrary child from a request
332 // for an immediate child of an object by its 0-based index.
338 #endif // UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_WIN_H_