2008-10-16 13:12:05 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
#ifndef nsAccUtils_h_
|
|
|
|
#define nsAccUtils_h_
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
#include "mozilla/a11y/LocalAccessible.h"
|
2018-03-12 21:03:55 +03:00
|
|
|
#include "mozilla/a11y/DocManager.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsCoreUtils.h"
|
2008-10-16 13:12:05 +04:00
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
#include "nsIDocShell.h"
|
2008-10-16 13:12:05 +04:00
|
|
|
#include "nsPoint.h"
|
|
|
|
|
2013-09-11 05:01:46 +04:00
|
|
|
namespace mozilla {
|
2013-09-11 02:18:59 +04:00
|
|
|
|
2019-04-13 15:13:15 +03:00
|
|
|
class PresShell;
|
|
|
|
|
2013-09-11 02:18:59 +04:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
}
|
|
|
|
|
2012-11-18 06:01:44 +04:00
|
|
|
namespace a11y {
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
class HyperTextAccessible;
|
2012-05-27 13:01:40 +04:00
|
|
|
class DocAccessible;
|
2018-11-12 19:41:31 +03:00
|
|
|
class Attribute;
|
2008-11-01 06:58:07 +03:00
|
|
|
|
2008-10-16 13:12:05 +04:00
|
|
|
class nsAccUtils {
|
|
|
|
public:
|
|
|
|
/**
|
2010-01-06 13:36:50 +03:00
|
|
|
* Set group attributes ('level', 'setsize', 'posinset').
|
2008-10-16 13:12:05 +04:00
|
|
|
*/
|
2021-06-11 02:07:05 +03:00
|
|
|
static void SetAccGroupAttrs(AccAttributes* aAttributes, int32_t aLevel,
|
|
|
|
int32_t aSetSize, int32_t aPosInSet);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
/**
|
2010-01-06 13:36:50 +03:00
|
|
|
* Compute group level for nsIDOMXULContainerItemElement node.
|
2008-10-16 13:12:05 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t GetLevelForXULContainerItem(nsIContent* aContent);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set container-foo live region attributes for the given node.
|
|
|
|
*
|
|
|
|
* @param aAttributes where to store the attributes
|
|
|
|
* @param aStartContent node to start from
|
|
|
|
*/
|
2021-06-11 02:07:05 +03:00
|
|
|
static void SetLiveContainerAttributes(AccAttributes* aAttributes,
|
2020-05-11 14:13:43 +03:00
|
|
|
nsIContent* aStartContent);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
/**
|
2009-01-12 20:20:34 +03:00
|
|
|
* Any ARIA property of type boolean or NMTOKEN is undefined if the ARIA
|
|
|
|
* property is not present, or is "" or "undefined". Do not call
|
|
|
|
* this method for properties of type string, decimal, IDREF or IDREFS.
|
|
|
|
*
|
2011-10-17 18:59:28 +04:00
|
|
|
* Return true if the ARIA property is defined, otherwise false
|
2009-01-12 20:20:34 +03:00
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static bool HasDefinedARIAToken(nsIContent* aContent, nsAtom* aAtom);
|
2009-01-12 20:20:34 +03:00
|
|
|
|
2011-08-11 15:45:36 +04:00
|
|
|
/**
|
|
|
|
* Return atomic value of ARIA attribute of boolean or NMTOKEN type.
|
|
|
|
*/
|
2018-04-03 06:21:06 +03:00
|
|
|
static nsStaticAtom* GetARIAToken(mozilla::dom::Element* aElement,
|
|
|
|
nsAtom* aAttr);
|
2018-11-02 09:40:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the given ARIA attribute has a specific known token value, return it.
|
|
|
|
* If the specification demands for a fallback value for unknown attribute
|
|
|
|
* values, return that. For all others, return a nullptr.
|
|
|
|
*/
|
|
|
|
static nsStaticAtom* NormalizeARIAToken(mozilla::dom::Element* aElement,
|
|
|
|
nsAtom* aAttr);
|
2011-08-11 15:45:36 +04:00
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
/**
|
|
|
|
* Return document accessible for the given DOM node.
|
|
|
|
*/
|
2012-05-27 13:01:40 +04:00
|
|
|
static DocAccessible* GetDocAccessibleFor(nsINode* aNode) {
|
2019-04-13 15:13:15 +03:00
|
|
|
return GetAccService()->GetDocAccessible(
|
|
|
|
nsCoreUtils::GetPresShellFor(aNode));
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return document accessible for the given docshell.
|
|
|
|
*/
|
2012-05-27 13:01:40 +04:00
|
|
|
static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer) {
|
2010-06-08 20:39:58 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
2012-12-29 05:56:42 +04:00
|
|
|
return GetAccService()->GetDocAccessible(docShell->GetPresShell());
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 22:38:55 +03:00
|
|
|
/**
|
|
|
|
* Return single or multi selectable container for the given item.
|
|
|
|
*
|
|
|
|
* @param aAccessible [in] the item accessible
|
|
|
|
* @param aState [in] the state of the item accessible
|
|
|
|
*/
|
2021-02-20 02:14:32 +03:00
|
|
|
static LocalAccessible* GetSelectableContainer(LocalAccessible* aAccessible,
|
|
|
|
uint64_t aState);
|
2009-12-11 22:38:55 +03:00
|
|
|
|
2009-09-11 05:07:56 +04:00
|
|
|
/**
|
2013-10-26 18:58:53 +04:00
|
|
|
* Return a text container accessible for the given node.
|
2009-09-11 05:07:56 +04:00
|
|
|
*/
|
2013-10-26 18:58:53 +04:00
|
|
|
static HyperTextAccessible* GetTextContainer(nsINode* aNode);
|
2009-09-11 05:07:56 +04:00
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
static LocalAccessible* TableFor(LocalAccessible* aRow);
|
2015-06-27 00:41:22 +03:00
|
|
|
|
2018-08-02 09:27:18 +03:00
|
|
|
/**
|
|
|
|
* Return true if the DOM node of a given accessible has a given attribute
|
|
|
|
* with a value of "true".
|
|
|
|
*/
|
2021-02-20 02:14:32 +03:00
|
|
|
static bool IsDOMAttrTrue(const LocalAccessible* aAccessible, nsAtom* aAttr);
|
2018-09-07 17:47:51 +03:00
|
|
|
|
2008-10-28 11:43:07 +03:00
|
|
|
/**
|
2013-10-26 18:58:53 +04:00
|
|
|
* Return true if the DOM node of given accessible has aria-selected="true"
|
|
|
|
* attribute.
|
2008-10-28 11:43:07 +03:00
|
|
|
*/
|
2021-02-20 02:14:32 +03:00
|
|
|
static inline bool IsARIASelected(const LocalAccessible* aAccessible) {
|
2018-08-02 09:27:18 +03:00
|
|
|
return IsDOMAttrTrue(aAccessible, nsGkAtoms::aria_selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the DOM node of given accessible has
|
|
|
|
* aria-multiselectable="true" attribute.
|
|
|
|
*/
|
2021-02-20 02:14:32 +03:00
|
|
|
static inline bool IsARIAMultiSelectable(const LocalAccessible* aAccessible) {
|
2018-08-02 09:27:18 +03:00
|
|
|
return IsDOMAttrTrue(aAccessible, nsGkAtoms::aria_multiselectable);
|
|
|
|
}
|
2008-10-28 11:43:07 +03:00
|
|
|
|
2008-10-16 13:12:05 +04:00
|
|
|
/**
|
|
|
|
* Converts the given coordinates to coordinates relative screen.
|
|
|
|
*
|
2022-01-19 02:31:21 +03:00
|
|
|
* @param aX [in] the given x coord in dev pixels
|
|
|
|
* @param aY [in] the given y coord in dev pixels
|
2008-10-16 13:12:05 +04:00
|
|
|
* @param aCoordinateType [in] specifies coordinates origin (refer to
|
|
|
|
* nsIAccessibleCoordinateType)
|
2012-12-18 00:11:02 +04:00
|
|
|
* @param aAccessible [in] the accessible if coordinates are given
|
2008-10-16 13:12:05 +04:00
|
|
|
* relative it.
|
2012-12-18 00:11:02 +04:00
|
|
|
* @return converted coordinates
|
2008-10-16 13:12:05 +04:00
|
|
|
*/
|
2022-01-19 02:31:21 +03:00
|
|
|
static LayoutDeviceIntPoint ConvertToScreenCoords(
|
|
|
|
int32_t aX, int32_t aY, uint32_t aCoordinateType,
|
|
|
|
LocalAccessible* aAccessible);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the given coordinates relative screen to another coordinate
|
|
|
|
* system.
|
|
|
|
*
|
2022-01-19 02:31:21 +03:00
|
|
|
* @param aX [in, out] the given x coord in dev pixels
|
|
|
|
* @param aY [in, out] the given y coord in dev pixels
|
2008-10-16 13:12:05 +04:00
|
|
|
* @param aCoordinateType [in] specifies coordinates origin (refer to
|
|
|
|
* nsIAccessibleCoordinateType)
|
2012-12-18 00:11:02 +04:00
|
|
|
* @param aAccessible [in] the accessible if coordinates are given
|
2008-10-16 13:12:05 +04:00
|
|
|
* relative it
|
|
|
|
*/
|
2012-12-18 00:11:02 +04:00
|
|
|
static void ConvertScreenCoordsTo(int32_t* aX, int32_t* aY,
|
|
|
|
uint32_t aCoordinateType,
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* aAccessible);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
/**
|
2022-01-19 02:31:21 +03:00
|
|
|
* Returns screen-relative coordinates (in dev pixels) for the parent of the
|
|
|
|
* given accessible.
|
2008-10-16 13:12:05 +04:00
|
|
|
*
|
2012-12-18 00:11:02 +04:00
|
|
|
* @param [in] aAccessible the accessible
|
2008-10-16 13:12:05 +04:00
|
|
|
*/
|
2022-01-19 02:31:21 +03:00
|
|
|
static LayoutDeviceIntPoint GetScreenCoordsForParent(
|
|
|
|
LocalAccessible* aAccessible);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
2009-02-19 09:56:19 +03:00
|
|
|
/**
|
2009-08-28 09:27:27 +04:00
|
|
|
* Get the 'live' or 'container-live' object attribute value from the given
|
2009-02-19 09:56:19 +03:00
|
|
|
* ELiveAttrRule constant.
|
2009-08-28 09:27:27 +04:00
|
|
|
*
|
|
|
|
* @param aRule [in] rule constant (see ELiveAttrRule in nsAccMap.h)
|
|
|
|
* @param aValue [out] object attribute value
|
|
|
|
*
|
|
|
|
* @return true if object attribute should be exposed
|
2009-02-19 09:56:19 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static bool GetLiveAttrValue(uint32_t aRule, nsAString& aValue);
|
2009-02-19 09:56:19 +03:00
|
|
|
|
2012-05-08 03:49:41 +04:00
|
|
|
#ifdef DEBUG
|
2008-10-17 14:10:43 +04:00
|
|
|
/**
|
|
|
|
* Detect whether the given accessible object implements nsIAccessibleText,
|
|
|
|
* when it is text or has text child node.
|
|
|
|
*/
|
2021-02-20 02:14:32 +03:00
|
|
|
static bool IsTextInterfaceSupportCorrect(LocalAccessible* aAccessible);
|
2008-10-16 13:12:05 +04:00
|
|
|
#endif
|
|
|
|
|
2008-10-17 14:10:43 +04:00
|
|
|
/**
|
2010-05-25 12:40:54 +04:00
|
|
|
* Return text length of the given accessible, return 0 on failure.
|
2008-10-17 14:10:43 +04:00
|
|
|
*/
|
2021-10-06 07:53:53 +03:00
|
|
|
static uint32_t TextLength(Accessible* aAccessible);
|
2008-10-17 14:10:43 +04:00
|
|
|
|
|
|
|
/**
|
2011-04-10 03:38:06 +04:00
|
|
|
* Transform nsIAccessibleStates constants to internal state constant.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static inline uint64_t To64State(uint32_t aState1, uint32_t aState2) {
|
|
|
|
return static_cast<uint64_t>(aState1) +
|
|
|
|
(static_cast<uint64_t>(aState2) << 31);
|
2011-04-10 03:38:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform internal state constant to nsIAccessibleStates constants.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static inline void To32States(uint64_t aState64, uint32_t* aState1,
|
|
|
|
uint32_t* aState2) {
|
2011-04-10 03:38:06 +04:00
|
|
|
*aState1 = aState64 & 0x7fffffff;
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aState2) *aState2 = static_cast<uint32_t>(aState64 >> 31);
|
2011-04-10 03:38:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-19 19:38:01 +04:00
|
|
|
static uint32_t To32States(uint64_t aState, bool* aIsExtra) {
|
|
|
|
uint32_t extraState = aState >> 31;
|
|
|
|
*aIsExtra = !!extraState;
|
2021-10-22 01:47:43 +03:00
|
|
|
return extraState ? extraState : aState;
|
2013-01-19 19:38:01 +04:00
|
|
|
}
|
|
|
|
|
2008-10-17 14:10:43 +04:00
|
|
|
/**
|
|
|
|
* Return true if the given accessible can't have children. Used when exposing
|
|
|
|
* to platform accessibility APIs, should the children be pruned off?
|
|
|
|
*/
|
2021-07-22 20:58:49 +03:00
|
|
|
static bool MustPrune(Accessible* aAccessible);
|
2018-11-12 19:41:31 +03:00
|
|
|
|
2018-12-21 12:16:38 +03:00
|
|
|
/**
|
|
|
|
* Return true if the given accessible is within an ARIA live region; i.e.
|
|
|
|
* the container-live attribute would be something other than "off" or empty.
|
|
|
|
*/
|
2021-02-20 02:14:32 +03:00
|
|
|
static bool IsARIALive(const LocalAccessible* aAccessible);
|
2022-04-01 12:49:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the document Accessible which owns a given Accessible.
|
|
|
|
* This function is needed because there is no unified base class for local
|
|
|
|
* and remote documents.
|
|
|
|
* If aAcc is null, null will be returned.
|
|
|
|
*/
|
|
|
|
static Accessible* DocumentFor(Accessible* aAcc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an Accessible in a given document by its unique id.
|
|
|
|
* An Accessible's id can be obtained using Accessible::ID.
|
|
|
|
* This function is needed because there is no unified base class for local
|
|
|
|
* and remote documents.
|
|
|
|
* If aDoc is nul, null will be returned.
|
|
|
|
*/
|
|
|
|
static Accessible* GetAccessibleByID(Accessible* aDoc, uint64_t aID);
|
2008-10-17 14:10:43 +04:00
|
|
|
};
|
|
|
|
|
2012-11-18 06:01:44 +04:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-10-17 14:10:43 +04:00
|
|
|
#endif
|