michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsCoreUtils_h_ michael@0: #define nsCoreUtils_h_ michael@0: michael@0: #include "nsIContent.h" michael@0: #include "nsIDocument.h" michael@0: #include "nsIPresShell.h" michael@0: michael@0: #include "nsPoint.h" michael@0: #include "nsTArray.h" michael@0: michael@0: class nsRange; michael@0: class nsIBoxObject; michael@0: class nsIFrame; michael@0: class nsIDocShell; michael@0: class nsITreeColumn; michael@0: class nsITreeBoxObject; michael@0: class nsIWidget; michael@0: michael@0: /** michael@0: * Core utils. michael@0: */ michael@0: class nsCoreUtils michael@0: { michael@0: public: michael@0: /** michael@0: * Return true if the given node has registered click, mousedown or mouseup michael@0: * event listeners. michael@0: */ michael@0: static bool HasClickListener(nsIContent *aContent); michael@0: michael@0: /** michael@0: * Dispatch click event to XUL tree cell. michael@0: * michael@0: * @param aTreeBoxObj [in] tree box object michael@0: * @param aRowIndex [in] row index michael@0: * @param aColumn [in] column object michael@0: * @param aPseudoElm [in] pseudo elemenet inside the cell, see michael@0: * nsITreeBoxObject for available values michael@0: */ michael@0: static void DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj, michael@0: int32_t aRowIndex, nsITreeColumn *aColumn, michael@0: const nsCString& aPseudoElt = EmptyCString()); michael@0: michael@0: /** michael@0: * Send mouse event to the given element. michael@0: * michael@0: * @param aEventType [in] an event type (see BasicEvents.h for constants) michael@0: * @param aX [in] x coordinate in dev pixels michael@0: * @param aY [in] y coordinate in dev pixels michael@0: * @param aContent [in] the element michael@0: * @param aFrame [in] frame of the element michael@0: * @param aPresShell [in] the presshell for the element michael@0: * @param aRootWidget [in] the root widget of the element michael@0: */ michael@0: static void DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY, michael@0: nsIContent *aContent, nsIFrame *aFrame, michael@0: nsIPresShell *aPresShell, nsIWidget *aRootWidget); michael@0: michael@0: /** michael@0: * Send a touch event with a single touch point to the given element. michael@0: * michael@0: * @param aEventType [in] an event type (see BasicEvents.h for constants) michael@0: * @param aX [in] x coordinate in dev pixels michael@0: * @param aY [in] y coordinate in dev pixels michael@0: * @param aContent [in] the element michael@0: * @param aFrame [in] frame of the element michael@0: * @param aPresShell [in] the presshell for the element michael@0: * @param aRootWidget [in] the root widget of the element michael@0: */ michael@0: static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY, michael@0: nsIContent* aContent, nsIFrame* aFrame, michael@0: nsIPresShell* aPresShell, nsIWidget* aRootWidget); michael@0: michael@0: /** michael@0: * Return an accesskey registered on the given element by michael@0: * EventStateManager or 0 if there is no registered accesskey. michael@0: * michael@0: * @param aContent - the given element. michael@0: */ michael@0: static uint32_t GetAccessKeyFor(nsIContent *aContent); michael@0: michael@0: /** michael@0: * Return DOM element related with the given node, i.e. michael@0: * a) itself if it is DOM element michael@0: * b) parent element if it is text node michael@0: * c) otherwise nullptr michael@0: * michael@0: * @param aNode [in] the given DOM node michael@0: */ michael@0: static nsIContent* GetDOMElementFor(nsIContent *aContent); michael@0: michael@0: /** michael@0: * Return DOM node for the given DOM point. michael@0: */ michael@0: static nsINode *GetDOMNodeFromDOMPoint(nsINode *aNode, uint32_t aOffset); michael@0: michael@0: /** michael@0: * Return the nsIContent* to check for ARIA attributes on -- this may not michael@0: * always be the DOM node for the accessible. Specifically, for doc michael@0: * accessibles, it is not the document node, but either the root element or michael@0: *
in HTML. michael@0: * michael@0: * @param aNode [in] DOM node for the accessible that may be affected by ARIA michael@0: * @return the nsIContent which may have ARIA markup michael@0: */ michael@0: static nsIContent* GetRoleContent(nsINode *aNode); michael@0: michael@0: /** michael@0: * Is the first passed in node an ancestor of the second? michael@0: * Note: A node is not considered to be the ancestor of itself. michael@0: * michael@0: * @param aPossibleAncestorNode [in] node to test for ancestor-ness of michael@0: * aPossibleDescendantNode michael@0: * @param aPossibleDescendantNode [in] node to test for descendant-ness of michael@0: * aPossibleAncestorNode michael@0: * @param aRootNode [in, optional] the root node that search michael@0: * search should be performed within michael@0: * @return true if aPossibleAncestorNode is an ancestor of michael@0: * aPossibleDescendantNode michael@0: */ michael@0: static bool IsAncestorOf(nsINode *aPossibleAncestorNode, michael@0: nsINode *aPossibleDescendantNode, michael@0: nsINode *aRootNode = nullptr); michael@0: michael@0: /** michael@0: * Helper method to scroll range into view, used for implementation of michael@0: * nsIAccessibleText::scrollSubstringTo(). michael@0: * michael@0: * @param aFrame the frame for accessible the range belongs to. michael@0: * @param aRange the range to scroll to michael@0: * @param aScrollType the place a range should be scrolled to michael@0: */ michael@0: static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange, michael@0: uint32_t aScrollType); michael@0: michael@0: /** Helper method to scroll range into view, used for implementation of michael@0: * nsIAccessibleText::scrollSubstringTo[Point](). michael@0: * michael@0: * @param aFrame the frame for accessible the range belongs to. michael@0: * @param aRange the range to scroll to michael@0: * @param aVertical how to align vertically, specified in percents, and when. michael@0: * @param aHorizontal how to align horizontally, specified in percents, and when. michael@0: */ michael@0: static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange, michael@0: nsIPresShell::ScrollAxis aVertical, michael@0: nsIPresShell::ScrollAxis aHorizontal); michael@0: michael@0: /** michael@0: * Scrolls the given frame to the point, used for implememntation of michael@0: * nsIAccessible::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint. michael@0: * michael@0: * @param aScrollableFrame the scrollable frame michael@0: * @param aFrame the frame to scroll michael@0: * @param aPoint the point scroll to michael@0: */ michael@0: static void ScrollFrameToPoint(nsIFrame *aScrollableFrame, michael@0: nsIFrame *aFrame, const nsIntPoint& aPoint); michael@0: michael@0: /** michael@0: * Converts scroll type constant defined in nsIAccessibleScrollType to michael@0: * vertical and horizontal parameters. michael@0: */ michael@0: static void ConvertScrollTypeToPercents(uint32_t aScrollType, michael@0: nsIPresShell::ScrollAxis *aVertical, michael@0: nsIPresShell::ScrollAxis *aHorizontal); michael@0: michael@0: /** michael@0: * Returns coordinates in device pixels relative screen for the top level michael@0: * window. michael@0: * michael@0: * @param aNode the DOM node hosted in the window. michael@0: */ michael@0: static nsIntPoint GetScreenCoordsForWindow(nsINode *aNode); michael@0: michael@0: /** michael@0: * Return document shell for the given DOM node. michael@0: */ michael@0: static already_AddRefed