2007-03-27 16:17:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-27 16:17:11 +04:00
|
|
|
|
2008-10-16 05:52:58 +04:00
|
|
|
#ifndef nsCoreUtils_h_
|
|
|
|
#define nsCoreUtils_h_
|
2007-03-27 16:17:11 +04:00
|
|
|
|
2007-05-09 01:44:04 +04:00
|
|
|
#include "nsIContent.h"
|
2014-08-18 18:44:50 +04:00
|
|
|
#include "nsIDocument.h" // for GetShell()
|
2012-08-01 22:31:10 +04:00
|
|
|
#include "nsIPresShell.h"
|
2009-05-06 13:54:26 +04:00
|
|
|
|
2007-09-05 11:39:09 +04:00
|
|
|
#include "nsPoint.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsTArray.h"
|
2007-03-27 16:17:11 +04:00
|
|
|
|
2012-04-06 22:08:24 +04:00
|
|
|
class nsRange;
|
2013-09-11 02:18:59 +04:00
|
|
|
class nsIBoxObject;
|
2012-08-01 22:31:10 +04:00
|
|
|
class nsIFrame;
|
2013-02-13 02:02:51 +04:00
|
|
|
class nsIDocShell;
|
2012-08-01 22:31:10 +04:00
|
|
|
class nsITreeColumn;
|
|
|
|
class nsITreeBoxObject;
|
|
|
|
class nsIWidget;
|
2012-04-06 22:08:24 +04:00
|
|
|
|
2010-04-27 10:52:03 +04:00
|
|
|
/**
|
|
|
|
* Core utils.
|
|
|
|
*/
|
2008-10-16 05:52:58 +04:00
|
|
|
class nsCoreUtils
|
2007-03-27 16:17:11 +04:00
|
|
|
{
|
|
|
|
public:
|
2007-07-05 20:02:55 +04:00
|
|
|
/**
|
2010-02-03 18:00:25 +03:00
|
|
|
* Return true if the given node has registered click, mousedown or mouseup
|
|
|
|
* event listeners.
|
2007-07-05 20:02:55 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool HasClickListener(nsIContent *aContent);
|
2007-07-05 20:02:55 +04:00
|
|
|
|
2008-08-06 16:16:54 +04:00
|
|
|
/**
|
2009-08-20 10:45:19 +04:00
|
|
|
* Dispatch click event to XUL tree cell.
|
2008-08-06 16:16:54 +04:00
|
|
|
*
|
2009-08-20 10:45:19 +04:00
|
|
|
* @param aTreeBoxObj [in] tree box object
|
|
|
|
* @param aRowIndex [in] row index
|
|
|
|
* @param aColumn [in] column object
|
|
|
|
* @param aPseudoElm [in] pseudo elemenet inside the cell, see
|
|
|
|
* nsITreeBoxObject for available values
|
|
|
|
*/
|
|
|
|
static void DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aRowIndex, nsITreeColumn *aColumn,
|
2014-10-15 00:15:21 +04:00
|
|
|
const nsAString& aPseudoElt = EmptyString());
|
2009-08-20 10:45:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send mouse event to the given element.
|
|
|
|
*
|
2013-09-25 15:21:22 +04:00
|
|
|
* @param aEventType [in] an event type (see BasicEvents.h for constants)
|
2013-07-25 19:59:08 +04:00
|
|
|
* @param aX [in] x coordinate in dev pixels
|
|
|
|
* @param aY [in] y coordinate in dev pixels
|
|
|
|
* @param aContent [in] the element
|
|
|
|
* @param aFrame [in] frame of the element
|
|
|
|
* @param aPresShell [in] the presshell for the element
|
|
|
|
* @param aRootWidget [in] the root widget of the element
|
2008-08-06 16:16:54 +04:00
|
|
|
*/
|
2013-07-25 19:59:08 +04:00
|
|
|
static void DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY,
|
|
|
|
nsIContent *aContent, nsIFrame *aFrame,
|
|
|
|
nsIPresShell *aPresShell, nsIWidget *aRootWidget);
|
2008-08-06 16:16:54 +04:00
|
|
|
|
2009-08-20 10:45:19 +04:00
|
|
|
/**
|
2013-07-25 19:59:08 +04:00
|
|
|
* Send a touch event with a single touch point to the given element.
|
2009-08-20 10:45:19 +04:00
|
|
|
*
|
2013-09-25 15:21:22 +04:00
|
|
|
* @param aEventType [in] an event type (see BasicEvents.h for constants)
|
2009-08-20 10:45:19 +04:00
|
|
|
* @param aX [in] x coordinate in dev pixels
|
|
|
|
* @param aY [in] y coordinate in dev pixels
|
|
|
|
* @param aContent [in] the element
|
|
|
|
* @param aFrame [in] frame of the element
|
|
|
|
* @param aPresShell [in] the presshell for the element
|
|
|
|
* @param aRootWidget [in] the root widget of the element
|
|
|
|
*/
|
2013-07-25 19:59:08 +04:00
|
|
|
static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY,
|
|
|
|
nsIContent* aContent, nsIFrame* aFrame,
|
|
|
|
nsIPresShell* aPresShell, nsIWidget* aRootWidget);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
2007-08-29 10:52:46 +04:00
|
|
|
/**
|
|
|
|
* Return an accesskey registered on the given element by
|
2014-04-01 08:09:23 +04:00
|
|
|
* EventStateManager or 0 if there is no registered accesskey.
|
2007-08-29 10:52:46 +04:00
|
|
|
*
|
|
|
|
* @param aContent - the given element.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t GetAccessKeyFor(nsIContent *aContent);
|
2007-08-29 10:52:46 +04:00
|
|
|
|
2008-07-17 16:06:24 +04:00
|
|
|
/**
|
|
|
|
* Return DOM element related with the given node, i.e.
|
|
|
|
* a) itself if it is DOM element
|
|
|
|
* b) parent element if it is text node
|
2012-07-30 18:20:58 +04:00
|
|
|
* c) otherwise nullptr
|
2008-07-17 16:06:24 +04:00
|
|
|
*
|
|
|
|
* @param aNode [in] the given DOM node
|
|
|
|
*/
|
2010-06-11 12:23:18 +04:00
|
|
|
static nsIContent* GetDOMElementFor(nsIContent *aContent);
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2008-12-16 13:14:20 +03:00
|
|
|
/**
|
|
|
|
* Return DOM node for the given DOM point.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static nsINode *GetDOMNodeFromDOMPoint(nsINode *aNode, uint32_t aOffset);
|
2010-05-25 12:12:43 +04:00
|
|
|
|
2008-10-17 14:10:43 +04:00
|
|
|
/**
|
|
|
|
* Return the nsIContent* to check for ARIA attributes on -- this may not
|
|
|
|
* always be the DOM node for the accessible. Specifically, for doc
|
|
|
|
* accessibles, it is not the document node, but either the root element or
|
2010-06-11 12:23:18 +04:00
|
|
|
* <body> in HTML.
|
2008-10-17 14:10:43 +04:00
|
|
|
*
|
2010-06-11 12:23:18 +04:00
|
|
|
* @param aNode [in] DOM node for the accessible that may be affected by ARIA
|
|
|
|
* @return the nsIContent which may have ARIA markup
|
2008-10-17 14:10:43 +04:00
|
|
|
*/
|
2010-06-11 12:23:18 +04:00
|
|
|
static nsIContent* GetRoleContent(nsINode *aNode);
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2007-08-14 22:47:49 +04:00
|
|
|
/**
|
|
|
|
* Is the first passed in node an ancestor of the second?
|
|
|
|
* Note: A node is not considered to be the ancestor of itself.
|
2010-01-27 14:43:25 +03:00
|
|
|
*
|
|
|
|
* @param aPossibleAncestorNode [in] node to test for ancestor-ness of
|
|
|
|
* aPossibleDescendantNode
|
|
|
|
* @param aPossibleDescendantNode [in] node to test for descendant-ness of
|
|
|
|
* aPossibleAncestorNode
|
2010-06-10 07:29:56 +04:00
|
|
|
* @param aRootNode [in, optional] the root node that search
|
|
|
|
* search should be performed within
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return true if aPossibleAncestorNode is an ancestor of
|
2010-01-27 14:43:25 +03:00
|
|
|
* aPossibleDescendantNode
|
2007-08-14 22:47:49 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsAncestorOf(nsINode *aPossibleAncestorNode,
|
2010-06-10 07:29:56 +04:00
|
|
|
nsINode *aPossibleDescendantNode,
|
2012-07-30 18:20:58 +04:00
|
|
|
nsINode *aRootNode = nullptr);
|
2007-08-21 07:16:27 +04:00
|
|
|
|
2007-08-24 08:54:45 +04:00
|
|
|
/**
|
|
|
|
* Helper method to scroll range into view, used for implementation of
|
|
|
|
* nsIAccessibleText::scrollSubstringTo().
|
|
|
|
*
|
|
|
|
* @param aFrame the frame for accessible the range belongs to.
|
2012-04-06 22:08:24 +04:00
|
|
|
* @param aRange the range to scroll to
|
2007-08-24 08:54:45 +04:00
|
|
|
* @param aScrollType the place a range should be scrolled to
|
|
|
|
*/
|
2012-04-06 22:08:24 +04:00
|
|
|
static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aScrollType);
|
2007-08-24 08:54:45 +04:00
|
|
|
|
2007-09-25 09:48:51 +04: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.
|
2012-04-06 22:08:24 +04:00
|
|
|
* @param aRange the range to scroll to
|
2012-03-20 06:09:50 +04:00
|
|
|
* @param aVertical how to align vertically, specified in percents, and when.
|
|
|
|
* @param aHorizontal how to align horizontally, specified in percents, and when.
|
2007-09-25 09:48:51 +04:00
|
|
|
*/
|
2012-04-06 22:08:24 +04:00
|
|
|
static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
2012-03-20 06:09:50 +04:00
|
|
|
nsIPresShell::ScrollAxis aVertical,
|
|
|
|
nsIPresShell::ScrollAxis aHorizontal);
|
2007-09-25 09:48:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrolls the given frame to the point, used for implememntation of
|
2012-02-07 17:18:33 +04:00
|
|
|
* nsIAccessible::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint.
|
2007-09-25 09:48:51 +04:00
|
|
|
*
|
|
|
|
* @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-24 08:54:45 +04:00
|
|
|
/**
|
|
|
|
* Converts scroll type constant defined in nsIAccessibleScrollType to
|
2012-03-20 06:09:50 +04:00
|
|
|
* vertical and horizontal parameters.
|
2007-08-24 08:54:45 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static void ConvertScrollTypeToPercents(uint32_t aScrollType,
|
2012-03-20 06:09:50 +04:00
|
|
|
nsIPresShell::ScrollAxis *aVertical,
|
|
|
|
nsIPresShell::ScrollAxis *aHorizontal);
|
2007-09-05 11:39:09 +04:00
|
|
|
|
|
|
|
/**
|
2012-10-19 19:10:28 +04:00
|
|
|
* Returns coordinates in device pixels relative screen for the top level
|
|
|
|
* window.
|
2007-09-05 11:39:09 +04:00
|
|
|
*
|
2007-12-01 20:30:09 +03:00
|
|
|
* @param aNode the DOM node hosted in the window.
|
2007-09-05 11:39:09 +04:00
|
|
|
*/
|
2010-06-11 12:23:18 +04:00
|
|
|
static nsIntPoint GetScreenCoordsForWindow(nsINode *aNode);
|
2007-09-05 11:39:09 +04:00
|
|
|
|
|
|
|
/**
|
2013-02-13 02:02:51 +04:00
|
|
|
* Return document shell for the given DOM node.
|
2007-09-05 11:39:09 +04:00
|
|
|
*/
|
2013-02-13 02:02:51 +04:00
|
|
|
static already_AddRefed<nsIDocShell> GetDocShellFor(nsINode *aNode);
|
2007-09-19 01:36:41 +04:00
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
/**
|
|
|
|
* Return true if the given document is root document.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsRootDocument(nsIDocument *aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the given document is content document (not chrome).
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsContentDocument(nsIDocument *aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2011-07-22 04:49:35 +04:00
|
|
|
/**
|
|
|
|
* Return true if the given document node is for tab document accessible.
|
|
|
|
*/
|
|
|
|
static bool IsTabDocument(nsIDocument* aDocumentNode);
|
|
|
|
|
2010-06-08 20:39:58 +04:00
|
|
|
/**
|
|
|
|
* Return true if the given document is an error page.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsErrorPage(nsIDocument *aDocument);
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2008-10-17 14:10:43 +04:00
|
|
|
/**
|
|
|
|
* Return presShell for the document containing the given DOM node.
|
|
|
|
*/
|
2010-06-11 12:23:18 +04:00
|
|
|
static nsIPresShell *GetPresShellFor(nsINode *aNode)
|
2010-05-17 17:42:32 +04:00
|
|
|
{
|
2011-10-18 15:19:44 +04:00
|
|
|
return aNode->OwnerDoc()->GetShell();
|
2010-05-17 17:42:32 +04:00
|
|
|
}
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2007-09-19 01:36:41 +04: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
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return true if there is an ID set for this node
|
2007-09-19 01:36:41 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool GetID(nsIContent *aContent, nsAString& aID);
|
2007-09-25 05:19:03 +04:00
|
|
|
|
2010-01-12 22:07:38 +03:00
|
|
|
/**
|
|
|
|
* Convert attribute value of the given node to positive integer. If no
|
|
|
|
* attribute or wrong value then false is returned.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool GetUIntAttr(nsIContent *aContent, nsIAtom *aAttr,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *aUInt);
|
2010-01-12 22:07:38 +03:00
|
|
|
|
2008-07-17 16:06:24 +04:00
|
|
|
/**
|
|
|
|
* Returns language for the given node.
|
|
|
|
*
|
|
|
|
* @param aContent [in] the given node
|
|
|
|
* @param aRootContent [in] container of the given node
|
|
|
|
* @param aLanguage [out] language
|
|
|
|
*/
|
|
|
|
static void GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
|
|
|
|
nsAString& aLanguage);
|
|
|
|
|
2009-05-06 13:54:26 +04:00
|
|
|
/**
|
|
|
|
* Return box object for XUL treechildren element by tree box object.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIBoxObject>
|
|
|
|
GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj);
|
2009-05-14 09:31:09 +04:00
|
|
|
|
2009-08-20 10:45:19 +04:00
|
|
|
/**
|
|
|
|
* Return tree box object from any levels DOMNode under the XUL tree.
|
|
|
|
*/
|
2010-06-11 12:23:18 +04:00
|
|
|
static already_AddRefed<nsITreeBoxObject>
|
|
|
|
GetTreeBoxObject(nsIContent* aContent);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return first sensible column for the given tree box object.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsITreeColumn>
|
|
|
|
GetFirstSensibleColumn(nsITreeBoxObject *aTree);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return sensible columns count for the given tree box object.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t GetSensibleColumnCount(nsITreeBoxObject *aTree);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return sensible column at the given index for the given tree box object.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsITreeColumn>
|
2012-08-22 19:56:38 +04:00
|
|
|
GetSensibleColumnAt(nsITreeBoxObject *aTree, uint32_t aIndex);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return next sensible column for the given column.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsITreeColumn>
|
|
|
|
GetNextSensibleColumn(nsITreeColumn *aColumn);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return previous sensible column for the given column.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsITreeColumn>
|
|
|
|
GetPreviousSensibleColumn(nsITreeColumn *aColumn);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the given column is hidden (i.e. not sensible).
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsColumnHidden(nsITreeColumn *aColumn);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
2012-04-10 04:39:00 +04:00
|
|
|
/**
|
|
|
|
* Scroll content into view.
|
|
|
|
*/
|
|
|
|
static void ScrollTo(nsIPresShell* aPresShell, nsIContent* aContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aScrollType);
|
2012-04-10 04:39:00 +04:00
|
|
|
|
2009-05-14 09:31:09 +04:00
|
|
|
/**
|
|
|
|
* Return true if the given node is table header element.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsHTMLTableHeader(nsIContent *aContent)
|
2009-05-14 09:31:09 +04:00
|
|
|
{
|
2011-06-04 01:35:17 +04:00
|
|
|
return aContent->NodeInfo()->Equals(nsGkAtoms::th) ||
|
|
|
|
aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scope);
|
2009-05-14 09:31:09 +04:00
|
|
|
}
|
2011-05-30 22:23:36 +04:00
|
|
|
|
2013-07-18 19:09:45 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the given string is empty or contains whitespace symbols
|
|
|
|
* only. In contrast to nsWhitespaceTokenizer class it takes into account
|
|
|
|
* non-breaking space (0xa0).
|
|
|
|
*/
|
|
|
|
static bool IsWhitespaceString(const nsSubstring& aString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given character is whitespace symbol.
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool IsWhitespace(char16_t aChar)
|
2013-07-18 19:09:45 +04:00
|
|
|
{
|
|
|
|
return aChar == ' ' || aChar == '\n' ||
|
|
|
|
aChar == '\r' || aChar == '\t' || aChar == 0xa0;
|
|
|
|
}
|
2007-03-27 16:17:11 +04:00
|
|
|
};
|
|
|
|
|
2007-03-31 11:14:03 +04:00
|
|
|
#endif
|