2007-03-27 05:17:11 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsAccessibilityUtils_h_
|
|
|
|
#define nsAccessibilityUtils_h_
|
|
|
|
|
|
|
|
#include "nsAccessibilityAtoms.h"
|
2007-07-05 09:02:55 -07:00
|
|
|
#include "nsIAccessible.h"
|
2007-09-24 22:48:51 -07:00
|
|
|
#include "nsIAccessNode.h"
|
2007-09-24 18:19:03 -07:00
|
|
|
#include "nsARIAMap.h"
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIPersistentProperties2.h"
|
2007-05-08 14:44:04 -07:00
|
|
|
#include "nsIContent.h"
|
2007-08-23 21:54:45 -07:00
|
|
|
#include "nsIFrame.h"
|
2007-09-05 00:39:09 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsPoint.h"
|
2007-09-24 18:19:03 -07:00
|
|
|
#include "nsIAccessibleDocument.h"
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2007-07-05 04:29:28 -07:00
|
|
|
class nsAccUtils
|
2007-03-27 05:17:11 -07:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return values of group attributes ('level', 'setsize', 'posinset')
|
|
|
|
*/
|
|
|
|
static void GetAccGroupAttrs(nsIPersistentProperties *aAttributes,
|
|
|
|
PRInt32 *aLevel,
|
|
|
|
PRInt32 *aPosInSet,
|
2007-04-07 02:07:24 -07:00
|
|
|
PRInt32 *aSetSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if there are level, posinset and sizeset attributes.
|
|
|
|
*/
|
|
|
|
static PRBool HasAccGroupAttrs(nsIPersistentProperties *aAttributes);
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set group attributes ('level', 'setsize', 'posinset').
|
|
|
|
*/
|
|
|
|
static void SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
|
|
|
|
PRInt32 aLevel,
|
|
|
|
PRInt32 aPosInSet,
|
2007-04-07 02:07:24 -07:00
|
|
|
PRInt32 aSetSize);
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set group attributes - 'level', 'setsize', 'posinset'.
|
|
|
|
*
|
|
|
|
* @param aNode - XUL element that implements
|
|
|
|
* nsIDOMXULSelectControlItemElement interface
|
|
|
|
* @param aAttributes - attributes container
|
|
|
|
*/
|
|
|
|
static void SetAccAttrsForXULSelectControlItem(nsIDOMNode *aNode,
|
|
|
|
nsIPersistentProperties *aAttributes);
|
2007-05-08 14:44:04 -07:00
|
|
|
|
2007-07-05 09:02:55 -07:00
|
|
|
/**
|
|
|
|
* Return true if the given node has registered event listener of the given
|
|
|
|
* type.
|
|
|
|
*/
|
2007-05-08 14:44:04 -07:00
|
|
|
static PRBool HasListener(nsIContent *aContent, const nsAString& aEventType);
|
2007-07-05 09:02:55 -07:00
|
|
|
|
2007-08-28 23:52:46 -07:00
|
|
|
/**
|
|
|
|
* Return an accesskey registered on the given element by
|
|
|
|
* nsIEventStateManager or 0 if there is no registered accesskey.
|
|
|
|
*
|
|
|
|
* @param aContent - the given element.
|
|
|
|
*/
|
|
|
|
static PRUint32 GetAccessKeyFor(nsIContent *aContent);
|
|
|
|
|
2007-07-05 09:02:55 -07:00
|
|
|
/**
|
|
|
|
* Fire accessible event of the given type for the given accessible.
|
|
|
|
*/
|
2007-08-10 18:44:44 -07:00
|
|
|
static nsresult FireAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible,
|
|
|
|
PRBool aIsAsynch = PR_FALSE);
|
2007-08-14 11:47:49 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the first passed in node an ancestor of the second?
|
|
|
|
* Note: A node is not considered to be the ancestor of itself.
|
2007-08-20 20:16:27 -07:00
|
|
|
* @param aPossibleAncestorNode -- node to test for ancestor-ness of aPossibleDescendantNode
|
|
|
|
* @param aPossibleDescendantNode -- node to test for descendant-ness of aPossibleAncestorNode
|
2007-08-14 11:47:49 -07:00
|
|
|
* @return PR_TRUE if aPossibleAncestorNode is an ancestor of aPossibleDescendantNode
|
|
|
|
*/
|
2007-08-20 20:16:27 -07:00
|
|
|
static PRBool IsAncestorOf(nsIDOMNode *aPossibleAncestorNode,
|
|
|
|
nsIDOMNode *aPossibleDescendantNode);
|
|
|
|
|
2007-08-23 21:54:45 -07:00
|
|
|
/**
|
2007-08-20 20:16:27 -07:00
|
|
|
* If an ancestor in this document exists with the given role, return it
|
|
|
|
* @param aDescendant Descendant to start search with
|
|
|
|
* @param aRole Role to find matching ancestor for
|
|
|
|
* @return The ancestor accessible with the given role, or nsnull if no match is found
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIAccessible>
|
|
|
|
GetAncestorWithRole(nsIAccessible *aDescendant, PRUint32 aRole);
|
2007-08-23 21:54:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to scroll range into view, used for implementation of
|
|
|
|
* nsIAccessibleText::scrollSubstringTo().
|
|
|
|
*
|
|
|
|
* @param aFrame the frame for accessible the range belongs to.
|
|
|
|
* @param aStartNode start node of a range
|
|
|
|
* @param aStartOffset an offset inside the start node
|
|
|
|
* @param aEndNode end node of a range
|
|
|
|
* @param aEndOffset an offset inside the end node
|
|
|
|
* @param aScrollType the place a range should be scrolled to
|
|
|
|
*/
|
|
|
|
static nsresult ScrollSubstringTo(nsIFrame *aFrame,
|
|
|
|
nsIDOMNode *aStartNode, PRInt32 aStartIndex,
|
|
|
|
nsIDOMNode *aEndNode, PRInt32 aEndIndex,
|
|
|
|
PRUint32 aScrollType);
|
|
|
|
|
2007-09-24 22:48:51 -07:00
|
|
|
/** Helper method to scroll range into view, used for implementation of
|
|
|
|
* nsIAccessibleText::scrollSubstringTo[Point]().
|
|
|
|
*
|
|
|
|
* @param aFrame the frame for accessible the range belongs to.
|
|
|
|
* @param aStartNode start node of a range
|
|
|
|
* @param aStartOffset an offset inside the start node
|
|
|
|
* @param aEndNode end node of a range
|
|
|
|
* @param aEndOffset an offset inside the end node
|
|
|
|
* @param aVPercent how to align vertically, specified in percents
|
|
|
|
* @param aHPercent how to align horizontally, specified in percents
|
|
|
|
*/
|
|
|
|
static nsresult ScrollSubstringTo(nsIFrame *aFrame,
|
|
|
|
nsIDOMNode *aStartNode, PRInt32 aStartIndex,
|
|
|
|
nsIDOMNode *aEndNode, PRInt32 aEndIndex,
|
|
|
|
PRInt16 aVPercent, PRInt16 aHPercent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrolls the given frame to the point, used for implememntation of
|
|
|
|
* nsIAccessNode::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint.
|
|
|
|
*
|
|
|
|
* @param aScrollableFrame the scrollable frame
|
|
|
|
* @param aFrame the frame to scroll
|
|
|
|
* @param aPoint the point scroll to
|
|
|
|
*/
|
|
|
|
static void ScrollFrameToPoint(nsIFrame *aScrollableFrame,
|
|
|
|
nsIFrame *aFrame, const nsIntPoint& aPoint);
|
|
|
|
|
2007-08-23 21:54:45 -07:00
|
|
|
/**
|
|
|
|
* Converts scroll type constant defined in nsIAccessibleScrollType to
|
|
|
|
* vertical and horizontal percents.
|
|
|
|
*/
|
|
|
|
static void ConvertScrollTypeToPercents(PRUint32 aScrollType,
|
|
|
|
PRInt16 *aVPercent,
|
|
|
|
PRInt16 *aHPercent);
|
2007-09-05 00:39:09 -07:00
|
|
|
|
2007-09-24 22:48:51 -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)
|
|
|
|
* @param aAccessNode [in] the accessible if coordinates are given
|
|
|
|
* relative it.
|
|
|
|
* @param aCoords [out] converted coordinates
|
|
|
|
*/
|
|
|
|
static nsresult ConvertToScreenCoords(PRInt32 aX, PRInt32 aY,
|
|
|
|
PRUint32 aCoordinateType,
|
|
|
|
nsIAccessNode *aAccessNode,
|
|
|
|
nsIntPoint *aCoords);
|
|
|
|
|
2007-12-01 09:30:09 -08: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)
|
|
|
|
* @param aAccessNode [in] the accessible if coordinates are given
|
|
|
|
* relative it
|
|
|
|
*/
|
|
|
|
static nsresult ConvertScreenCoordsTo(PRInt32 *aX, PRInt32 *aY,
|
|
|
|
PRUint32 aCoordinateType,
|
|
|
|
nsIAccessNode *aAccessNode);
|
|
|
|
|
2007-09-05 00:39:09 -07:00
|
|
|
/**
|
|
|
|
* Returns coordinates relative screen for the top level window.
|
|
|
|
*
|
2007-12-01 09:30:09 -08:00
|
|
|
* @param aNode the DOM node hosted in the window.
|
2007-09-05 00:39:09 -07:00
|
|
|
*/
|
|
|
|
static nsIntPoint GetScreenCoordsForWindow(nsIDOMNode *aNode);
|
|
|
|
|
2007-12-01 09:30:09 -08:00
|
|
|
/**
|
|
|
|
* Returns coordinates relative screen for the top level window.
|
|
|
|
*
|
|
|
|
* @param aAccessNode the accessible hosted in the window
|
|
|
|
*/
|
|
|
|
static nsIntPoint GetScreenCoordsForWindow(nsIAccessNode *aAccessNode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns coordinates relative screen for the parent of the given accessible.
|
|
|
|
*
|
|
|
|
* @param aAccessNode the accessible
|
|
|
|
*/
|
|
|
|
static nsIntPoint GetScreenCoordsForParent(nsIAccessNode *aAccessNode);
|
|
|
|
|
2007-09-05 00:39:09 -07:00
|
|
|
/**
|
|
|
|
* Return document shell tree item for the given DOM node.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIDocShellTreeItem>
|
|
|
|
GetDocShellTreeItemFor(nsIDOMNode *aNode);
|
2007-09-18 14:36:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ID for an element, in some types of XML this may not be the ID attribute
|
|
|
|
* @param aContent Node to get the ID for
|
|
|
|
* @param aID Where to put ID string
|
|
|
|
* @return PR_TRUE if there is an ID set for this node
|
|
|
|
*/
|
|
|
|
static PRBool GetID(nsIContent *aContent, nsAString& aID);
|
2007-09-24 18:19:03 -07:00
|
|
|
|
2007-11-11 17:05:37 -08:00
|
|
|
/**
|
|
|
|
* Get the role map entry for a given DOM node. This will use the first
|
|
|
|
* ARIA role if the role attribute provides a space delimited list of roles.
|
|
|
|
* @param aNode The DOM node to get the role map entry for
|
|
|
|
* @return A pointer to the role map entry for the ARIA role, or nsnull if none
|
|
|
|
*/
|
|
|
|
static nsRoleMapEntry* GetRoleMapEntry(nsIDOMNode *aNode);
|
|
|
|
|
2007-09-24 18:19:03 -07:00
|
|
|
/**
|
|
|
|
* Search element in neighborhood of the given element by tag name and
|
|
|
|
* attribute value that equals to ID attribute of the given element.
|
|
|
|
* ID attribute can be either 'id' attribute or 'anonid' if the element is
|
|
|
|
* anonymous.
|
2008-01-21 19:17:37 -08:00
|
|
|
* The first matched content will be returned.
|
2007-09-24 18:19:03 -07:00
|
|
|
*
|
|
|
|
* @param aForNode - the given element the search is performed for
|
2008-01-21 19:17:37 -08:00
|
|
|
* @param aRelationAttrs - an array of attributes, element is attribute name of searched element, ignored if aAriaProperty passed in
|
|
|
|
* @param aAttrNum - how many attributes in aRelationAttrs
|
2007-12-11 18:10:26 -08:00
|
|
|
* @param aTagName - tag name of searched element, or nsnull for any -- ignored if aAriaProperty passed in
|
2007-09-24 18:19:03 -07:00
|
|
|
* @param aAncestorLevelsToSearch - points how is the neighborhood of the
|
|
|
|
* given element big.
|
|
|
|
*/
|
|
|
|
static nsIContent *FindNeighbourPointingToNode(nsIContent *aForNode,
|
2008-01-21 19:17:37 -08:00
|
|
|
nsIAtom **aRelationAttrs,
|
|
|
|
PRUint32 aAttrNum,
|
|
|
|
nsIAtom *aTagName = nsnull,
|
|
|
|
PRUint32 aAncestorLevelsToSearch = 5);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overloaded version of FindNeighbourPointingToNode to accept only one
|
|
|
|
* relation attribute.
|
|
|
|
*/
|
|
|
|
static nsIContent *FindNeighbourPointingToNode(nsIContent *aForNode,
|
|
|
|
nsIAtom *aRelationAttr,
|
2007-09-24 18:19:03 -07:00
|
|
|
nsIAtom *aTagName = nsnull,
|
|
|
|
PRUint32 aAncestorLevelsToSearch = 5);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for element that satisfies the requirements in subtree of the given
|
|
|
|
* element. The requirements are tag name, attribute name and value of
|
|
|
|
* attribute.
|
2008-01-21 19:17:37 -08:00
|
|
|
* The first matched content will be returned.
|
2007-09-24 18:19:03 -07:00
|
|
|
*
|
|
|
|
* @param aId - value of searched attribute
|
|
|
|
* @param aLookContent - element that search is performed inside
|
2008-01-21 19:17:37 -08:00
|
|
|
* @param aRelationAttrs - an array of searched attributes
|
|
|
|
* @param aAttrNum - how many attributes in aRelationAttrs
|
|
|
|
* @param if both aAriaProperty and aRelationAttrs are null, then any element with aTagType will do
|
2007-09-24 18:19:03 -07:00
|
|
|
* @param aExcludeContent - element that is skiped for search
|
|
|
|
* @param aTagType - tag name of searched element, by default it is 'label' --
|
|
|
|
* ignored if aAriaProperty passed in
|
|
|
|
*/
|
2008-01-21 19:17:37 -08:00
|
|
|
static nsIContent *FindDescendantPointingToID(const nsString *aId,
|
|
|
|
nsIContent *aLookContent,
|
|
|
|
nsIAtom **aRelationAttrs,
|
|
|
|
PRUint32 aAttrNum = 1,
|
|
|
|
nsIContent *aExcludeContent = nsnull,
|
|
|
|
nsIAtom *aTagType = nsAccessibilityAtoms::label);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overloaded version of FindDescendantPointingToID to accept only one
|
|
|
|
* relation attribute.
|
|
|
|
*/
|
2007-09-24 18:19:03 -07:00
|
|
|
static nsIContent *FindDescendantPointingToID(const nsString *aId,
|
|
|
|
nsIContent *aLookContent,
|
2007-12-11 18:10:26 -08:00
|
|
|
nsIAtom *aRelationAttr,
|
2007-09-24 18:19:03 -07:00
|
|
|
nsIContent *aExcludeContent = nsnull,
|
|
|
|
nsIAtom *aTagType = nsAccessibilityAtoms::label);
|
|
|
|
|
|
|
|
// Helper for FindDescendantPointingToID(), same args
|
|
|
|
static nsIContent *FindDescendantPointingToIDImpl(nsCString& aIdWithSpaces,
|
|
|
|
nsIContent *aLookContent,
|
2008-01-21 19:17:37 -08:00
|
|
|
nsIAtom **aRelationAttrs,
|
|
|
|
PRUint32 aAttrNum = 1,
|
2007-09-24 18:19:03 -07:00
|
|
|
nsIContent *aExcludeContent = nsnull,
|
|
|
|
nsIAtom *aTagType = nsAccessibilityAtoms::label);
|
2007-03-27 05:17:11 -07:00
|
|
|
};
|
|
|
|
|
2007-03-31 00:14:03 -07:00
|
|
|
#endif
|
2007-08-23 21:54:45 -07:00
|
|
|
|