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
);
109 static const LocalAccessible
* TableFor(const LocalAccessible
* aAcc
) {
110 return TableFor(const_cast<LocalAccessible
*>(aAcc
));
114 * Return true if the DOM node of a given accessible has a given attribute
115 * with a value of "true".
117 static bool IsDOMAttrTrue(const LocalAccessible
* aAccessible
, nsAtom
* aAttr
);
120 * Return true if the DOM node of given accessible has aria-selected="true"
123 static inline bool IsARIASelected(const LocalAccessible
* aAccessible
) {
124 return IsDOMAttrTrue(aAccessible
, nsGkAtoms::aria_selected
);
128 * Return true if the DOM node of given accessible has
129 * aria-multiselectable="true" attribute.
131 static inline bool IsARIAMultiSelectable(const LocalAccessible
* aAccessible
) {
132 return IsDOMAttrTrue(aAccessible
, nsGkAtoms::aria_multiselectable
);
136 * Converts the given coordinates to coordinates relative screen.
138 * @param aX [in] the given x coord in dev pixels
139 * @param aY [in] the given y coord in dev pixels
140 * @param aCoordinateType [in] specifies coordinates origin (refer to
141 * nsIAccessibleCoordinateType)
142 * @param aAccessible [in] the accessible if coordinates are given
144 * @return converted coordinates
146 static LayoutDeviceIntPoint
ConvertToScreenCoords(int32_t aX
, int32_t aY
,
147 uint32_t aCoordinateType
,
148 Accessible
* aAccessible
);
151 * Converts the given coordinates relative screen to another coordinate
154 * @param aX [in, out] the given x coord in dev pixels
155 * @param aY [in, out] the given y coord in dev pixels
156 * @param aCoordinateType [in] specifies coordinates origin (refer to
157 * nsIAccessibleCoordinateType)
158 * @param aAccessible [in] the accessible if coordinates are given
161 static void ConvertScreenCoordsTo(int32_t* aX
, int32_t* aY
,
162 uint32_t aCoordinateType
,
163 Accessible
* aAccessible
);
166 * Returns screen-relative coordinates (in dev pixels) for the parent of the
169 * @param [in] aAccessible the accessible
171 static LayoutDeviceIntPoint
GetScreenCoordsForParent(Accessible
* aAccessible
);
174 * Returns coordinates in device pixels relative screen for the top level
177 * @param aAccessible the acc hosted in the window.
179 static mozilla::LayoutDeviceIntPoint
GetScreenCoordsForWindow(
180 mozilla::a11y::Accessible
* aAccessible
);
183 * Get the 'live' or 'container-live' object attribute value from the given
184 * ELiveAttrRule constant.
186 * @param aRule [in] rule constant (see ELiveAttrRule in nsAccMap.h)
187 * @param aValue [out] object attribute value
189 * @return true if object attribute should be exposed
191 static bool GetLiveAttrValue(uint32_t aRule
, nsAString
& aValue
);
195 * Detect whether the given accessible object implements nsIAccessibleText,
196 * when it is text or has text child node.
198 static bool IsTextInterfaceSupportCorrect(LocalAccessible
* aAccessible
);
202 * Return text length of the given accessible, return 0 on failure.
204 static uint32_t TextLength(Accessible
* aAccessible
);
207 * Transform nsIAccessibleStates constants to internal state constant.
209 static inline uint64_t To64State(uint32_t aState1
, uint32_t aState2
) {
210 return static_cast<uint64_t>(aState1
) +
211 (static_cast<uint64_t>(aState2
) << 31);
215 * Transform internal state constant to nsIAccessibleStates constants.
217 static inline void To32States(uint64_t aState64
, uint32_t* aState1
,
219 *aState1
= aState64
& 0x7fffffff;
220 if (aState2
) *aState2
= static_cast<uint32_t>(aState64
>> 31);
223 static uint32_t To32States(uint64_t aState
, bool* aIsExtra
) {
224 uint32_t extraState
= aState
>> 31;
225 *aIsExtra
= !!extraState
;
226 return extraState
? extraState
: aState
;
230 * Return true if the given accessible can't have children. Used when exposing
231 * to platform accessibility APIs, should the children be pruned off?
233 static bool MustPrune(Accessible
* aAccessible
);
236 * Get the live region setting (polite, etc.) for this Accessible. This does
237 * not walk ancestors. It does account for implicit live regions as
238 * determined from the ARIA role or markup tag name.
240 static void GetLiveRegionSetting(Accessible
* aAcc
, nsAString
& aLive
);
243 * If the given Accessible is inside a live region, return the root of the
244 * live region. Otherwise, return null.
246 static Accessible
* GetLiveRegionRoot(Accessible
* aAcc
);
249 * Get the document Accessible which owns a given Accessible.
250 * This function is needed because there is no unified base class for local
251 * and remote documents.
252 * If aAcc is null, null will be returned.
254 static Accessible
* DocumentFor(Accessible
* aAcc
);
257 * Get an Accessible in a given document by its unique id.
258 * An Accessible's id can be obtained using Accessible::ID.
259 * This function is needed because there is no unified base class for local
260 * and remote documents.
261 * If aDoc is nul, null will be returned.
263 static Accessible
* GetAccessibleByID(Accessible
* aDoc
, uint64_t aID
);
266 * Get the URL for a given document.
267 * This function is needed because there is no unified base class for local
268 * and remote documents.
270 static void DocumentURL(Accessible
* aDoc
, nsAString
& aURL
);
273 * Get the mime type for a given document.
274 * This function is needed because there is no unified base class for local
275 * and remote documents.
277 static void DocumentMimeType(Accessible
* aDoc
, nsAString
& aMimeType
);
280 * Accessors for element attributes that are aware of CustomElement ARIA
281 * accessibility defaults. If the element does not have the provided
282 * attribute defined directly on it, we will then attempt to fetch the
285 static const AttrArray
* GetARIADefaults(dom::Element
* aElement
);
286 static bool HasARIAAttr(dom::Element
* aElement
, const nsAtom
* aName
);
287 static bool GetARIAAttr(dom::Element
* aElement
, const nsAtom
* aName
,
289 static const nsAttrValue
* GetARIAAttr(dom::Element
* aElement
,
290 const nsAtom
* aName
);
291 static bool ARIAAttrValueIs(dom::Element
* aElement
, const nsAtom
* aName
,
292 const nsAString
& aValue
,
293 nsCaseTreatment aCaseSensitive
);
294 static bool ARIAAttrValueIs(dom::Element
* aElement
, const nsAtom
* aName
,
295 const nsAtom
* aValue
,
296 nsCaseTreatment aCaseSensitive
);
297 static int32_t FindARIAAttrValueIn(dom::Element
* aElement
,
299 AttrArray::AttrValuesArray
* aValues
,
300 nsCaseTreatment aCaseSensitive
);
304 } // namespace mozilla