RenderTextFragment: Tighten first-letter logic.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Nov 2013 00:39:21 +0000 (00:39 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Nov 2013 00:39:21 +0000 (00:39 +0000)
<https://webkit.org/b/123714>

Reviewed by Antti Koivisto.

* editing/TextIterator.cpp:
(WebCore::firstRenderTextInFirstLetter):

    Use iterator helper to find first RenderText child.

(WebCore::TextIterator::handleTextNodeFirstLetter):

    Tightening through type inference.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::updateFirstLetterStyle):
(WebCore::RenderBlock::createFirstLetterRenderer):
* rendering/RenderTextFragment.h:

    The first letter renderer is always a RenderBoxModelObject,
    so make the code deal in that instead of RenderObject.

* rendering/RenderChildIterator.h:
(WebCore::RenderChildIteratorAdapter::first):
(WebCore::RenderChildIteratorAdapter::last):

    Remove excess ampersands that were keeping this from building.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158551 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderChildIterator.h
Source/WebCore/rendering/RenderTextFragment.h

index fb4296a..b0f9155 100644 (file)
@@ -1,5 +1,35 @@
 2013-11-03  Andreas Kling  <akling@apple.com>
 
+        RenderTextFragment: Tighten first-letter logic.
+        <https://webkit.org/b/123714>
+
+        Reviewed by Antti Koivisto.
+
+        * editing/TextIterator.cpp:
+        (WebCore::firstRenderTextInFirstLetter):
+
+            Use iterator helper to find first RenderText child.
+
+        (WebCore::TextIterator::handleTextNodeFirstLetter):
+
+            Tightening through type inference.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::updateFirstLetterStyle):
+        (WebCore::RenderBlock::createFirstLetterRenderer):
+        * rendering/RenderTextFragment.h:
+
+            The first letter renderer is always a RenderBoxModelObject,
+            so make the code deal in that instead of RenderObject.
+
+        * rendering/RenderChildIterator.h:
+        (WebCore::RenderChildIteratorAdapter::first):
+        (WebCore::RenderChildIteratorAdapter::last):
+
+            Remove excess ampersands that were keeping this from building.
+
+2013-11-03  Andreas Kling  <akling@apple.com>
+
         CSSPrimitiveValue identifier constructors should return PassRef.
         <https://webkit.org/b/123712>
 
index b79f61a..acc81d3 100644 (file)
@@ -37,6 +37,7 @@
 #include "InlineTextBox.h"
 #include "NodeTraversal.h"
 #include "RenderImage.h"
+#include "RenderIterator.h"
 #include "RenderTableCell.h"
 #include "RenderTableRow.h"
 #include "RenderTextControl.h"
@@ -665,31 +666,26 @@ void TextIterator::handleTextBox()
     }
 }
 
-static inline RenderText* firstRenderTextInFirstLetter(RenderObject* firstLetter)
+static inline RenderText* firstRenderTextInFirstLetter(RenderBoxModelObject* firstLetter)
 {
     if (!firstLetter)
-        return 0;
+        return nullptr;
 
     // FIXME: Should this check descendent objects?
-    for (RenderObject* current = firstLetter->firstChildSlow(); current; current = current->nextSibling()) {
-        if (current->isText())
-            return toRenderText(current);
-    }
-    return 0;
+    return childrenOfType<RenderText>(*firstLetter).first();
 }
 
 void TextIterator::handleTextNodeFirstLetter(RenderTextFragment* renderer)
 {
-    if (renderer->firstLetter()) {
-        RenderObject* r = renderer->firstLetter();
-        if (r->style().visibility() != VISIBLE && !m_ignoresStyleVisibility)
+    if (auto firstLetter = renderer->firstLetter()) {
+        if (firstLetter->style().visibility() != VISIBLE && !m_ignoresStyleVisibility)
             return;
-        if (RenderText* firstLetter = firstRenderTextInFirstLetter(r)) {
+        if (RenderText* firstLetterText = firstRenderTextInFirstLetter(firstLetter)) {
             m_handledFirstLetter = true;
             m_remainingTextBox = m_textBox;
-            m_textBox = firstLetter->firstTextBox();
+            m_textBox = firstLetterText->firstTextBox();
             m_sortedTextBoxes.clear();
-            m_firstLetterText = firstLetter;
+            m_firstLetterText = firstLetterText;
         }
     }
     m_handledFirstLetter = true;
index 8166e8e..43800ed 100644 (file)
@@ -4755,7 +4755,7 @@ void RenderBlock::updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderO
         if (RenderTextFragment* remainingText = toRenderBoxModelObject(firstLetter)->firstLetterRemainingText()) {
             ASSERT(remainingText->isAnonymous() || remainingText->textNode()->renderer() == remainingText);
             // Replace the old renderer with the new one.
-            remainingText->setFirstLetter(newFirstLetter);
+            remainingText->setFirstLetter(*newFirstLetter);
             newFirstLetter->setFirstLetterRemainingText(remainingText);
         }
         // To prevent removal of single anonymous block in RenderBlock::removeChild and causing
@@ -4821,7 +4821,7 @@ void RenderBlock::createFirstLetterRenderer(RenderObject* firstLetterBlock, Rend
 
         firstLetterContainer->addChild(remainingText, currentTextChild);
         firstLetterContainer->removeChild(*currentTextChild);
-        remainingText->setFirstLetter(firstLetter);
+        remainingText->setFirstLetter(*firstLetter);
         firstLetter->setFirstLetterRemainingText(remainingText);
         
         // construct text fragment for the first letter
index f6f6d52..b5fcd0f 100644 (file)
@@ -140,13 +140,13 @@ inline RenderChildIterator<T> RenderChildIteratorAdapter<T>::end()
 template <typename T>
 inline T* RenderChildIteratorAdapter<T>::first()
 {
-    return RenderTraversal::firstChild<T>(&m_parent);
+    return RenderTraversal::firstChild<T>(m_parent);
 }
 
 template <typename T>
 inline T* RenderChildIteratorAdapter<T>::last()
 {
-    return RenderTraversal::lastChild<T>(&m_parent);
+    return RenderTraversal::lastChild<T>(m_parent);
 }
 
 // RenderChildConstIteratorAdapter
index b1a42b3..a467090 100644 (file)
@@ -46,8 +46,8 @@ public:
     unsigned start() const { return m_start; }
     unsigned end() const { return m_end; }
 
-    RenderObject* firstLetter() const { return m_firstLetter; }
-    void setFirstLetter(RenderObject* firstLetter) { m_firstLetter = firstLetter; }
+    RenderBoxModelObject* firstLetter() const { return m_firstLetter; }
+    void setFirstLetter(RenderBoxModelObject& firstLetter) { m_firstLetter = &firstLetter; }
 
     StringImpl* contentString() const { return m_contentString.impl(); }
     virtual String originalText() const OVERRIDE;
@@ -66,7 +66,7 @@ private:
     unsigned m_start;
     unsigned m_end;
     String m_contentString;
-    RenderObject* m_firstLetter;
+    RenderBoxModelObject* m_firstLetter;
 };
 
 inline RenderTextFragment* toRenderTextFragment(RenderObject* object)