| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 private: | 67 private: |
| 68 unsigned m_size; | 68 unsigned m_size; |
| 69 Vector<unsigned, 1> m_words; | 69 Vector<unsigned, 1> m_words; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // Iterates through the DOM range, returning all the text, and 0-length boundari
es | 72 // Iterates through the DOM range, returning all the text, and 0-length boundari
es |
| 73 // at points where replaced elements break up the text flow. The text comes bac
k in | 73 // at points where replaced elements break up the text flow. The text comes bac
k in |
| 74 // chunks so as to optimize for performance of the iteration. | 74 // chunks so as to optimize for performance of the iteration. |
| 75 | 75 |
| 76 class TextIterator { | 76 class TextIterator { |
| 77 STACK_ALLOCATED(); |
| 77 public: | 78 public: |
| 78 explicit TextIterator(const Range*, TextIteratorBehaviorFlags = TextIterator
DefaultBehavior); | 79 explicit TextIterator(const Range*, TextIteratorBehaviorFlags = TextIterator
DefaultBehavior); |
| 79 // [start, end] indicates the document range that the iteration should take
place within (both ends inclusive). | 80 // [start, end] indicates the document range that the iteration should take
place within (both ends inclusive). |
| 80 TextIterator(const Position& start, const Position& end, TextIteratorBehavio
rFlags = TextIteratorDefaultBehavior); | 81 TextIterator(const Position& start, const Position& end, TextIteratorBehavio
rFlags = TextIteratorDefaultBehavior); |
| 81 ~TextIterator(); | 82 ~TextIterator(); |
| 82 | 83 |
| 83 bool atEnd() const { return !m_positionNode || m_shouldStop; } | 84 bool atEnd() const { return !m_positionNode || m_shouldStop; } |
| 84 void advance(); | 85 void advance(); |
| 85 | 86 |
| 86 int length() const { return m_textLength; } | 87 int length() const { return m_textLength; } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 bool handleNonTextNode(); | 133 bool handleNonTextNode(); |
| 133 void handleTextBox(); | 134 void handleTextBox(); |
| 134 void handleTextNodeFirstLetter(RenderTextFragment*); | 135 void handleTextNodeFirstLetter(RenderTextFragment*); |
| 135 bool hasVisibleTextNode(RenderText*); | 136 bool hasVisibleTextNode(RenderText*); |
| 136 void emitCharacter(UChar, Node* textNode, Node* offsetBaseNode, int textStar
tOffset, int textEndOffset); | 137 void emitCharacter(UChar, Node* textNode, Node* offsetBaseNode, int textStar
tOffset, int textEndOffset); |
| 137 void emitText(Node* textNode, RenderObject* renderObject, int textStartOffse
t, int textEndOffset); | 138 void emitText(Node* textNode, RenderObject* renderObject, int textStartOffse
t, int textEndOffset); |
| 138 void emitText(Node* textNode, int textStartOffset, int textEndOffset); | 139 void emitText(Node* textNode, int textStartOffset, int textEndOffset); |
| 139 | 140 |
| 140 // Current position, not necessarily of the text being returned, but positio
n | 141 // Current position, not necessarily of the text being returned, but positio
n |
| 141 // as we walk through the DOM tree. | 142 // as we walk through the DOM tree. |
| 142 Node* m_node; | 143 RawPtrWillBeMember<Node> m_node; |
| 143 int m_offset; | 144 int m_offset; |
| 144 IterationProgress m_iterationProgress; | 145 IterationProgress m_iterationProgress; |
| 145 BitStack m_fullyClippedStack; | 146 BitStack m_fullyClippedStack; |
| 146 int m_shadowDepth; | 147 int m_shadowDepth; |
| 147 | 148 |
| 148 // The range. | 149 // The range. |
| 149 Node* m_startContainer; | 150 RawPtrWillBeMember<Node> m_startContainer; |
| 150 int m_startOffset; | 151 int m_startOffset; |
| 151 Node* m_endContainer; | 152 RawPtrWillBeMember<Node> m_endContainer; |
| 152 int m_endOffset; | 153 int m_endOffset; |
| 153 Node* m_pastEndNode; | 154 RawPtrWillBeMember<Node> m_pastEndNode; |
| 154 | 155 |
| 155 // The current text and its position, in the form to be returned from the it
erator. | 156 // The current text and its position, in the form to be returned from the it
erator. |
| 156 Node* m_positionNode; | 157 RawPtrWillBeMember<Node> m_positionNode; |
| 157 mutable Node* m_positionOffsetBaseNode; | 158 mutable RawPtrWillBeMember<Node> m_positionOffsetBaseNode; |
| 158 mutable int m_positionStartOffset; | 159 mutable int m_positionStartOffset; |
| 159 mutable int m_positionEndOffset; | 160 mutable int m_positionEndOffset; |
| 160 int m_textLength; | 161 int m_textLength; |
| 161 String m_text; | 162 String m_text; |
| 162 | 163 |
| 163 // Used when there is still some pending text from the current node; when th
ese | 164 // Used when there is still some pending text from the current node; when th
ese |
| 164 // are false and 0, we go back to normal iterating. | 165 // are false and 0, we go back to normal iterating. |
| 165 bool m_needsAnotherNewline; | 166 bool m_needsAnotherNewline; |
| 166 InlineTextBox* m_textBox; | 167 InlineTextBox* m_textBox; |
| 167 // Used when iteration over :first-letter text to save pointer to | 168 // Used when iteration over :first-letter text to save pointer to |
| 168 // remaining text box. | 169 // remaining text box. |
| 169 InlineTextBox* m_remainingTextBox; | 170 InlineTextBox* m_remainingTextBox; |
| 170 // Used to point to RenderText object for :first-letter. | 171 // Used to point to RenderText object for :first-letter. |
| 171 RenderText *m_firstLetterText; | 172 RenderText *m_firstLetterText; |
| 172 | 173 |
| 173 // Used to do the whitespace collapsing logic. | 174 // Used to do the whitespace collapsing logic. |
| 174 Node* m_lastTextNode; | 175 RawPtrWillBeMember<Node> m_lastTextNode; |
| 175 bool m_lastTextNodeEndedWithCollapsedSpace; | 176 bool m_lastTextNodeEndedWithCollapsedSpace; |
| 176 UChar m_lastCharacter; | 177 UChar m_lastCharacter; |
| 177 | 178 |
| 178 // Used for whitespace characters that aren't in the DOM, so we can point at
them. | 179 // Used for whitespace characters that aren't in the DOM, so we can point at
them. |
| 179 // If non-zero, overrides m_text. | 180 // If non-zero, overrides m_text. |
| 180 UChar m_singleCharacterBuffer; | 181 UChar m_singleCharacterBuffer; |
| 181 | 182 |
| 182 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text) | 183 // Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text) |
| 183 Vector<InlineTextBox*> m_sortedTextBoxes; | 184 Vector<InlineTextBox*> m_sortedTextBoxes; |
| 184 size_t m_sortedTextBoxesPosition; | 185 size_t m_sortedTextBoxesPosition; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 206 | 207 |
| 207 bool m_emitsImageAltText; | 208 bool m_emitsImageAltText; |
| 208 | 209 |
| 209 bool m_entersAuthorShadowRoots; | 210 bool m_entersAuthorShadowRoots; |
| 210 }; | 211 }; |
| 211 | 212 |
| 212 // Iterates through the DOM range, returning all the text, and 0-length boundari
es | 213 // Iterates through the DOM range, returning all the text, and 0-length boundari
es |
| 213 // at points where replaced elements break up the text flow. The text comes back
in | 214 // at points where replaced elements break up the text flow. The text comes back
in |
| 214 // chunks so as to optimize for performance of the iteration. | 215 // chunks so as to optimize for performance of the iteration. |
| 215 class SimplifiedBackwardsTextIterator { | 216 class SimplifiedBackwardsTextIterator { |
| 217 STACK_ALLOCATED(); |
| 216 public: | 218 public: |
| 217 explicit SimplifiedBackwardsTextIterator(const Range*, TextIteratorBehaviorF
lags = TextIteratorDefaultBehavior); | 219 explicit SimplifiedBackwardsTextIterator(const Range*, TextIteratorBehaviorF
lags = TextIteratorDefaultBehavior); |
| 218 | 220 |
| 219 bool atEnd() const { return !m_positionNode || m_shouldStop; } | 221 bool atEnd() const { return !m_positionNode || m_shouldStop; } |
| 220 void advance(); | 222 void advance(); |
| 221 | 223 |
| 222 int length() const { return m_textLength; } | 224 int length() const { return m_textLength; } |
| 223 | 225 |
| 224 Node* node() const { return m_node; } | 226 Node* node() const { return m_node; } |
| 225 | 227 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 240 void exitNode(); | 242 void exitNode(); |
| 241 bool handleTextNode(); | 243 bool handleTextNode(); |
| 242 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); | 244 RenderText* handleFirstLetter(int& startOffset, int& offsetInNode); |
| 243 bool handleReplacedElement(); | 245 bool handleReplacedElement(); |
| 244 bool handleNonTextNode(); | 246 bool handleNonTextNode(); |
| 245 void emitCharacter(UChar, Node*, int startOffset, int endOffset); | 247 void emitCharacter(UChar, Node*, int startOffset, int endOffset); |
| 246 bool advanceRespectingRange(Node*); | 248 bool advanceRespectingRange(Node*); |
| 247 | 249 |
| 248 // Current position, not necessarily of the text being returned, but positio
n | 250 // Current position, not necessarily of the text being returned, but positio
n |
| 249 // as we walk through the DOM tree. | 251 // as we walk through the DOM tree. |
| 250 Node* m_node; | 252 RawPtrWillBeMember<Node> m_node; |
| 251 int m_offset; | 253 int m_offset; |
| 252 bool m_handledNode; | 254 bool m_handledNode; |
| 253 bool m_handledChildren; | 255 bool m_handledChildren; |
| 254 BitStack m_fullyClippedStack; | 256 BitStack m_fullyClippedStack; |
| 255 | 257 |
| 256 // End of the range. | 258 // End of the range. |
| 257 Node* m_startNode; | 259 RawPtrWillBeMember<Node> m_startNode; |
| 258 int m_startOffset; | 260 int m_startOffset; |
| 259 // Start of the range. | 261 // Start of the range. |
| 260 Node* m_endNode; | 262 RawPtrWillBeMember<Node> m_endNode; |
| 261 int m_endOffset; | 263 int m_endOffset; |
| 262 | 264 |
| 263 // The current text and its position, in the form to be returned from the it
erator. | 265 // The current text and its position, in the form to be returned from the it
erator. |
| 264 Node* m_positionNode; | 266 RawPtrWillBeMember<Node> m_positionNode; |
| 265 int m_positionStartOffset; | 267 int m_positionStartOffset; |
| 266 int m_positionEndOffset; | 268 int m_positionEndOffset; |
| 267 | 269 |
| 268 String m_textContainer; // We're interested in the range [m_textOffset, m_te
xtOffset + m_textLength) of m_textContainer. | 270 String m_textContainer; // We're interested in the range [m_textOffset, m_te
xtOffset + m_textLength) of m_textContainer. |
| 269 int m_textOffset; | 271 int m_textOffset; |
| 270 int m_textLength; | 272 int m_textLength; |
| 271 | 273 |
| 272 // Used to do the whitespace logic. | 274 // Used to do the whitespace logic. |
| 273 Node* m_lastTextNode; | 275 RawPtrWillBeMember<Node> m_lastTextNode; |
| 274 UChar m_lastCharacter; | 276 UChar m_lastCharacter; |
| 275 | 277 |
| 276 // Used for whitespace characters that aren't in the DOM, so we can point at
them. | 278 // Used for whitespace characters that aren't in the DOM, so we can point at
them. |
| 277 UChar m_singleCharacterBuffer; | 279 UChar m_singleCharacterBuffer; |
| 278 | 280 |
| 279 // Whether m_node has advanced beyond the iteration range (i.e. m_startNode)
. | 281 // Whether m_node has advanced beyond the iteration range (i.e. m_startNode)
. |
| 280 bool m_havePassedStartNode; | 282 bool m_havePassedStartNode; |
| 281 | 283 |
| 282 // Should handle first-letter renderer in the next call to handleTextNode. | 284 // Should handle first-letter renderer in the next call to handleTextNode. |
| 283 bool m_shouldHandleFirstLetter; | 285 bool m_shouldHandleFirstLetter; |
| 284 | 286 |
| 285 // Used when the iteration should stop if form controls are reached. | 287 // Used when the iteration should stop if form controls are reached. |
| 286 bool m_stopsOnFormControls; | 288 bool m_stopsOnFormControls; |
| 287 | 289 |
| 288 // Used when m_stopsOnFormControls is set to determine if the iterator shoul
d keep advancing. | 290 // Used when m_stopsOnFormControls is set to determine if the iterator shoul
d keep advancing. |
| 289 bool m_shouldStop; | 291 bool m_shouldStop; |
| 290 | 292 |
| 291 // Used in pasting inside password field. | 293 // Used in pasting inside password field. |
| 292 bool m_emitsOriginalText; | 294 bool m_emitsOriginalText; |
| 293 }; | 295 }; |
| 294 | 296 |
| 295 // Builds on the text iterator, adding a character position so we can walk one | 297 // Builds on the text iterator, adding a character position so we can walk one |
| 296 // character at a time, or faster, as needed. Useful for searching. | 298 // character at a time, or faster, as needed. Useful for searching. |
| 297 class CharacterIterator { | 299 class CharacterIterator { |
| 300 STACK_ALLOCATED(); |
| 298 public: | 301 public: |
| 299 explicit CharacterIterator(const Range*, TextIteratorBehaviorFlags = TextIte
ratorDefaultBehavior); | 302 explicit CharacterIterator(const Range*, TextIteratorBehaviorFlags = TextIte
ratorDefaultBehavior); |
| 300 CharacterIterator(const Position& start, const Position& end, TextIteratorBe
haviorFlags = TextIteratorDefaultBehavior); | 303 CharacterIterator(const Position& start, const Position& end, TextIteratorBe
haviorFlags = TextIteratorDefaultBehavior); |
| 301 | 304 |
| 302 void advance(int numCharacters); | 305 void advance(int numCharacters); |
| 303 | 306 |
| 304 bool atBreak() const { return m_atBreak; } | 307 bool atBreak() const { return m_atBreak; } |
| 305 bool atEnd() const { return m_textIterator.atEnd(); } | 308 bool atEnd() const { return m_textIterator.atEnd(); } |
| 306 | 309 |
| 307 int length() const { return m_textIterator.length() - m_runOffset; } | 310 int length() const { return m_textIterator.length() - m_runOffset; } |
| 308 UChar characterAt(unsigned index) const { return m_textIterator.characterAt(
m_runOffset + index); } | 311 UChar characterAt(unsigned index) const { return m_textIterator.characterAt(
m_runOffset + index); } |
| 309 | 312 |
| 310 template<typename BufferType> | 313 template<typename BufferType> |
| 311 void appendTextTo(BufferType& output) { m_textIterator.appendTextTo(output,
m_runOffset); } | 314 void appendTextTo(BufferType& output) { m_textIterator.appendTextTo(output,
m_runOffset); } |
| 312 | 315 |
| 313 int characterOffset() const { return m_offset; } | 316 int characterOffset() const { return m_offset; } |
| 314 PassRefPtrWillBeRawPtr<Range> range() const; | 317 PassRefPtrWillBeRawPtr<Range> range() const; |
| 315 | 318 |
| 316 private: | 319 private: |
| 317 void initialize(); | 320 void initialize(); |
| 318 | 321 |
| 319 int m_offset; | 322 int m_offset; |
| 320 int m_runOffset; | 323 int m_runOffset; |
| 321 bool m_atBreak; | 324 bool m_atBreak; |
| 322 | 325 |
| 323 TextIterator m_textIterator; | 326 TextIterator m_textIterator; |
| 324 }; | 327 }; |
| 325 | 328 |
| 326 class BackwardsCharacterIterator { | 329 class BackwardsCharacterIterator { |
| 330 STACK_ALLOCATED(); |
| 327 public: | 331 public: |
| 328 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); | 332 explicit BackwardsCharacterIterator(const Range*, TextIteratorBehaviorFlags
= TextIteratorDefaultBehavior); |
| 329 | 333 |
| 330 void advance(int); | 334 void advance(int); |
| 331 | 335 |
| 332 bool atEnd() const { return m_textIterator.atEnd(); } | 336 bool atEnd() const { return m_textIterator.atEnd(); } |
| 333 | 337 |
| 334 PassRefPtrWillBeRawPtr<Range> range() const; | 338 PassRefPtrWillBeRawPtr<Range> range() const; |
| 335 | 339 |
| 336 private: | 340 private: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 360 Vector<UChar> m_buffer; | 364 Vector<UChar> m_buffer; |
| 361 // Did we have to look ahead in the textIterator to confirm the current chun
k? | 365 // Did we have to look ahead in the textIterator to confirm the current chun
k? |
| 362 bool m_didLookAhead; | 366 bool m_didLookAhead; |
| 363 RefPtrWillBeMember<Range> m_range; | 367 RefPtrWillBeMember<Range> m_range; |
| 364 TextIterator m_textIterator; | 368 TextIterator m_textIterator; |
| 365 }; | 369 }; |
| 366 | 370 |
| 367 } | 371 } |
| 368 | 372 |
| 369 #endif | 373 #endif |
| OLD | NEW |