Line data Source code
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/. */
7 :
8 : #ifndef mozilla_a11y_aria_ARIAMap_h_
9 : #define mozilla_a11y_aria_ARIAMap_h_
10 :
11 : #include "ARIAStateMap.h"
12 : #include "mozilla/a11y/AccTypes.h"
13 : #include "mozilla/a11y/Role.h"
14 :
15 : #include "nsIAtom.h"
16 : #include "nsIContent.h"
17 :
18 : class nsINode;
19 :
20 : ////////////////////////////////////////////////////////////////////////////////
21 : // Value constants
22 :
23 : /**
24 : * Used to define if role requires to expose Value interface.
25 : */
26 : enum EValueRule
27 : {
28 : /**
29 : * Value interface isn't exposed.
30 : */
31 : eNoValue,
32 :
33 : /**
34 : * Value interface is implemented, supports value, min and max from
35 : * aria-valuenow, aria-valuemin and aria-valuemax.
36 : */
37 : eHasValueMinMax,
38 :
39 : /**
40 : * Value interface is implemented, but only if the element is focusable.
41 : * For instance, in ARIA 1.1 the ability for authors to create adjustable
42 : * splitters was provided by supporting the value interface on separators
43 : * that are focusable. Non-focusable separators expose no value information.
44 : */
45 : eHasValueMinMaxIfFocusable
46 : };
47 :
48 :
49 : ////////////////////////////////////////////////////////////////////////////////
50 : // Action constants
51 :
52 : /**
53 : * Used to define if the role requires to expose action.
54 : */
55 : enum EActionRule
56 : {
57 : eNoAction,
58 : eActivateAction,
59 : eClickAction,
60 : ePressAction,
61 : eCheckUncheckAction,
62 : eExpandAction,
63 : eJumpAction,
64 : eOpenCloseAction,
65 : eSelectAction,
66 : eSortAction,
67 : eSwitchAction
68 : };
69 :
70 :
71 : ////////////////////////////////////////////////////////////////////////////////
72 : // Live region constants
73 :
74 : /**
75 : * Used to define if role exposes default value of aria-live attribute.
76 : */
77 : enum ELiveAttrRule
78 : {
79 : eNoLiveAttr,
80 : eOffLiveAttr,
81 : ePoliteLiveAttr
82 : };
83 :
84 :
85 : ////////////////////////////////////////////////////////////////////////////////
86 : // Role constants
87 :
88 : /**
89 : * ARIA role overrides role from native markup.
90 : */
91 : const bool kUseMapRole = true;
92 :
93 : /**
94 : * ARIA role doesn't override the role from native markup.
95 : */
96 : const bool kUseNativeRole = false;
97 :
98 :
99 : ////////////////////////////////////////////////////////////////////////////////
100 : // ARIA attribute characteristic masks
101 :
102 : /**
103 : * This mask indicates the attribute should not be exposed as an object
104 : * attribute via the catch-all logic in Accessible::Attributes().
105 : * This means it either isn't mean't to be exposed as an object attribute, or
106 : * that it should, but is already handled in other code.
107 : */
108 : const uint8_t ATTR_BYPASSOBJ = 0x1 << 0;
109 : const uint8_t ATTR_BYPASSOBJ_IF_FALSE = 0x1 << 1;
110 :
111 : /**
112 : * This mask indicates the attribute is expected to have an NMTOKEN or bool value.
113 : * (See for example usage in Accessible::Attributes())
114 : */
115 : const uint8_t ATTR_VALTOKEN = 0x1 << 2;
116 :
117 : /**
118 : * Indicate the attribute is global state or property (refer to
119 : * http://www.w3.org/TR/wai-aria/states_and_properties#global_states).
120 : */
121 : const uint8_t ATTR_GLOBAL = 0x1 << 3;
122 :
123 : ////////////////////////////////////////////////////////////////////////////////
124 : // State map entry
125 :
126 : /**
127 : * Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for
128 : * a given role.
129 : */
130 : #define kNoReqStates 0
131 :
132 : ////////////////////////////////////////////////////////////////////////////////
133 : // Role map entry
134 :
135 : /**
136 : * For each ARIA role, this maps the nsIAccessible information.
137 : */
138 : struct nsRoleMapEntry
139 : {
140 : /**
141 : * Return true if matches to the given ARIA role.
142 : */
143 0 : bool Is(nsIAtom* aARIARole) const
144 0 : { return *roleAtom == aARIARole; }
145 :
146 : /**
147 : * Return true if ARIA role has the given accessible type.
148 : */
149 0 : bool IsOfType(mozilla::a11y::AccGenericType aType) const
150 0 : { return accTypes & aType; }
151 :
152 : /**
153 : * Return ARIA role.
154 : */
155 0 : const nsDependentAtomString ARIARoleString() const
156 0 : { return nsDependentAtomString(*roleAtom); }
157 :
158 : // ARIA role: string representation such as "button"
159 : nsIAtom** roleAtom;
160 :
161 : // Role mapping rule: maps to enum Role
162 : mozilla::a11y::role role;
163 :
164 : // Role rule: whether to use mapped role or native semantics
165 : bool roleRule;
166 :
167 : // Value mapping rule: how to compute accessible value
168 : EValueRule valueRule;
169 :
170 : // Action mapping rule, how to expose accessible action
171 : EActionRule actionRule;
172 :
173 : // 'live' and 'container-live' object attributes mapping rule: how to expose
174 : // these object attributes if ARIA 'live' attribute is missed.
175 : ELiveAttrRule liveAttRule;
176 :
177 : // Accessible types this role belongs to.
178 : uint32_t accTypes;
179 :
180 : // Automatic state mapping rule: always include in states
181 : uint64_t state; // or kNoReqStates if no default state for this role
182 :
183 : // ARIA properties supported for this role (in other words, the aria-foo
184 : // attribute to accessible states mapping rules).
185 : // Currently you cannot have unlimited mappings, because
186 : // a variable sized array would not allow the use of
187 : // C++'s struct initialization feature.
188 : mozilla::a11y::aria::EStateRule attributeMap1;
189 : mozilla::a11y::aria::EStateRule attributeMap2;
190 : mozilla::a11y::aria::EStateRule attributeMap3;
191 : mozilla::a11y::aria::EStateRule attributeMap4;
192 : };
193 :
194 :
195 : ////////////////////////////////////////////////////////////////////////////////
196 : // ARIA map
197 :
198 : /**
199 : * These provide the mappings for WAI-ARIA roles, states and properties using
200 : * the structs defined in this file and ARIAStateMap files.
201 : */
202 : namespace mozilla {
203 : namespace a11y {
204 : namespace aria {
205 :
206 : /**
207 : * Empty role map entry. Used by accessibility service to create an accessible
208 : * if the accessible can't use role of used accessible class. For example,
209 : * it is used for table cells that aren't contained by table.
210 : */
211 : extern nsRoleMapEntry gEmptyRoleMap;
212 :
213 : /**
214 : * Constants for the role map entry index to indicate that the role map entry
215 : * isn't in sWAIRoleMaps, but rather is a special entry: nullptr,
216 : * gEmptyRoleMap, and sLandmarkRoleMap
217 : */
218 : const uint8_t NO_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 2;
219 : const uint8_t EMPTY_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 1;
220 : const uint8_t LANDMARK_ROLE_MAP_ENTRY_INDEX = UINT8_MAX;
221 :
222 : /**
223 : * Get the role map entry for a given DOM node. This will use the first
224 : * ARIA role if the role attribute provides a space delimited list of roles.
225 : *
226 : * @param aEl [in] the DOM node to get the role map entry for
227 : * @return a pointer to the role map entry for the ARIA role, or nullptr
228 : * if none
229 : */
230 : const nsRoleMapEntry* GetRoleMap(dom::Element* aEl);
231 :
232 : /**
233 : * Get the role map entry pointer's index for a given DOM node. This will use
234 : * the first ARIA role if the role attribute provides a space delimited list of
235 : * roles.
236 : *
237 : * @param aEl [in] the DOM node to get the role map entry for
238 : * @return the index of the pointer to the role map entry for the ARIA
239 : * role, or NO_ROLE_MAP_ENTRY_INDEX if none
240 : */
241 : uint8_t GetRoleMapIndex(dom::Element* aEl);
242 :
243 : /**
244 : * Get the role map entry pointer for a given role map entry index.
245 : *
246 : * @param aRoleMapIndex [in] the role map index to get the role map entry
247 : * pointer for
248 : * @return a pointer to the role map entry for the ARIA role,
249 : * or nullptr, if none
250 : */
251 : const nsRoleMapEntry* GetRoleMapFromIndex(uint8_t aRoleMapIndex);
252 :
253 : /**
254 : * Get the role map entry index for a given role map entry pointer. If the role
255 : * map entry is within sWAIRoleMaps, return the index within that array,
256 : * otherwise return one of the special index constants listed above.
257 : *
258 : * @param aRoleMap [in] the role map entry pointer to get the index for
259 : * @return the index of the pointer to the role map entry, or
260 : * NO_ROLE_MAP_ENTRY_INDEX if none
261 : */
262 : uint8_t GetIndexFromRoleMap(const nsRoleMapEntry* aRoleMap);
263 :
264 : /**
265 : * Return accessible state from ARIA universal states applied to the given
266 : * element.
267 : */
268 : uint64_t UniversalStatesFor(mozilla::dom::Element* aElement);
269 :
270 : /**
271 : * Get the ARIA attribute characteristics for a given ARIA attribute.
272 : *
273 : * @param aAtom ARIA attribute
274 : * @return A bitflag representing the attribute characteristics
275 : * (see above for possible bit masks, prefixed "ATTR_")
276 : */
277 : uint8_t AttrCharacteristicsFor(nsIAtom* aAtom);
278 :
279 : /**
280 : * Return true if the element has defined aria-hidden.
281 : */
282 : bool HasDefinedARIAHidden(nsIContent* aContent);
283 :
284 : /**
285 : * Represents a simple enumerator for iterating through ARIA attributes
286 : * exposed as object attributes on a given accessible.
287 : */
288 : class AttrIterator
289 : {
290 : public:
291 0 : explicit AttrIterator(nsIContent* aContent) :
292 0 : mContent(aContent), mAttrIdx(0)
293 : {
294 0 : mAttrCount = mContent->GetAttrCount();
295 0 : }
296 :
297 : bool Next(nsAString& aAttrName, nsAString& aAttrValue);
298 :
299 : private:
300 : AttrIterator() = delete;
301 : AttrIterator(const AttrIterator&) = delete;
302 : AttrIterator& operator= (const AttrIterator&) = delete;
303 :
304 : nsIContent* mContent;
305 : uint32_t mAttrIdx;
306 : uint32_t mAttrCount;
307 : };
308 :
309 : } // namespace aria
310 : } // namespace a11y
311 : } // namespace mozilla
312 :
313 : #endif
|