1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/EventForwards.h"
10 #include "mozilla/dom/Element.h"
11 #include "nsIAccessibleEvent.h"
12 #include "nsIContent.h"
13 #include "mozilla/dom/Document.h" // for GetPresShell()
29 } // namespace mozilla
36 typedef mozilla::PresShell PresShell
;
37 typedef mozilla::dom::Document Document
;
40 * Return true if the given node is a label of a control.
42 static bool IsLabelWithControl(nsIContent
* aContent
);
45 * Return true if the given node has registered click, mousedown or mouseup
48 static bool HasClickListener(nsIContent
* aContent
);
51 * Dispatch click event to XUL tree cell.
53 * @param aTree [in] tree
54 * @param aRowIndex [in] row index
55 * @param aColumn [in] column object
56 * @param aPseudoElm [in] pseudo element inside the cell, see
57 * XULTreeElement for available values
60 static void DispatchClickEvent(mozilla::dom::XULTreeElement
* aTree
,
61 int32_t aRowIndex
, nsTreeColumn
* aColumn
,
62 const nsAString
& aPseudoElt
= EmptyString());
65 * Send mouse event to the given element.
67 * @param aMessage [in] an event message (see EventForwards.h)
68 * @param aX [in] x coordinate in dev pixels
69 * @param aY [in] y coordinate in dev pixels
70 * @param aContent [in] the element
71 * @param aFrame [in] frame of the element
72 * @param aPresShell [in] the presshell for the element
73 * @param aRootWidget [in] the root widget of the element
76 static void DispatchMouseEvent(mozilla::EventMessage aMessage
, int32_t aX
,
77 int32_t aY
, nsIContent
* aContent
,
78 nsIFrame
* aFrame
, PresShell
* aPresShell
,
79 nsIWidget
* aRootWidget
);
82 * Send a touch event with a single touch point to the given element.
84 * @param aMessage [in] an event message (see EventForwards.h)
85 * @param aX [in] x coordinate in dev pixels
86 * @param aY [in] y coordinate in dev pixels
87 * @param aContent [in] the element
88 * @param aFrame [in] frame of the element
89 * @param aPresShell [in] the presshell for the element
90 * @param aRootWidget [in] the root widget of the element
93 static void DispatchTouchEvent(mozilla::EventMessage aMessage
, int32_t aX
,
94 int32_t aY
, nsIContent
* aContent
,
95 nsIFrame
* aFrame
, PresShell
* aPresShell
,
96 nsIWidget
* aRootWidget
);
99 * Return an accesskey registered on the given element by
100 * EventStateManager or 0 if there is no registered accesskey.
102 * @param aContent - the given element.
104 static uint32_t GetAccessKeyFor(nsIContent
* aContent
);
107 * Return DOM element related with the given node, i.e.
108 * a) itself if it is DOM element
109 * b) parent element if it is text node
110 * c) otherwise nullptr
112 * @param aNode [in] the given DOM node
114 static nsIContent
* GetDOMElementFor(nsIContent
* aContent
);
117 * Return DOM node for the given DOM point.
119 static nsINode
* GetDOMNodeFromDOMPoint(nsINode
* aNode
, uint32_t aOffset
);
122 * Is the first passed in node an ancestor of the second?
123 * Note: A node is not considered to be the ancestor of itself.
125 * @param aPossibleAncestorNode [in] node to test for ancestor-ness of
126 * aPossibleDescendantNode
127 * @param aPossibleDescendantNode [in] node to test for descendant-ness of
128 * aPossibleAncestorNode
129 * @param aRootNode [in, optional] the root node that search
130 * search should be performed within
131 * @return true if aPossibleAncestorNode is an ancestor of
132 * aPossibleDescendantNode
134 static bool IsAncestorOf(nsINode
* aPossibleAncestorNode
,
135 nsINode
* aPossibleDescendantNode
,
136 nsINode
* aRootNode
= nullptr);
139 * Helper method to scroll range into view, used for implementation of
140 * nsIAccessibleText::scrollSubstringTo().
142 * @param aFrame the frame for accessible the range belongs to.
143 * @param aRange the range to scroll to
144 * @param aScrollType the place a range should be scrolled to
146 static nsresult
ScrollSubstringTo(nsIFrame
* aFrame
, nsRange
* aRange
,
147 uint32_t aScrollType
);
149 /** Helper method to scroll range into view, used for implementation of
150 * nsIAccessibleText::scrollSubstringTo[Point]().
152 * @param aFrame the frame for accessible the range belongs to.
153 * @param aRange the range to scroll to
154 * @param aVertical how to align vertically, specified in percents, and
156 * @param aHorizontal how to align horizontally, specified in percents,
159 static nsresult
ScrollSubstringTo(nsIFrame
* aFrame
, nsRange
* aRange
,
160 mozilla::ScrollAxis aVertical
,
161 mozilla::ScrollAxis aHorizontal
);
164 * Scrolls the given frame to the point, used for implememntation of
165 * nsIAccessible::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint.
167 * @param aScrollableFrame the scrollable frame
168 * @param aFrame the frame to scroll
169 * @param aPoint the point scroll to
171 static void ScrollFrameToPoint(nsIFrame
* aScrollableFrame
, nsIFrame
* aFrame
,
172 const nsIntPoint
& aPoint
);
175 * Converts scroll type constant defined in nsIAccessibleScrollType to
176 * vertical and horizontal parameters.
178 static void ConvertScrollTypeToPercents(uint32_t aScrollType
,
179 mozilla::ScrollAxis
* aVertical
,
180 mozilla::ScrollAxis
* aHorizontal
);
183 * Returns coordinates in device pixels relative screen for the top level
186 * @param aNode the DOM node hosted in the window.
188 static nsIntPoint
GetScreenCoordsForWindow(nsINode
* aNode
);
191 * Return document shell for the given DOM node.
193 static already_AddRefed
<nsIDocShell
> GetDocShellFor(nsINode
* aNode
);
196 * Return true if the given document is root document.
198 static bool IsRootDocument(Document
* aDocument
);
201 * Return true if the given document is content document (not chrome).
203 static bool IsContentDocument(Document
* aDocument
);
206 * Return true if the given document node is for tab document accessible.
208 static bool IsTabDocument(Document
* aDocumentNode
);
211 * Return true if the given document is an error page.
213 static bool IsErrorPage(Document
* aDocument
);
216 * Return presShell for the document containing the given DOM node.
218 static PresShell
* GetPresShellFor(nsINode
* aNode
) {
219 return aNode
->OwnerDoc()->GetPresShell();
223 * Get the ID for an element, in some types of XML this may not be the ID
225 * @param aContent Node to get the ID for
226 * @param aID Where to put ID string
227 * @return true if there is an ID set for this node
229 static bool GetID(nsIContent
* aContent
, nsAString
& aID
);
232 * Convert attribute value of the given node to positive integer. If no
233 * attribute or wrong value then false is returned.
235 static bool GetUIntAttr(nsIContent
* aContent
, nsAtom
* aAttr
, int32_t* aUInt
);
238 * Returns language for the given node.
240 * @param aContent [in] the given node
241 * @param aRootContent [in] container of the given node
242 * @param aLanguage [out] language
244 static void GetLanguageFor(nsIContent
* aContent
, nsIContent
* aRootContent
,
245 nsAString
& aLanguage
);
248 * Return tree from any levels DOMNode under the XUL tree.
250 static mozilla::dom::XULTreeElement
* GetTree(nsIContent
* aContent
);
253 * Return first sensible column for the given tree box object.
255 static already_AddRefed
<nsTreeColumn
> GetFirstSensibleColumn(
256 mozilla::dom::XULTreeElement
* aTree
);
259 * Return sensible columns count for the given tree box object.
261 static uint32_t GetSensibleColumnCount(mozilla::dom::XULTreeElement
* aTree
);
264 * Return sensible column at the given index for the given tree box object.
266 static already_AddRefed
<nsTreeColumn
> GetSensibleColumnAt(
267 mozilla::dom::XULTreeElement
* aTree
, uint32_t aIndex
);
270 * Return next sensible column for the given column.
272 static already_AddRefed
<nsTreeColumn
> GetNextSensibleColumn(
273 nsTreeColumn
* aColumn
);
276 * Return previous sensible column for the given column.
278 static already_AddRefed
<nsTreeColumn
> GetPreviousSensibleColumn(
279 nsTreeColumn
* aColumn
);
282 * Return true if the given column is hidden (i.e. not sensible).
284 static bool IsColumnHidden(nsTreeColumn
* aColumn
);
287 * Scroll content into view.
290 static void ScrollTo(PresShell
* aPresShell
, nsIContent
* aContent
,
291 uint32_t aScrollType
);
294 * Return true if the given node is table header element.
296 static bool IsHTMLTableHeader(nsIContent
* aContent
) {
297 return aContent
->NodeInfo()->Equals(nsGkAtoms::th
) ||
298 (aContent
->IsElement() && aContent
->AsElement()->HasAttr(
299 kNameSpaceID_None
, nsGkAtoms::scope
));
303 * Returns true if the given string is empty or contains whitespace symbols
304 * only. In contrast to nsWhitespaceTokenizer class it takes into account
305 * non-breaking space (0xa0).
307 static bool IsWhitespaceString(const nsAString
& aString
);
310 * Returns true if the given character is whitespace symbol.
312 static bool IsWhitespace(char16_t aChar
) {
313 return aChar
== ' ' || aChar
== '\n' || aChar
== '\r' || aChar
== '\t' ||
318 * Return true if there are any observers of accessible events.
320 static bool AccEventObserversExist();
323 * Notify accessible event observers of an event.
325 static void DispatchAccEvent(RefPtr
<nsIAccessibleEvent
> aEvent
);
327 static bool IsDisplayContents(nsIContent
* aContent
);