2007-03-27 05:17:11 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 05:17:11 -07:00
|
|
|
|
2008-10-15 18:52:58 -07:00
|
|
|
#ifndef nsCoreUtils_h_
|
|
|
|
#define nsCoreUtils_h_
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2007-05-08 14:44:04 -07:00
|
|
|
#include "nsIContent.h"
|
2014-08-18 07:44:50 -07:00
|
|
|
#include "nsIDocument.h" // for GetShell()
|
2012-08-01 11:31:10 -07:00
|
|
|
#include "nsIPresShell.h"
|
2009-05-06 02:54:26 -07:00
|
|
|
|
2007-09-05 00:39:09 -07:00
|
|
|
#include "nsPoint.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsTArray.h"
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
class nsRange;
|
2013-09-10 15:18:59 -07:00
|
|
|
class nsIBoxObject;
|
2012-08-01 11:31:10 -07:00
|
|
|
class nsIFrame;
|
2013-02-12 14:02:51 -08:00
|
|
|
class nsIDocShell;
|
2012-08-01 11:31:10 -07:00
|
|
|
class nsITreeColumn;
|
|
|
|
class nsITreeBoxObject;
|
|
|
|
class nsIWidget;
|
2012-04-06 11:08:24 -07:00
|
|
|
|
2010-04-26 23:52:03 -07:00
|
|
|
/**
|
|
|
|
* Core utils.
|
|
|
|
*/
|
2008-10-15 18:52:58 -07:00
|
|
|
class nsCoreUtils
|
2007-03-27 05:17:11 -07:00
|
|
|
{
|
|
|
|
public:
|
2007-07-05 09:02:55 -07:00
|
|
|
/**
|
2010-02-03 07:00:25 -08:00
|
|
|
* Return true if the given node has registered click, mousedown or mouseup
|
|
|
|
* event listeners.
|
2007-07-05 09:02:55 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool HasClickListener(nsIContent *aContent);
|
2007-07-05 09:02:55 -07:00
|
|
|
|
2008-08-06 05:16:54 -07:00
|
|
|
/**
|
2009-08-19 23:45:19 -07:00
|
|
|
* Dispatch click event to XUL tree cell.
|
2008-08-06 05:16:54 -07:00
|
|
|
*
|
2009-08-19 23:45:19 -07: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 08:56:38 -07:00
|
|
|
int32_t aRowIndex, nsITreeColumn *aColumn,
|
2009-08-19 23:45:19 -07:00
|
|
|
const nsCString& aPseudoElt = EmptyCString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send mouse event to the given element.
|
|
|
|
*
|
2013-09-25 04:21:22 -07:00
|
|
|
* @param aEventType [in] an event type (see BasicEvents.h for constants)
|
2013-07-25 08:59:08 -07: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 05:16:54 -07:00
|
|
|
*/
|
2013-07-25 08:59:08 -07:00
|
|
|
static void DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY,
|
|
|
|
nsIContent *aContent, nsIFrame *aFrame,
|
|
|
|
nsIPresShell *aPresShell, nsIWidget *aRootWidget);
|
2008-08-06 05:16:54 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
/**
|
2013-07-25 08:59:08 -07:00
|
|
|
* Send a touch event with a single touch point to the given element.
|
2009-08-19 23:45:19 -07:00
|
|
|
*
|
2013-09-25 04:21:22 -07:00
|
|
|
* @param aEventType [in] an event type (see BasicEvents.h for constants)
|
2009-08-19 23:45:19 -07: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 08:59:08 -07:00
|
|
|
static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY,
|
|
|
|
nsIContent* aContent, nsIFrame* aFrame,
|
|
|
|
nsIPresShell* aPresShell, nsIWidget* aRootWidget);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2007-08-28 23:52:46 -07:00
|
|
|
/**
|
|
|
|
* Return an accesskey registered on the given element by
|
2014-03-31 21:09:23 -07:00
|
|
|
* EventStateManager or 0 if there is no registered accesskey.
|
2007-08-28 23:52:46 -07:00
|
|
|
*
|
|
|
|
* @param aContent - the given element.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t GetAccessKeyFor(nsIContent *aContent);
|
2007-08-28 23:52:46 -07:00
|
|
|
|
2008-07-17 05:06:24 -07: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 07:20:58 -07:00
|
|
|
* c) otherwise nullptr
|
2008-07-17 05:06:24 -07:00
|
|
|
*
|
|
|
|
* @param aNode [in] the given DOM node
|
|
|
|
*/
|
2010-06-11 01:23:18 -07:00
|
|
|
static nsIContent* GetDOMElementFor(nsIContent *aContent);
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2008-12-16 02:14:20 -08:00
|
|
|
/**
|
|
|
|
* Return DOM node for the given DOM point.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static nsINode *GetDOMNodeFromDOMPoint(nsINode *aNode, uint32_t aOffset);
|
2010-05-25 01:12:43 -07:00
|
|
|
|
2008-10-17 03:10:43 -07: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 01:23:18 -07:00
|
|
|
* <body> in HTML.
|
2008-10-17 03:10:43 -07:00
|
|
|
*
|
2010-06-11 01:23:18 -07: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 03:10:43 -07:00
|
|
|
*/
|
2010-06-11 01:23:18 -07:00
|
|
|
static nsIContent* GetRoleContent(nsINode *aNode);
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2007-08-14 11:47:49 -07: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 03:43:25 -08: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-09 20:29:56 -07:00
|
|
|
* @param aRootNode [in, optional] the root node that search
|
|
|
|
* search should be performed within
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return true if aPossibleAncestorNode is an ancestor of
|
2010-01-27 03:43:25 -08:00
|
|
|
* aPossibleDescendantNode
|
2007-08-14 11:47:49 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsAncestorOf(nsINode *aPossibleAncestorNode,
|
2010-06-09 20:29:56 -07:00
|
|
|
nsINode *aPossibleDescendantNode,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsINode *aRootNode = nullptr);
|
2007-08-20 20:16:27 -07:00
|
|
|
|
2007-08-23 21:54:45 -07: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 11:08:24 -07:00
|
|
|
* @param aRange the range to scroll to
|
2007-08-23 21:54:45 -07:00
|
|
|
* @param aScrollType the place a range should be scrolled to
|
|
|
|
*/
|
2012-04-06 11:08:24 -07:00
|
|
|
static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aScrollType);
|
2007-08-23 21:54:45 -07:00
|
|
|
|
2007-09-24 22:48:51 -07: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 11:08:24 -07:00
|
|
|
* @param aRange the range to scroll to
|
2012-03-19 19:09:50 -07: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-24 22:48:51 -07:00
|
|
|
*/
|
2012-04-06 11:08:24 -07:00
|
|
|
static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
2012-03-19 19:09:50 -07:00
|
|
|
nsIPresShell::ScrollAxis aVertical,
|
|
|
|
nsIPresShell::ScrollAxis aHorizontal);
|
2007-09-24 22:48:51 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrolls the given frame to the point, used for implememntation of
|
2012-02-07 05:18:33 -08:00
|
|
|
* nsIAccessible::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint.
|
2007-09-24 22:48:51 -07: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-23 21:54:45 -07:00
|
|
|
/**
|
|
|
|
* Converts scroll type constant defined in nsIAccessibleScrollType to
|
2012-03-19 19:09:50 -07:00
|
|
|
* vertical and horizontal parameters.
|
2007-08-23 21:54:45 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static void ConvertScrollTypeToPercents(uint32_t aScrollType,
|
2012-03-19 19:09:50 -07:00
|
|
|
nsIPresShell::ScrollAxis *aVertical,
|
|
|
|
nsIPresShell::ScrollAxis *aHorizontal);
|
2007-09-05 00:39:09 -07:00
|
|
|
|
|
|
|
/**
|
2012-10-19 08:10:28 -07:00
|
|
|
* Returns coordinates in device pixels relative screen for the top level
|
|
|
|
* window.
|
2007-09-05 00:39:09 -07:00
|
|
|
*
|
2007-12-01 09:30:09 -08:00
|
|
|
* @param aNode the DOM node hosted in the window.
|
2007-09-05 00:39:09 -07:00
|
|
|
*/
|
2010-06-11 01:23:18 -07:00
|
|
|
static nsIntPoint GetScreenCoordsForWindow(nsINode *aNode);
|
2007-09-05 00:39:09 -07:00
|
|
|
|
|
|
|
/**
|
2013-02-12 14:02:51 -08:00
|
|
|
* Return document shell for the given DOM node.
|
2007-09-05 00:39:09 -07:00
|
|
|
*/
|
2013-02-12 14:02:51 -08:00
|
|
|
static already_AddRefed<nsIDocShell> GetDocShellFor(nsINode *aNode);
|
2007-09-18 14:36:41 -07:00
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
/**
|
|
|
|
* Return true if the given document is root document.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsRootDocument(nsIDocument *aDocument);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the given document is content document (not chrome).
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsContentDocument(nsIDocument *aDocument);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2011-07-21 17:49:35 -07:00
|
|
|
/**
|
|
|
|
* Return true if the given document node is for tab document accessible.
|
|
|
|
*/
|
|
|
|
static bool IsTabDocument(nsIDocument* aDocumentNode);
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
/**
|
|
|
|
* Return true if the given document is an error page.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsErrorPage(nsIDocument *aDocument);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
/**
|
|
|
|
* Return presShell for the document containing the given DOM node.
|
|
|
|
*/
|
2010-06-11 01:23:18 -07:00
|
|
|
static nsIPresShell *GetPresShellFor(nsINode *aNode)
|
2010-05-17 06:42:32 -07:00
|
|
|
{
|
2011-10-18 04:19:44 -07:00
|
|
|
return aNode->OwnerDoc()->GetShell();
|
2010-05-17 06:42:32 -07:00
|
|
|
}
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2007-09-18 14:36:41 -07: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 07:59:28 -07:00
|
|
|
* @return true if there is an ID set for this node
|
2007-09-18 14:36:41 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool GetID(nsIContent *aContent, nsAString& aID);
|
2007-09-24 18:19:03 -07:00
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
/**
|
|
|
|
* Convert attribute value of the given node to positive integer. If no
|
|
|
|
* attribute or wrong value then false is returned.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool GetUIntAttr(nsIContent *aContent, nsIAtom *aAttr,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t *aUInt);
|
2010-01-12 11:07:38 -08:00
|
|
|
|
2008-07-17 05:06:24 -07: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 02:54:26 -07:00
|
|
|
/**
|
|
|
|
* Return box object for XUL treechildren element by tree box object.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsIBoxObject>
|
|
|
|
GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj);
|
2009-05-13 22:31:09 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
/**
|
|
|
|
* Return tree box object from any levels DOMNode under the XUL tree.
|
|
|
|
*/
|
2010-06-11 01:23:18 -07:00
|
|
|
static already_AddRefed<nsITreeBoxObject>
|
|
|
|
GetTreeBoxObject(nsIContent* aContent);
|
2009-08-19 23:45:19 -07: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 08:56:38 -07:00
|
|
|
static uint32_t GetSensibleColumnCount(nsITreeBoxObject *aTree);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return sensible column at the given index for the given tree box object.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<nsITreeColumn>
|
2012-08-22 08:56:38 -07:00
|
|
|
GetSensibleColumnAt(nsITreeBoxObject *aTree, uint32_t aIndex);
|
2009-08-19 23:45:19 -07: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-28 23:19:26 -07:00
|
|
|
static bool IsColumnHidden(nsITreeColumn *aColumn);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2012-04-09 17:39:00 -07:00
|
|
|
/**
|
|
|
|
* Scroll content into view.
|
|
|
|
*/
|
|
|
|
static void ScrollTo(nsIPresShell* aPresShell, nsIContent* aContent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aScrollType);
|
2012-04-09 17:39:00 -07:00
|
|
|
|
2009-05-13 22:31:09 -07:00
|
|
|
/**
|
|
|
|
* Return true if the given node is table header element.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsHTMLTableHeader(nsIContent *aContent)
|
2009-05-13 22:31:09 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
return aContent->NodeInfo()->Equals(nsGkAtoms::th) ||
|
|
|
|
aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scope);
|
2009-05-13 22:31:09 -07:00
|
|
|
}
|
2011-05-30 11:23:36 -07:00
|
|
|
|
2013-07-18 08:09:45 -07: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 07:02:17 -08:00
|
|
|
static bool IsWhitespace(char16_t aChar)
|
2013-07-18 08:09:45 -07:00
|
|
|
{
|
|
|
|
return aChar == ' ' || aChar == '\n' ||
|
|
|
|
aChar == '\r' || aChar == '\t' || aChar == 0xa0;
|
|
|
|
}
|
2007-03-27 05:17:11 -07:00
|
|
|
};
|
|
|
|
|
2007-03-31 00:14:03 -07:00
|
|
|
#endif
|
2007-08-23 21:54:45 -07:00
|
|
|
|