Coverage Report

Created: 2018-09-25 14:53

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