1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:expandtab:shiftwidth=2:tabstop=2:
3 : */
4 : /* ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is mozilla.org code.
18 : *
19 : * The Initial Developer of the Original Code is IBM Corporation
20 : * Portions created by the Initial Developer are Copyright (C) 2007
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Aaron Leventhal <aleventh@us.ibm.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef _nsARIAMap_H_
41 : #define _nsARIAMap_H_
42 :
43 : #include "mozilla/a11y/Role.h"
44 : #include "prtypes.h"
45 :
46 : class nsIAtom;
47 : class nsIContent;
48 :
49 : ////////////////////////////////////////////////////////////////////////////////
50 : // Value constants
51 :
52 : /**
53 : * Used to define if role requires to expose nsIAccessibleValue.
54 : */
55 : enum EValueRule
56 : {
57 : /**
58 : * nsIAccessibleValue isn't exposed.
59 : */
60 : eNoValue,
61 :
62 : /**
63 : * nsIAccessibleValue is implemented, supports value, min and max from
64 : * aria-valuenow, aria-valuemin and aria-valuemax.
65 : */
66 : eHasValueMinMax
67 : };
68 :
69 :
70 : ////////////////////////////////////////////////////////////////////////////////
71 : // Action constants
72 :
73 : /**
74 : * Used to define if the role requires to expose action.
75 : */
76 : enum EActionRule
77 : {
78 : eNoAction,
79 : eActivateAction,
80 : eClickAction,
81 : ePressAction,
82 : eCheckUncheckAction,
83 : eExpandAction,
84 : eJumpAction,
85 : eOpenCloseAction,
86 : eSelectAction,
87 : eSortAction,
88 : eSwitchAction
89 : };
90 :
91 :
92 : ////////////////////////////////////////////////////////////////////////////////
93 : // Live region constants
94 :
95 : /**
96 : * Used to define if role exposes default value of aria-live attribute.
97 : */
98 : enum ELiveAttrRule
99 : {
100 : eNoLiveAttr,
101 : eOffLiveAttr,
102 : ePoliteLiveAttr
103 : };
104 :
105 :
106 : ////////////////////////////////////////////////////////////////////////////////
107 : // Role constants
108 :
109 : /**
110 : * ARIA role overrides role from native markup.
111 : */
112 : const bool kUseMapRole = true;
113 :
114 : /**
115 : * ARIA role doesn't override the role from native markup.
116 : */
117 : const bool kUseNativeRole = false;
118 :
119 :
120 : ////////////////////////////////////////////////////////////////////////////////
121 : // ARIA attribute characteristic masks
122 :
123 : /**
124 : * This mask indicates the attribute should not be exposed as an object
125 : * attribute via the catch-all logic in nsAccessible::GetAttributes.
126 : * This means it either isn't mean't to be exposed as an object attribute, or
127 : * that it should, but is already handled in other code.
128 : */
129 : const PRUint8 ATTR_BYPASSOBJ = 0x0001;
130 :
131 : /**
132 : * This mask indicates the attribute is expected to have an NMTOKEN or bool value.
133 : * (See for example usage in nsAccessible::GetAttributes)
134 : */
135 : const PRUint8 ATTR_VALTOKEN = 0x0010;
136 :
137 : /**
138 : * Small footprint storage of persistent aria attribute characteristics.
139 : */
140 : struct nsAttributeCharacteristics
141 : {
142 : nsIAtom** attributeName;
143 : const PRUint8 characteristics;
144 : };
145 :
146 :
147 : ////////////////////////////////////////////////////////////////////////////////
148 : // State map entry
149 :
150 : /**
151 : * Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for
152 : * a given role.
153 : */
154 : #define kNoReqStates 0
155 :
156 : enum eStateValueType
157 : {
158 : kBoolType,
159 : kMixedType
160 : };
161 :
162 : enum EDefaultStateRule
163 : {
164 : //eNoDefaultState,
165 : eUseFirstState
166 : };
167 :
168 : /**
169 : * ID for state map entry, used in nsRoleMapEntry.
170 : */
171 : enum eStateMapEntryID
172 : {
173 : eARIANone,
174 : eARIAAutoComplete,
175 : eARIABusy,
176 : eARIACheckableBool,
177 : eARIACheckableMixed,
178 : eARIACheckedMixed,
179 : eARIADisabled,
180 : eARIAExpanded,
181 : eARIAHasPopup,
182 : eARIAInvalid,
183 : eARIAMultiline,
184 : eARIAMultiSelectable,
185 : eARIAOrientation,
186 : eARIAPressed,
187 : eARIAReadonly,
188 : eARIAReadonlyOrEditable,
189 : eARIARequired,
190 : eARIASelectable
191 : };
192 :
193 : class nsStateMapEntry
194 : {
195 : public:
196 : /**
197 : * Used to create stub.
198 : */
199 : nsStateMapEntry();
200 :
201 : /**
202 : * Used for ARIA attributes having boolean or mixed values.
203 : */
204 : nsStateMapEntry(nsIAtom** aAttrName, eStateValueType aType,
205 : PRUint64 aPermanentState,
206 : PRUint64 aTrueState,
207 : PRUint64 aFalseState = 0,
208 : bool aDefinedIfAbsent = false);
209 :
210 : /**
211 : * Used for ARIA attributes having enumerated values.
212 : */
213 : nsStateMapEntry(nsIAtom** aAttrName,
214 : const char* aValue1, PRUint64 aState1,
215 : const char* aValue2, PRUint64 aState2,
216 : const char* aValue3 = 0, PRUint64 aState3 = 0);
217 :
218 : /**
219 : * Used for ARIA attributes having enumerated values, and where a default
220 : * attribute state should be assumed when not supplied by the author.
221 : */
222 : nsStateMapEntry(nsIAtom** aAttrName, EDefaultStateRule aDefaultStateRule,
223 : const char* aValue1, PRUint64 aState1,
224 : const char* aValue2, PRUint64 aState2,
225 : const char* aValue3 = 0, PRUint64 aState3 = 0);
226 :
227 : /**
228 : * Maps ARIA state map pointed by state map entry ID to accessible states.
229 : *
230 : * @param aContent [in] node of the accessible
231 : * @param aState [in/out] accessible states
232 : * @param aStateMapEntryID [in] state map entry ID
233 : * @return true if state map entry ID is valid
234 : */
235 : static bool MapToStates(nsIContent* aContent, PRUint64* aState,
236 : eStateMapEntryID aStateMapEntryID);
237 :
238 : private:
239 : // ARIA attribute name
240 : nsIAtom** mAttributeName;
241 :
242 : // Indicates if attribute is token (can be undefined)
243 : bool mIsToken;
244 :
245 : // State applied always if attribute is defined
246 : PRUint64 mPermanentState;
247 :
248 : // States applied if attribute value is matched to the stored value
249 : const char* mValue1;
250 : PRUint64 mState1;
251 :
252 : const char* mValue2;
253 : PRUint64 mState2;
254 :
255 : const char* mValue3;
256 : PRUint64 mState3;
257 :
258 : // States applied if no stored values above are matched
259 : PRUint64 mDefaultState;
260 :
261 : // Permanent and false states are applied if attribute is absent
262 : bool mDefinedIfAbsent;
263 : };
264 :
265 :
266 : ////////////////////////////////////////////////////////////////////////////////
267 : // Role map entry
268 :
269 : /**
270 : * For each ARIA role, this maps the nsIAccessible information.
271 : */
272 : struct nsRoleMapEntry
273 : {
274 : // ARIA role: string representation such as "button"
275 : const char *roleString;
276 :
277 : // Role mapping rule: maps to this nsIAccessibleRole
278 : mozilla::a11y::role role;
279 :
280 : // Role rule: whether to use mapped role or native semantics
281 : bool roleRule;
282 :
283 : // Value mapping rule: how to compute nsIAccessible value
284 : EValueRule valueRule;
285 :
286 : // Action mapping rule, how to expose nsIAccessible action
287 : EActionRule actionRule;
288 :
289 : // 'live' and 'container-live' object attributes mapping rule: how to expose
290 : // these object attributes if ARIA 'live' attribute is missed.
291 : ELiveAttrRule liveAttRule;
292 :
293 : // Automatic state mapping rule: always include in nsIAccessibleStates
294 : PRUint64 state; // or kNoReqStates if no nsIAccessibleStates are automatic for this role.
295 :
296 : // ARIA properties supported for this role
297 : // (in other words, the aria-foo attribute to nsIAccessibleStates mapping rules)
298 : // Currently you cannot have unlimited mappings, because
299 : // a variable sized array would not allow the use of
300 : // C++'s struct initialization feature.
301 : eStateMapEntryID attributeMap1;
302 : eStateMapEntryID attributeMap2;
303 : eStateMapEntryID attributeMap3;
304 : };
305 :
306 :
307 : ////////////////////////////////////////////////////////////////////////////////
308 : // ARIA map
309 :
310 : /**
311 : * These are currently initialized (hardcoded) in nsARIAMap.cpp,
312 : * and provide the mappings for WAI-ARIA roles and properties using the
313 : * structs defined in this file.
314 : */
315 : struct nsARIAMap
316 : {
317 : /**
318 : * Array of supported ARIA role map entries and its length.
319 : */
320 : static nsRoleMapEntry gWAIRoleMap[];
321 : static PRUint32 gWAIRoleMapLength;
322 :
323 : /**
324 : * Landmark role map entry. Used when specified ARIA role isn't mapped to
325 : * accessibility API.
326 : */
327 : static nsRoleMapEntry gLandmarkRoleMap;
328 :
329 : /**
330 : * Empty role map entry. Used by accessibility service to create an accessible
331 : * if the accessible can't use role of used accessible class. For example,
332 : * it is used for table cells that aren't contained by table.
333 : */
334 : static nsRoleMapEntry gEmptyRoleMap;
335 :
336 : /**
337 : * State map of ARIA state attributes.
338 : */
339 : static nsStateMapEntry gWAIStateMap[];
340 :
341 : /**
342 : * State map of ARIA states applied to any accessible not depending on
343 : * the role.
344 : */
345 : static eStateMapEntryID gWAIUnivStateMap[];
346 :
347 : /**
348 : * Map of attribute to attribute characteristics.
349 : */
350 : static nsAttributeCharacteristics gWAIUnivAttrMap[];
351 : static PRUint32 gWAIUnivAttrMapLength;
352 :
353 : /**
354 : * Return accessible state from ARIA universal states applied to the given
355 : * element.
356 : */
357 0 : static PRUint64 UniversalStatesFor(nsIContent* aContent)
358 : {
359 0 : PRUint64 state = 0;
360 0 : PRUint32 index = 0;
361 0 : while (nsStateMapEntry::MapToStates(aContent, &state, gWAIUnivStateMap[index]))
362 0 : index++;
363 :
364 0 : return state;
365 : }
366 : };
367 :
368 : #endif
|