Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / accessible / src / base / nsCoreUtils.h
blob01e5bdc5ac059aa7f286bc72f0b1f6bb225757b0
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
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
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 ***** */
39 #ifndef nsCoreUtils_h_
40 #define nsCoreUtils_h_
42 #include "nsAccessibilityAtoms.h"
44 #include "nsIDOMNode.h"
45 #include "nsIContent.h"
46 #include "nsIFrame.h"
47 #include "nsIDocShellTreeItem.h"
48 #include "nsPoint.h"
50 class nsCoreUtils
52 public:
53 /**
54 * Return true if the given node has registered event listener of the given
55 * type.
57 static PRBool HasListener(nsIContent *aContent, const nsAString& aEventType);
59 /**
60 * Send mouse events to the given element.
62 * @param aEventType an event type (see nsGUIEvent.h for constants)
63 * @param aPresShell the presshell for the given element
64 * @param aContent the element element
66 static PRBool DispatchMouseEvent(PRUint32 aEventType,
67 nsIPresShell *aPresShell,
68 nsIContent *aContent);
70 /**
71 * Return an accesskey registered on the given element by
72 * nsIEventStateManager or 0 if there is no registered accesskey.
74 * @param aContent - the given element.
76 static PRUint32 GetAccessKeyFor(nsIContent *aContent);
78 /**
79 * Return DOM element related with the given node, i.e.
80 * a) itself if it is DOM element
81 * b) parent element if it is text node
82 * c) body element if it is HTML document node
83 * d) document element if it is document node.
85 * @param aNode [in] the given DOM node
87 static already_AddRefed<nsIDOMElement> GetDOMElementFor(nsIDOMNode *aNode);
89 /**
90 * Return the nsIContent* to check for ARIA attributes on -- this may not
91 * always be the DOM node for the accessible. Specifically, for doc
92 * accessibles, it is not the document node, but either the root element or
93 * <body> in HTML. Similar with GetDOMElementFor() method.
95 * @param aDOMNode DOM node for the accessible that may be affected by ARIA
96 * @return the nsIContent which may have ARIA markup
98 static nsIContent *GetRoleContent(nsIDOMNode *aDOMNode);
101 * Is the first passed in node an ancestor of the second?
102 * Note: A node is not considered to be the ancestor of itself.
103 * @param aPossibleAncestorNode -- node to test for ancestor-ness of aPossibleDescendantNode
104 * @param aPossibleDescendantNode -- node to test for descendant-ness of aPossibleAncestorNode
105 * @return PR_TRUE if aPossibleAncestorNode is an ancestor of aPossibleDescendantNode
107 static PRBool IsAncestorOf(nsIDOMNode *aPossibleAncestorNode,
108 nsIDOMNode *aPossibleDescendantNode);
111 * Are the first node and the second siblings?
112 * @return PR_TRUE if aDOMNode1 and aDOMNode2 have same parent
114 static PRBool AreSiblings(nsIDOMNode *aDOMNode1,
115 nsIDOMNode *aDOMNode2);
118 * Helper method to scroll range into view, used for implementation of
119 * nsIAccessibleText::scrollSubstringTo().
121 * @param aFrame the frame for accessible the range belongs to.
122 * @param aStartNode start node of a range
123 * @param aStartOffset an offset inside the start node
124 * @param aEndNode end node of a range
125 * @param aEndOffset an offset inside the end node
126 * @param aScrollType the place a range should be scrolled to
128 static nsresult ScrollSubstringTo(nsIFrame *aFrame,
129 nsIDOMNode *aStartNode, PRInt32 aStartIndex,
130 nsIDOMNode *aEndNode, PRInt32 aEndIndex,
131 PRUint32 aScrollType);
133 /** Helper method to scroll range into view, used for implementation of
134 * nsIAccessibleText::scrollSubstringTo[Point]().
136 * @param aFrame the frame for accessible the range belongs to.
137 * @param aStartNode start node of a range
138 * @param aStartOffset an offset inside the start node
139 * @param aEndNode end node of a range
140 * @param aEndOffset an offset inside the end node
141 * @param aVPercent how to align vertically, specified in percents
142 * @param aHPercent how to align horizontally, specified in percents
144 static nsresult ScrollSubstringTo(nsIFrame *aFrame,
145 nsIDOMNode *aStartNode, PRInt32 aStartIndex,
146 nsIDOMNode *aEndNode, PRInt32 aEndIndex,
147 PRInt16 aVPercent, PRInt16 aHPercent);
150 * Scrolls the given frame to the point, used for implememntation of
151 * nsIAccessNode::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint.
153 * @param aScrollableFrame the scrollable frame
154 * @param aFrame the frame to scroll
155 * @param aPoint the point scroll to
157 static void ScrollFrameToPoint(nsIFrame *aScrollableFrame,
158 nsIFrame *aFrame, const nsIntPoint& aPoint);
161 * Converts scroll type constant defined in nsIAccessibleScrollType to
162 * vertical and horizontal percents.
164 static void ConvertScrollTypeToPercents(PRUint32 aScrollType,
165 PRInt16 *aVPercent,
166 PRInt16 *aHPercent);
169 * Returns coordinates relative screen for the top level window.
171 * @param aNode the DOM node hosted in the window.
173 static nsIntPoint GetScreenCoordsForWindow(nsIDOMNode *aNode);
176 * Return document shell tree item for the given DOM node.
178 static already_AddRefed<nsIDocShellTreeItem>
179 GetDocShellTreeItemFor(nsIDOMNode *aNode);
182 * Retrun frame for the given DOM element.
184 static nsIFrame* GetFrameFor(nsIDOMElement *aElm);
187 * Retrun true if the type of given frame equals to the given frame type.
189 * @param aFrame the frame
190 * @param aAtom the frame type
192 static PRBool IsCorrectFrameType(nsIFrame* aFrame, nsIAtom* aAtom);
195 * Return presShell for the document containing the given DOM node.
197 static already_AddRefed<nsIPresShell> GetPresShellFor(nsIDOMNode *aNode);
200 * Return document node for the given document shell tree item.
202 static already_AddRefed<nsIDOMNode>
203 GetDOMNodeForContainer(nsIDocShellTreeItem *aContainer);
206 * Get the ID for an element, in some types of XML this may not be the ID attribute
207 * @param aContent Node to get the ID for
208 * @param aID Where to put ID string
209 * @return PR_TRUE if there is an ID set for this node
211 static PRBool GetID(nsIContent *aContent, nsAString& aID);
214 * Check if the given element is XLink.
216 * @param aContent the given element
217 * @return PR_TRUE if the given element is XLink
219 static PRBool IsXLink(nsIContent *aContent);
222 * Returns language for the given node.
224 * @param aContent [in] the given node
225 * @param aRootContent [in] container of the given node
226 * @param aLanguage [out] language
228 static void GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
229 nsAString& aLanguage);
232 * Return computed styles declaration for the given node.
234 static void GetComputedStyleDeclaration(const nsAString& aPseudoElt,
235 nsIDOMNode *aNode,
236 nsIDOMCSSStyleDeclaration **aCssDecl);
239 * Search element in neighborhood of the given element by tag name and
240 * attribute value that equals to ID attribute of the given element.
241 * ID attribute can be either 'id' attribute or 'anonid' if the element is
242 * anonymous.
243 * The first matched content will be returned.
245 * @param aForNode - the given element the search is performed for
246 * @param aRelationAttrs - an array of attributes, element is attribute name of searched element, ignored if aAriaProperty passed in
247 * @param aAttrNum - how many attributes in aRelationAttrs
248 * @param aTagName - tag name of searched element, or nsnull for any -- ignored if aAriaProperty passed in
249 * @param aAncestorLevelsToSearch - points how is the neighborhood of the
250 * given element big.
252 static nsIContent *FindNeighbourPointingToNode(nsIContent *aForNode,
253 nsIAtom **aRelationAttrs,
254 PRUint32 aAttrNum,
255 nsIAtom *aTagName = nsnull,
256 PRUint32 aAncestorLevelsToSearch = 5);
259 * Overloaded version of FindNeighbourPointingToNode to accept only one
260 * relation attribute.
262 static nsIContent *FindNeighbourPointingToNode(nsIContent *aForNode,
263 nsIAtom *aRelationAttr,
264 nsIAtom *aTagName = nsnull,
265 PRUint32 aAncestorLevelsToSearch = 5);
268 * Search for element that satisfies the requirements in subtree of the given
269 * element. The requirements are tag name, attribute name and value of
270 * attribute.
271 * The first matched content will be returned.
273 * @param aId - value of searched attribute
274 * @param aLookContent - element that search is performed inside
275 * @param aRelationAttrs - an array of searched attributes
276 * @param aAttrNum - how many attributes in aRelationAttrs
277 * @param if both aAriaProperty and aRelationAttrs are null, then any element with aTagType will do
278 * @param aExcludeContent - element that is skiped for search
279 * @param aTagType - tag name of searched element, by default it is 'label' --
280 * ignored if aAriaProperty passed in
282 static nsIContent *FindDescendantPointingToID(const nsString *aId,
283 nsIContent *aLookContent,
284 nsIAtom **aRelationAttrs,
285 PRUint32 aAttrNum = 1,
286 nsIContent *aExcludeContent = nsnull,
287 nsIAtom *aTagType = nsAccessibilityAtoms::label);
290 * Overloaded version of FindDescendantPointingToID to accept only one
291 * relation attribute.
293 static nsIContent *FindDescendantPointingToID(const nsString *aId,
294 nsIContent *aLookContent,
295 nsIAtom *aRelationAttr,
296 nsIContent *aExcludeContent = nsnull,
297 nsIAtom *aTagType = nsAccessibilityAtoms::label);
299 // Helper for FindDescendantPointingToID(), same args
300 static nsIContent *FindDescendantPointingToIDImpl(nsCString& aIdWithSpaces,
301 nsIContent *aLookContent,
302 nsIAtom **aRelationAttrs,
303 PRUint32 aAttrNum = 1,
304 nsIContent *aExcludeContent = nsnull,
305 nsIAtom *aTagType = nsAccessibilityAtoms::label);
308 * Return the label element for the given DOM element.
310 static nsIContent *GetLabelContent(nsIContent *aForNode);
313 * Return the HTML label element for the given HTML element.
315 static nsIContent *GetHTMLLabelContent(nsIContent *aForNode);
320 #endif