Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / accessibility / platform / ax_platform_node_win.h
blob5d264211b3439dde860fbf2d431b4e63f3181c90
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_
8 #include <atlbase.h>
9 #include <atlcom.h>
10 #include <oleacc.h>
12 #include "third_party/iaccessible2/ia2_api_all.h"
13 #include "ui/accessibility/platform/ax_platform_node_base.h"
15 namespace ui {
17 class __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
18 AXPlatformNodeWin
19 : public CComObjectRootEx<CComMultiThreadModel>,
20 public IDispatchImpl<IAccessible2_2, &IID_IAccessible2,
21 &LIBID_IAccessible2Lib>,
22 public IAccessibleText,
23 public IServiceProvider,
24 public AXPlatformNodeBase {
25 public:
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)
34 END_COM_MAP()
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,
58 LONG* y_top,
59 LONG* width,
60 LONG* height,
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,
111 VARIANT var_id,
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,
128 long max_targets,
129 IUnknown*** targets,
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;
141 STDMETHODIMP get_extendedRole(BSTR* extended_role) override;
142 STDMETHODIMP get_nRelations(LONG* n_relations) override;
143 STDMETHODIMP get_relation(LONG relation_index,
144 IAccessibleRelation** relation) override;
145 STDMETHODIMP get_relations(LONG max_relations,
146 IAccessibleRelation** relations,
147 LONG* n_relations) override;
148 STDMETHODIMP scrollTo(enum IA2ScrollType scroll_type) override;
149 STDMETHODIMP scrollToPoint(enum IA2CoordinateType coordinate_type,
150 LONG x,
151 LONG y) override;
152 STDMETHODIMP get_groupPosition(LONG* group_level,
153 LONG* similar_items_in_group,
154 LONG* position_in_group) override;
155 STDMETHODIMP get_localizedExtendedRole(
156 BSTR* localized_extended_role) override;
157 STDMETHODIMP get_nExtendedStates(LONG* n_extended_states) override;
158 STDMETHODIMP get_extendedStates(LONG max_extended_states,
159 BSTR** extended_states,
160 LONG* n_extended_states) override;
161 STDMETHODIMP get_localizedExtendedStates(
162 LONG max_localized_extended_states,
163 BSTR** localized_extended_states,
164 LONG* n_localized_extended_states) override;
165 STDMETHODIMP get_locale(IA2Locale* locale) override;
166 STDMETHODIMP get_accessibleWithCaret(IUnknown** accessible,
167 long* caret_offset) override;
170 // IAccessibleText methods.
173 STDMETHODIMP get_nCharacters(LONG* n_characters) override;
175 STDMETHODIMP get_caretOffset(LONG* offset) override;
177 STDMETHODIMP get_nSelections(LONG* n_selections) override;
179 STDMETHODIMP get_selection(LONG selection_index,
180 LONG* start_offset,
181 LONG* end_offset) override;
183 STDMETHODIMP get_text(LONG start_offset,
184 LONG end_offset,
185 BSTR* text) override;
187 STDMETHODIMP get_textAtOffset(LONG offset,
188 enum IA2TextBoundaryType boundary_type,
189 LONG* start_offset,
190 LONG* end_offset,
191 BSTR* text) override;
193 STDMETHODIMP get_textBeforeOffset(LONG offset,
194 enum IA2TextBoundaryType boundary_type,
195 LONG* start_offset,
196 LONG* end_offset,
197 BSTR* text) override;
199 STDMETHODIMP get_textAfterOffset(LONG offset,
200 enum IA2TextBoundaryType boundary_type,
201 LONG* start_offset,
202 LONG* end_offset,
203 BSTR* text) override;
205 STDMETHODIMP get_offsetAtPoint(LONG x,
206 LONG y,
207 enum IA2CoordinateType coord_type,
208 LONG* offset) override;
211 // IAccessibleText methods not implemented.
214 STDMETHODIMP get_newText(IA2TextSegment* new_text) override;
215 STDMETHODIMP get_oldText(IA2TextSegment* old_text) override;
216 STDMETHODIMP addSelection(LONG start_offset, LONG end_offset) override;
217 STDMETHODIMP get_attributes(LONG offset,
218 LONG* start_offset,
219 LONG* end_offset,
220 BSTR* text_attributes) override;
221 STDMETHODIMP get_characterExtents(LONG offset,
222 enum IA2CoordinateType coord_type,
223 LONG* x,
224 LONG* y,
225 LONG* width,
226 LONG* height) override;
227 STDMETHODIMP removeSelection(LONG selection_index) override;
228 STDMETHODIMP setCaretOffset(LONG offset) override;
229 STDMETHODIMP setSelection(LONG selection_index,
230 LONG start_offset,
231 LONG end_offset) override;
232 STDMETHODIMP scrollSubstringTo(LONG start_index,
233 LONG end_index,
234 enum IA2ScrollType scroll_type) override;
235 STDMETHODIMP scrollSubstringToPoint(LONG start_index,
236 LONG end_index,
237 enum IA2CoordinateType coordinate_type,
238 LONG x,
239 LONG y) override;
242 // IServiceProvider methods.
245 STDMETHODIMP QueryService(REFGUID guidService,
246 REFIID riid,
247 void** object) override;
249 protected:
250 AXPlatformNodeWin();
252 private:
253 bool IsValidId(const VARIANT& child) const;
254 int MSAARole();
255 int MSAAState();
256 int MSAAEvent(ui::AXEvent event);
258 HRESULT GetStringAttributeAsBstr(
259 ui::AXStringAttribute attribute,
260 BSTR* value_bstr) const;
262 void AddAlertTarget();
263 void RemoveAlertTarget();
265 // Return the text to use for IAccessibleText.
266 base::string16 TextForIAccessibleText();
268 // If offset is a member of IA2TextSpecialOffsets this function updates the
269 // value of offset and returns, otherwise offset remains unchanged.
270 void HandleSpecialTextOffset(const base::string16& text, LONG* offset);
272 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType.
273 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type);
275 // Search forwards (direction == 1) or backwards (direction == -1)
276 // from the given offset until the given boundary is found, and
277 // return the offset of that boundary.
278 LONG FindBoundary(const base::string16& text,
279 IA2TextBoundaryType ia2_boundary,
280 LONG start_offset,
281 ui::TextBoundaryDirection direction);
283 // A windows-specific unique ID for this object. It's returned in
284 // IAccessible2::get_uniqueID, but more importantly it's used for
285 // firing events. On Windows, we fire events on the nearest parent HWND
286 // and pass the unique ID as the child id parameter. When the client
287 // wants to retrieve the object the event was fired on, it calls
288 // get_accChild and passes the child ID. We use negative IDs for the unique
289 // ID so we can distinguish a request for an arbitrary child from a request
290 // for an immediate child of an object by its 0-based index.
291 LONG unique_id_win_;
294 } // namespace ui
296 #endif // UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_WIN_H_