Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/editing/TextIterator.h" | 28 #include "core/editing/TextIterator.h" |
| 29 | 29 |
| 30 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 30 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 31 #include "core/HTMLNames.h" | 31 #include "core/HTMLNames.h" |
| 32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 33 #include "core/dom/FirstLetterPseudoElement.h" | |
| 33 #include "core/dom/NodeTraversal.h" | 34 #include "core/dom/NodeTraversal.h" |
| 34 #include "core/dom/shadow/ShadowRoot.h" | 35 #include "core/dom/shadow/ShadowRoot.h" |
| 35 #include "core/editing/VisiblePosition.h" | 36 #include "core/editing/VisiblePosition.h" |
| 36 #include "core/editing/VisibleUnits.h" | 37 #include "core/editing/VisibleUnits.h" |
| 37 #include "core/editing/htmlediting.h" | 38 #include "core/editing/htmlediting.h" |
| 38 #include "core/frame/FrameView.h" | 39 #include "core/frame/FrameView.h" |
| 39 #include "core/html/HTMLElement.h" | 40 #include "core/html/HTMLElement.h" |
| 40 #include "core/html/HTMLTextFormControlElement.h" | 41 #include "core/html/HTMLTextFormControlElement.h" |
| 41 #include "core/rendering/InlineTextBox.h" | 42 #include "core/rendering/InlineTextBox.h" |
| 42 #include "core/rendering/RenderImage.h" | 43 #include "core/rendering/RenderImage.h" |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 } | 755 } |
| 755 if (!m_textBox && m_remainingTextBox) { | 756 if (!m_textBox && m_remainingTextBox) { |
| 756 m_textBox = m_remainingTextBox; | 757 m_textBox = m_remainingTextBox; |
| 757 m_remainingTextBox = 0; | 758 m_remainingTextBox = 0; |
| 758 m_firstLetterText = nullptr; | 759 m_firstLetterText = nullptr; |
| 759 m_offset = 0; | 760 m_offset = 0; |
| 760 handleTextBox(); | 761 handleTextBox(); |
| 761 } | 762 } |
| 762 } | 763 } |
| 763 | 764 |
| 764 static inline RenderText* firstRenderTextInFirstLetter(RenderBoxModelObject* fir stLetter) | |
| 765 { | |
| 766 if (!firstLetter) | |
| 767 return 0; | |
| 768 | |
| 769 // FIXME: Should this check descendent objects? | |
| 770 for (RenderObject* current = firstLetter->slowFirstChild(); current; current = current->nextSibling()) { | |
| 771 if (current->isText()) | |
| 772 return toRenderText(current); | |
| 773 } | |
| 774 return 0; | |
| 775 } | |
| 776 | |
| 777 void TextIterator::handleTextNodeFirstLetter(RenderTextFragment* renderer) | 765 void TextIterator::handleTextNodeFirstLetter(RenderTextFragment* renderer) |
| 778 { | 766 { |
| 779 if (renderer->firstLetter()) { | 767 if (FirstLetterPseudoElement* firstLetterElement = renderer->firstLetterPseu doElement()) { |
| 780 RenderBoxModelObject* r = renderer->firstLetter(); | 768 RenderObject* pseudoRenderer = firstLetterElement->renderer(); |
| 781 if (r->style()->visibility() != VISIBLE && !m_ignoresStyleVisibility) | 769 if (pseudoRenderer->style()->visibility() != VISIBLE && !m_ignoresStyleV isibility) |
| 782 return; | 770 return; |
| 783 if (RenderText* firstLetter = firstRenderTextInFirstLetter(r)) { | 771 |
| 784 m_handledFirstLetter = true; | 772 RenderObject* firstLetter = pseudoRenderer->slowFirstChild(); |
| 785 m_remainingTextBox = m_textBox; | 773 ASSERT(firstLetter); |
| 786 m_textBox = firstLetter->firstTextBox(); | 774 |
| 787 m_sortedTextBoxes.clear(); | 775 m_handledFirstLetter = true; |
| 788 m_firstLetterText = firstLetter; | 776 m_remainingTextBox = m_textBox; |
| 789 } | 777 m_textBox = toRenderText(firstLetter)->firstTextBox(); |
| 778 m_sortedTextBoxes.clear(); | |
| 779 m_firstLetterText = toRenderText(firstLetter); | |
| 790 } | 780 } |
| 791 m_handledFirstLetter = true; | 781 m_handledFirstLetter = true; |
| 792 } | 782 } |
| 793 | 783 |
| 794 bool TextIterator::handleReplacedElement() | 784 bool TextIterator::handleReplacedElement() |
| 795 { | 785 { |
| 796 if (m_fullyClippedStack.top()) | 786 if (m_fullyClippedStack.top()) |
| 797 return false; | 787 return false; |
| 798 | 788 |
| 799 RenderObject* renderer = m_node->renderer(); | 789 RenderObject* renderer = m_node->renderer(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 m_textLength = 0; | 833 m_textLength = 0; |
| 844 m_lastCharacter = 0; | 834 m_lastCharacter = 0; |
| 845 | 835 |
| 846 return true; | 836 return true; |
| 847 } | 837 } |
| 848 | 838 |
| 849 bool TextIterator::hasVisibleTextNode(RenderText* renderer) | 839 bool TextIterator::hasVisibleTextNode(RenderText* renderer) |
| 850 { | 840 { |
| 851 if (renderer->style()->visibility() == VISIBLE) | 841 if (renderer->style()->visibility() == VISIBLE) |
| 852 return true; | 842 return true; |
| 853 if (renderer->isTextFragment()) { | 843 if (renderer->isTextFragment() && toRenderTextFragment(renderer)->firstLette rPseudoElement()) { |
| 854 RenderTextFragment* fragment = toRenderTextFragment(renderer); | 844 RenderObject* pseudoElementRenderer = toRenderTextFragment(renderer)->fi rstLetterPseudoElement()->renderer(); |
| 855 if (fragment->firstLetter() && fragment->firstLetter()->style()->visibil ity() == VISIBLE) | 845 if (pseudoElementRenderer && pseudoElementRenderer->style()->visibility( ) == VISIBLE) |
| 856 return true; | 846 return true; |
| 857 } | 847 } |
| 858 return false; | 848 return false; |
| 859 } | 849 } |
| 860 | 850 |
| 861 static bool shouldEmitTabBeforeNode(Node* node) | 851 static bool shouldEmitTabBeforeNode(Node* node) |
| 862 { | 852 { |
| 863 RenderObject* r = node->renderer(); | 853 RenderObject* r = node->renderer(); |
| 864 | 854 |
| 865 // Table cells are delimited by tabs. | 855 // Table cells are delimited by tabs. |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 } | 1511 } |
| 1522 | 1512 |
| 1523 if (!m_shouldHandleFirstLetter && offsetAfterFirstLetter < m_offset) { | 1513 if (!m_shouldHandleFirstLetter && offsetAfterFirstLetter < m_offset) { |
| 1524 m_shouldHandleFirstLetter = true; | 1514 m_shouldHandleFirstLetter = true; |
| 1525 offsetInNode = offsetAfterFirstLetter; | 1515 offsetInNode = offsetAfterFirstLetter; |
| 1526 return renderer; | 1516 return renderer; |
| 1527 } | 1517 } |
| 1528 | 1518 |
| 1529 m_shouldHandleFirstLetter = false; | 1519 m_shouldHandleFirstLetter = false; |
| 1530 offsetInNode = 0; | 1520 offsetInNode = 0; |
| 1531 RenderText* firstLetterRenderer = firstRenderTextInFirstLetter(fragment->fir stLetter()); | 1521 |
| 1522 ASSERT(fragment->firstLetterPseudoElement()); | |
| 1523 | |
| 1524 RenderObject* pseudoElementRenderer = fragment->firstLetterPseudoElement()-> renderer(); | |
| 1525 ASSERT(pseudoElementRenderer && pseudoElementRenderer->slowFirstChild()); | |
|
Julien - ping for review
2014/10/10 22:47:23
Let's split this ASSERT in 2 (cf my rationale earl
dsinclair
2014/10/14 14:31:28
Done.
| |
| 1526 RenderText* firstLetterRenderer = toRenderText(pseudoElementRenderer->slowFi rstChild()); | |
| 1532 | 1527 |
| 1533 m_offset = firstLetterRenderer->caretMaxOffset(); | 1528 m_offset = firstLetterRenderer->caretMaxOffset(); |
| 1534 m_offset += collapsedSpaceLength(firstLetterRenderer, m_offset); | 1529 m_offset += collapsedSpaceLength(firstLetterRenderer, m_offset); |
| 1535 | 1530 |
| 1536 return firstLetterRenderer; | 1531 return firstLetterRenderer; |
| 1537 } | 1532 } |
| 1538 | 1533 |
| 1539 bool SimplifiedBackwardsTextIterator::handleReplacedElement() | 1534 bool SimplifiedBackwardsTextIterator::handleReplacedElement() |
| 1540 { | 1535 { |
| 1541 unsigned index = m_node->nodeIndex(); | 1536 unsigned index = m_node->nodeIndex(); |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2421 resultEnd = collapseTo; | 2416 resultEnd = collapseTo; |
| 2422 return; | 2417 return; |
| 2423 } | 2418 } |
| 2424 } | 2419 } |
| 2425 | 2420 |
| 2426 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo rFindPlainText); | 2421 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo rFindPlainText); |
| 2427 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re sultStart, resultEnd); | 2422 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re sultStart, resultEnd); |
| 2428 } | 2423 } |
| 2429 | 2424 |
| 2430 } | 2425 } |
| OLD | NEW |