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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 bool m_emitsObjectReplacementCharacter; | 225 bool m_emitsObjectReplacementCharacter; |
226 }; | 226 }; |
227 | 227 |
228 // Iterates through the DOM range, returning all the text, and 0-length boundari
es | 228 // Iterates through the DOM range, returning all the text, and 0-length boundari
es |
229 // at points where replaced elements break up the text flow. The text comes back
in | 229 // at points where replaced elements break up the text flow. The text comes back
in |
230 // chunks so as to optimize for performance of the iteration. | 230 // chunks so as to optimize for performance of the iteration. |
231 class SimplifiedBackwardsTextIterator { | 231 class SimplifiedBackwardsTextIterator { |
232 STACK_ALLOCATED(); | 232 STACK_ALLOCATED(); |
233 public: | 233 public: |
234 explicit SimplifiedBackwardsTextIterator(const Range*, TextIteratorBehaviorF
lags = TextIteratorDefaultBehavior); | 234 explicit SimplifiedBackwardsTextIterator(const Range*, TextIteratorBehaviorF
lags = TextIteratorDefaultBehavior); |
| 235 SimplifiedBackwardsTextIterator(const Position& start, const Position& end,
TextIteratorBehaviorFlags = TextIteratorDefaultBehavior); |
235 | 236 |
236 bool atEnd() const { return !m_positionNode || m_shouldStop; } | 237 bool atEnd() const { return !m_positionNode || m_shouldStop; } |
237 void advance(); | 238 void advance(); |
238 | 239 |
239 int length() const { return m_textLength; } | 240 int length() const { return m_textLength; } |
240 | 241 |
241 Node* node() const { return m_node; } | 242 Node* node() const { return m_node; } |
242 | 243 |
243 template<typename BufferType> | 244 template<typename BufferType> |
244 void prependTextTo(BufferType& output) | 245 void prependTextTo(BufferType& output) |
245 { | 246 { |
246 if (!m_textLength) | 247 if (!m_textLength) |
247 return; | 248 return; |
248 if (m_singleCharacterBuffer) | 249 if (m_singleCharacterBuffer) |
249 output.prepend(&m_singleCharacterBuffer, 1); | 250 output.prepend(&m_singleCharacterBuffer, 1); |
250 else | 251 else |
251 m_textContainer.prependTo(output, m_textOffset, m_textLength); | 252 m_textContainer.prependTo(output, m_textOffset, m_textLength); |
252 } | 253 } |
253 | 254 |
254 PassRefPtrWillBeRawPtr<Range> range() const; | 255 PassRefPtrWillBeRawPtr<Range> range() const; |
255 | 256 |
256 Node* startContainer() const; | 257 Node* startContainer() const; |
257 int endOffset() const; | 258 int endOffset() const; |
258 Position startPosition() const; | 259 Position startPosition() const; |
259 | 260 |
260 private: | 261 private: |
| 262 void init(Node* startNode, Node* endNode, int startOffset, int endOffset); |
261 void exitNode(); | 263 void exitNode(); |
262 bool handleTextNode(); | 264 bool handleTextNode(); |
263 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); | 265 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); |
264 bool handleReplacedElement(); | 266 bool handleReplacedElement(); |
265 bool handleNonTextNode(); | 267 bool handleNonTextNode(); |
266 void emitCharacter(UChar, Node*, int startOffset, int endOffset); | 268 void emitCharacter(UChar, Node*, int startOffset, int endOffset); |
267 bool advanceRespectingRange(Node*); | 269 bool advanceRespectingRange(Node*); |
268 | 270 |
269 // Current position, not necessarily of the text being returned, but positio
n | 271 // Current position, not necessarily of the text being returned, but positio
n |
270 // as we walk through the DOM tree. | 272 // as we walk through the DOM tree. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 int m_runOffset; | 349 int m_runOffset; |
348 bool m_atBreak; | 350 bool m_atBreak; |
349 | 351 |
350 TextIterator m_textIterator; | 352 TextIterator m_textIterator; |
351 }; | 353 }; |
352 | 354 |
353 class BackwardsCharacterIterator { | 355 class BackwardsCharacterIterator { |
354 STACK_ALLOCATED(); | 356 STACK_ALLOCATED(); |
355 public: | 357 public: |
356 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); | 358 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); |
| 359 BackwardsCharacterIterator(const Position&, const Position&, TextIteratorBeh
aviorFlags = TextIteratorDefaultBehavior); |
357 | 360 |
358 void advance(int); | 361 void advance(int); |
359 | 362 |
360 bool atEnd() const { return m_textIterator.atEnd(); } | 363 bool atEnd() const { return m_textIterator.atEnd(); } |
361 | 364 |
362 PassRefPtrWillBeRawPtr<Range> range() const; | 365 PassRefPtrWillBeRawPtr<Range> range() const; |
363 | 366 |
364 Position endPosition() const; | 367 Position endPosition() const; |
365 | 368 |
366 private: | 369 private: |
(...skipping 22 matching lines...) Expand all Loading... |
389 private: | 392 private: |
390 Vector<UChar> m_buffer; | 393 Vector<UChar> m_buffer; |
391 // Did we have to look ahead in the textIterator to confirm the current chun
k? | 394 // Did we have to look ahead in the textIterator to confirm the current chun
k? |
392 bool m_didLookAhead; | 395 bool m_didLookAhead; |
393 TextIterator m_textIterator; | 396 TextIterator m_textIterator; |
394 }; | 397 }; |
395 | 398 |
396 } | 399 } |
397 | 400 |
398 #endif | 401 #endif |
OLD | NEW |