Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/accessible/base/nsAccUtils.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef nsAccUtils_h_
7
#define nsAccUtils_h_
8
9
#include "mozilla/a11y/Accessible.h"
10
#include "mozilla/a11y/DocManager.h"
11
12
#include "nsAccessibilityService.h"
13
#include "nsCoreUtils.h"
14
15
#include "nsIDocShell.h"
16
#include "nsPoint.h"
17
18
namespace mozilla {
19
20
namespace dom {
21
class Element;
22
}
23
24
namespace a11y {
25
26
class HyperTextAccessible;
27
class DocAccessible;
28
29
class nsAccUtils
30
{
31
public:
32
  /**
33
   * Returns value of attribute from the given attributes container.
34
   *
35
   * @param aAttributes - attributes container
36
   * @param aAttrName - the name of requested attribute
37
   * @param aAttrValue - value of attribute
38
   */
39
  static void GetAccAttr(nsIPersistentProperties *aAttributes,
40
                         nsAtom *aAttrName,
41
                         nsAString& aAttrValue);
42
43
  /**
44
   * Set value of attribute for the given attributes container.
45
   *
46
   * @param aAttributes - attributes container
47
   * @param aAttrName - the name of requested attribute
48
   * @param aAttrValue - new value of attribute
49
   */
50
  static void SetAccAttr(nsIPersistentProperties *aAttributes,
51
                         nsAtom *aAttrName,
52
                         const nsAString& aAttrValue);
53
54
  static void SetAccAttr(nsIPersistentProperties *aAttributes,
55
                         nsAtom* aAttrName,
56
                         nsAtom* aAttrValue);
57
58
  /**
59
   * Set group attributes ('level', 'setsize', 'posinset').
60
   */
61
  static void SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
62
                               int32_t aLevel, int32_t aSetSize,
63
                               int32_t aPosInSet);
64
65
  /**
66
   * Get default value of the level for the given accessible.
67
   */
68
  static int32_t GetDefaultLevel(const Accessible* aAcc);
69
70
  /**
71
   * Return ARIA level value or the default one if ARIA is missed for the
72
   * given accessible.
73
   */
74
  static int32_t GetARIAOrDefaultLevel(const Accessible* aAccessible);
75
76
  /**
77
   * Compute group level for nsIDOMXULContainerItemElement node.
78
   */
79
  static int32_t GetLevelForXULContainerItem(nsIContent *aContent);
80
81
  /**
82
   * Set container-foo live region attributes for the given node.
83
   *
84
   * @param aAttributes    where to store the attributes
85
   * @param aStartContent  node to start from
86
   * @param aTopContent    node to end at
87
   */
88
  static void SetLiveContainerAttributes(nsIPersistentProperties *aAttributes,
89
                                         nsIContent* aStartContent,
90
                                         mozilla::dom::Element* aTopEl);
91
92
  /**
93
   * Any ARIA property of type boolean or NMTOKEN is undefined if the ARIA
94
   * property is not present, or is "" or "undefined". Do not call
95
   * this method for properties of type string, decimal, IDREF or IDREFS.
96
   *
97
   * Return true if the ARIA property is defined, otherwise false
98
   */
99
  static bool HasDefinedARIAToken(nsIContent *aContent, nsAtom *aAtom);
100
101
  /**
102
   * Return atomic value of ARIA attribute of boolean or NMTOKEN type.
103
   */
104
  static nsAtom* GetARIAToken(mozilla::dom::Element* aElement, nsAtom* aAttr);
105
106
  /**
107
   * Return document accessible for the given DOM node.
108
   */
109
  static DocAccessible* GetDocAccessibleFor(nsINode* aNode)
110
0
  {
111
0
    nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode);
112
0
    return GetAccService()->GetDocAccessible(presShell);
113
0
  }
114
115
  /**
116
   * Return document accessible for the given docshell.
117
   */
118
  static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer)
119
0
  {
120
0
    nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
121
0
    return GetAccService()->GetDocAccessible(docShell->GetPresShell());
122
0
  }
123
124
  /**
125
   * Return single or multi selectable container for the given item.
126
   *
127
   * @param  aAccessible  [in] the item accessible
128
   * @param  aState       [in] the state of the item accessible
129
   */
130
  static Accessible* GetSelectableContainer(Accessible* aAccessible,
131
                                            uint64_t aState);
132
133
  /**
134
   * Return a text container accessible for the given node.
135
   */
136
  static HyperTextAccessible* GetTextContainer(nsINode* aNode);
137
138
  static Accessible* TableFor(Accessible* aRow);
