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 (renderer->firstLetterPseudoElement()) { |
|
Julien - ping for review
2014/10/09 18:24:48
if (FirstLetterPseudoElement* firstLetterElement =
dsinclair
2014/10/09 21:14:22
Done.
| |
| 780 RenderBoxModelObject* r = renderer->firstLetter(); | 768 RenderObject* pseudoRenderer = renderer->firstLetterPseudoElement()->ren derer(); |
| 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 // First letter pseudo elements only have one child which is the text. |
|
Julien - ping for review
2014/10/09 18:24:48
This comment sounds like the following 'if' is not
dsinclair
2014/10/09 21:14:22
Changed it to an ASSERT as it should always exist.
| |
| 772 if (RenderObject* firstLetter = pseudoRenderer->slowFirstChild()) { | |
| 784 m_handledFirstLetter = true; | 773 m_handledFirstLetter = true; |
| 785 m_remainingTextBox = m_textBox; | 774 m_remainingTextBox = m_textBox; |
| 786 m_textBox = firstLetter->firstTextBox(); | 775 m_textBox = toRenderText(firstLetter)->firstTextBox(); |
| 787 m_sortedTextBoxes.clear(); | 776 m_sortedTextBoxes.clear(); |
| 788 m_firstLetterText = firstLetter; | 777 m_firstLetterText = toRenderText(firstLetter); |
| 789 } | 778 } |
| 790 } | 779 } |
| 791 m_handledFirstLetter = true; | 780 m_handledFirstLetter = true; |
| 792 } | 781 } |
| 793 | 782 |
| 794 bool TextIterator::handleReplacedElement() | 783 bool TextIterator::handleReplacedElement() |
| 795 { | 784 { |
| 796 if (m_fullyClippedStack.top()) | 785 if (m_fullyClippedStack.top()) |
| 797 return false; | 786 return false; |
| 798 | 787 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 m_textLength = 0; | 832 m_textLength = 0; |
| 844 m_lastCharacter = 0; | 833 m_lastCharacter = 0; |
| 845 | 834 |
| 846 return true; | 835 return true; |
| 847 } | 836 } |
| 848 | 837 |
| 849 bool TextIterator::hasVisibleTextNode(RenderText* renderer) | 838 bool TextIterator::hasVisibleTextNode(RenderText* renderer) |
| 850 { | 839 { |
| 851 if (renderer->style()->visibility() == VISIBLE) | 840 if (renderer->style()->visibility() == VISIBLE) |
| 852 return true; | 841 return true; |
| 853 if (renderer->isTextFragment()) { | 842 if (renderer->isTextFragment() && toRenderTextFragment(renderer)->firstLette rPseudoElement()) { |
| 854 RenderTextFragment* fragment = toRenderTextFragment(renderer); | 843 RenderObject* pseudoElement = toRenderTextFragment(renderer)->firstLette rPseudoElement()->renderer(); |
|
Julien - ping for review
2014/10/09 18:24:48
We do a lot of NULL-check against the :first-lette
dsinclair
2014/10/09 21:14:22
The spec doesn't list display as valid in first-le
| |
| 855 if (fragment->firstLetter() && fragment->firstLetter()->style()->visibil ity() == VISIBLE) | 844 if (pseudoElement && pseudoElement->style()->visibility() == VISIBLE) |
| 856 return true; | 845 return true; |
| 857 } | 846 } |
| 858 return false; | 847 return false; |
| 859 } | 848 } |
| 860 | 849 |
| 861 static bool shouldEmitTabBeforeNode(Node* node) | 850 static bool shouldEmitTabBeforeNode(Node* node) |
| 862 { | 851 { |
| 863 RenderObject* r = node->renderer(); | 852 RenderObject* r = node->renderer(); |
| 864 | 853 |
| 865 // Table cells are delimited by tabs. | 854 // Table cells are delimited by tabs. |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 } | 1510 } |
| 1522 | 1511 |
| 1523 if (!m_shouldHandleFirstLetter && offsetAfterFirstLetter < m_offset) { | 1512 if (!m_shouldHandleFirstLetter && offsetAfterFirstLetter < m_offset) { |
| 1524 m_shouldHandleFirstLetter = true; | 1513 m_shouldHandleFirstLetter = true; |
| 1525 offsetInNode = offsetAfterFirstLetter; | 1514 offsetInNode = offsetAfterFirstLetter; |
| 1526 return renderer; | 1515 return renderer; |
| 1527 } | 1516 } |
| 1528 | 1517 |
| 1529 m_shouldHandleFirstLetter = false; | 1518 m_shouldHandleFirstLetter = false; |
| 1530 offsetInNode = 0; | 1519 offsetInNode = 0; |
| 1531 RenderText* firstLetterRenderer = firstRenderTextInFirstLetter(fragment->fir stLetter()); | 1520 |
| 1521 ASSERT(fragment->firstLetterPseudoElement()); | |
| 1522 | |
| 1523 RenderObject* pseudoElement = fragment->firstLetterPseudoElement()->renderer (); | |
|
Julien - ping for review
2014/10/09 18:24:48
s/pseudoElement/pseudoElementRenderer/
dsinclair
2014/10/09 21:14:22
Done.
| |
| 1524 ASSERT(pseudoElement && pseudoElement->slowFirstChild()); | |
| 1525 RenderText* firstLetterRenderer = toRenderText(pseudoElement->slowFirstChild ()); | |
| 1532 | 1526 |
| 1533 m_offset = firstLetterRenderer->caretMaxOffset(); | 1527 m_offset = firstLetterRenderer->caretMaxOffset(); |
| 1534 m_offset += collapsedSpaceLength(firstLetterRenderer, m_offset); | 1528 m_offset += collapsedSpaceLength(firstLetterRenderer, m_offset); |
| 1535 | 1529 |
| 1536 return firstLetterRenderer; | 1530 return firstLetterRenderer; |
| 1537 } | 1531 } |
| 1538 | 1532 |
| 1539 bool SimplifiedBackwardsTextIterator::handleReplacedElement() | 1533 bool SimplifiedBackwardsTextIterator::handleReplacedElement() |
| 1540 { | 1534 { |
| 1541 unsigned index = m_node->nodeIndex(); | 1535 unsigned index = m_node->nodeIndex(); |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2421 resultEnd = collapseTo; | 2415 resultEnd = collapseTo; |
| 2422 return; | 2416 return; |
| 2423 } | 2417 } |
| 2424 } | 2418 } |
| 2425 | 2419 |
| 2426 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo rFindPlainText); | 2420 CharacterIterator computeRangeIterator(inputStart, inputEnd, iteratorFlagsFo rFindPlainText); |
| 2427 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re sultStart, resultEnd); | 2421 calculateCharacterSubrange(computeRangeIterator, matchStart, matchLength, re sultStart, resultEnd); |
| 2428 } | 2422 } |
| 2429 | 2423 |
| 2430 } | 2424 } |
| OLD | NEW |