1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
23 * Alexander Surkov <surkov.alexander@gmail.com> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
42 #include "nsIAccessible.h"
43 #include "nsIAccessNode.h"
44 #include "nsIAccessibleDocument.h"
45 #include "nsIAccessibleRole.h"
46 #include "nsIAccessibleText.h"
47 #include "nsARIAMap.h"
49 #include "nsIDOMNode.h"
50 #include "nsIPersistentProperties2.h"
51 #include "nsIContent.h"
60 * Returns value of attribute from the given attributes container.
62 * @param aAttributes - attributes container
63 * @param aAttrName - the name of requested attribute
64 * @param aAttrValue - value of attribute
66 static void GetAccAttr(nsIPersistentProperties
*aAttributes
,
68 nsAString
& aAttrValue
);
71 * Set value of attribute for the given attributes container.
73 * @param aAttributes - attributes container
74 * @param aAttrName - the name of requested attribute
75 * @param aAttrValue - new value of attribute
77 static void SetAccAttr(nsIPersistentProperties
*aAttributes
,
79 const nsAString
& aAttrValue
);
82 * Return values of group attributes ('level', 'setsize', 'posinset')
84 static void GetAccGroupAttrs(nsIPersistentProperties
*aAttributes
,
90 * Returns true if there are level, posinset and sizeset attributes.
92 static PRBool
HasAccGroupAttrs(nsIPersistentProperties
*aAttributes
);
95 * Set group attributes ('level', 'setsize', 'posinset').
97 static void SetAccGroupAttrs(nsIPersistentProperties
*aAttributes
,
103 * Set group attributes - 'level', 'setsize', 'posinset'.
105 * @param aNode - XUL element that implements
106 * nsIDOMXULSelectControlItemElement interface
107 * @param aAttributes - attributes container
109 static void SetAccAttrsForXULSelectControlItem(nsIDOMNode
*aNode
,
110 nsIPersistentProperties
*aAttributes
);
113 * Set group attributes - 'level', 'setsize', 'posinset'.
115 * @param aNode XUL element that implements
116 * nsIDOMXULContainerItemElement interface
117 * @param aAttributes attributes container
119 static void SetAccAttrsForXULContainerItem(nsIDOMNode
*aNode
,
120 nsIPersistentProperties
*aAttributes
);
123 * Set container-foo live region attributes for the given node.
125 * @param aAttributes where to store the attributes
126 * @param aStartContent node to start from
127 * @param aTopContent node to end at
129 static void SetLiveContainerAttributes(nsIPersistentProperties
*aAttributes
,
130 nsIContent
*aStartContent
,
131 nsIContent
*aTopContent
);
134 * Return PR_TRUE if the ARIA property should always be exposed as an object
137 static PRBool
IsARIAPropForObjectAttr(nsIAtom
*aAtom
);
140 * Fire accessible event of the given type for the given accessible.
142 static nsresult
FireAccEvent(PRUint32 aEventType
, nsIAccessible
*aAccessible
,
143 PRBool aIsAsynch
= PR_FALSE
);
146 * If an ancestor in this document exists with the given role, return it
147 * @param aDescendant Descendant to start search with
148 * @param aRole Role to find matching ancestor for
149 * @return The ancestor accessible with the given role, or nsnull if no match is found
151 static already_AddRefed
<nsIAccessible
>
152 GetAncestorWithRole(nsIAccessible
*aDescendant
, PRUint32 aRole
);
155 * For an ARIA tree item , get the accessible that represents its conceptual parent.
156 * This method will use the correct method for the given way the tree is constructed.
157 * The conceptual parent is what the user sees as the parent, not the DOM or accessible parent.
158 * @param aStartTreeItem The tree item to get the parent for
159 * @param aStartTreeItemContent The content node for the tree item
160 * @param The tree item's parent, or null if none
163 GetARIATreeItemParent(nsIAccessible
*aStartTreeItem
,
164 nsIContent
*aStartTreeItemContent
,
165 nsIAccessible
**aTreeItemParent
);
168 * Return text accessible containing focus point of the given selection.
169 * Used for normal and misspelling selection changes processing.
171 * @param aSelection [in] the given selection
172 * @param aNode [out, optional] the DOM node of text accessible
173 * @return text accessible
175 static already_AddRefed
<nsIAccessibleText
>
176 GetTextAccessibleFromSelection(nsISelection
*aSelection
,
177 nsIDOMNode
**aNode
= nsnull
);
180 * Converts the given coordinates to coordinates relative screen.
182 * @param aX [in] the given x coord
183 * @param aY [in] the given y coord
184 * @param aCoordinateType [in] specifies coordinates origin (refer to
185 * nsIAccessibleCoordinateType)
186 * @param aAccessNode [in] the accessible if coordinates are given
188 * @param aCoords [out] converted coordinates
190 static nsresult
ConvertToScreenCoords(PRInt32 aX
, PRInt32 aY
,
191 PRUint32 aCoordinateType
,
192 nsIAccessNode
*aAccessNode
,
193 nsIntPoint
*aCoords
);
196 * Converts the given coordinates relative screen to another coordinate
199 * @param aX [in, out] the given x coord
200 * @param aY [in, out] the given y coord
201 * @param aCoordinateType [in] specifies coordinates origin (refer to
202 * nsIAccessibleCoordinateType)
203 * @param aAccessNode [in] the accessible if coordinates are given
206 static nsresult
ConvertScreenCoordsTo(PRInt32
*aX
, PRInt32
*aY
,
207 PRUint32 aCoordinateType
,
208 nsIAccessNode
*aAccessNode
);
211 * Returns coordinates relative screen for the top level window.
213 * @param aAccessNode the accessible hosted in the window
215 static nsIntPoint
GetScreenCoordsForWindow(nsIAccessNode
*aAccessNode
);
218 * Returns coordinates relative screen for the parent of the given accessible.
220 * @param aAccessNode the accessible
222 static nsIntPoint
GetScreenCoordsForParent(nsIAccessNode
*aAccessNode
);
225 * Get the role map entry for a given DOM node. This will use the first
226 * ARIA role if the role attribute provides a space delimited list of roles.
227 * @param aNode The DOM node to get the role map entry for
228 * @return A pointer to the role map entry for the ARIA role, or nsnull if none
230 static nsRoleMapEntry
* GetRoleMapEntry(nsIDOMNode
*aNode
);
233 * Return the role of the given accessible.
235 static PRUint32
Role(nsIAccessible
*aAcc
)
237 PRUint32 role
= nsIAccessibleRole::ROLE_NOTHING
;
239 aAcc
->GetFinalRole(&role
);
245 * Return the state for the given accessible.
247 static PRUint32
State(nsIAccessible
*aAcc
)
251 aAcc
->GetState(&state
, nsnull
);
257 * Query nsAccessNode from the given nsIAccessible.
259 static already_AddRefed
<nsAccessNode
>
260 QueryAccessNode(nsIAccessible
*aAccessible
)
262 nsAccessNode
* accessNode
= nsnull
;
264 CallQueryInterface(aAccessible
, &accessNode
);
270 * Query nsAccessNode from the given nsIAccessNode.
272 static already_AddRefed
<nsAccessNode
>
273 QueryAccessNode(nsIAccessNode
*aAccessNode
)
275 nsAccessNode
* accessNode
= nsnull
;
277 CallQueryInterface(aAccessNode
, &accessNode
);
283 * Query nsAccessNode from the given nsIAccessNode.
285 static already_AddRefed
<nsAccessNode
>
286 QueryAccessNode(nsIAccessibleDocument
*aAccessibleDocument
)
288 nsAccessNode
* accessNode
= nsnull
;
289 if (aAccessibleDocument
)
290 CallQueryInterface(aAccessibleDocument
, &accessNode
);
297 * Detect whether the given accessible object implements nsIAccessibleText,
298 * when it is text or has text child node.
300 static PRBool
IsTextInterfaceSupportCorrect(nsIAccessible
*aAccessible
);
304 * Return true if the given accessible has text role.
306 static PRBool
IsText(nsIAccessible
*aAcc
)
308 PRUint32 role
= Role(aAcc
);
309 return role
== nsIAccessibleRole::ROLE_TEXT_LEAF
||
310 role
== nsIAccessibleRole::ROLE_STATICTEXT
;
314 * Return text length of the given accessible, return -1 on failure.
316 static PRInt32
TextLength(nsIAccessible
*aAccessible
);
319 * Return true if the given accessible is embedded object.
321 static PRBool
IsEmbeddedObject(nsIAccessible
*aAcc
)
323 PRUint32 role
= Role(aAcc
);
324 return role
!= nsIAccessibleRole::ROLE_TEXT_LEAF
&&
325 role
!= nsIAccessibleRole::ROLE_WHITESPACE
&&
326 role
!= nsIAccessibleRole::ROLE_STATICTEXT
;
330 * Return true if the given accessible hasn't children.
332 static PRBool
IsLeaf(nsIAccessible
*aAcc
)
335 aAcc
->GetChildCount(&numChildren
);
336 return numChildren
> 0;
340 * Return true if the given accessible can't have children. Used when exposing
341 * to platform accessibility APIs, should the children be pruned off?
343 static PRBool
MustPrune(nsIAccessible
*aAccessible
);
346 * Return true if the given node can be accessible and attached to
347 * the document's accessible tree.
349 static PRBool
IsNodeRelevant(nsIDOMNode
*aNode
);
352 * Return multiselectable parent for the given selectable accessible if any.
354 static already_AddRefed
<nsIAccessible
> GetMultiSelectFor(nsIDOMNode
*aNode
);