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/. */
9 #include "mozilla/a11y/LocalAccessible.h"
10 #include "mozilla/a11y/DocManager.h"
12 #include "nsAccessibilityService.h"
13 #include "nsCoreUtils.h"
15 #include "nsIDocShell.h"
28 class HyperTextAccessible
;
35 * Set group attributes ('level', 'setsize', 'posinset').
37 static void SetAccGroupAttrs(AccAttributes
* aAttributes
, int32_t aLevel
,
38 int32_t aSetSize
, int32_t aPosInSet
);
41 * Compute group level for nsIDOMXULContainerItemElement node.
43 static int32_t GetLevelForXULContainerItem(nsIContent
* aContent
);
46 * Set container-foo live region attributes for the given node.
48 * @param aAttributes where to store the attributes
49 * @param aStartAcc Accessible to start from
51 static void SetLiveContainerAttributes(AccAttributes
* aAttributes
,
52 Accessible
* aStartAcc
);
55 * Any ARIA property of type boolean or NMTOKEN is undefined if the ARIA
56 * property is not present, or is "" or "undefined". Do not call
57 * this method for properties of type string, decimal, IDREF or IDREFS.
59 * Return true if the ARIA property is defined, otherwise false
61 static bool HasDefinedARIAToken(nsIContent
* aContent
, nsAtom
* aAtom
);
62 static bool HasDefinedARIAToken(const AttrArray
* aAttrs
, nsAtom
* aAtom
);
65 * If the given ARIA attribute has a specific known token value, return it.
66 * If the specification demands for a fallback value for unknown attribute
67 * values, return that. For all others, return a nullptr.
69 static nsStaticAtom
* NormalizeARIAToken(const AttrArray
* aAttrs
,
71 static nsStaticAtom
* NormalizeARIAToken(mozilla::dom::Element
* aElement
,
75 * Return document accessible for the given DOM node.
77 static DocAccessible
* GetDocAccessibleFor(nsINode
* aNode
) {
78 return GetAccService()->GetDocAccessible(
79 nsCoreUtils::GetPresShellFor(aNode
));
83 * Return document accessible for the given docshell.
85 static DocAccessible
* GetDocAccessibleFor(nsIDocShellTreeItem
* aContainer
) {
86 nsCOMPtr
<nsIDocShell
> docShell(do_QueryInterface(aContainer
));
87 return GetAccService()->GetDocAccessible(docShell
->GetPresShell());
91 * Return single or multi selectable container for the given item.
93 * @param aAccessible [in] the item accessible
94 * @param aState [in] the state of the item accessible
96 static Accessible
* GetSelectableContainer(const Accessible
* aAccessible
,
98 static LocalAccessible
* GetSelectableContainer(LocalAccessible
* aAccessible
,
102 * Return a text container accessible for the given node.
104 static HyperTextAccessible
* GetTextContainer(nsINode
* aNode
);
106 static Accessible
* TableFor(Accessible
* aRow
);
107 static LocalAccessible
* TableFor(LocalAccessible
* aRow
);
110 * Return true if the DOM node of a given accessible has a given attribute
111 * with a value of "true".
113 static bool IsDOMAttrTrue(const LocalAccessible
* aAccessible
, nsAtom
* aAttr
);
116 * Return true if the DOM node of given accessible has aria-selected="true"
119 static inline bool IsARIASelected(const LocalAccessible
* aAccessible
) {
120 return IsDOMAttrTrue(aAccessible
, nsGkAtoms::aria_selected
);
124 * Return true if the DOM node of given accessible has
125 * aria-multiselectable="true" attribute.
127 static inline bool IsARIAMultiSelectable(const LocalAccessible
* aAccessible
) {
128 return IsDOMAttrTrue(aAccessible
, nsGkAtoms::aria_multiselectable
);
132 * Converts the given coordinates to coordinates relative screen.
134 * @param aX [in] the given x coord in dev pixels
135 * @param aY [in] the given y coord in dev pixels
136 * @param aCoordinateType [in] specifies coordinates origin (refer to
137 * nsIAccessibleCoordinateType)
138 * @param aAccessible [in] the accessible if coordinates are given
140 * @return converted coordinates
142 static LayoutDeviceIntPoint
ConvertToScreenCoords(int32_t aX
, int32_t aY
,
143 uint32_t aCoordinateType
,
144 Accessible
* aAccessible
);
147 * Converts the given coordinates relative screen to another coordinate
150 * @param aX [in, out] the given x coord in dev pixels
151 * @param aY [in, out] the given y coord in dev pixels
152 * @param aCoordinateType [in] specifies coordinates origin (refer to
153 * nsIAccessibleCoordinateType)
154 * @param aAccessible [in] the accessible if coordinates are given
157 static void ConvertScreenCoordsTo(int32_t* aX
, int32_t* aY
,
158 uint32_t aCoordinateType
,
159 Accessible
* aAccessible
);
162 * Returns screen-relative coordinates (in dev pixels) for the parent of the
165 * @param [in] aAccessible the accessible
167 static LayoutDeviceIntPoint
GetScreenCoordsForParent(Accessible
* aAccessible
);
170 * Returns coordinates in device pixels relative screen for the top level
173 * @param aAccessible the acc hosted in the window.
175 static mozilla::LayoutDeviceIntPoint
GetScreenCoordsForWindow(
176 mozilla::a11y::Accessible
* aAccessible
);
179 * Get the 'live' or 'container-live' object attribute value from the given
180 * ELiveAttrRule constant.
182 * @param aRule [in] rule constant (see ELiveAttrRule in nsAccMap.h)
183 * @param aValue [out] object attribute value
185 * @return true if object attribute should be exposed
187 static bool GetLiveAttrValue(uint32_t aRule
, nsAString
& aValue
);
191 * Detect whether the given accessible object implements nsIAccessibleText,
192 * when it is text or has text child node.
194 static bool IsTextInterfaceSupportCorrect(LocalAccessible
* aAccessible
);
198 * Return text length of the given accessible, return 0 on failure.
200 static uint32_t TextLength(Accessible
* aAccessible
);
203 * Transform nsIAccessibleStates constants to internal state constant.
205 static inline uint64_t To64State(uint32_t aState1
, uint32_t aState2
) {
206 return static_cast<uint64_t>(aState1
) +
207 (static_cast<uint64_t>(aState2
) << 31);
211 * Transform internal state constant to nsIAccessibleStates constants.
213 static inline void To32States(uint64_t aState64
, uint32_t* aState1
,
215 *aState1
= aState64
& 0x7fffffff;
216 if (aState2
) *aState2
= static_cast<uint32_t>(aState64
>> 31);
219 static uint32_t To32States(uint64_t aState
, bool* aIsExtra
) {
220 uint32_t extraState
= aState
>> 31;
221 *aIsExtra
= !!extraState
;
222 return extraState
? extraState
: aState
;
226 * Return true if the given accessible can't have children. Used when exposing
227 * to platform accessibility APIs, should the children be pruned off?
229 static bool MustPrune(Accessible
* aAccessible
);
232 * Return true if the given accessible is within an ARIA live region; i.e.
233 * the container-live attribute would be something other than "off" or empty.
235 static bool IsARIALive(const LocalAccessible
* aAccessible
);
238 * Get the document Accessible which owns a given Accessible.
239 * This function is needed because there is no unified base class for local
240 * and remote documents.
241 * If aAcc is null, null will be returned.
243 static Accessible
* DocumentFor(Accessible
* aAcc
);
246 * Get an Accessible in a given document by its unique id.
247 * An Accessible's id can be obtained using Accessible::ID.
248 * This function is needed because there is no unified base class for local
249 * and remote documents.
250 * If aDoc is nul, null will be returned.
252 static Accessible
* GetAccessibleByID(Accessible
* aDoc
, uint64_t aID
);
255 * Get the URL for a given document.
256 * This function is needed because there is no unified base class for local
257 * and remote documents.
259 static void DocumentURL(Accessible
* aDoc
, nsAString
& aURL
);
262 * Accessors for element attributes that are aware of CustomElement ARIA
263 * accessibility defaults. If the element does not have the provided
264 * attribute defined directly on it, we will then attempt to fetch the
267 static const AttrArray
* GetARIADefaults(dom::Element
* aElement
);
268 static bool HasARIAAttr(dom::Element
* aElement
, const nsAtom
* aName
);
269 static bool GetARIAAttr(dom::Element
* aElement
, const nsAtom
* aName
,
271 static const nsAttrValue
* GetARIAAttr(dom::Element
* aElement
,
272 const nsAtom
* aName
);
273 static bool ARIAAttrValueIs(dom::Element
* aElement
, const nsAtom
* aName
,
274 const nsAString
& aValue
,
275 nsCaseTreatment aCaseSensitive
);
276 static bool ARIAAttrValueIs(dom::Element
* aElement
, const nsAtom
* aName
,
277 const nsAtom
* aValue
,
278 nsCaseTreatment aCaseSensitive
);
279 static int32_t FindARIAAttrValueIn(dom::Element
* aElement
,
281 AttrArray::AttrValuesArray
* aValues
,
282 nsCaseTreatment aCaseSensitive
);
286 } // namespace mozilla