139
140
  /**
141
   * Return true if the DOM node of a given accessible has a given attribute
142
   * with a value of "true".
143
   */
144
  static bool IsDOMAttrTrue(const Accessible* aAccessible, nsAtom* aAttr);
145
146
  /**
147
   * Return true if the DOM node of given accessible has aria-selected="true"
148
   * attribute.
149
   */
150
0
  static inline bool IsARIASelected(const Accessible* aAccessible) {
151
0
    return IsDOMAttrTrue(aAccessible, nsGkAtoms::aria_selected);
152
0
  }
153
154
  /**
155
   * Return true if the DOM node of given accessible has
156
   * aria-multiselectable="true" attribute.
157
   */
158
0
  static inline bool IsARIAMultiSelectable(const Accessible* aAccessible) {
159
0
    return IsDOMAttrTrue(aAccessible, nsGkAtoms::aria_multiselectable);
160
0
  }
161
162
  /**
163
   * Converts the given coordinates to coordinates relative screen.
164
   *
165
   * @param aX               [in] the given x coord
166
   * @param aY               [in] the given y coord
167
   * @param aCoordinateType  [in] specifies coordinates origin (refer to
168
   *                         nsIAccessibleCoordinateType)
169
   * @param aAccessible      [in] the accessible if coordinates are given
170
   *                         relative it.
171
   * @return converted coordinates
172
   */
173
  static nsIntPoint ConvertToScreenCoords(int32_t aX, int32_t aY,
174
                                          uint32_t aCoordinateType,
175
                                          Accessible* aAccessible);
176
177
  /**
178
   * Converts the given coordinates relative screen to another coordinate
179
   * system.
180
   *
181
   * @param aX               [in, out] the given x coord
182
   * @param aY               [in, out] the given y coord
183
   * @param aCoordinateType  [in] specifies coordinates origin (refer to
184
   *                         nsIAccessibleCoordinateType)
185
   * @param aAccessible      [in] the accessible if coordinates are given
186
   *                         relative it
187
   */
188
  static void ConvertScreenCoordsTo(int32_t* aX, int32_t* aY,
189
                                    uint32_t aCoordinateType,
190
                                    Accessible* aAccessible);
191
192
  /**
193
   * Returns coordinates relative screen for the parent of the given accessible.
194
   *
195
   * @param [in] aAccessible  the accessible
196
   */
197
  static nsIntPoint GetScreenCoordsForParent(Accessible* aAccessible);
198
199
  /**
200
   * Get the 'live' or 'container-live' object attribute value from the given
201
   * ELiveAttrRule constant.
202
   *
203
   * @param  aRule   [in] rule constant (see ELiveAttrRule in nsAccMap.h)
204
   * @param  aValue  [out] object attribute value
205
   *
206
   * @return         true if object attribute should be exposed
207
   */
208
  static bool GetLiveAttrValue(uint32_t aRule, nsAString& aValue);
209
210
#ifdef DEBUG
211
  /**
212
   * Detect whether the given accessible object implements nsIAccessibleText,
213
   * when it is text or has text child node.
214
   */
215
  static bool IsTextInterfaceSupportCorrect(Accessible* aAccessible);
216
#endif
217
218
  /**
219
   * Return text length of the given accessible, return 0 on failure.
220
   */
221
  static uint32_t TextLength(Accessible* aAccessible);
222
223
  /**
224
   * Transform nsIAccessibleStates constants to internal state constant.
225
   */
226
  static inline uint64_t To64State(uint32_t aState1, uint32_t aState2)
227
0
  {
228
0
    return static_cast<uint64_t>(aState1) +
229
0
        (static_cast<uint64_t>(aState2) << 31);
230
0
  }
231
232
  /**
233
   * Transform internal state constant to nsIAccessibleStates constants.
234
   */
235
  static inline void To32States(uint64_t aState64,
236
                                uint32_t* aState1, uint32_t* aState2)
237
0
  {
238
0
    *aState1 = aState64 & 0x7fffffff;
239
0
    if (aState2)
240
0
      *aState2 = static_cast<uint32_t>(aState64 >> 31);
241
0
  }
242
243
  static uint32_t To32States(uint64_t aState, bool* aIsExtra)
244
0
  {
245
0
    uint32_t extraState = aState >> 31;
246
0
    *aIsExtra = !!extraState;
247
0
    return aState | extraState;
248
0
  }
249
250
  /**
251
   * Return true if the given accessible can't have children. Used when exposing
252
   * to platform accessibility APIs, should the children be pruned off?
253
   */
254
  static bool MustPrune(Accessible* aAccessible);
255
};
256
257
} // namespace a11y
258
} // namespace mozilla
259
260
#endif