Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsCoreUtils_h_ |
michael@0 | 7 | #define nsCoreUtils_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIContent.h" |
michael@0 | 10 | #include "nsIDocument.h" |
michael@0 | 11 | #include "nsIPresShell.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsPoint.h" |
michael@0 | 14 | #include "nsTArray.h" |
michael@0 | 15 | |
michael@0 | 16 | class nsRange; |
michael@0 | 17 | class nsIBoxObject; |
michael@0 | 18 | class nsIFrame; |
michael@0 | 19 | class nsIDocShell; |
michael@0 | 20 | class nsITreeColumn; |
michael@0 | 21 | class nsITreeBoxObject; |
michael@0 | 22 | class nsIWidget; |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * Core utils. |
michael@0 | 26 | */ |
michael@0 | 27 | class nsCoreUtils |
michael@0 | 28 | { |
michael@0 | 29 | public: |
michael@0 | 30 | /** |
michael@0 | 31 | * Return true if the given node has registered click, mousedown or mouseup |
michael@0 | 32 | * event listeners. |
michael@0 | 33 | */ |
michael@0 | 34 | static bool HasClickListener(nsIContent *aContent); |
michael@0 | 35 | |
michael@0 | 36 | /** |
michael@0 | 37 | * Dispatch click event to XUL tree cell. |
michael@0 | 38 | * |
michael@0 | 39 | * @param aTreeBoxObj [in] tree box object |
michael@0 | 40 | * @param aRowIndex [in] row index |
michael@0 | 41 | * @param aColumn [in] column object |
michael@0 | 42 | * @param aPseudoElm [in] pseudo elemenet inside the cell, see |
michael@0 | 43 | * nsITreeBoxObject for available values |
michael@0 | 44 | */ |
michael@0 | 45 | static void DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj, |
michael@0 | 46 | int32_t aRowIndex, nsITreeColumn *aColumn, |
michael@0 | 47 | const nsCString& aPseudoElt = EmptyCString()); |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * Send mouse event to the given element. |
michael@0 | 51 | * |
michael@0 | 52 | * @param aEventType [in] an event type (see BasicEvents.h for constants) |
michael@0 | 53 | * @param aX [in] x coordinate in dev pixels |
michael@0 | 54 | * @param aY [in] y coordinate in dev pixels |
michael@0 | 55 | * @param aContent [in] the element |
michael@0 | 56 | * @param aFrame [in] frame of the element |
michael@0 | 57 | * @param aPresShell [in] the presshell for the element |
michael@0 | 58 | * @param aRootWidget [in] the root widget of the element |
michael@0 | 59 | */ |
michael@0 | 60 | static void DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY, |
michael@0 | 61 | nsIContent *aContent, nsIFrame *aFrame, |
michael@0 | 62 | nsIPresShell *aPresShell, nsIWidget *aRootWidget); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Send a touch event with a single touch point to the given element. |
michael@0 | 66 | * |
michael@0 | 67 | * @param aEventType [in] an event type (see BasicEvents.h for constants) |
michael@0 | 68 | * @param aX [in] x coordinate in dev pixels |
michael@0 | 69 | * @param aY [in] y coordinate in dev pixels |
michael@0 | 70 | * @param aContent [in] the element |
michael@0 | 71 | * @param aFrame [in] frame of the element |
michael@0 | 72 | * @param aPresShell [in] the presshell for the element |
michael@0 | 73 | * @param aRootWidget [in] the root widget of the element |
michael@0 | 74 | */ |
michael@0 | 75 | static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY, |
michael@0 | 76 | nsIContent* aContent, nsIFrame* aFrame, |
michael@0 | 77 | nsIPresShell* aPresShell, nsIWidget* aRootWidget); |
michael@0 | 78 | |
michael@0 | 79 | /** |
michael@0 | 80 | * Return an accesskey registered on the given element by |
michael@0 | 81 | * EventStateManager or 0 if there is no registered accesskey. |
michael@0 | 82 | * |
michael@0 | 83 | * @param aContent - the given element. |
michael@0 | 84 | */ |
michael@0 | 85 | static uint32_t GetAccessKeyFor(nsIContent *aContent); |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Return DOM element related with the given node, i.e. |
michael@0 | 89 | * a) itself if it is DOM element |
michael@0 | 90 | * b) parent element if it is text node |
michael@0 | 91 | * c) otherwise nullptr |
michael@0 | 92 | * |
michael@0 | 93 | * @param aNode [in] the given DOM node |
michael@0 | 94 | */ |
michael@0 | 95 | static nsIContent* GetDOMElementFor(nsIContent *aContent); |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Return DOM node for the given DOM point. |
michael@0 | 99 | */ |
michael@0 | 100 | static nsINode *GetDOMNodeFromDOMPoint(nsINode *aNode, uint32_t aOffset); |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * Return the nsIContent* to check for ARIA attributes on -- this may not |
michael@0 | 104 | * always be the DOM node for the accessible. Specifically, for doc |
michael@0 | 105 | * accessibles, it is not the document node, but either the root element or |
michael@0 | 106 | * <body> in HTML. |
michael@0 | 107 | * |
michael@0 | 108 | * @param aNode [in] DOM node for the accessible that may be affected by ARIA |
michael@0 | 109 | * @return the nsIContent which may have ARIA markup |
michael@0 | 110 | */ |
michael@0 | 111 | static nsIContent* GetRoleContent(nsINode *aNode); |
michael@0 | 112 | |
michael@0 | 113 | /** |
michael@0 | 114 | * Is the first passed in node an ancestor of the second? |
michael@0 | 115 | * Note: A node is not considered to be the ancestor of itself. |
michael@0 | 116 | * |
michael@0 | 117 | * @param aPossibleAncestorNode [in] node to test for ancestor-ness of |
michael@0 | 118 | * aPossibleDescendantNode |
michael@0 | 119 | * @param aPossibleDescendantNode [in] node to test for descendant-ness of |
michael@0 | 120 | * aPossibleAncestorNode |
michael@0 | 121 | * @param aRootNode [in, optional] the root node that search |
michael@0 | 122 | * search should be performed within |
michael@0 | 123 | * @return true if aPossibleAncestorNode is an ancestor of |
michael@0 | 124 | * aPossibleDescendantNode |
michael@0 | 125 | */ |
michael@0 | 126 | static bool IsAncestorOf(nsINode *aPossibleAncestorNode, |
michael@0 | 127 | nsINode *aPossibleDescendantNode, |
michael@0 | 128 | nsINode *aRootNode = nullptr); |
michael@0 | 129 | |
michael@0 | 130 | /** |
michael@0 | 131 | * Helper method to scroll range into view, used for implementation of |
michael@0 | 132 | * nsIAccessibleText::scrollSubstringTo(). |
michael@0 | 133 | * |
michael@0 | 134 | * @param aFrame the frame for accessible the range belongs to. |
michael@0 | 135 | * @param aRange the range to scroll to |
michael@0 | 136 | * @param aScrollType the place a range should be scrolled to |
michael@0 | 137 | */ |
michael@0 | 138 | static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange, |
michael@0 | 139 | uint32_t aScrollType); |
michael@0 | 140 | |
michael@0 | 141 | /** Helper method to scroll range into view, used for implementation of |
michael@0 | 142 | * nsIAccessibleText::scrollSubstringTo[Point](). |
michael@0 | 143 | * |
michael@0 | 144 | * @param aFrame the frame for accessible the range belongs to. |
michael@0 | 145 | * @param aRange the range to scroll to |
michael@0 | 146 | * @param aVertical how to align vertically, specified in percents, and when. |
michael@0 | 147 | * @param aHorizontal how to align horizontally, specified in percents, and when. |
michael@0 | 148 | */ |
michael@0 | 149 | static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange, |
michael@0 | 150 | nsIPresShell::ScrollAxis aVertical, |
michael@0 | 151 | nsIPresShell::ScrollAxis aHorizontal); |
michael@0 | 152 | |
michael@0 | 153 | /** |
michael@0 | 154 | * Scrolls the given frame to the point, used for implememntation of |
michael@0 | 155 | * nsIAccessible::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint. |
michael@0 | 156 | * |
michael@0 | 157 | * @param aScrollableFrame the scrollable frame |
michael@0 | 158 | * @param aFrame the frame to scroll |
michael@0 | 159 | * @param aPoint the point scroll to |
michael@0 | 160 | */ |
michael@0 | 161 | static void ScrollFrameToPoint(nsIFrame *aScrollableFrame, |
michael@0 | 162 | nsIFrame *aFrame, const nsIntPoint& aPoint); |
michael@0 | 163 | |
michael@0 | 164 | /** |
michael@0 | 165 | * Converts scroll type constant defined in nsIAccessibleScrollType to |
michael@0 | 166 | * vertical and horizontal parameters. |
michael@0 | 167 | */ |
michael@0 | 168 | static void ConvertScrollTypeToPercents(uint32_t aScrollType, |
michael@0 | 169 | nsIPresShell::ScrollAxis *aVertical, |
michael@0 | 170 | nsIPresShell::ScrollAxis *aHorizontal); |
michael@0 | 171 | |
michael@0 | 172 | /** |
michael@0 | 173 | * Returns coordinates in device pixels relative screen for the top level |
michael@0 | 174 | * window. |
michael@0 | 175 | * |
michael@0 | 176 | * @param aNode the DOM node hosted in the window. |
michael@0 | 177 | */ |
michael@0 | 178 | static nsIntPoint GetScreenCoordsForWindow(nsINode *aNode); |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * Return document shell for the given DOM node. |
michael@0 | 182 | */ |
michael@0 | 183 | static already_AddRefed<nsIDocShell> GetDocShellFor(nsINode *aNode); |
michael@0 | 184 | |
michael@0 | 185 | /** |
michael@0 | 186 | * Return true if the given document is root document. |
michael@0 | 187 | */ |
michael@0 | 188 | static bool IsRootDocument(nsIDocument *aDocument); |
michael@0 | 189 | |
michael@0 | 190 | /** |
michael@0 | 191 | * Return true if the given document is content document (not chrome). |
michael@0 | 192 | */ |
michael@0 | 193 | static bool IsContentDocument(nsIDocument *aDocument); |
michael@0 | 194 | |
michael@0 | 195 | /** |
michael@0 | 196 | * Return true if the given document node is for tab document accessible. |
michael@0 | 197 | */ |
michael@0 | 198 | static bool IsTabDocument(nsIDocument* aDocumentNode); |
michael@0 | 199 | |
michael@0 | 200 | /** |
michael@0 | 201 | * Return true if the given document is an error page. |
michael@0 | 202 | */ |
michael@0 | 203 | static bool IsErrorPage(nsIDocument *aDocument); |
michael@0 | 204 | |
michael@0 | 205 | /** |
michael@0 | 206 | * Return presShell for the document containing the given DOM node. |
michael@0 | 207 | */ |
michael@0 | 208 | static nsIPresShell *GetPresShellFor(nsINode *aNode) |
michael@0 | 209 | { |
michael@0 | 210 | return aNode->OwnerDoc()->GetShell(); |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | /** |
michael@0 | 214 | * Get the ID for an element, in some types of XML this may not be the ID attribute |
michael@0 | 215 | * @param aContent Node to get the ID for |
michael@0 | 216 | * @param aID Where to put ID string |
michael@0 | 217 | * @return true if there is an ID set for this node |
michael@0 | 218 | */ |
michael@0 | 219 | static bool GetID(nsIContent *aContent, nsAString& aID); |
michael@0 | 220 | |
michael@0 | 221 | /** |
michael@0 | 222 | * Convert attribute value of the given node to positive integer. If no |
michael@0 | 223 | * attribute or wrong value then false is returned. |
michael@0 | 224 | */ |
michael@0 | 225 | static bool GetUIntAttr(nsIContent *aContent, nsIAtom *aAttr, |
michael@0 | 226 | int32_t *aUInt); |
michael@0 | 227 | |
michael@0 | 228 | /** |
michael@0 | 229 | * Returns language for the given node. |
michael@0 | 230 | * |
michael@0 | 231 | * @param aContent [in] the given node |
michael@0 | 232 | * @param aRootContent [in] container of the given node |
michael@0 | 233 | * @param aLanguage [out] language |
michael@0 | 234 | */ |
michael@0 | 235 | static void GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent, |
michael@0 | 236 | nsAString& aLanguage); |
michael@0 | 237 | |
michael@0 | 238 | /** |
michael@0 | 239 | * Return box object for XUL treechildren element by tree box object. |
michael@0 | 240 | */ |
michael@0 | 241 | static already_AddRefed<nsIBoxObject> |
michael@0 | 242 | GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj); |
michael@0 | 243 | |
michael@0 | 244 | /** |
michael@0 | 245 | * Return tree box object from any levels DOMNode under the XUL tree. |
michael@0 | 246 | */ |
michael@0 | 247 | static already_AddRefed<nsITreeBoxObject> |
michael@0 | 248 | GetTreeBoxObject(nsIContent* aContent); |
michael@0 | 249 | |
michael@0 | 250 | /** |
michael@0 | 251 | * Return first sensible column for the given tree box object. |
michael@0 | 252 | */ |
michael@0 | 253 | static already_AddRefed<nsITreeColumn> |
michael@0 | 254 | GetFirstSensibleColumn(nsITreeBoxObject *aTree); |
michael@0 | 255 | |
michael@0 | 256 | /** |
michael@0 | 257 | * Return sensible columns count for the given tree box object. |
michael@0 | 258 | */ |
michael@0 | 259 | static uint32_t GetSensibleColumnCount(nsITreeBoxObject *aTree); |
michael@0 | 260 | |
michael@0 | 261 | /** |
michael@0 | 262 | * Return sensible column at the given index for the given tree box object. |
michael@0 | 263 | */ |
michael@0 | 264 | static already_AddRefed<nsITreeColumn> |
michael@0 | 265 | GetSensibleColumnAt(nsITreeBoxObject *aTree, uint32_t aIndex); |
michael@0 | 266 | |
michael@0 | 267 | /** |
michael@0 | 268 | * Return next sensible column for the given column. |
michael@0 | 269 | */ |
michael@0 | 270 | static already_AddRefed<nsITreeColumn> |
michael@0 | 271 | GetNextSensibleColumn(nsITreeColumn *aColumn); |
michael@0 | 272 | |
michael@0 | 273 | /** |
michael@0 | 274 | * Return previous sensible column for the given column. |
michael@0 | 275 | */ |
michael@0 | 276 | static already_AddRefed<nsITreeColumn> |
michael@0 | 277 | GetPreviousSensibleColumn(nsITreeColumn *aColumn); |
michael@0 | 278 | |
michael@0 | 279 | /** |
michael@0 | 280 | * Return true if the given column is hidden (i.e. not sensible). |
michael@0 | 281 | */ |
michael@0 | 282 | static bool IsColumnHidden(nsITreeColumn *aColumn); |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Scroll content into view. |
michael@0 | 286 | */ |
michael@0 | 287 | static void ScrollTo(nsIPresShell* aPresShell, nsIContent* aContent, |
michael@0 | 288 | uint32_t aScrollType); |
michael@0 | 289 | |
michael@0 | 290 | /** |
michael@0 | 291 | * Return true if the given node is table header element. |
michael@0 | 292 | */ |
michael@0 | 293 | static bool IsHTMLTableHeader(nsIContent *aContent) |
michael@0 | 294 | { |
michael@0 | 295 | return aContent->NodeInfo()->Equals(nsGkAtoms::th) || |
michael@0 | 296 | aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scope); |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | /** |
michael@0 | 300 | * Returns true if the given string is empty or contains whitespace symbols |
michael@0 | 301 | * only. In contrast to nsWhitespaceTokenizer class it takes into account |
michael@0 | 302 | * non-breaking space (0xa0). |
michael@0 | 303 | */ |
michael@0 | 304 | static bool IsWhitespaceString(const nsSubstring& aString); |
michael@0 | 305 | |
michael@0 | 306 | /** |
michael@0 | 307 | * Returns true if the given character is whitespace symbol. |
michael@0 | 308 | */ |
michael@0 | 309 | static bool IsWhitespace(char16_t aChar) |
michael@0 | 310 | { |
michael@0 | 311 | return aChar == ' ' || aChar == '\n' || |
michael@0 | 312 | aChar == '\r' || aChar == '\t' || aChar == 0xa0; |
michael@0 | 313 | } |
michael@0 | 314 | }; |
michael@0 | 315 | |
michael@0 | 316 | #endif |
michael@0 | 317 |