Bug 1877642 - Disable browser_fullscreen-tab-close-race.js on apple_silicon !debug...
[gecko.git] / accessible / base / nsAccUtils.h
blobed51eef7094e48a08e7e2795ea408324a1e37681
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/. */
6 #ifndef nsAccUtils_h_
7 #define nsAccUtils_h_
9 #include "mozilla/a11y/LocalAccessible.h"
10 #include "mozilla/a11y/DocManager.h"
12 #include "nsAccessibilityService.h"
13 #include "nsCoreUtils.h"
15 #include "nsIDocShell.h"
16 #include "nsPoint.h"
18 namespace mozilla {
20 class PresShell;
22 namespace dom {
23 class Element;
26 namespace a11y {
28 class HyperTextAccessible;
29 class DocAccessible;
30 class Attribute;
32 class nsAccUtils {
33 public:
34 /**
35 * Set group attributes ('level', 'setsize', 'posinset').
37 static void SetAccGroupAttrs(AccAttributes* aAttributes, int32_t aLevel,
38 int32_t aSetSize, int32_t aPosInSet);
40 /**
41 * Compute group level for nsIDOMXULContainerItemElement node.
43 static int32_t GetLevelForXULContainerItem(nsIContent* aContent);
45 /**
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);
54 /**
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);
64 /**
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,
70 nsAtom* aAttr);
71 static nsStaticAtom* NormalizeARIAToken(mozilla::dom::Element* aElement,
72 nsAtom* aAttr);
74 /**
75 * Return document accessible for the given DOM node.
77 static DocAccessible* GetDocAccessibleFor(nsINode* aNode) {
78 return GetAccService()->GetDocAccessible(
79 nsCoreUtils::GetPresShellFor(aNode));
82 /**
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());
90 /**
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,
97 uint64_t aState);
98 static LocalAccessible* GetSelectableContainer(LocalAccessible* aAccessible,
99 uint64_t aState);
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"
121 * attribute.
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
143 * relative it.
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
152 * system.
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
159 * relative it
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
167 * given accessible.
169 * @param [in] aAccessible the accessible
171 static LayoutDeviceIntPoint GetScreenCoordsForParent(Accessible* aAccessible);
174 * Returns coordinates in device pixels relative screen for the top level
175 * window.
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);
193 #ifdef DEBUG
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);
199 #endif
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,
218 uint32_t* aState2) {
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
276 * default instead.
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,
281 nsAString& aResult);
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,
291 const nsAtom* aName,
292 AttrArray::AttrValuesArray* aValues,
293 nsCaseTreatment aCaseSensitive);
296 } // namespace a11y
297 } // namespace mozilla
299 #endif