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 * Return true if the given accessible is within an ARIA live region; i.e.
237 * the container-live attribute would be something other than "off" or empty.
239 static bool IsARIALive(const LocalAccessible
* aAccessible
);
242 * Get the document Accessible which owns a given Accessible.
243 * This function is needed because there is no unified base class for local
244 * and remote documents.
245 * If aAcc is null, null will be returned.
247 static Accessible
* DocumentFor(Accessible
* aAcc
);
250 * Get an Accessible in a given document by its unique id.
251 * An Accessible's id can be obtained using Accessible::ID.
252 * This function is needed because there is no unified base class for local
253 * and remote documents.
254 * If aDoc is nul, null will be returned.
256 static Accessible
* GetAccessibleByID(Accessible
* aDoc
, uint64_t aID
);
259 * Get the URL for a given document.
260 * This function is needed because there is no unified base class for local
261 * and remote documents.
263 static void DocumentURL(Accessible
* aDoc
, nsAString
& aURL
);
266 * Get the mime type 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 DocumentMimeType(Accessible
* aDoc
, nsAString
& aMimeType
);
273 * Accessors for element attributes that are aware of CustomElement ARIA
274 * accessibility defaults. If the element does not have the provided
275 * attribute defined directly on it, we will then attempt to fetch the
278 static const AttrArray
* GetARIADefaults(dom::Element
* aElement
);
279 static bool HasARIAAttr(dom::Element
* aElement
, const nsAtom
* aName
);
280 static bool GetARIAAttr(dom::Element
* aElement
, const nsAtom
* aName
,
282 static const nsAttrValue
* GetARIAAttr(dom::Element
* aElement
,
283 const nsAtom
* aName
);
284 static bool ARIAAttrValueIs(dom::Element
* aElement
, const nsAtom
* aName
,
285 const nsAString
& aValue
,
286 nsCaseTreatment aCaseSensitive
);
287 static bool ARIAAttrValueIs(dom::Element
* aElement
, const nsAtom
* aName
,
288 const nsAtom
* aValue
,
289 nsCaseTreatment aCaseSensitive
);
290 static int32_t FindARIAAttrValueIn(dom::Element
* aElement
,
292 AttrArray::AttrValuesArray
* aValues
,
293 nsCaseTreatment aCaseSensitive
);
297 } // namespace mozilla