Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 mozilla_a11y_HyperTextAccessible_h__ |
michael@0 | 7 | #define mozilla_a11y_HyperTextAccessible_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "AccessibleWrap.h" |
michael@0 | 10 | #include "nsIAccessibleTypes.h" |
michael@0 | 11 | #include "xpcAccessibleHyperText.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsFrameSelection.h" |
michael@0 | 14 | #include "nsISelectionController.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace a11y { |
michael@0 | 18 | |
michael@0 | 19 | class TextRange; |
michael@0 | 20 | |
michael@0 | 21 | struct DOMPoint { |
michael@0 | 22 | DOMPoint() : node(nullptr), idx(0) { } |
michael@0 | 23 | DOMPoint(nsINode* aNode, int32_t aIdx) : node(aNode), idx(aIdx) { } |
michael@0 | 24 | |
michael@0 | 25 | nsINode* node; |
michael@0 | 26 | int32_t idx; |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | // This character marks where in the text returned via nsIAccessibleText(), |
michael@0 | 30 | // that embedded object characters exist |
michael@0 | 31 | const char16_t kEmbeddedObjectChar = 0xfffc; |
michael@0 | 32 | const char16_t kImaginaryEmbeddedObjectChar = ' '; |
michael@0 | 33 | const char16_t kForcedNewLineChar = '\n'; |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * Special Accessible that knows how contain both text and embedded objects |
michael@0 | 37 | */ |
michael@0 | 38 | class HyperTextAccessible : public AccessibleWrap, |
michael@0 | 39 | public xpcAccessibleHyperText |
michael@0 | 40 | { |
michael@0 | 41 | public: |
michael@0 | 42 | HyperTextAccessible(nsIContent* aContent, DocAccessible* aDoc); |
michael@0 | 43 | virtual ~HyperTextAccessible() { } |
michael@0 | 44 | |
michael@0 | 45 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 46 | |
michael@0 | 47 | // Accessible |
michael@0 | 48 | virtual int32_t GetLevelInternal(); |
michael@0 | 49 | virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() MOZ_OVERRIDE; |
michael@0 | 50 | virtual mozilla::a11y::role NativeRole(); |
michael@0 | 51 | virtual uint64_t NativeState(); |
michael@0 | 52 | |
michael@0 | 53 | virtual void InvalidateChildren(); |
michael@0 | 54 | virtual bool RemoveChild(Accessible* aAccessible); |
michael@0 | 55 | |
michael@0 | 56 | // HyperTextAccessible (static helper method) |
michael@0 | 57 | |
michael@0 | 58 | // Convert content offset to rendered text offset |
michael@0 | 59 | nsresult ContentToRenderedOffset(nsIFrame *aFrame, int32_t aContentOffset, |
michael@0 | 60 | uint32_t *aRenderedOffset) const; |
michael@0 | 61 | |
michael@0 | 62 | // Convert rendered text offset to content offset |
michael@0 | 63 | nsresult RenderedToContentOffset(nsIFrame *aFrame, uint32_t aRenderedOffset, |
michael@0 | 64 | int32_t *aContentOffset) const; |
michael@0 | 65 | |
michael@0 | 66 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 67 | // HyperLinkAccessible |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Return link count within this hypertext accessible. |
michael@0 | 71 | */ |
michael@0 | 72 | uint32_t LinkCount() |
michael@0 | 73 | { return EmbeddedChildCount(); } |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * Return link accessible at the given index. |
michael@0 | 77 | */ |
michael@0 | 78 | Accessible* LinkAt(uint32_t aIndex) |
michael@0 | 79 | { |
michael@0 | 80 | return GetEmbeddedChildAt(aIndex); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * Return index for the given link accessible. |
michael@0 | 85 | */ |
michael@0 | 86 | int32_t LinkIndexOf(Accessible* aLink) |
michael@0 | 87 | { |
michael@0 | 88 | return GetIndexOfEmbeddedChild(aLink); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Return link accessible at the given text offset. |
michael@0 | 93 | */ |
michael@0 | 94 | int32_t LinkIndexAtOffset(uint32_t aOffset) |
michael@0 | 95 | { |
michael@0 | 96 | Accessible* child = GetChildAtOffset(aOffset); |
michael@0 | 97 | return child ? LinkIndexOf(child) : -1; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 101 | // HyperTextAccessible: DOM point to text offset conversions. |
michael@0 | 102 | |
michael@0 | 103 | /** |
michael@0 | 104 | * Turn a DOM point (node and offset) into a character offset of this |
michael@0 | 105 | * hypertext. Will look for closest match when the DOM node does not have |
michael@0 | 106 | * an accessible object associated with it. Will return an offset for the end |
michael@0 | 107 | * of the string if the node is not found. |
michael@0 | 108 | * |
michael@0 | 109 | * @param aNode [in] the node to look for |
michael@0 | 110 | * @param aNodeOffset [in] the offset to look for |
michael@0 | 111 | * if -1 just look directly for the node |
michael@0 | 112 | * if >=0 and aNode is text, this represents a char offset |
michael@0 | 113 | * if >=0 and aNode is not text, this represents a child node offset |
michael@0 | 114 | * @param aIsEndOffset [in] if true, then then this offset is not inclusive. The character |
michael@0 | 115 | * indicated by the offset returned is at [offset - 1]. This means |
michael@0 | 116 | * if the passed-in offset is really in a descendant, then the offset returned |
michael@0 | 117 | * will come just after the relevant embedded object characer. |
michael@0 | 118 | * If false, then the offset is inclusive. The character indicated |
michael@0 | 119 | * by the offset returned is at [offset]. If the passed-in offset in inside a |
michael@0 | 120 | * descendant, then the returned offset will be on the relevant embedded object char. |
michael@0 | 121 | */ |
michael@0 | 122 | int32_t DOMPointToOffset(nsINode* aNode, int32_t aNodeOffset, |
michael@0 | 123 | bool aIsEndOffset = false) const; |
michael@0 | 124 | |
michael@0 | 125 | /** |
michael@0 | 126 | * Transform the given a11y point into the offset relative this hypertext. |
michael@0 | 127 | */ |
michael@0 | 128 | int32_t TransformOffset(Accessible* aDescendant, int32_t aOffset, |
michael@0 | 129 | bool aIsEndOffset) const; |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Convert start and end hypertext offsets into DOM range. |
michael@0 | 133 | * |
michael@0 | 134 | * @param aStartOffset [in] the given start hypertext offset |
michael@0 | 135 | * @param aEndOffset [in] the given end hypertext offset |
michael@0 | 136 | * @param aRange [in, out] the range whose bounds to set |
michael@0 | 137 | * @return true if conversion was successful |
michael@0 | 138 | */ |
michael@0 | 139 | bool OffsetsToDOMRange(int32_t aStartOffset, int32_t aEndOffset, |
michael@0 | 140 | nsRange* aRange); |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Convert the given offset into DOM point. |
michael@0 | 144 | * |
michael@0 | 145 | * If offset is at text leaf then DOM point is (text node, offsetInTextNode), |
michael@0 | 146 | * if before embedded object then (parent node, indexInParent), if after then |
michael@0 | 147 | * (parent node, indexInParent + 1). |
michael@0 | 148 | */ |
michael@0 | 149 | DOMPoint OffsetToDOMPoint(int32_t aOffset); |
michael@0 | 150 | |
michael@0 | 151 | /** |
michael@0 | 152 | * Return true if the used ARIA role (if any) allows the hypertext accessible |
michael@0 | 153 | * to expose text interfaces. |
michael@0 | 154 | */ |
michael@0 | 155 | bool IsTextRole(); |
michael@0 | 156 | |
michael@0 | 157 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 158 | // TextAccessible |
michael@0 | 159 | |
michael@0 | 160 | /** |
michael@0 | 161 | * Return character count within the hypertext accessible. |
michael@0 | 162 | */ |
michael@0 | 163 | uint32_t CharacterCount() const |
michael@0 | 164 | { return GetChildOffset(ChildCount()); } |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Get a character at the given offset (don't support magic offsets). |
michael@0 | 168 | */ |
michael@0 | 169 | bool CharAt(int32_t aOffset, nsAString& aChar, |
michael@0 | 170 | int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr) |
michael@0 | 171 | { |
michael@0 | 172 | NS_ASSERTION(!aStartOffset == !aEndOffset, |
michael@0 | 173 | "Offsets should be both defined or both undefined!"); |
michael@0 | 174 | |
michael@0 | 175 | int32_t childIdx = GetChildIndexAtOffset(aOffset); |
michael@0 | 176 | if (childIdx == -1) |
michael@0 | 177 | return false; |
michael@0 | 178 | |
michael@0 | 179 | Accessible* child = GetChildAt(childIdx); |
michael@0 | 180 | child->AppendTextTo(aChar, aOffset - GetChildOffset(childIdx), 1); |
michael@0 | 181 | |
michael@0 | 182 | if (aStartOffset && aEndOffset) { |
michael@0 | 183 | *aStartOffset = aOffset; |
michael@0 | 184 | *aEndOffset = aOffset + aChar.Length(); |
michael@0 | 185 | } |
michael@0 | 186 | return true; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | char16_t CharAt(int32_t aOffset) |
michael@0 | 190 | { |
michael@0 | 191 | nsAutoString charAtOffset; |
michael@0 | 192 | CharAt(aOffset, charAtOffset); |
michael@0 | 193 | return charAtOffset.CharAt(0); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | /** |
michael@0 | 197 | * Return true if char at the given offset equals to given char. |
michael@0 | 198 | */ |
michael@0 | 199 | bool IsCharAt(int32_t aOffset, char16_t aChar) |
michael@0 | 200 | { return CharAt(aOffset) == aChar; } |
michael@0 | 201 | |
michael@0 | 202 | /** |
michael@0 | 203 | * Return true if terminal char is at the given offset. |
michael@0 | 204 | */ |
michael@0 | 205 | bool IsLineEndCharAt(int32_t aOffset) |
michael@0 | 206 | { return IsCharAt(aOffset, '\n'); } |
michael@0 | 207 | |
michael@0 | 208 | /** |
michael@0 | 209 | * Return text between given offsets. |
michael@0 | 210 | */ |
michael@0 | 211 | void TextSubstring(int32_t aStartOffset, int32_t aEndOffset, nsAString& aText); |
michael@0 | 212 | |
michael@0 | 213 | /** |
michael@0 | 214 | * Return text before/at/after the given offset corresponding to |
michael@0 | 215 | * the boundary type. |
michael@0 | 216 | */ |
michael@0 | 217 | void TextBeforeOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType, |
michael@0 | 218 | int32_t* aStartOffset, int32_t* aEndOffset, |
michael@0 | 219 | nsAString& aText); |
michael@0 | 220 | void TextAtOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType, |
michael@0 | 221 | int32_t* aStartOffset, int32_t* aEndOffset, |
michael@0 | 222 | nsAString& aText); |
michael@0 | 223 | void TextAfterOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType, |
michael@0 | 224 | int32_t* aStartOffset, int32_t* aEndOffset, |
michael@0 | 225 | nsAString& aText); |
michael@0 | 226 | |
michael@0 | 227 | /** |
michael@0 | 228 | * Return text attributes for the given text range. |
michael@0 | 229 | */ |
michael@0 | 230 | already_AddRefed<nsIPersistentProperties> |
michael@0 | 231 | TextAttributes(bool aIncludeDefAttrs, int32_t aOffset, |
michael@0 | 232 | int32_t* aStartOffset, int32_t* aEndOffset); |
michael@0 | 233 | |
michael@0 | 234 | /** |
michael@0 | 235 | * Return text attributes applied to the accessible. |
michael@0 | 236 | */ |
michael@0 | 237 | already_AddRefed<nsIPersistentProperties> DefaultTextAttributes(); |
michael@0 | 238 | |
michael@0 | 239 | /** |
michael@0 | 240 | * Return text offset of the given child accessible within hypertext |
michael@0 | 241 | * accessible. |
michael@0 | 242 | * |
michael@0 | 243 | * @param aChild [in] accessible child to get text offset for |
michael@0 | 244 | * @param aInvalidateAfter [in, optional] indicates whether invalidate |
michael@0 | 245 | * cached offsets for next siblings of the child |
michael@0 | 246 | */ |
michael@0 | 247 | int32_t GetChildOffset(Accessible* aChild, |
michael@0 | 248 | bool aInvalidateAfter = false) const |
michael@0 | 249 | { |
michael@0 | 250 | int32_t index = GetIndexOf(aChild); |
michael@0 | 251 | return index == -1 ? -1 : GetChildOffset(index, aInvalidateAfter); |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | /** |
michael@0 | 255 | * Return text offset for the child accessible index. |
michael@0 | 256 | */ |
michael@0 | 257 | int32_t GetChildOffset(uint32_t aChildIndex, |
michael@0 | 258 | bool aInvalidateAfter = false) const; |
michael@0 | 259 | |
michael@0 | 260 | /** |
michael@0 | 261 | * Return child accessible at the given text offset. |
michael@0 | 262 | * |
michael@0 | 263 | * @param aOffset [in] the given text offset |
michael@0 | 264 | */ |
michael@0 | 265 | int32_t GetChildIndexAtOffset(uint32_t aOffset) const; |
michael@0 | 266 | |
michael@0 | 267 | /** |
michael@0 | 268 | * Return child accessible at the given text offset. |
michael@0 | 269 | * |
michael@0 | 270 | * @param aOffset [in] the given text offset |
michael@0 | 271 | */ |
michael@0 | 272 | Accessible* GetChildAtOffset(uint32_t aOffset) const |
michael@0 | 273 | { |
michael@0 | 274 | return GetChildAt(GetChildIndexAtOffset(aOffset)); |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | /** |
michael@0 | 278 | * Return true if the given offset/range is valid. |
michael@0 | 279 | */ |
michael@0 | 280 | bool IsValidOffset(int32_t aOffset); |
michael@0 | 281 | bool IsValidRange(int32_t aStartOffset, int32_t aEndOffset); |
michael@0 | 282 | |
michael@0 | 283 | /** |
michael@0 | 284 | * Return an offset at the given point. |
michael@0 | 285 | */ |
michael@0 | 286 | int32_t OffsetAtPoint(int32_t aX, int32_t aY, uint32_t aCoordType); |
michael@0 | 287 | |
michael@0 | 288 | /** |
michael@0 | 289 | * Return a rect of the given text range relative given coordinate system. |
michael@0 | 290 | */ |
michael@0 | 291 | nsIntRect TextBounds(int32_t aStartOffset, int32_t aEndOffset, |
michael@0 | 292 | uint32_t aCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE); |
michael@0 | 293 | |
michael@0 | 294 | /** |
michael@0 | 295 | * Return a rect for character at given offset relative given coordinate |
michael@0 | 296 | * system. |
michael@0 | 297 | */ |
michael@0 | 298 | nsIntRect CharBounds(int32_t aOffset, uint32_t aCoordType) |
michael@0 | 299 | { return TextBounds(aOffset, aOffset + 1, aCoordType); } |
michael@0 | 300 | |
michael@0 | 301 | /** |
michael@0 | 302 | * Get/set caret offset, if no caret then -1. |
michael@0 | 303 | */ |
michael@0 | 304 | int32_t CaretOffset() const; |
michael@0 | 305 | void SetCaretOffset(int32_t aOffset) { SetSelectionRange(aOffset, aOffset); } |
michael@0 | 306 | |
michael@0 | 307 | /** |
michael@0 | 308 | * Provide the line number for the caret. |
michael@0 | 309 | * @return 1-based index for the line number with the caret |
michael@0 | 310 | */ |
michael@0 | 311 | int32_t CaretLineNumber(); |
michael@0 | 312 | |
michael@0 | 313 | /** |
michael@0 | 314 | * Return the caret rect and the widget containing the caret within this |
michael@0 | 315 | * text accessible. |
michael@0 | 316 | * |
michael@0 | 317 | * @param [out] the widget containing the caret |
michael@0 | 318 | * @return the caret rect |
michael@0 | 319 | */ |
michael@0 | 320 | nsIntRect GetCaretRect(nsIWidget** aWidget); |
michael@0 | 321 | |
michael@0 | 322 | /** |
michael@0 | 323 | * Return selected regions count within the accessible. |
michael@0 | 324 | */ |
michael@0 | 325 | int32_t SelectionCount(); |
michael@0 | 326 | |
michael@0 | 327 | /** |
michael@0 | 328 | * Return the start and end offset of the specified selection. |
michael@0 | 329 | */ |
michael@0 | 330 | bool SelectionBoundsAt(int32_t aSelectionNum, |
michael@0 | 331 | int32_t* aStartOffset, int32_t* aEndOffset); |
michael@0 | 332 | |
michael@0 | 333 | /* |
michael@0 | 334 | * Changes the start and end offset of the specified selection. |
michael@0 | 335 | * @return true if succeeded |
michael@0 | 336 | */ |
michael@0 | 337 | bool SetSelectionBoundsAt(int32_t aSelectionNum, |
michael@0 | 338 | int32_t aStartOffset, int32_t aEndOffset); |
michael@0 | 339 | |
michael@0 | 340 | /** |
michael@0 | 341 | * Adds a selection bounded by the specified offsets. |
michael@0 | 342 | * @return true if succeeded |
michael@0 | 343 | */ |
michael@0 | 344 | bool AddToSelection(int32_t aStartOffset, int32_t aEndOffset); |
michael@0 | 345 | |
michael@0 | 346 | /* |
michael@0 | 347 | * Removes the specified selection. |
michael@0 | 348 | * @return true if succeeded |
michael@0 | 349 | */ |
michael@0 | 350 | bool RemoveFromSelection(int32_t aSelectionNum); |
michael@0 | 351 | |
michael@0 | 352 | /** |
michael@0 | 353 | * Scroll the given text range into view. |
michael@0 | 354 | */ |
michael@0 | 355 | void ScrollSubstringTo(int32_t aStartOffset, int32_t aEndOffset, |
michael@0 | 356 | uint32_t aScrollType); |
michael@0 | 357 | |
michael@0 | 358 | /** |
michael@0 | 359 | * Scroll the given text range to the given point. |
michael@0 | 360 | */ |
michael@0 | 361 | void ScrollSubstringToPoint(int32_t aStartOffset, |
michael@0 | 362 | int32_t aEndOffset, |
michael@0 | 363 | uint32_t aCoordinateType, |
michael@0 | 364 | int32_t aX, int32_t aY); |
michael@0 | 365 | |
michael@0 | 366 | /** |
michael@0 | 367 | * Return a range that encloses the text control or the document this |
michael@0 | 368 | * accessible belongs to. |
michael@0 | 369 | */ |
michael@0 | 370 | void EnclosingRange(TextRange& aRange) const; |
michael@0 | 371 | |
michael@0 | 372 | /** |
michael@0 | 373 | * Return an array of disjoint ranges for selected text within the text control |
michael@0 | 374 | * or the document this accessible belongs to. |
michael@0 | 375 | */ |
michael@0 | 376 | void SelectionRanges(nsTArray<TextRange>* aRanges) const; |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * Return an array of disjoint ranges of visible text within the text control |
michael@0 | 380 | * or the document this accessible belongs to. |
michael@0 | 381 | */ |
michael@0 | 382 | void VisibleRanges(nsTArray<TextRange>* aRanges) const; |
michael@0 | 383 | |
michael@0 | 384 | /** |
michael@0 | 385 | * Return a range containing the given accessible. |
michael@0 | 386 | */ |
michael@0 | 387 | void RangeByChild(Accessible* aChild, TextRange& aRange) const; |
michael@0 | 388 | |
michael@0 | 389 | /** |
michael@0 | 390 | * Return a range containing an accessible at the given point. |
michael@0 | 391 | */ |
michael@0 | 392 | void RangeAtPoint(int32_t aX, int32_t aY, TextRange& aRange) const; |
michael@0 | 393 | |
michael@0 | 394 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 395 | // EditableTextAccessible |
michael@0 | 396 | |
michael@0 | 397 | void ReplaceText(const nsAString& aText); |
michael@0 | 398 | void InsertText(const nsAString& aText, int32_t aPosition); |
michael@0 | 399 | void CopyText(int32_t aStartPos, int32_t aEndPos); |
michael@0 | 400 | void CutText(int32_t aStartPos, int32_t aEndPos); |
michael@0 | 401 | void DeleteText(int32_t aStartPos, int32_t aEndPos); |
michael@0 | 402 | void PasteText(int32_t aPosition); |
michael@0 | 403 | |
michael@0 | 404 | /** |
michael@0 | 405 | * Return the editor associated with the accessible. |
michael@0 | 406 | */ |
michael@0 | 407 | virtual already_AddRefed<nsIEditor> GetEditor() const; |
michael@0 | 408 | |
michael@0 | 409 | protected: |
michael@0 | 410 | // Accessible |
michael@0 | 411 | virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE; |
michael@0 | 412 | virtual void CacheChildren() MOZ_OVERRIDE; |
michael@0 | 413 | |
michael@0 | 414 | // HyperTextAccessible |
michael@0 | 415 | |
michael@0 | 416 | /** |
michael@0 | 417 | * Transform magic offset into text offset. |
michael@0 | 418 | */ |
michael@0 | 419 | int32_t ConvertMagicOffset(int32_t aOffset); |
michael@0 | 420 | |
michael@0 | 421 | /** |
michael@0 | 422 | * Adjust an offset the caret stays at to get a text by line boundary. |
michael@0 | 423 | */ |
michael@0 | 424 | int32_t AdjustCaretOffset(int32_t aOffset) const; |
michael@0 | 425 | |
michael@0 | 426 | /** |
michael@0 | 427 | * Return true if caret is at end of line. |
michael@0 | 428 | */ |
michael@0 | 429 | bool IsCaretAtEndOfLine() const; |
michael@0 | 430 | |
michael@0 | 431 | /** |
michael@0 | 432 | * Return true if the given offset points to terminal empty line if any. |
michael@0 | 433 | */ |
michael@0 | 434 | bool IsEmptyLastLineOffset(int32_t aOffset) |
michael@0 | 435 | { |
michael@0 | 436 | return aOffset == static_cast<int32_t>(CharacterCount()) && |
michael@0 | 437 | IsLineEndCharAt(aOffset - 1); |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | /** |
michael@0 | 441 | * Return an offset of the found word boundary. |
michael@0 | 442 | */ |
michael@0 | 443 | int32_t FindWordBoundary(int32_t aOffset, nsDirection aDirection, |
michael@0 | 444 | EWordMovementType aWordMovementType) |
michael@0 | 445 | { |
michael@0 | 446 | return FindOffset(aOffset, aDirection, eSelectWord, aWordMovementType); |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | /** |
michael@0 | 450 | * Used to get begin/end of previous/this/next line. Note: end of line |
michael@0 | 451 | * is an offset right before '\n' character if any, the offset is right after |
michael@0 | 452 | * '\n' character is begin of line. In case of wrap word breaks these offsets |
michael@0 | 453 | * are equal. |
michael@0 | 454 | */ |
michael@0 | 455 | enum EWhichLineBoundary { |
michael@0 | 456 | ePrevLineBegin, |
michael@0 | 457 | ePrevLineEnd, |
michael@0 | 458 | eThisLineBegin, |
michael@0 | 459 | eThisLineEnd, |
michael@0 | 460 | eNextLineBegin, |
michael@0 | 461 | eNextLineEnd |
michael@0 | 462 | }; |
michael@0 | 463 | |
michael@0 | 464 | /** |
michael@0 | 465 | * Return an offset for requested line boundary. See constants above. |
michael@0 | 466 | */ |
michael@0 | 467 | int32_t FindLineBoundary(int32_t aOffset, |
michael@0 | 468 | EWhichLineBoundary aWhichLineBoundary); |
michael@0 | 469 | |
michael@0 | 470 | /** |
michael@0 | 471 | * Return an offset corresponding to the given direction and selection amount |
michael@0 | 472 | * relative the given offset. A helper used to find word or line boundaries. |
michael@0 | 473 | */ |
michael@0 | 474 | int32_t FindOffset(int32_t aOffset, nsDirection aDirection, |
michael@0 | 475 | nsSelectionAmount aAmount, |
michael@0 | 476 | EWordMovementType aWordMovementType = eDefaultBehavior); |
michael@0 | 477 | |
michael@0 | 478 | /** |
michael@0 | 479 | * Return the boundaries of the substring in case of textual frame or |
michael@0 | 480 | * frame boundaries in case of non textual frame, offsets are ignored. |
michael@0 | 481 | */ |
michael@0 | 482 | nsIntRect GetBoundsInFrame(nsIFrame* aFrame, |
michael@0 | 483 | uint32_t aStartRenderedOffset, |
michael@0 | 484 | uint32_t aEndRenderedOffset); |
michael@0 | 485 | |
michael@0 | 486 | // Selection helpers |
michael@0 | 487 | |
michael@0 | 488 | /** |
michael@0 | 489 | * Return frame/DOM selection object for the accessible. |
michael@0 | 490 | */ |
michael@0 | 491 | already_AddRefed<nsFrameSelection> FrameSelection() const; |
michael@0 | 492 | dom::Selection* DOMSelection() const; |
michael@0 | 493 | |
michael@0 | 494 | /** |
michael@0 | 495 | * Return selection ranges within the accessible subtree. |
michael@0 | 496 | */ |
michael@0 | 497 | void GetSelectionDOMRanges(int16_t aType, nsTArray<nsRange*>* aRanges); |
michael@0 | 498 | |
michael@0 | 499 | nsresult SetSelectionRange(int32_t aStartPos, int32_t aEndPos); |
michael@0 | 500 | |
michael@0 | 501 | // Helpers |
michael@0 | 502 | nsresult GetDOMPointByFrameOffset(nsIFrame* aFrame, int32_t aOffset, |
michael@0 | 503 | Accessible* aAccessible, |
michael@0 | 504 | mozilla::a11y::DOMPoint* aPoint); |
michael@0 | 505 | |
michael@0 | 506 | /** |
michael@0 | 507 | * Set 'misspelled' text attribute and return range offsets where the |
michael@0 | 508 | * attibute is stretched. If the text is not misspelled at the given offset |
michael@0 | 509 | * then we expose only range offsets where text is not misspelled. The method |
michael@0 | 510 | * is used by TextAttributes() method. |
michael@0 | 511 | * |
michael@0 | 512 | * @param aIncludeDefAttrs [in] points whether text attributes having default |
michael@0 | 513 | * values of attributes should be included |
michael@0 | 514 | * @param aSourceNode [in] the node we start to traverse from |
michael@0 | 515 | * @param aStartOffset [in, out] the start offset |
michael@0 | 516 | * @param aEndOffset [in, out] the end offset |
michael@0 | 517 | * @param aAttributes [out, optional] result attributes |
michael@0 | 518 | */ |
michael@0 | 519 | nsresult GetSpellTextAttribute(nsINode* aNode, int32_t aNodeOffset, |
michael@0 | 520 | int32_t *aStartOffset, |
michael@0 | 521 | int32_t *aEndOffset, |
michael@0 | 522 | nsIPersistentProperties *aAttributes); |
michael@0 | 523 | |
michael@0 | 524 | private: |
michael@0 | 525 | /** |
michael@0 | 526 | * End text offsets array. |
michael@0 | 527 | */ |
michael@0 | 528 | mutable nsTArray<uint32_t> mOffsets; |
michael@0 | 529 | }; |
michael@0 | 530 | |
michael@0 | 531 | |
michael@0 | 532 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 533 | // Accessible downcasting method |
michael@0 | 534 | |
michael@0 | 535 | inline HyperTextAccessible* |
michael@0 | 536 | Accessible::AsHyperText() |
michael@0 | 537 | { |
michael@0 | 538 | return IsHyperText() ? static_cast<HyperTextAccessible*>(this) : nullptr; |
michael@0 | 539 | } |
michael@0 | 540 | |
michael@0 | 541 | } // namespace a11y |
michael@0 | 542 | } // namespace mozilla |
michael@0 | 543 | |
michael@0 | 544 | #endif |
michael@0 | 545 |