| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 ASSERT(length() == 1); | 103 ASSERT(length() == 1); |
| 104 output.append(&m_singleCharacterBuffer, 1); | 104 output.append(&m_singleCharacterBuffer, 1); |
| 105 } else { | 105 } else { |
| 106 string().appendTo(output, startOffset() + position, lengthToAppend); | 106 string().appendTo(output, startOffset() + position, lengthToAppend); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 PassRefPtrWillBeRawPtr<Range> range() const; | 110 PassRefPtrWillBeRawPtr<Range> range() const; |
| 111 Node* node() const; | 111 Node* node() const; |
| 112 | 112 |
| 113 int startOffset() const; |
| 114 int endOffset() const; |
| 115 Node* startContainer() const; |
| 116 Position startPosition() const; |
| 117 Position endPosition() const; |
| 118 |
| 113 // Computes the length of the given range using a text iterator. The default | 119 // Computes the length of the given range using a text iterator. The default |
| 114 // iteration behavior is to always emit object replacement characters for | 120 // iteration behavior is to always emit object replacement characters for |
| 115 // replaced elements. When |forSelectionPreservation| is set to true, it | 121 // replaced elements. When |forSelectionPreservation| is set to true, it |
| 116 // also emits spaces for other non-text nodes using the | 122 // also emits spaces for other non-text nodes using the |
| 117 // |TextIteratorEmitsCharactersBetweenAllVisiblePosition| mode. | 123 // |TextIteratorEmitsCharactersBetweenAllVisiblePosition| mode. |
| 118 static int rangeLength(const Range*, bool forSelectionPreservation = false); | 124 static int rangeLength(const Range*, bool forSelectionPreservation = false); |
| 119 static PassRefPtrWillBeRawPtr<Range> subrange(Range* entireRange, int charac
terOffset, int characterCount); | 125 static PassRefPtrWillBeRawPtr<Range> subrange(Range* entireRange, int charac
terOffset, int characterCount); |
| 120 | 126 |
| 121 private: | 127 private: |
| 122 enum IterationProgress { | 128 enum IterationProgress { |
| 123 HandledNone, | 129 HandledNone, |
| 124 HandledAuthorShadowRoots, | 130 HandledAuthorShadowRoots, |
| 125 HandledUserAgentShadowRoot, | 131 HandledUserAgentShadowRoot, |
| 126 HandledNode, | 132 HandledNode, |
| 127 HandledChildren | 133 HandledChildren |
| 128 }; | 134 }; |
| 129 | 135 |
| 130 void initialize(const Position& start, const Position& end); | 136 void initialize(const Position& start, const Position& end); |
| 131 | 137 |
| 132 int startOffset() const { return m_positionStartOffset; } | 138 void flushPositionOffsets() const; |
| 139 int positionStartOffset() const { return m_positionStartOffset; } |
| 133 const String& string() const { return m_text; } | 140 const String& string() const { return m_text; } |
| 134 void exitNode(); | 141 void exitNode(); |
| 135 bool shouldRepresentNodeOffsetZero(); | 142 bool shouldRepresentNodeOffsetZero(); |
| 136 bool shouldEmitSpaceBeforeAndAfterNode(Node*); | 143 bool shouldEmitSpaceBeforeAndAfterNode(Node*); |
| 137 void representNodeOffsetZero(); | 144 void representNodeOffsetZero(); |
| 138 bool handleTextNode(); | 145 bool handleTextNode(); |
| 139 bool handleReplacedElement(); | 146 bool handleReplacedElement(); |
| 140 bool handleNonTextNode(); | 147 bool handleNonTextNode(); |
| 141 void handleTextBox(); | 148 void handleTextBox(); |
| 142 void handleTextNodeFirstLetter(RenderTextFragment*); | 149 void handleTextNodeFirstLetter(RenderTextFragment*); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 if (!m_textLength) | 246 if (!m_textLength) |
| 240 return; | 247 return; |
| 241 if (m_singleCharacterBuffer) | 248 if (m_singleCharacterBuffer) |
| 242 output.prepend(&m_singleCharacterBuffer, 1); | 249 output.prepend(&m_singleCharacterBuffer, 1); |
| 243 else | 250 else |
| 244 m_textContainer.prependTo(output, m_textOffset, m_textLength); | 251 m_textContainer.prependTo(output, m_textOffset, m_textLength); |
| 245 } | 252 } |
| 246 | 253 |
| 247 PassRefPtrWillBeRawPtr<Range> range() const; | 254 PassRefPtrWillBeRawPtr<Range> range() const; |
| 248 | 255 |
| 256 Node* startContainer() const; |
| 257 int endOffset() const; |
| 258 Position startPosition() const; |
| 259 |
| 249 private: | 260 private: |
| 250 void exitNode(); | 261 void exitNode(); |
| 251 bool handleTextNode(); | 262 bool handleTextNode(); |
| 252 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); | 263 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); |
| 253 bool handleReplacedElement(); | 264 bool handleReplacedElement(); |
| 254 bool handleNonTextNode(); | 265 bool handleNonTextNode(); |
| 255 void emitCharacter(UChar, Node*, int startOffset, int endOffset); | 266 void emitCharacter(UChar, Node*, int startOffset, int endOffset); |
| 256 bool advanceRespectingRange(Node*); | 267 bool advanceRespectingRange(Node*); |
| 257 | 268 |
| 258 // Current position, not necessarily of the text being returned, but positio
n | 269 // Current position, not necessarily of the text being returned, but positio
n |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 328 |
| 318 int length() const { return m_textIterator.length() - m_runOffset; } | 329 int length() const { return m_textIterator.length() - m_runOffset; } |
| 319 UChar characterAt(unsigned index) const { return m_textIterator.characterAt(
m_runOffset + index); } | 330 UChar characterAt(unsigned index) const { return m_textIterator.characterAt(
m_runOffset + index); } |
| 320 | 331 |
| 321 template<typename BufferType> | 332 template<typename BufferType> |
| 322 void appendTextTo(BufferType& output) { m_textIterator.appendTextTo(output,
m_runOffset); } | 333 void appendTextTo(BufferType& output) { m_textIterator.appendTextTo(output,
m_runOffset); } |
| 323 | 334 |
| 324 int characterOffset() const { return m_offset; } | 335 int characterOffset() const { return m_offset; } |
| 325 PassRefPtrWillBeRawPtr<Range> range() const; | 336 PassRefPtrWillBeRawPtr<Range> range() const; |
| 326 | 337 |
| 338 Node* startContainer() const; |
| 339 int startOffset() const; |
| 340 Position startPosition() const; |
| 341 Position endPosition() const; |
| 342 |
| 327 private: | 343 private: |
| 328 void initialize(); | 344 void initialize(); |
| 329 | 345 |
| 330 int m_offset; | 346 int m_offset; |
| 331 int m_runOffset; | 347 int m_runOffset; |
| 332 bool m_atBreak; | 348 bool m_atBreak; |
| 333 | 349 |
| 334 TextIterator m_textIterator; | 350 TextIterator m_textIterator; |
| 335 }; | 351 }; |
| 336 | 352 |
| 337 class BackwardsCharacterIterator { | 353 class BackwardsCharacterIterator { |
| 338 STACK_ALLOCATED(); | 354 STACK_ALLOCATED(); |
| 339 public: | 355 public: |
| 340 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); | 356 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); |
| 341 | 357 |
| 342 void advance(int); | 358 void advance(int); |
| 343 | 359 |
| 344 bool atEnd() const { return m_textIterator.atEnd(); } | 360 bool atEnd() const { return m_textIterator.atEnd(); } |
| 345 | 361 |
| 346 PassRefPtrWillBeRawPtr<Range> range() const; | 362 PassRefPtrWillBeRawPtr<Range> range() const; |
| 347 | 363 |
| 364 Position endPosition() const; |
| 365 |
| 348 private: | 366 private: |
| 349 int m_offset; | 367 int m_offset; |
| 350 int m_runOffset; | 368 int m_runOffset; |
| 351 bool m_atBreak; | 369 bool m_atBreak; |
| 352 | 370 |
| 353 SimplifiedBackwardsTextIterator m_textIterator; | 371 SimplifiedBackwardsTextIterator m_textIterator; |
| 354 }; | 372 }; |
| 355 | 373 |
| 356 // Very similar to the TextIterator, except that the chunks of text returned are
"well behaved", | 374 // Very similar to the TextIterator, except that the chunks of text returned are
"well behaved", |
| 357 // meaning they never end split up a word. This is useful for spellcheck or (pe
rhaps one day) searching. | 375 // meaning they never end split up a word. This is useful for spellcheck or (pe
rhaps one day) searching. |
| 358 class WordAwareIterator { | 376 class WordAwareIterator { |
| 359 STACK_ALLOCATED(); | 377 STACK_ALLOCATED(); |
| 360 public: | 378 public: |
| 361 explicit WordAwareIterator(const Range*); | 379 explicit WordAwareIterator(const Range*); |
| 362 ~WordAwareIterator(); | 380 ~WordAwareIterator(); |
| 363 | 381 |
| 364 bool atEnd() const { return !m_didLookAhead && m_textIterator.atEnd(); } | 382 bool atEnd() const { return !m_didLookAhead && m_textIterator.atEnd(); } |
| 365 void advance(); | 383 void advance(); |
| 366 | 384 |
| 367 String substring(unsigned position, unsigned length) const; | 385 String substring(unsigned position, unsigned length) const; |
| 368 UChar characterAt(unsigned index) const; | 386 UChar characterAt(unsigned index) const; |
| 369 int length() const; | 387 int length() const; |
| 370 | 388 |
| 371 private: | 389 private: |
| 372 Vector<UChar> m_buffer; | 390 Vector<UChar> m_buffer; |
| 373 // Did we have to look ahead in the textIterator to confirm the current chun
k? | 391 // Did we have to look ahead in the textIterator to confirm the current chun
k? |
| 374 bool m_didLookAhead; | 392 bool m_didLookAhead; |
| 375 RefPtrWillBeMember<Range> m_range; | |
| 376 TextIterator m_textIterator; | 393 TextIterator m_textIterator; |
| 377 }; | 394 }; |
| 378 | 395 |
| 379 } | 396 } |
| 380 | 397 |
| 381 #endif | 398 #endif |
| OLD | NEW |