| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r
ights reserved. |
| 3 * Copyright (C) 2005 Alexey Proskuryakov. | 3 * Copyright (C) 2005 Alexey Proskuryakov. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 , m_startOffset(0) | 234 , m_startOffset(0) |
| 235 , m_endContainer(0) | 235 , m_endContainer(0) |
| 236 , m_endOffset(0) | 236 , m_endOffset(0) |
| 237 , m_positionNode(0) | 237 , m_positionNode(0) |
| 238 , m_textLength(0) | 238 , m_textLength(0) |
| 239 , m_remainingTextBox(0) | 239 , m_remainingTextBox(0) |
| 240 , m_firstLetterText(0) | 240 , m_firstLetterText(0) |
| 241 , m_sortedTextBoxesPosition(0) | 241 , m_sortedTextBoxesPosition(0) |
| 242 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh
aractersBetweenAllVisiblePositions) | 242 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh
aractersBetweenAllVisiblePositions) |
| 243 , m_entersTextControls(behavior & TextIteratorEntersTextControls) | 243 , m_entersTextControls(behavior & TextIteratorEntersTextControls) |
| 244 , m_emitsTextWithoutTranscoding(behavior & TextIteratorEmitsTextsWithoutTran
scoding) | |
| 245 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) | 244 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) |
| 246 , m_handledFirstLetter(false) | 245 , m_handledFirstLetter(false) |
| 247 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) | 246 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) |
| 248 , m_emitsObjectReplacementCharacters(behavior & TextIteratorEmitsObjectRepla
cementCharacters) | 247 , m_emitsObjectReplacementCharacters(behavior & TextIteratorEmitsObjectRepla
cementCharacters) |
| 249 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls) | 248 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls) |
| 250 , m_shouldStop(false) | 249 , m_shouldStop(false) |
| 251 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) | 250 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) |
| 252 { | 251 { |
| 253 if (!r) | 252 if (!r) |
| 254 return; | 253 return; |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 m_textLength = 1; | 1009 m_textLength = 1; |
| 1011 | 1010 |
| 1012 // remember some iteration state | 1011 // remember some iteration state |
| 1013 m_lastTextNodeEndedWithCollapsedSpace = false; | 1012 m_lastTextNodeEndedWithCollapsedSpace = false; |
| 1014 m_lastCharacter = c; | 1013 m_lastCharacter = c; |
| 1015 } | 1014 } |
| 1016 | 1015 |
| 1017 void TextIterator::emitText(Node* textNode, RenderObject* renderObject, int text
StartOffset, int textEndOffset) | 1016 void TextIterator::emitText(Node* textNode, RenderObject* renderObject, int text
StartOffset, int textEndOffset) |
| 1018 { | 1017 { |
| 1019 RenderText* renderer = toRenderText(renderObject); | 1018 RenderText* renderer = toRenderText(renderObject); |
| 1020 m_text = m_emitsOriginalText ? renderer->originalText() : (m_emitsTextWithou
tTranscoding ? renderer->textWithoutTranscoding() : renderer->text()); | 1019 m_text = m_emitsOriginalText ? renderer->originalText() : renderer->text(); |
| 1021 ASSERT(!m_text.isEmpty()); | 1020 ASSERT(!m_text.isEmpty()); |
| 1022 ASSERT(0 <= textStartOffset && textStartOffset < static_cast<int>(m_text.len
gth())); | 1021 ASSERT(0 <= textStartOffset && textStartOffset < static_cast<int>(m_text.len
gth())); |
| 1023 ASSERT(0 <= textEndOffset && textEndOffset <= static_cast<int>(m_text.length
())); | 1022 ASSERT(0 <= textEndOffset && textEndOffset <= static_cast<int>(m_text.length
())); |
| 1024 ASSERT(textStartOffset <= textEndOffset); | 1023 ASSERT(textStartOffset <= textEndOffset); |
| 1025 | 1024 |
| 1026 m_positionNode = textNode; | 1025 m_positionNode = textNode; |
| 1027 m_positionOffsetBaseNode = 0; | 1026 m_positionOffsetBaseNode = 0; |
| 1028 m_positionStartOffset = textStartOffset; | 1027 m_positionStartOffset = textStartOffset; |
| 1029 m_positionEndOffset = textEndOffset; | 1028 m_positionEndOffset = textEndOffset; |
| 1030 m_singleCharacterBuffer = 0; | 1029 m_singleCharacterBuffer = 0; |
| (...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2342 location = TextIterator::rangeLength(testRange.get()); | 2341 location = TextIterator::rangeLength(testRange.get()); |
| 2343 | 2342 |
| 2344 testRange->setEnd(range->endContainer(), range->endOffset(), IGNORE_EXCEPTIO
N); | 2343 testRange->setEnd(range->endContainer(), range->endOffset(), IGNORE_EXCEPTIO
N); |
| 2345 ASSERT(testRange->startContainer() == scope); | 2344 ASSERT(testRange->startContainer() == scope); |
| 2346 length = TextIterator::rangeLength(testRange.get()) - location; | 2345 length = TextIterator::rangeLength(testRange.get()) - location; |
| 2347 return true; | 2346 return true; |
| 2348 } | 2347 } |
| 2349 | 2348 |
| 2350 // -------- | 2349 // -------- |
| 2351 | 2350 |
| 2352 String plainText(const Range* r, TextIteratorBehavior defaultBehavior, bool isDi
splayString) | 2351 String plainText(const Range* r, TextIteratorBehavior defaultBehavior) |
| 2353 { | 2352 { |
| 2354 // The initial buffer size can be critical for performance: https://bugs.web
kit.org/show_bug.cgi?id=81192 | 2353 // The initial buffer size can be critical for performance: https://bugs.web
kit.org/show_bug.cgi?id=81192 |
| 2355 static const unsigned initialCapacity = 1 << 15; | 2354 static const unsigned initialCapacity = 1 << 15; |
| 2356 | 2355 |
| 2357 unsigned bufferLength = 0; | 2356 unsigned bufferLength = 0; |
| 2358 StringBuilder builder; | 2357 StringBuilder builder; |
| 2359 builder.reserveCapacity(initialCapacity); | 2358 builder.reserveCapacity(initialCapacity); |
| 2360 TextIteratorBehavior behavior = defaultBehavior; | |
| 2361 if (!isDisplayString) | |
| 2362 behavior = static_cast<TextIteratorBehavior>(behavior | TextIteratorEmit
sTextsWithoutTranscoding); | |
| 2363 | 2359 |
| 2364 for (TextIterator it(r, behavior); !it.atEnd(); it.advance()) { | 2360 for (TextIterator it(r, defaultBehavior); !it.atEnd(); it.advance()) { |
| 2365 it.appendTextToStringBuilder(builder); | 2361 it.appendTextToStringBuilder(builder); |
| 2366 bufferLength += it.length(); | 2362 bufferLength += it.length(); |
| 2367 } | 2363 } |
| 2368 | 2364 |
| 2369 if (!bufferLength) | 2365 if (!bufferLength) |
| 2370 return emptyString(); | 2366 return emptyString(); |
| 2371 | 2367 |
| 2372 String result = builder.toString(); | 2368 return builder.toString(); |
| 2373 | |
| 2374 if (isDisplayString) | |
| 2375 r->ownerDocument().displayStringModifiedByEncoding(result); | |
| 2376 | |
| 2377 return result; | |
| 2378 } | 2369 } |
| 2379 | 2370 |
| 2380 static PassRefPtr<Range> collapsedToBoundary(const Range* range, bool forward) | 2371 static PassRefPtr<Range> collapsedToBoundary(const Range* range, bool forward) |
| 2381 { | 2372 { |
| 2382 RefPtr<Range> result = range->cloneRange(ASSERT_NO_EXCEPTION); | 2373 RefPtr<Range> result = range->cloneRange(ASSERT_NO_EXCEPTION); |
| 2383 result->collapse(!forward, ASSERT_NO_EXCEPTION); | 2374 result->collapse(!forward, ASSERT_NO_EXCEPTION); |
| 2384 return result.release(); | 2375 return result.release(); |
| 2385 } | 2376 } |
| 2386 | 2377 |
| 2387 static size_t findPlainText(CharacterIterator& it, const String& target, FindOpt
ions options, size_t& matchStart) | 2378 static size_t findPlainText(CharacterIterator& it, const String& target, FindOpt
ions options, size_t& matchStart) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2444 if (!matchLength) | 2435 if (!matchLength) |
| 2445 return collapsedToBoundary(range, !(options & Backwards)); | 2436 return collapsedToBoundary(range, !(options & Backwards)); |
| 2446 } | 2437 } |
| 2447 | 2438 |
| 2448 // Then, find the document position of the start and the end of the text. | 2439 // Then, find the document position of the start and the end of the text. |
| 2449 CharacterIterator computeRangeIterator(range, TextIteratorEntersTextControls
); | 2440 CharacterIterator computeRangeIterator(range, TextIteratorEntersTextControls
); |
| 2450 return characterSubrange(computeRangeIterator, matchStart, matchLength); | 2441 return characterSubrange(computeRangeIterator, matchStart, matchLength); |
| 2451 } | 2442 } |
| 2452 | 2443 |
| 2453 } | 2444 } |
| OLD | NEW |