| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio
r) | 243 TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio
r) |
| 244 : m_startContainer(nullptr) | 244 : m_startContainer(nullptr) |
| 245 , m_startOffset(0) | 245 , m_startOffset(0) |
| 246 , m_endContainer(nullptr) | 246 , m_endContainer(nullptr) |
| 247 , m_endOffset(0) | 247 , m_endOffset(0) |
| 248 , m_positionNode(nullptr) | 248 , m_positionNode(nullptr) |
| 249 , m_textLength(0) | 249 , m_textLength(0) |
| 250 , m_needsAnotherNewline(false) | 250 , m_needsAnotherNewline(false) |
| 251 , m_textBox(0) | 251 , m_textBox(0) |
| 252 , m_remainingTextBox(0) | 252 , m_remainingTextBox(0) |
| 253 , m_firstLetterText(nullptr) | 253 , m_firstLetterText(0) |
| 254 , m_lastTextNode(nullptr) | 254 , m_lastTextNode(nullptr) |
| 255 , m_lastTextNodeEndedWithCollapsedSpace(false) | 255 , m_lastTextNodeEndedWithCollapsedSpace(false) |
| 256 , m_lastCharacter(0) | 256 , m_lastCharacter(0) |
| 257 , m_sortedTextBoxesPosition(0) | 257 , m_sortedTextBoxesPosition(0) |
| 258 , m_hasEmitted(false) | 258 , m_hasEmitted(false) |
| 259 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh
aractersBetweenAllVisiblePositions) | 259 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh
aractersBetweenAllVisiblePositions) |
| 260 , m_entersTextControls(behavior & TextIteratorEntersTextControls) | 260 , m_entersTextControls(behavior & TextIteratorEntersTextControls) |
| 261 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) | 261 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) |
| 262 , m_handledFirstLetter(false) | 262 , m_handledFirstLetter(false) |
| 263 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) | 263 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 274 TextIterator::TextIterator(const Position& start, const Position& end, TextItera
torBehaviorFlags behavior) | 274 TextIterator::TextIterator(const Position& start, const Position& end, TextItera
torBehaviorFlags behavior) |
| 275 : m_startContainer(nullptr) | 275 : m_startContainer(nullptr) |
| 276 , m_startOffset(0) | 276 , m_startOffset(0) |
| 277 , m_endContainer(nullptr) | 277 , m_endContainer(nullptr) |
| 278 , m_endOffset(0) | 278 , m_endOffset(0) |
| 279 , m_positionNode(nullptr) | 279 , m_positionNode(nullptr) |
| 280 , m_textLength(0) | 280 , m_textLength(0) |
| 281 , m_needsAnotherNewline(false) | 281 , m_needsAnotherNewline(false) |
| 282 , m_textBox(0) | 282 , m_textBox(0) |
| 283 , m_remainingTextBox(0) | 283 , m_remainingTextBox(0) |
| 284 , m_firstLetterText(nullptr) | 284 , m_firstLetterText(0) |
| 285 , m_lastTextNode(nullptr) | 285 , m_lastTextNode(nullptr) |
| 286 , m_lastTextNodeEndedWithCollapsedSpace(false) | 286 , m_lastTextNodeEndedWithCollapsedSpace(false) |
| 287 , m_lastCharacter(0) | 287 , m_lastCharacter(0) |
| 288 , m_sortedTextBoxesPosition(0) | 288 , m_sortedTextBoxesPosition(0) |
| 289 , m_hasEmitted(false) | 289 , m_hasEmitted(false) |
| 290 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh
aractersBetweenAllVisiblePositions) | 290 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh
aractersBetweenAllVisiblePositions) |
| 291 , m_entersTextControls(behavior & TextIteratorEntersTextControls) | 291 , m_entersTextControls(behavior & TextIteratorEntersTextControls) |
| 292 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) | 292 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) |
| 293 , m_handledFirstLetter(false) | 293 , m_handledFirstLetter(false) |
| 294 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) | 294 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // iteration, instead of using m_needsAnotherNewline. | 389 // iteration, instead of using m_needsAnotherNewline. |
| 390 Node* baseNode = m_node->lastChild() ? m_node->lastChild() : m_node.get(
); | 390 Node* baseNode = m_node->lastChild() ? m_node->lastChild() : m_node.get(
); |
| 391 emitCharacter('\n', baseNode->parentNode(), baseNode, 1, 1); | 391 emitCharacter('\n', baseNode->parentNode(), baseNode, 1, 1); |
| 392 m_needsAnotherNewline = false; | 392 m_needsAnotherNewline = false; |
| 393 return; | 393 return; |
| 394 } | 394 } |
| 395 | 395 |
| 396 if (!m_textBox && m_remainingTextBox) { | 396 if (!m_textBox && m_remainingTextBox) { |
| 397 m_textBox = m_remainingTextBox; | 397 m_textBox = m_remainingTextBox; |
| 398 m_remainingTextBox = 0; | 398 m_remainingTextBox = 0; |
| 399 m_firstLetterText = nullptr; | 399 m_firstLetterText = 0; |
| 400 m_offset = 0; | 400 m_offset = 0; |
| 401 } | 401 } |
| 402 // handle remembered text box | 402 // handle remembered text box |
| 403 if (m_textBox) { | 403 if (m_textBox) { |
| 404 handleTextBox(); | 404 handleTextBox(); |
| 405 if (m_positionNode) | 405 if (m_positionNode) |
| 406 return; | 406 return; |
| 407 } | 407 } |
| 408 | 408 |
| 409 while (m_node && (m_node != m_pastEndNode || m_shadowDepth > 0)) { | 409 while (m_node && (m_node != m_pastEndNode || m_shadowDepth > 0)) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 530 } |
| 531 } else { | 531 } else { |
| 532 // If we are in a user-agent shadow root, then go back t
o the host. | 532 // If we are in a user-agent shadow root, then go back t
o the host. |
| 533 ASSERT(shadowRoot->type() == ShadowRoot::UserAgentShadow
Root); | 533 ASSERT(shadowRoot->type() == ShadowRoot::UserAgentShadow
Root); |
| 534 m_node = shadowRoot->host(); | 534 m_node = shadowRoot->host(); |
| 535 m_iterationProgress = HandledUserAgentShadowRoot; | 535 m_iterationProgress = HandledUserAgentShadowRoot; |
| 536 --m_shadowDepth; | 536 --m_shadowDepth; |
| 537 m_fullyClippedStack.pop(); | 537 m_fullyClippedStack.pop(); |
| 538 } | 538 } |
| 539 m_handledFirstLetter = false; | 539 m_handledFirstLetter = false; |
| 540 m_firstLetterText = nullptr; | 540 m_firstLetterText = 0; |
| 541 continue; | 541 continue; |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 m_fullyClippedStack.pop(); | 544 m_fullyClippedStack.pop(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 // set the new current node | 547 // set the new current node |
| 548 m_node = next; | 548 m_node = next; |
| 549 if (m_node) | 549 if (m_node) |
| 550 pushFullyClippedState(m_fullyClippedStack, m_node); | 550 pushFullyClippedState(m_fullyClippedStack, m_node); |
| 551 m_iterationProgress = HandledNone; | 551 m_iterationProgress = HandledNone; |
| 552 m_handledFirstLetter = false; | 552 m_handledFirstLetter = false; |
| 553 m_firstLetterText = nullptr; | 553 m_firstLetterText = 0; |
| 554 | 554 |
| 555 // how would this ever be? | 555 // how would this ever be? |
| 556 if (m_positionNode) | 556 if (m_positionNode) |
| 557 return; | 557 return; |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 UChar TextIterator::characterAt(unsigned index) const | 561 UChar TextIterator::characterAt(unsigned index) const |
| 562 { | 562 { |
| 563 ASSERT_WITH_SECURITY_IMPLICATION(index < static_cast<unsigned>(length())); | 563 ASSERT_WITH_SECURITY_IMPLICATION(index < static_cast<unsigned>(length())); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 int runStart = m_offset; | 615 int runStart = m_offset; |
| 616 if (m_lastTextNodeEndedWithCollapsedSpace && hasVisibleTextNode(renderer
)) { | 616 if (m_lastTextNodeEndedWithCollapsedSpace && hasVisibleTextNode(renderer
)) { |
| 617 emitCharacter(' ', m_node, 0, runStart, runStart); | 617 emitCharacter(' ', m_node, 0, runStart, runStart); |
| 618 return false; | 618 return false; |
| 619 } | 619 } |
| 620 if (!m_handledFirstLetter && renderer->isTextFragment() && !m_offset) { | 620 if (!m_handledFirstLetter && renderer->isTextFragment() && !m_offset) { |
| 621 handleTextNodeFirstLetter(toRenderTextFragment(renderer)); | 621 handleTextNodeFirstLetter(toRenderTextFragment(renderer)); |
| 622 if (m_firstLetterText) { | 622 if (m_firstLetterText) { |
| 623 String firstLetter = m_firstLetterText->text(); | 623 String firstLetter = m_firstLetterText->text(); |
| 624 emitText(m_node, m_firstLetterText, m_offset, m_offset + firstLe
tter.length()); | 624 emitText(m_node, m_firstLetterText, m_offset, m_offset + firstLe
tter.length()); |
| 625 m_firstLetterText = nullptr; | 625 m_firstLetterText = 0; |
| 626 m_textBox = 0; | 626 m_textBox = 0; |
| 627 return false; | 627 return false; |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibil
ity) | 630 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibil
ity) |
| 631 return false; | 631 return false; |
| 632 int strLength = str.length(); | 632 int strLength = str.length(); |
| 633 int end = (m_node == m_endContainer) ? m_endOffset : INT_MAX; | 633 int end = (m_node == m_endContainer) ? m_endOffset : INT_MAX; |
| 634 int runEnd = std::min(strLength, end); | 634 int runEnd = std::min(strLength, end); |
| 635 | 635 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 m_sortedTextBoxesPosition = 0; | 667 m_sortedTextBoxesPosition = 0; |
| 668 m_textBox = m_sortedTextBoxes.isEmpty() ? 0 : m_sortedTextBoxes[0]; | 668 m_textBox = m_sortedTextBoxes.isEmpty() ? 0 : m_sortedTextBoxes[0]; |
| 669 } | 669 } |
| 670 | 670 |
| 671 handleTextBox(); | 671 handleTextBox(); |
| 672 return true; | 672 return true; |
| 673 } | 673 } |
| 674 | 674 |
| 675 void TextIterator::handleTextBox() | 675 void TextIterator::handleTextBox() |
| 676 { | 676 { |
| 677 RenderText* renderer = m_firstLetterText ? m_firstLetterText.get() : toRende
rText(m_node->renderer()); | 677 RenderText* renderer = m_firstLetterText ? m_firstLetterText : toRenderText(
m_node->renderer()); |
| 678 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibility)
{ | 678 if (renderer->style()->visibility() != VISIBLE && !m_ignoresStyleVisibility)
{ |
| 679 m_textBox = 0; | 679 m_textBox = 0; |
| 680 return; | 680 return; |
| 681 } | 681 } |
| 682 String str = renderer->text(); | 682 String str = renderer->text(); |
| 683 unsigned start = m_offset; | 683 unsigned start = m_offset; |
| 684 unsigned end = (m_node == m_endContainer) ? static_cast<unsigned>(m_endOffse
t) : INT_MAX; | 684 unsigned end = (m_node == m_endContainer) ? static_cast<unsigned>(m_endOffse
t) : INT_MAX; |
| 685 while (m_textBox) { | 685 while (m_textBox) { |
| 686 unsigned textBoxStart = m_textBox->start(); | 686 unsigned textBoxStart = m_textBox->start(); |
| 687 unsigned runStart = std::max(textBoxStart, start); | 687 unsigned runStart = std::max(textBoxStart, start); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 return; | 745 return; |
| 746 } | 746 } |
| 747 // Advance and continue | 747 // Advance and continue |
| 748 m_textBox = nextTextBox; | 748 m_textBox = nextTextBox; |
| 749 if (renderer->containsReversedText()) | 749 if (renderer->containsReversedText()) |
| 750 ++m_sortedTextBoxesPosition; | 750 ++m_sortedTextBoxesPosition; |
| 751 } | 751 } |
| 752 if (!m_textBox && m_remainingTextBox) { | 752 if (!m_textBox && m_remainingTextBox) { |
| 753 m_textBox = m_remainingTextBox; | 753 m_textBox = m_remainingTextBox; |
| 754 m_remainingTextBox = 0; | 754 m_remainingTextBox = 0; |
| 755 m_firstLetterText = nullptr; | 755 m_firstLetterText = 0; |
| 756 m_offset = 0; | 756 m_offset = 0; |
| 757 handleTextBox(); | 757 handleTextBox(); |
| 758 } | 758 } |
| 759 } | 759 } |
| 760 | 760 |
| 761 static inline RenderText* firstRenderTextInFirstLetter(RenderBoxModelObject* fir
stLetter) | 761 static inline RenderText* firstRenderTextInFirstLetter(RenderBoxModelObject* fir
stLetter) |
| 762 { | 762 { |
| 763 if (!firstLetter) | 763 if (!firstLetter) |
| 764 return 0; | 764 return 0; |
| 765 | 765 |
| (...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 resultEnd = collapseTo; | 2220 resultEnd = collapseTo; |
| 2221 return; | 2221 return; |
| 2222 } | 2222 } |
| 2223 } | 2223 } |
| 2224 | 2224 |
| 2225 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); | 2225 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo
rFindPlainText); |
| 2226 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); | 2226 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re
sultStart, resultEnd); |
| 2227 } | 2227 } |
| 2228 | 2228 |
| 2229 } | 2229 } |
| OLD | NEW |