Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / accessible / base / ARIAMap.h
blob58a96b7112a4cfddd58e9fee2272febe44f33cbe
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"
17 #include "nsTHashSet.h"
19 class nsINode;
21 namespace mozilla::dom {
22 class Element;
25 ////////////////////////////////////////////////////////////////////////////////
26 // Value constants
28 /**
29 * Used to define if role requires to expose Value interface.
31 enum EValueRule {
32 /**
33 * Value interface isn't exposed.
35 eNoValue,
37 /**
38 * Value interface is implemented, supports value, min and max from
39 * aria-valuenow, aria-valuemin and aria-valuemax.
41 eHasValueMinMax,
43 /**
44 * Value interface is implemented, but only if the element is focusable.
45 * For instance, in ARIA 1.1 the ability for authors to create adjustable
46 * splitters was provided by supporting the value interface on separators
47 * that are focusable. Non-focusable separators expose no value information.
49 eHasValueMinMaxIfFocusable
52 ////////////////////////////////////////////////////////////////////////////////
53 // Action constants
55 /**
56 * Used to define if the role requires to expose action.
58 enum EActionRule {
59 eNoAction,
60 eActivateAction,
61 eClickAction,
62 ePressAction,
63 eCheckUncheckAction,
64 eExpandAction,
65 eJumpAction,
66 eOpenCloseAction,
67 eSelectAction,
68 eSortAction,
69 eSwitchAction
72 ////////////////////////////////////////////////////////////////////////////////
73 // Live region constants
75 /**
76 * Used to define if role exposes default value of aria-live attribute.
78 enum ELiveAttrRule {
79 eNoLiveAttr,
80 eOffLiveAttr,
81 ePoliteLiveAttr,
82 eAssertiveLiveAttr
85 ////////////////////////////////////////////////////////////////////////////////
86 // Role constants
88 /**
89 * ARIA role overrides role from native markup.
91 const bool kUseMapRole = true;
93 /**
94 * ARIA role doesn't override the role from native markup.
96 const bool kUseNativeRole = false;
98 ////////////////////////////////////////////////////////////////////////////////
99 // ARIA attribute characteristic masks
102 * This mask indicates the attribute should not be exposed as an object
103 * attribute via the catch-all logic in Accessible::Attributes().
104 * This means it either isn't mean't to be exposed as an object attribute, or
105 * that it should, but is already handled in other code.
107 const uint8_t ATTR_BYPASSOBJ = 0x1 << 0;
108 const uint8_t ATTR_BYPASSOBJ_IF_FALSE = 0x1 << 1;
111 * This mask indicates the attribute is expected to have an NMTOKEN or bool
112 * value. (See for example usage in Accessible::Attributes())
114 const uint8_t ATTR_VALTOKEN = 0x1 << 2;
117 * Indicate the attribute is global state or property (refer to
118 * http://www.w3.org/TR/wai-aria/states_and_properties#global_states).
120 const uint8_t ATTR_GLOBAL = 0x1 << 3;
123 * Indicates that the attribute should have an integer value.
125 const uint8_t ATTR_VALINT = 0x1 << 4;
127 ////////////////////////////////////////////////////////////////////////////////
128 // State map entry
131 * Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for
132 * a given role.
134 #define kNoReqStates 0
136 ////////////////////////////////////////////////////////////////////////////////
137 // Role map entry
140 * For each ARIA role, this maps the nsIAccessible information.
142 struct nsRoleMapEntry {
144 * Return true if matches to the given ARIA role.
146 bool Is(nsAtom* aARIARole) const { return roleAtom == aARIARole; }
149 * Return true if ARIA role has the given accessible type.
151 bool IsOfType(mozilla::a11y::AccGenericType aType) const {
152 return accTypes & aType;
156 * Return ARIA role.
158 const nsDependentAtomString ARIARoleString() const {
159 return nsDependentAtomString(roleAtom);
162 // ARIA role: string representation such as "button"
163 nsStaticAtom* const roleAtom;
165 // Role mapping rule: maps to enum Role
166 mozilla::a11y::role role;
168 // Role rule: whether to use mapped role or native semantics
169 bool roleRule;
171 // Value mapping rule: how to compute accessible value
172 EValueRule valueRule;
174 // Action mapping rule, how to expose accessible action
175 EActionRule actionRule;
177 // 'live' and 'container-live' object attributes mapping rule: how to expose
178 // these object attributes if ARIA 'live' attribute is missed.
179 ELiveAttrRule liveAttRule;
181 // LocalAccessible types this role belongs to.
182 uint32_t accTypes;
184 // Automatic state mapping rule: always include in states
185 uint64_t state; // or kNoReqStates if no default state for this role
187 // ARIA properties supported for this role (in other words, the aria-foo
188 // attribute to accessible states mapping rules).
189 // Currently you cannot have unlimited mappings, because
190 // a variable sized array would not allow the use of
191 // C++'s struct initialization feature.
192 mozilla::a11y::aria::EStateRule attributeMap1;
193 mozilla::a11y::aria::EStateRule attributeMap2;
194 mozilla::a11y::aria::EStateRule attributeMap3;
195 mozilla::a11y::aria::EStateRule attributeMap4;
198 ////////////////////////////////////////////////////////////////////////////////
199 // ARIA map
202 * These provide the mappings for WAI-ARIA roles, states and properties using
203 * the structs defined in this file and ARIAStateMap files.
205 namespace mozilla {
206 namespace a11y {
207 class AccAttributes;
209 namespace aria {
212 * Empty role map entry. Used by accessibility service to create an accessible
213 * if the accessible can't use role of used accessible class. For example,
214 * it is used for table cells that aren't contained by table.
216 extern nsRoleMapEntry gEmptyRoleMap;
219 * Constants for the role map entry index to indicate that the role map entry
220 * isn't in sWAIRoleMaps, but rather is a special entry: nullptr,
221 * gEmptyRoleMap, and sLandmarkRoleMap
223 const uint8_t NO_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 2;
224 const uint8_t EMPTY_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 1;
225 const uint8_t LANDMARK_ROLE_MAP_ENTRY_INDEX = UINT8_MAX;
228 * Get the role map entry for a given DOM node. This will use the first
229 * ARIA role if the role attribute provides a space delimited list of roles.
231 * @param aEl [in] the DOM node to get the role map entry for
232 * @return a pointer to the role map entry for the ARIA role, or nullptr
233 * if none
235 const nsRoleMapEntry* GetRoleMap(dom::Element* aEl);
238 * Get the role map entry pointer's index for a given DOM node, skipping any
239 * given roles. This will use the first valid ARIA role if the role attribute
240 * provides a space delimited list of roles, excluding any given roles.
242 * @param aEl [in] the DOM node to get the role map entry for
243 * @param aRolesToSkip [in] the roles to skip when searching the role string
244 * @return the index of the pointer to the role map entry for the
245 * ARIA role, or NO_ROLE_MAP_ENTRY_INDEX if none
247 uint8_t GetFirstValidRoleMapIndexExcluding(
248 dom::Element* aEl, std::initializer_list<nsStaticAtom*> aRolesToSkip);
251 * Get the role map entry pointer's index for a given DOM node. This will use
252 * the first ARIA role if the role attribute provides a space delimited list of
253 * roles.
255 * @param aEl [in] the DOM node to get the role map entry for
256 * @return the index of the pointer to the role map entry for the ARIA
257 * role, or NO_ROLE_MAP_ENTRY_INDEX if none
259 uint8_t GetRoleMapIndex(dom::Element* aEl);
262 * Get the role map entry pointer for a given role map entry index.
264 * @param aRoleMapIndex [in] the role map index to get the role map entry
265 * pointer for
266 * @return a pointer to the role map entry for the ARIA role,
267 * or nullptr, if none
269 const nsRoleMapEntry* GetRoleMapFromIndex(uint8_t aRoleMapIndex);
272 * Get the role map entry index for a given role map entry pointer. If the role
273 * map entry is within sWAIRoleMaps, return the index within that array,
274 * otherwise return one of the special index constants listed above.
276 * @param aRoleMap [in] the role map entry pointer to get the index for
277 * @return the index of the pointer to the role map entry, or
278 * NO_ROLE_MAP_ENTRY_INDEX if none
280 uint8_t GetIndexFromRoleMap(const nsRoleMapEntry* aRoleMap);
283 * Determine whether a role map entry index is valid.
285 bool IsRoleMapIndexValid(uint8_t aRoleMapIndex);
288 * Return accessible state from ARIA universal states applied to the given
289 * element.
291 uint64_t UniversalStatesFor(dom::Element* aElement);
294 * Get the ARIA attribute characteristics for a given ARIA attribute.
296 * @param aAtom ARIA attribute
297 * @return A bitflag representing the attribute characteristics
298 * (see above for possible bit masks, prefixed "ATTR_")
300 uint8_t AttrCharacteristicsFor(nsAtom* aAtom);
303 * Return true if the element has defined aria-hidden.
305 bool HasDefinedARIAHidden(nsIContent* aContent);
308 * Represents a simple enumerator for iterating through ARIA attributes
309 * exposed as object attributes on a given accessible.
311 class AttrIterator {
312 public:
313 explicit AttrIterator(nsIContent* aContent);
315 bool Next();
317 nsAtom* AttrName() const;
319 void AttrValue(nsAString& aAttrValue) const;
322 * Expose this ARIA attribute in a specified AccAttributes. The appropriate
323 * type will be used for the attribute; e.g. an atom for a token value.
325 bool ExposeAttr(AccAttributes* aTargetAttrs) const;
327 private:
328 AttrIterator() = delete;
329 AttrIterator(const AttrIterator&) = delete;
330 AttrIterator& operator=(const AttrIterator&) = delete;
332 dom::Element* mElement;
334 bool mIteratingDefaults;
335 nsTHashSet<RefPtr<nsAtom>> mOverriddenAttrs;
337 const AttrArray* mAttrs;
338 uint32_t mAttrIdx;
339 uint32_t mAttrCount;
340 RefPtr<nsAtom> mAttrAtom;
341 uint8_t mAttrCharacteristics;
344 } // namespace aria
345 } // namespace a11y
346 } // namespace mozilla
348 #endif