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