Bug 1568157 - Part 4: Replace `toolbox.walker` with the contextual WalkerFront. r...
[gecko.git] / accessible / base / nsAccessibilityService.h
blob94596bef1bddde0cbf2be950409945954dc1da16
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __nsAccessibilityService_h__
7 #define __nsAccessibilityService_h__
9 #include "mozilla/a11y/DocManager.h"
10 #include "mozilla/a11y/FocusManager.h"
11 #include "mozilla/a11y/Platform.h"
12 #include "mozilla/a11y/Role.h"
13 #include "mozilla/a11y/SelectionManager.h"
14 #include "mozilla/Preferences.h"
16 #include "nsIObserver.h"
17 #include "nsIAccessibleEvent.h"
18 #include "nsIEventListenerService.h"
19 #include "xpcAccessibilityService.h"
21 class nsImageFrame;
22 class nsIArray;
23 class nsIPersistentProperties;
24 class nsPluginFrame;
25 class nsITreeView;
27 namespace mozilla {
29 class PresShell;
31 namespace dom {
32 class DOMStringList;
35 namespace a11y {
37 class ApplicationAccessible;
38 class xpcAccessibleApplication;
40 /**
41 * Return focus manager.
43 FocusManager* FocusMgr();
45 /**
46 * Return selection manager.
48 SelectionManager* SelectionMgr();
50 /**
51 * Returns the application accessible.
53 ApplicationAccessible* ApplicationAcc();
54 xpcAccessibleApplication* XPCApplicationAcc();
56 typedef Accessible*(New_Accessible)(Element* aElement, Accessible* aContext);
58 // These fields are not `nsStaticAtom* const` because MSVC doesn't like it.
59 struct MarkupAttrInfo {
60 nsStaticAtom* name;
61 nsStaticAtom* value;
63 nsStaticAtom* DOMAttrName;
64 nsStaticAtom* DOMAttrValue;
67 struct HTMLMarkupMapInfo {
68 const nsStaticAtom* const tag;
69 New_Accessible* new_func;
70 a11y::role role;
71 MarkupAttrInfo attrs[4];
74 #ifdef MOZ_XUL
75 struct XULMarkupMapInfo {
76 const nsStaticAtom* const tag;
77 New_Accessible* new_func;
79 #endif
81 /**
82 * PREF_ACCESSIBILITY_FORCE_DISABLED preference change callback.
84 void PrefChanged(const char* aPref, void* aClosure);
86 /**
87 * Read and normalize PREF_ACCESSIBILITY_FORCE_DISABLED preference.
89 EPlatformDisabledState ReadPlatformDisabledState();
91 } // namespace a11y
92 } // namespace mozilla
94 class nsAccessibilityService final : public mozilla::a11y::DocManager,
95 public mozilla::a11y::FocusManager,
96 public mozilla::a11y::SelectionManager,
97 public nsIListenerChangeListener,
98 public nsIObserver {
99 public:
100 typedef mozilla::a11y::Accessible Accessible;
101 typedef mozilla::a11y::DocAccessible DocAccessible;
103 // nsIListenerChangeListener
104 NS_IMETHOD ListenersChanged(nsIArray* aEventChanges) override;
106 protected:
107 ~nsAccessibilityService();
109 public:
110 NS_DECL_ISUPPORTS_INHERITED
111 NS_DECL_NSIOBSERVER
113 Accessible* GetRootDocumentAccessible(mozilla::PresShell* aPresShell,
114 bool aCanCreate);
115 already_AddRefed<Accessible> CreatePluginAccessible(nsPluginFrame* aFrame,
116 nsIContent* aContent,
117 Accessible* aContext);
120 * Adds/remove ATK root accessible for gtk+ native window to/from children
121 * of the application accessible.
123 Accessible* AddNativeRootAccessible(void* aAtkAccessible);
124 void RemoveNativeRootAccessible(Accessible* aRootAccessible);
126 bool HasAccessible(nsINode* aDOMNode);
129 * Get a string equivalent for an accessible role value.
131 void GetStringRole(uint32_t aRole, nsAString& aString);
134 * Get a string equivalent for an accessible state/extra state.
136 already_AddRefed<mozilla::dom::DOMStringList> GetStringStates(
137 uint64_t aStates) const;
138 void GetStringStates(uint32_t aState, uint32_t aExtraState,
139 nsISupports** aStringStates);
142 * Get a string equivalent for an accessible event value.
144 void GetStringEventType(uint32_t aEventType, nsAString& aString);
147 * Get a string equivalent for an accessible event value.
149 void GetStringEventType(uint32_t aEventType, nsACString& aString);
152 * Get a string equivalent for an accessible relation type.
154 void GetStringRelationType(uint32_t aRelationType, nsAString& aString);
156 // nsAccesibilityService
158 * Notification used to update the accessible tree when deck panel is
159 * switched.
161 void DeckPanelSwitched(mozilla::PresShell* aPresShell, nsIContent* aDeckNode,
162 nsIFrame* aPrevBoxFrame, nsIFrame* aCurrentBoxFrame);
165 * Notification used to update the accessible tree when new content is
166 * inserted.
168 void ContentRangeInserted(mozilla::PresShell* aPresShell,
169 nsIContent* aStartChild, nsIContent* aEndChild);
172 * Notification used to update the accessible tree when content is removed.
174 void ContentRemoved(mozilla::PresShell* aPresShell, nsIContent* aChild);
176 void UpdateText(mozilla::PresShell* aPresShell, nsIContent* aContent);
179 * Update XUL:tree accessible tree when treeview is changed.
181 void TreeViewChanged(mozilla::PresShell* aPresShell, nsIContent* aContent,
182 nsITreeView* aView);
185 * Notify of input@type="element" value change.
187 void RangeValueChanged(mozilla::PresShell* aPresShell, nsIContent* aContent);
190 * Update list bullet accessible.
192 void UpdateListBullet(mozilla::PresShell* aPresShell,
193 nsIContent* aHTMLListItemContent, bool aHasBullet);
196 * Update the image map.
198 void UpdateImageMap(nsImageFrame* aImageFrame);
201 * Update the label accessible tree when rendered @value is changed.
203 void UpdateLabelValue(mozilla::PresShell* aPresShell, nsIContent* aLabelElm,
204 const nsString& aNewValue);
207 * Notify accessibility that anchor jump has been accomplished to the given
208 * target. Used by layout.
210 void NotifyOfAnchorJumpTo(nsIContent* aTarget);
213 * Notify that presshell is activated.
215 void PresShellActivated(mozilla::PresShell* aPresShell);
218 * Recreate an accessible for the given content node in the presshell.
220 void RecreateAccessible(mozilla::PresShell* aPresShell, nsIContent* aContent);
222 void FireAccessibleEvent(uint32_t aEvent, Accessible* aTarget);
224 // nsAccessibiltiyService
227 * Return true if accessibility service has been shutdown.
229 static bool IsShutdown() { return gConsumers == 0; };
232 * Creates an accessible for the given DOM node.
234 * @param aNode [in] the given node
235 * @param aContext [in] context the accessible is created in
236 * @param aIsSubtreeHidden [out, optional] indicates whether the node's
237 * frame and its subtree is hidden
239 Accessible* CreateAccessible(nsINode* aNode, Accessible* aContext,
240 bool* aIsSubtreeHidden = nullptr);
242 mozilla::a11y::role MarkupRole(const nsIContent* aContent) const {
243 const mozilla::a11y::HTMLMarkupMapInfo* markupMap =
244 mHTMLMarkupMap.Get(aContent->NodeInfo()->NameAtom());
245 return markupMap ? markupMap->role : mozilla::a11y::roles::NOTHING;
249 * Set the object attribute defined by markup for the given element.
251 void MarkupAttributes(const nsIContent* aContent,
252 nsIPersistentProperties* aAttributes) const;
255 * A list of possible accessibility service consumers. Accessibility service
256 * can only be shut down when there are no remaining consumers.
258 * eXPCOM - accessibility service is used by XPCOM.
260 * eMainProcess - accessibility service was started by main process in the
261 * content process.
263 * ePlatformAPI - accessibility service is used by the platform api in the
264 * main process.
266 enum ServiceConsumer {
267 eXPCOM = 1 << 0,
268 eMainProcess = 1 << 1,
269 ePlatformAPI = 1 << 2,
272 private:
273 // nsAccessibilityService creation is controlled by friend
274 // GetOrCreateAccService, keep constructors private.
275 nsAccessibilityService();
276 nsAccessibilityService(const nsAccessibilityService&);
277 nsAccessibilityService& operator=(const nsAccessibilityService&);
279 private:
281 * Initialize accessibility service.
283 bool Init();
286 * Shutdowns accessibility service.
288 void Shutdown();
291 * Create an accessible whose type depends on the given frame.
293 already_AddRefed<Accessible> CreateAccessibleByFrameType(
294 nsIFrame* aFrame, nsIContent* aContent, Accessible* aContext);
297 * Notify observers about change of the accessibility service's consumers.
299 void NotifyOfConsumersChange();
302 * Get a JSON string representing the accessibility service consumers.
304 void GetConsumers(nsAString& aString);
307 * Set accessibility service consumers.
309 void SetConsumers(uint32_t aConsumers, bool aNotify = true);
312 * Unset accessibility service consumers.
314 void UnsetConsumers(uint32_t aConsumers);
317 * Reference for accessibility service instance.
319 static nsAccessibilityService* gAccessibilityService;
322 * Reference for application accessible instance.
324 static mozilla::a11y::ApplicationAccessible* gApplicationAccessible;
325 static mozilla::a11y::xpcAccessibleApplication* gXPCApplicationAccessible;
328 * Contains a set of accessibility service consumers.
330 static uint32_t gConsumers;
332 nsDataHashtable<nsPtrHashKey<const nsAtom>,
333 const mozilla::a11y::HTMLMarkupMapInfo*>
334 mHTMLMarkupMap;
335 #ifdef MOZ_XUL
336 nsDataHashtable<nsPtrHashKey<const nsAtom>,
337 const mozilla::a11y::XULMarkupMapInfo*>
338 mXULMarkupMap;
339 #endif
341 friend nsAccessibilityService* GetAccService();
342 friend nsAccessibilityService* GetOrCreateAccService(uint32_t);
343 friend void MaybeShutdownAccService(uint32_t);
344 friend void mozilla::a11y::PrefChanged(const char*, void*);
345 friend mozilla::a11y::FocusManager* mozilla::a11y::FocusMgr();
346 friend mozilla::a11y::SelectionManager* mozilla::a11y::SelectionMgr();
347 friend mozilla::a11y::ApplicationAccessible* mozilla::a11y::ApplicationAcc();
348 friend mozilla::a11y::xpcAccessibleApplication*
349 mozilla::a11y::XPCApplicationAcc();
350 friend class xpcAccessibilityService;
354 * Return the accessibility service instance. (Handy global function)
356 inline nsAccessibilityService* GetAccService() {
357 return nsAccessibilityService::gAccessibilityService;
361 * Return accessibility service instance; creating one if necessary.
363 nsAccessibilityService* GetOrCreateAccService(
364 uint32_t aNewConsumer = nsAccessibilityService::ePlatformAPI);
367 * Shutdown accessibility service if needed.
369 void MaybeShutdownAccService(uint32_t aFormerConsumer);
372 * Return true if we're in a content process and not B2G.
374 inline bool IPCAccessibilityActive() { return XRE_IsContentProcess(); }
377 * Map nsIAccessibleEvents constants to strings. Used by
378 * nsAccessibilityService::GetStringEventType() method.
380 static const char kEventTypeNames[][40] = {
381 "unknown", //
382 "show", // EVENT_SHOW
383 "hide", // EVENT_HIDE
384 "reorder", // EVENT_REORDER
385 "active decendent change", // EVENT_ACTIVE_DECENDENT_CHANGED
386 "focus", // EVENT_FOCUS
387 "state change", // EVENT_STATE_CHANGE
388 "location change", // EVENT_LOCATION_CHANGE
389 "name changed", // EVENT_NAME_CHANGE
390 "description change", // EVENT_DESCRIPTION_CHANGE
391 "value change", // EVENT_VALUE_CHANGE
392 "help change", // EVENT_HELP_CHANGE
393 "default action change", // EVENT_DEFACTION_CHANGE
394 "action change", // EVENT_ACTION_CHANGE
395 "accelerator change", // EVENT_ACCELERATOR_CHANGE
396 "selection", // EVENT_SELECTION
397 "selection add", // EVENT_SELECTION_ADD
398 "selection remove", // EVENT_SELECTION_REMOVE
399 "selection within", // EVENT_SELECTION_WITHIN
400 "alert", // EVENT_ALERT
401 "foreground", // EVENT_FOREGROUND
402 "menu start", // EVENT_MENU_START
403 "menu end", // EVENT_MENU_END
404 "menupopup start", // EVENT_MENUPOPUP_START
405 "menupopup end", // EVENT_MENUPOPUP_END
406 "capture start", // EVENT_CAPTURE_START
407 "capture end", // EVENT_CAPTURE_END
408 "movesize start", // EVENT_MOVESIZE_START
409 "movesize end", // EVENT_MOVESIZE_END
410 "contexthelp start", // EVENT_CONTEXTHELP_START
411 "contexthelp end", // EVENT_CONTEXTHELP_END
412 "dragdrop start", // EVENT_DRAGDROP_START
413 "dragdrop end", // EVENT_DRAGDROP_END
414 "dialog start", // EVENT_DIALOG_START
415 "dialog end", // EVENT_DIALOG_END
416 "scrolling start", // EVENT_SCROLLING_START
417 "scrolling end", // EVENT_SCROLLING_END
418 "minimize start", // EVENT_MINIMIZE_START
419 "minimize end", // EVENT_MINIMIZE_END
420 "document load complete", // EVENT_DOCUMENT_LOAD_COMPLETE
421 "document reload", // EVENT_DOCUMENT_RELOAD
422 "document load stopped", // EVENT_DOCUMENT_LOAD_STOPPED
423 "document attributes changed", // EVENT_DOCUMENT_ATTRIBUTES_CHANGED
424 "document content changed", // EVENT_DOCUMENT_CONTENT_CHANGED
425 "property changed", // EVENT_PROPERTY_CHANGED
426 "page changed", // EVENT_PAGE_CHANGED
427 "text attribute changed", // EVENT_TEXT_ATTRIBUTE_CHANGED
428 "text caret moved", // EVENT_TEXT_CARET_MOVED
429 "text changed", // EVENT_TEXT_CHANGED
430 "text inserted", // EVENT_TEXT_INSERTED
431 "text removed", // EVENT_TEXT_REMOVED
432 "text updated", // EVENT_TEXT_UPDATED
433 "text selection changed", // EVENT_TEXT_SELECTION_CHANGED
434 "visible data changed", // EVENT_VISIBLE_DATA_CHANGED
435 "text column changed", // EVENT_TEXT_COLUMN_CHANGED
436 "section changed", // EVENT_SECTION_CHANGED
437 "table caption changed", // EVENT_TABLE_CAPTION_CHANGED
438 "table model changed", // EVENT_TABLE_MODEL_CHANGED
439 "table summary changed", // EVENT_TABLE_SUMMARY_CHANGED
440 "table row description changed", // EVENT_TABLE_ROW_DESCRIPTION_CHANGED
441 "table row header changed", // EVENT_TABLE_ROW_HEADER_CHANGED
442 "table row insert", // EVENT_TABLE_ROW_INSERT
443 "table row delete", // EVENT_TABLE_ROW_DELETE
444 "table row reorder", // EVENT_TABLE_ROW_REORDER
445 "table column description changed", // EVENT_TABLE_COLUMN_DESCRIPTION_CHANGED
446 "table column header changed", // EVENT_TABLE_COLUMN_HEADER_CHANGED
447 "table column insert", // EVENT_TABLE_COLUMN_INSERT
448 "table column delete", // EVENT_TABLE_COLUMN_DELETE
449 "table column reorder", // EVENT_TABLE_COLUMN_REORDER
450 "window activate", // EVENT_WINDOW_ACTIVATE
451 "window create", // EVENT_WINDOW_CREATE
452 "window deactivate", // EVENT_WINDOW_DEACTIVATE
453 "window destroy", // EVENT_WINDOW_DESTROY
454 "window maximize", // EVENT_WINDOW_MAXIMIZE
455 "window minimize", // EVENT_WINDOW_MINIMIZE
456 "window resize", // EVENT_WINDOW_RESIZE
457 "window restore", // EVENT_WINDOW_RESTORE
458 "hyperlink end index changed", // EVENT_HYPERLINK_END_INDEX_CHANGED
459 "hyperlink number of anchors changed", // EVENT_HYPERLINK_NUMBER_OF_ANCHORS_CHANGED
460 "hyperlink selected link changed", // EVENT_HYPERLINK_SELECTED_LINK_CHANGED
461 "hypertext link activated", // EVENT_HYPERTEXT_LINK_ACTIVATED
462 "hypertext link selected", // EVENT_HYPERTEXT_LINK_SELECTED
463 "hyperlink start index changed", // EVENT_HYPERLINK_START_INDEX_CHANGED
464 "hypertext changed", // EVENT_HYPERTEXT_CHANGED
465 "hypertext links count changed", // EVENT_HYPERTEXT_NLINKS_CHANGED
466 "object attribute changed", // EVENT_OBJECT_ATTRIBUTE_CHANGED
467 "virtual cursor changed", // EVENT_VIRTUALCURSOR_CHANGED
468 "text value change", // EVENT_TEXT_VALUE_CHANGE
469 "scrolling", // EVENT_SCROLLING
470 "announcement", // EVENT_ANNOUNCEMENT
473 #endif