| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef TextIterator_h | 26 #ifndef TextIterator_h |
| 27 #define TextIterator_h | 27 #define TextIterator_h |
| 28 | 28 |
| 29 #include "core/dom/Range.h" | 29 #include "core/dom/Range.h" |
| 30 #include "core/editing/FindOptions.h" | 30 #include "core/editing/FindOptions.h" |
| 31 #include "platform/heap/Handle.h" |
| 31 #include "wtf/Vector.h" | 32 #include "wtf/Vector.h" |
| 32 | 33 |
| 33 namespace WebCore { | 34 namespace WebCore { |
| 34 | 35 |
| 35 class InlineTextBox; | 36 class InlineTextBox; |
| 36 class RenderText; | 37 class RenderText; |
| 37 class RenderTextFragment; | 38 class RenderTextFragment; |
| 38 | 39 |
| 39 enum TextIteratorBehavior { | 40 enum TextIteratorBehavior { |
| 40 TextIteratorDefaultBehavior = 0, | 41 TextIteratorDefaultBehavior = 0, |
| 41 TextIteratorEmitsCharactersBetweenAllVisiblePositions = 1 << 0, | 42 TextIteratorEmitsCharactersBetweenAllVisiblePositions = 1 << 0, |
| 42 TextIteratorEntersTextControls = 1 << 1, | 43 TextIteratorEntersTextControls = 1 << 1, |
| 43 TextIteratorIgnoresStyleVisibility = 1 << 2, | 44 TextIteratorIgnoresStyleVisibility = 1 << 2, |
| 44 TextIteratorEmitsOriginalText = 1 << 3, | 45 TextIteratorEmitsOriginalText = 1 << 3, |
| 45 TextIteratorStopsOnFormControls = 1 << 4, | 46 TextIteratorStopsOnFormControls = 1 << 4, |
| 46 TextIteratorEmitsImageAltText = 1 << 5, | 47 TextIteratorEmitsImageAltText = 1 << 5, |
| 47 TextIteratorEntersAuthorShadowRoots = 1 << 6 | 48 TextIteratorEntersAuthorShadowRoots = 1 << 6 |
| 48 }; | 49 }; |
| 49 typedef unsigned TextIteratorBehaviorFlags; | 50 typedef unsigned TextIteratorBehaviorFlags; |
| 50 | 51 |
| 51 String plainText(const Range*, TextIteratorBehaviorFlags = TextIteratorDefaultBe
havior); | 52 String plainText(const Range*, TextIteratorBehaviorFlags = TextIteratorDefaultBe
havior); |
| 52 PassRefPtr<Range> findPlainText(const Range*, const String&, FindOptions); | 53 PassRefPtrWillBeRawPtr<Range> findPlainText(const Range*, const String&, FindOpt
ions); |
| 53 PassRefPtr<Range> findPlainText(const Position& start, const Position& end, cons
t String&, FindOptions); | 54 PassRefPtrWillBeRawPtr<Range> findPlainText(const Position& start, const Positio
n& end, const String&, FindOptions); |
| 54 | 55 |
| 55 class BitStack { | 56 class BitStack { |
| 56 public: | 57 public: |
| 57 BitStack(); | 58 BitStack(); |
| 58 ~BitStack(); | 59 ~BitStack(); |
| 59 | 60 |
| 60 void push(bool); | 61 void push(bool); |
| 61 void pop(); | 62 void pop(); |
| 62 | 63 |
| 63 bool top() const; | 64 bool top() const; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return; | 97 return; |
| 97 if (m_singleCharacterBuffer) { | 98 if (m_singleCharacterBuffer) { |
| 98 ASSERT(!position); | 99 ASSERT(!position); |
| 99 ASSERT(length() == 1); | 100 ASSERT(length() == 1); |
| 100 output.append(&m_singleCharacterBuffer, 1); | 101 output.append(&m_singleCharacterBuffer, 1); |
| 101 } else { | 102 } else { |
| 102 string().appendTo(output, startOffset() + position, lengthToAppend); | 103 string().appendTo(output, startOffset() + position, lengthToAppend); |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 PassRefPtr<Range> range() const; | 107 PassRefPtrWillBeRawPtr<Range> range() const; |
| 107 Node* node() const; | 108 Node* node() const; |
| 108 | 109 |
| 109 static int rangeLength(const Range*, bool spacesForReplacedElements = false)
; | 110 static int rangeLength(const Range*, bool spacesForReplacedElements = false)
; |
| 110 static PassRefPtr<Range> subrange(Range* entireRange, int characterOffset, i
nt characterCount); | 111 static PassRefPtrWillBeRawPtr<Range> subrange(Range* entireRange, int charac
terOffset, int characterCount); |
| 111 | 112 |
| 112 private: | 113 private: |
| 113 enum IterationProgress { | 114 enum IterationProgress { |
| 114 HandledNone, | 115 HandledNone, |
| 115 HandledAuthorShadowRoots, | 116 HandledAuthorShadowRoots, |
| 116 HandledUserAgentShadowRoot, | 117 HandledUserAgentShadowRoot, |
| 117 HandledNode, | 118 HandledNode, |
| 118 HandledChildren | 119 HandledChildren |
| 119 }; | 120 }; |
| 120 | 121 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 void prependTextTo(BufferType& output) | 227 void prependTextTo(BufferType& output) |
| 227 { | 228 { |
| 228 if (!m_textLength) | 229 if (!m_textLength) |
| 229 return; | 230 return; |
| 230 if (m_singleCharacterBuffer) | 231 if (m_singleCharacterBuffer) |
| 231 output.prepend(&m_singleCharacterBuffer, 1); | 232 output.prepend(&m_singleCharacterBuffer, 1); |
| 232 else | 233 else |
| 233 m_textContainer.prependTo(output, m_textOffset, m_textLength); | 234 m_textContainer.prependTo(output, m_textOffset, m_textLength); |
| 234 } | 235 } |
| 235 | 236 |
| 236 PassRefPtr<Range> range() const; | 237 PassRefPtrWillBeRawPtr<Range> range() const; |
| 237 | 238 |
| 238 private: | 239 private: |
| 239 void exitNode(); | 240 void exitNode(); |
| 240 bool handleTextNode(); | 241 bool handleTextNode(); |
| 241 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); | 242 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); |
| 242 bool handleReplacedElement(); | 243 bool handleReplacedElement(); |
| 243 bool handleNonTextNode(); | 244 bool handleNonTextNode(); |
| 244 void emitCharacter(UChar, Node*, int startOffset, int endOffset); | 245 void emitCharacter(UChar, Node*, int startOffset, int endOffset); |
| 245 bool advanceRespectingRange(Node*); | 246 bool advanceRespectingRange(Node*); |
| 246 | 247 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 bool atBreak() const { return m_atBreak; } | 304 bool atBreak() const { return m_atBreak; } |
| 304 bool atEnd() const { return m_textIterator.atEnd(); } | 305 bool atEnd() const { return m_textIterator.atEnd(); } |
| 305 | 306 |
| 306 int length() const { return m_textIterator.length() - m_runOffset; } | 307 int length() const { return m_textIterator.length() - m_runOffset; } |
| 307 UChar characterAt(unsigned index) const { return m_textIterator.characterAt(
m_runOffset + index); } | 308 UChar characterAt(unsigned index) const { return m_textIterator.characterAt(
m_runOffset + index); } |
| 308 | 309 |
| 309 template<typename BufferType> | 310 template<typename BufferType> |
| 310 void appendTextTo(BufferType& output) { m_textIterator.appendTextTo(output,
m_runOffset); } | 311 void appendTextTo(BufferType& output) { m_textIterator.appendTextTo(output,
m_runOffset); } |
| 311 | 312 |
| 312 int characterOffset() const { return m_offset; } | 313 int characterOffset() const { return m_offset; } |
| 313 PassRefPtr<Range> range() const; | 314 PassRefPtrWillBeRawPtr<Range> range() const; |
| 314 | 315 |
| 315 private: | 316 private: |
| 316 void initialize(); | 317 void initialize(); |
| 317 | 318 |
| 318 int m_offset; | 319 int m_offset; |
| 319 int m_runOffset; | 320 int m_runOffset; |
| 320 bool m_atBreak; | 321 bool m_atBreak; |
| 321 | 322 |
| 322 TextIterator m_textIterator; | 323 TextIterator m_textIterator; |
| 323 }; | 324 }; |
| 324 | 325 |
| 325 class BackwardsCharacterIterator { | 326 class BackwardsCharacterIterator { |
| 326 public: | 327 public: |
| 327 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); | 328 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); |
| 328 | 329 |
| 329 void advance(int); | 330 void advance(int); |
| 330 | 331 |
| 331 bool atEnd() const { return m_textIterator.atEnd(); } | 332 bool atEnd() const { return m_textIterator.atEnd(); } |
| 332 | 333 |
| 333 PassRefPtr<Range> range() const; | 334 PassRefPtrWillBeRawPtr<Range> range() const; |
| 334 | 335 |
| 335 private: | 336 private: |
| 336 int m_offset; | 337 int m_offset; |
| 337 int m_runOffset; | 338 int m_runOffset; |
| 338 bool m_atBreak; | 339 bool m_atBreak; |
| 339 | 340 |
| 340 SimplifiedBackwardsTextIterator m_textIterator; | 341 SimplifiedBackwardsTextIterator m_textIterator; |
| 341 }; | 342 }; |
| 342 | 343 |
| 343 // Very similar to the TextIterator, except that the chunks of text returned are
"well behaved", | 344 // Very similar to the TextIterator, except that the chunks of text returned are
"well behaved", |
| 344 // meaning they never end split up a word. This is useful for spellcheck or (pe
rhaps one day) searching. | 345 // meaning they never end split up a word. This is useful for spellcheck or (pe
rhaps one day) searching. |
| 345 class WordAwareIterator { | 346 class WordAwareIterator { |
| 347 STACK_ALLOCATED(); |
| 346 public: | 348 public: |
| 347 explicit WordAwareIterator(const Range*); | 349 explicit WordAwareIterator(const Range*); |
| 348 ~WordAwareIterator(); | 350 ~WordAwareIterator(); |
| 349 | 351 |
| 350 bool atEnd() const { return !m_didLookAhead && m_textIterator.atEnd(); } | 352 bool atEnd() const { return !m_didLookAhead && m_textIterator.atEnd(); } |
| 351 void advance(); | 353 void advance(); |
| 352 | 354 |
| 353 String substring(unsigned position, unsigned length) const; | 355 String substring(unsigned position, unsigned length) const; |
| 354 UChar characterAt(unsigned index) const; | 356 UChar characterAt(unsigned index) const; |
| 355 int length() const; | 357 int length() const; |
| 356 | 358 |
| 357 private: | 359 private: |
| 358 Vector<UChar> m_buffer; | 360 Vector<UChar> m_buffer; |
| 359 // Did we have to look ahead in the textIterator to confirm the current chun
k? | 361 // Did we have to look ahead in the textIterator to confirm the current chun
k? |
| 360 bool m_didLookAhead; | 362 bool m_didLookAhead; |
| 361 RefPtr<Range> m_range; | 363 RefPtrWillBeMember<Range> m_range; |
| 362 TextIterator m_textIterator; | 364 TextIterator m_textIterator; |
| 363 }; | 365 }; |
| 364 | 366 |
| 365 } | 367 } |
| 366 | 368 |
| 367 #endif | 369 #endif |
| OLD | NEW |