Bug 1769547 - Do not MOZ_CRASH() on missing process r=nika
[gecko.git] / accessible / base / ARIAMap.h
blob8ab303f339b3c5ce333dfa16e367ffc3abac6a69
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef mozilla_a11y_aria_ARIAMap_h_
9 #define mozilla_a11y_aria_ARIAMap_h_
11 #include "ARIAStateMap.h"
12 #include "mozilla/a11y/AccTypes.h"
13 #include "mozilla/a11y/Role.h"
15 #include "nsAtom.h"
16 #include "nsIContent.h"
18 class nsINode;
20 namespace mozilla::dom {
21 class Element;
24 ////////////////////////////////////////////////////////////////////////////////
25 // Value constants
27 /**
28 * Used to define if role requires to expose Value interface.
30 enum EValueRule {
31 /**
32 * Value interface isn't exposed.
34 eNoValue,
36 /**
37 * Value interface is implemented, supports value, min and max from
38 * aria-valuenow, aria-valuemin and aria-valuemax.
40 eHasValueMinMax,
42 /**
43 * Value interface is implemented, but only if the element is focusable.
44 * For instance, in ARIA 1.1 the ability for authors to create adjustable
45 * splitters was provided by supporting the value interface on separators
46 * that are focusable. Non-focusable separators expose no value information.
48 eHasValueMinMaxIfFocusable
51 ////////////////////////////////////////////////////////////////////////////////
52 // Action constants
54 /**
55 * Used to define if the role requires to expose action.
57 enum EActionRule {
58 eNoAction,
59 eActivateAction,
60 eClickAction,
61 ePressAction,
62 eCheckUncheckAction,
63 eExpandAction,
64 eJumpAction,
65 eOpenCloseAction,
66 eSelectAction,
67 eSortAction,
68 eSwitchAction
71 ////////////////////////////////////////////////////////////////////////////////
72 // Live region constants
74 /**
75 * Used to define if role exposes default value of aria-live attribute.
77 enum ELiveAttrRule {
78 eNoLiveAttr,
79 eOffLiveAttr,
80 ePoliteLiveAttr,
81 eAssertiveLiveAttr
84 ////////////////////////////////////////////////////////////////////////////////
85 // Role constants
87 /**
88 * ARIA role overrides role from native markup.
90 const bool kUseMapRole = true;
92 /**
93 * ARIA role doesn't override the role from native markup.
95 const bool kUseNativeRole = false;
97 ////////////////////////////////////////////////////////////////////////////////
98 // ARIA attribute characteristic masks
101 * This mask indicates the attribute should not be exposed as an object
102 * attribute via the catch-all logic in Accessible::Attributes().
103 * This means it either isn't mean't to be exposed as an object attribute, or
104 * that it should, but is already handled in other code.
106 const uint8_t ATTR_BYPASSOBJ = 0x1 << 0;
107 const uint8_t ATTR_BYPASSOBJ_IF_FALSE = 0x1 << 1;
110 * This mask indicates the attribute is expected to have an NMTOKEN or bool
111 * value. (See for example usage in Accessible::Attributes())
113 const uint8_t ATTR_VALTOKEN = 0x1 << 2;
116 * Indicate the attribute is global state or property (refer to
117 * http://www.w3.org/TR/wai-aria/states_and_properties#global_states).
119 const uint8_t ATTR_GLOBAL = 0x1 << 3;
121 ////////////////////////////////////////////////////////////////////////////////
122 // State map entry
125 * Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for
126 * a given role.
128 #define kNoReqStates 0
130 ////////////////////////////////////////////////////////////////////////////////
131 // Role map entry
134 * For each ARIA role, this maps the nsIAccessible information.
136 struct nsRoleMapEntry {
138 * Return true if matches to the given ARIA role.
140 bool Is(nsAtom* aARIARole) const { return roleAtom == aARIARole; }
143 * Return true if ARIA role has the given accessible type.
145 bool IsOfType(mozilla::a11y::AccGenericType aType) const {
146 return accTypes & aType;
150 * Return ARIA role.
152 const nsDependentAtomString ARIARoleString() const {
153 return nsDependentAtomString(roleAtom);
156 // ARIA role: string representation such as "button"
157 nsStaticAtom* const roleAtom;
159 // Role mapping rule: maps to enum Role
160 mozilla::a11y::role role;
162 // Role rule: whether to use mapped role or native semantics
163 bool roleRule;
165 // Value mapping rule: how to compute accessible value
166 EValueRule valueRule;
168 // Action mapping rule, how to expose accessible action
169 EActionRule actionRule;
171 // 'live' and 'container-live' object attributes mapping rule: how to expose
172 // these object attributes if ARIA 'live' attribute is missed.
173 ELiveAttrRule liveAttRule;
175 // LocalAccessible types this role belongs to.
176 uint32_t accTypes;
178 // Automatic state mapping rule: always include in states
179 uint64_t state; // or kNoReqStates if no default state for this role
181 // ARIA properties supported for this role (in other words, the aria-foo
182 // attribute to accessible states mapping rules).
183 // Currently you cannot have unlimited mappings, because
184 // a variable sized array would not allow the use of
185 // C++'s struct initialization feature.
186 mozilla::a11y::aria::EStateRule attributeMap1;
187 mozilla::a11y::aria::EStateRule attributeMap2;
188 mozilla::a11y::aria::EStateRule attributeMap3;
189 mozilla::a11y::aria::EStateRule attributeMap4;
192 ////////////////////////////////////////////////////////////////////////////////
193 // ARIA map
196 * These provide the mappings for WAI-ARIA roles, states and properties using
197 * the structs defined in this file and ARIAStateMap files.
199 namespace mozilla {
200 namespace a11y {
201 namespace aria {
204 * Empty role map entry. Used by accessibility service to create an accessible
205 * if the accessible can't use role of used accessible class. For example,
206 * it is used for table cells that aren't contained by table.
208 extern nsRoleMapEntry gEmptyRoleMap;
211 * Constants for the role map entry index to indicate that the role map entry
212 * isn't in sWAIRoleMaps, but rather is a special entry: nullptr,
213 * gEmptyRoleMap, and sLandmarkRoleMap
215 const uint8_t NO_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 2;
216 const uint8_t EMPTY_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 1;
217 const uint8_t LANDMARK_ROLE_MAP_ENTRY_INDEX = UINT8_MAX;
220 * Get the role map entry for a given DOM node. This will use the first
221 * ARIA role if the role attribute provides a space delimited list of roles.
223 * @param aEl [in] the DOM node to get the role map entry for
224 * @return a pointer to the role map entry for the ARIA role, or nullptr
225 * if none
227 const nsRoleMapEntry* GetRoleMap(dom::Element* aEl);
230 * Get the role map entry pointer's index for a given DOM node. This will use
231 * the first ARIA role if the role attribute provides a space delimited list of
232 * roles.
234 * @param aEl [in] the DOM node to get the role map entry for
235 * @return the index of the pointer to the role map entry for the ARIA
236 * role, or NO_ROLE_MAP_ENTRY_INDEX if none
238 uint8_t GetRoleMapIndex(dom::Element* aEl);
241 * Get the role map entry pointer for a given role map entry index.
243 * @param aRoleMapIndex [in] the role map index to get the role map entry
244 * pointer for
245 * @return a pointer to the role map entry for the ARIA role,
246 * or nullptr, if none
248 const nsRoleMapEntry* GetRoleMapFromIndex(uint8_t aRoleMapIndex);
251 * Get the role map entry index for a given role map entry pointer. If the role
252 * map entry is within sWAIRoleMaps, return the index within that array,
253 * otherwise return one of the special index constants listed above.
255 * @param aRoleMap [in] the role map entry pointer to get the index for
256 * @return the index of the pointer to the role map entry, or
257 * NO_ROLE_MAP_ENTRY_INDEX if none
259 uint8_t GetIndexFromRoleMap(const nsRoleMapEntry* aRoleMap);
262 * Return accessible state from ARIA universal states applied to the given
263 * element.
265 uint64_t UniversalStatesFor(dom::Element* aElement);
268 * Get the ARIA attribute characteristics for a given ARIA attribute.
270 * @param aAtom ARIA attribute
271 * @return A bitflag representing the attribute characteristics
272 * (see above for possible bit masks, prefixed "ATTR_")
274 uint8_t AttrCharacteristicsFor(nsAtom* aAtom);
277 * Return true if the element has defined aria-hidden.
279 bool HasDefinedARIAHidden(nsIContent* aContent);
282 * Represents a simple enumerator for iterating through ARIA attributes
283 * exposed as object attributes on a given accessible.
285 class AttrIterator {
286 public:
287 explicit AttrIterator(nsIContent* aContent);
289 bool Next();
291 void AttrName(nsAString& aAttrName) const;
293 nsAtom* AttrName() const;
295 void AttrValue(nsAString& aAttrValue) const;
297 private:
298 AttrIterator() = delete;
299 AttrIterator(const AttrIterator&) = delete;
300 AttrIterator& operator=(const AttrIterator&) = delete;
302 dom::Element* mElement;
303 uint32_t mAttrIdx;
304 uint32_t mAttrCount;
305 RefPtr<nsAtom> mAttrAtom;
308 } // namespace aria
309 } // namespace a11y
310 } // namespace mozilla
312 #endif