2008-10-16 02:12:05 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 02:12:05 -07:00
|
|
|
|
|
|
|
#ifndef nsAccUtils_h_
|
|
|
|
#define nsAccUtils_h_
|
|
|
|
|
2013-03-31 17:57:07 -07:00
|
|
|
#include "mozilla/a11y/Accessible.h"
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsCoreUtils.h"
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
#include "nsIDocShell.h"
|
2008-10-16 02:12:05 -07:00
|
|
|
#include "nsPoint.h"
|
|
|
|
|
2013-09-10 18:01:46 -07:00
|
|
|
namespace mozilla {
|
2013-09-10 15:18:59 -07:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
}
|
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
namespace a11y {
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
class HyperTextAccessible;
|
2012-05-27 02:01:40 -07:00
|
|
|
class DocAccessible;
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
class nsAccUtils
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Returns value of attribute from the given attributes container.
|
|
|
|
*
|
|
|
|
* @param aAttributes - attributes container
|
|
|
|
* @param aAttrName - the name of requested attribute
|
|
|
|
* @param aAttrValue - value of attribute
|
|
|
|
*/
|
|
|
|
static void GetAccAttr(nsIPersistentProperties *aAttributes,
|
|
|
|
nsIAtom *aAttrName,
|
|
|
|
nsAString& aAttrValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set value of attribute for the given attributes container.
|
|
|
|
*
|
|
|
|
* @param aAttributes - attributes container
|
|
|
|
* @param aAttrName - the name of requested attribute
|
|
|
|
* @param aAttrValue - new value of attribute
|
|
|
|
*/
|
|
|
|
static void SetAccAttr(nsIPersistentProperties *aAttributes,
|
|
|
|
nsIAtom *aAttrName,
|
|
|
|
const nsAString& aAttrValue);
|
|
|
|
|
|
|
|
/**
|
2010-01-06 02:36:50 -08:00
|
|
|
* Set group attributes ('level', 'setsize', 'posinset').
|
2008-10-16 02:12:05 -07:00
|
|
|
*/
|
2010-01-06 02:36:50 -08:00
|
|
|
static void SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aLevel, int32_t aSetSize,
|
|
|
|
int32_t aPosInSet);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
/**
|
|
|
|
* Get default value of the level for the given accessible.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t GetDefaultLevel(Accessible* aAcc);
|
2010-01-12 11:07:38 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return ARIA level value or the default one if ARIA is missed for the
|
|
|
|
* given accessible.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t GetARIAOrDefaultLevel(Accessible* aAccessible);
|
2010-01-12 11:07:38 -08:00
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
/**
|
2010-01-06 02:36:50 -08:00
|
|
|
* Compute group level for nsIDOMXULContainerItemElement node.
|
2008-10-16 02:12:05 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t GetLevelForXULContainerItem(nsIContent *aContent);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set container-foo live region attributes for the given node.
|
|
|
|
*
|
|
|
|
* @param aAttributes where to store the attributes
|
|
|
|
* @param aStartContent node to start from
|
|
|
|
* @param aTopContent node to end at
|
|
|
|
*/
|
|
|
|
static void SetLiveContainerAttributes(nsIPersistentProperties *aAttributes,
|
|
|
|
nsIContent *aStartContent,
|
|
|
|
nsIContent *aTopContent);
|
|
|
|
|
|
|
|
/**
|
2009-01-12 09:20:34 -08: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 07:59:28 -07:00
|
|
|
* Return true if the ARIA property is defined, otherwise false
|
2009-01-12 09:20:34 -08:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool HasDefinedARIAToken(nsIContent *aContent, nsIAtom *aAtom);
|
2009-01-12 09:20:34 -08:00
|
|
|
|
2011-08-11 04:45:36 -07:00
|
|
|
/**
|
|
|
|
* Return atomic value of ARIA attribute of boolean or NMTOKEN type.
|
|
|
|
*/
|
|
|
|
static nsIAtom* GetARIAToken(mozilla::dom::Element* aElement, nsIAtom* aAttr);
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
/**
|
|
|
|
* Return document accessible for the given DOM node.
|
|
|
|
*/
|
2012-05-27 02:01:40 -07:00
|
|
|
static DocAccessible* GetDocAccessibleFor(nsINode* aNode)
|
2010-06-08 09:39:58 -07:00
|
|
|
{
|
|
|
|
nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode);
|
2012-04-16 22:29:47 -07:00
|
|
|
return GetAccService()->GetDocAccessible(presShell);
|
2010-06-08 09:39:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return document accessible for the given docshell.
|
|
|
|
*/
|
2012-05-27 02:01:40 -07:00
|
|
|
static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer)
|
2010-06-08 09:39:58 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
|
2012-12-28 17:56:42 -08:00
|
|
|
return GetAccService()->GetDocAccessible(docShell->GetPresShell());
|
2010-06-08 09:39:58 -07:00
|
|
|
}
|
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
/**
|
2010-06-11 01:23:18 -07:00
|
|
|
* Return ancestor in this document with the given role if it exists.
|
|
|
|
*
|
|
|
|
* @param aDescendant [in] descendant to start search with
|
|
|
|
* @param aRole [in] role to find matching ancestor for
|
|
|
|
* @return the ancestor accessible with the given role, or
|
2012-07-30 07:20:58 -07:00
|
|
|
* nullptr if no match is found
|
2008-10-16 02:12:05 -07:00
|
|
|
*/
|
2012-05-28 18:18:45 -07:00
|
|
|
static Accessible* GetAncestorWithRole(Accessible* aDescendant,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aRole);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2009-12-11 11:38:55 -08: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
|
|
|
|
*/
|
2012-05-28 18:18:45 -07:00
|
|
|
static Accessible* GetSelectableContainer(Accessible* aAccessible,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t aState);
|
2009-12-11 11:38:55 -08:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
/**
|
|
|
|
* Return true if the DOM node of given accessible has aria-selected="true"
|
|
|
|
* attribute.
|
|
|
|
*/
|
2012-05-28 18:18:45 -07:00
|
|
|
static bool IsARIASelected(Accessible* aAccessible);
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2008-10-28 01:43:07 -07:00
|
|
|
/**
|
|
|
|
* Return text accessible containing focus point of the given selection.
|
|
|
|
* Used for normal and misspelling selection changes processing.
|
|
|
|
*
|
|
|
|
* @param aSelection [in] the given selection
|
|
|
|
* @return text accessible
|
|
|
|
*/
|
2012-05-31 01:04:41 -07:00
|
|
|
static HyperTextAccessible*
|
2010-11-29 08:03:29 -08:00
|
|
|
GetTextAccessibleFromSelection(nsISelection* aSelection);
|
2008-10-28 01:43:07 -07:00
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
/**
|
|
|
|
* Converts the given coordinates to coordinates relative screen.
|
|
|
|
*
|
|
|
|
* @param aX [in] the given x coord
|
|
|
|
* @param aY [in] the given y coord
|
|
|
|
* @param aCoordinateType [in] specifies coordinates origin (refer to
|
|
|
|
* nsIAccessibleCoordinateType)
|
2012-12-17 12:11:02 -08:00
|
|
|
* @param aAccessible [in] the accessible if coordinates are given
|
2008-10-16 02:12:05 -07:00
|
|
|
* relative it.
|
2012-12-17 12:11:02 -08:00
|
|
|
* @return converted coordinates
|
2008-10-16 02:12:05 -07:00
|
|
|
*/
|
2012-12-17 12:11:02 -08:00
|
|
|
static nsIntPoint ConvertToScreenCoords(int32_t aX, int32_t aY,
|
|
|
|
uint32_t aCoordinateType,
|
|
|
|
Accessible* aAccessible);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the given coordinates relative screen to another coordinate
|
|
|
|
* system.
|
|
|
|
*
|
|
|
|
* @param aX [in, out] the given x coord
|
|
|
|
* @param aY [in, out] the given y coord
|
|
|
|
* @param aCoordinateType [in] specifies coordinates origin (refer to
|
|
|
|
* nsIAccessibleCoordinateType)
|
2012-12-17 12:11:02 -08:00
|
|
|
* @param aAccessible [in] the accessible if coordinates are given
|
2008-10-16 02:12:05 -07:00
|
|
|
* relative it
|
|
|
|
*/
|
2012-12-17 12:11:02 -08:00
|
|
|
static void ConvertScreenCoordsTo(int32_t* aX, int32_t* aY,
|
|
|
|
uint32_t aCoordinateType,
|
|
|
|
Accessible* aAccessible);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns coordinates relative screen for the parent of the given accessible.
|
|
|
|
*
|
2012-12-17 12:11:02 -08:00
|
|
|
* @param [in] aAccessible the accessible
|
2008-10-16 02:12:05 -07:00
|
|
|
*/
|
2012-12-17 12:11:02 -08:00
|
|
|
static nsIntPoint GetScreenCoordsForParent(Accessible* aAccessible);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2009-02-18 22:56:19 -08:00
|
|
|
/**
|
2009-08-27 22:27:27 -07:00
|
|
|
* Get the 'live' or 'container-live' object attribute value from the given
|
2009-02-18 22:56:19 -08:00
|
|
|
* ELiveAttrRule constant.
|
2009-08-27 22:27:27 -07: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-18 22:56:19 -08:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static bool GetLiveAttrValue(uint32_t aRule, nsAString& aValue);
|
2009-02-18 22:56:19 -08:00
|
|
|
|
2012-05-07 16:49:41 -07:00
|
|
|
#ifdef DEBUG
|
2008-10-17 03:10:43 -07:00
|
|
|
/**
|
|
|
|
* Detect whether the given accessible object implements nsIAccessibleText,
|
|
|
|
* when it is text or has text child node.
|
|
|
|
*/
|
2012-05-28 18:18:45 -07:00
|
|
|
static bool IsTextInterfaceSupportCorrect(Accessible* aAccessible);
|
2008-10-16 02:12:05 -07:00
|
|
|
#endif
|
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
/**
|
2010-05-25 01:40:54 -07:00
|
|
|
* Return text length of the given accessible, return 0 on failure.
|
2008-10-17 03:10:43 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t TextLength(Accessible* aAccessible);
|
2008-10-17 03:10:43 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the given accessible is embedded object.
|
|
|
|
*/
|
2013-03-31 17:57:07 -07:00
|
|
|
static bool IsEmbeddedObject(Accessible* aAcc)
|
2008-10-17 03:10:43 -07:00
|
|
|
{
|
2013-03-31 17:57:07 -07:00
|
|
|
uint32_t role = aAcc->Role();
|
|
|
|
return role != roles::TEXT_LEAF &&
|
|
|
|
role != roles::WHITESPACE &&
|
|
|
|
role != roles::STATICTEXT;
|
2008-10-17 03:10:43 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
/**
|
|
|
|
* Transform nsIAccessibleStates constants to internal state constant.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static inline uint64_t To64State(uint32_t aState1, uint32_t aState2)
|
2011-04-09 16:38:06 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
return static_cast<uint64_t>(aState1) +
|
|
|
|
(static_cast<uint64_t>(aState2) << 31);
|
2011-04-09 16:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform internal state constant to nsIAccessibleStates constants.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static inline void To32States(uint64_t aState64,
|
|
|
|
uint32_t* aState1, uint32_t* aState2)
|
2011-04-09 16:38:06 -07:00
|
|
|
{
|
|
|
|
*aState1 = aState64 & 0x7fffffff;
|
|
|
|
if (aState2)
|
2012-08-22 08:56:38 -07:00
|
|
|
*aState2 = static_cast<uint32_t>(aState64 >> 31);
|
2011-04-09 16:38:06 -07:00
|
|
|
}
|
|
|
|
|
2013-01-19 07:38:01 -08:00
|
|
|
static uint32_t To32States(uint64_t aState, bool* aIsExtra)
|
|
|
|
{
|
|
|
|
uint32_t extraState = aState >> 31;
|
|
|
|
*aIsExtra = !!extraState;
|
|
|
|
return aState | extraState;
|
|
|
|
}
|
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
/**
|
|
|
|
* Return true if the given accessible can't have children. Used when exposing
|
|
|
|
* to platform accessibility APIs, should the children be pruned off?
|
|
|
|
*/
|
2012-05-28 18:18:45 -07:00
|
|
|
static bool MustPrune(Accessible* aAccessible);
|
2008-10-17 03:10:43 -07:00
|
|
|
};
|
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
#endif
|