Move more code to RenderTextLineBoxes
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Oct 2013 18:40:48 +0000 (18:40 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Oct 2013 18:40:48 +0000 (18:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122697

Reviewed by Andreas Kling.

* rendering/RenderTextLineBoxes.cpp:
(WebCore::RenderTextLineBoxes::boundingBox):
(WebCore::RenderTextLineBoxes::visualOverflowBoundingBox):
(WebCore::RenderTextLineBoxes::hasRenderedText):
(WebCore::RenderTextLineBoxes::caretMinOffset):
(WebCore::RenderTextLineBoxes::caretMaxOffset):

    Moved these.

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderText.h
Source/WebCore/rendering/RenderTextLineBoxes.cpp
Source/WebCore/rendering/RenderTextLineBoxes.h

index 2798730..d9940da 100644 (file)
@@ -1,3 +1,19 @@
+2013-10-12  Antti Koivisto  <antti@apple.com>
+
+        Move more code to RenderTextLineBoxes
+        https://bugs.webkit.org/show_bug.cgi?id=122697
+
+        Reviewed by Andreas Kling.
+
+        * rendering/RenderTextLineBoxes.cpp:
+        (WebCore::RenderTextLineBoxes::boundingBox):
+        (WebCore::RenderTextLineBoxes::visualOverflowBoundingBox):
+        (WebCore::RenderTextLineBoxes::hasRenderedText):
+        (WebCore::RenderTextLineBoxes::caretMinOffset):
+        (WebCore::RenderTextLineBoxes::caretMaxOffset):
+        
+            Moved these.
+
 2013-10-12  Alexey Proskuryakov  <ap@apple.com>
 
         Add a feature define for SubtleCrypto
index 2ae12a1..d91bfe6 100644 (file)
@@ -246,7 +246,7 @@ void RenderText::removeAndDestroyTextBoxes()
         } else if (parent())
             parent()->dirtyLinesFromChangedChild(this);
     }
-    deleteTextBoxes();
+    m_lineBoxes.deleteAll(*this);
 }
 
 void RenderText::willBeDestroyed()
@@ -1337,7 +1337,7 @@ String RenderText::textWithoutConvertingBackslashToYenSymbol() const
 void RenderText::dirtyLineBoxes(bool fullLayout)
 {
     if (fullLayout)
-        deleteTextBoxes();
+        m_lineBoxes.deleteAll(*this);
     else if (!m_linesDirty) {
         for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox())
             box->dirtyLineBoxes();
@@ -1415,53 +1415,12 @@ float RenderText::width(unsigned from, unsigned len, const Font& f, float xPos,
 
 IntRect RenderText::linesBoundingBox() const
 {
-    IntRect result;
-    
-    ASSERT(!firstTextBox() == !lastTextBox());  // Either both are null or both exist.
-    if (firstTextBox() && lastTextBox()) {
-        // Return the width of the minimal left side and the maximal right side.
-        float logicalLeftSide = 0;
-        float logicalRightSide = 0;
-        for (InlineTextBox* curr = firstTextBox(); curr; curr = curr->nextTextBox()) {
-            if (curr == firstTextBox() || curr->logicalLeft() < logicalLeftSide)
-                logicalLeftSide = curr->logicalLeft();
-            if (curr == firstTextBox() || curr->logicalRight() > logicalRightSide)
-                logicalRightSide = curr->logicalRight();
-        }
-        
-        bool isHorizontal = style()->isHorizontalWritingMode();
-        
-        float x = isHorizontal ? logicalLeftSide : firstTextBox()->x();
-        float y = isHorizontal ? firstTextBox()->y() : logicalLeftSide;
-        float width = isHorizontal ? logicalRightSide - logicalLeftSide : lastTextBox()->logicalBottom() - x;
-        float height = isHorizontal ? lastTextBox()->logicalBottom() - y : logicalRightSide - logicalLeftSide;
-        result = enclosingIntRect(FloatRect(x, y, width, height));
-    }
-
-    return result;
+    return m_lineBoxes.boundingBox(*this);
 }
 
 LayoutRect RenderText::linesVisualOverflowBoundingBox() const
 {
-    if (!firstTextBox())
-        return LayoutRect();
-
-    // Return the width of the minimal left side and the maximal right side.
-    LayoutUnit logicalLeftSide = LayoutUnit::max();
-    LayoutUnit logicalRightSide = LayoutUnit::min();
-    for (InlineTextBox* curr = firstTextBox(); curr; curr = curr->nextTextBox()) {
-        logicalLeftSide = min(logicalLeftSide, curr->logicalLeftVisualOverflow());
-        logicalRightSide = max(logicalRightSide, curr->logicalRightVisualOverflow());
-    }
-    
-    LayoutUnit logicalTop = firstTextBox()->logicalTopVisualOverflow();
-    LayoutUnit logicalWidth = logicalRightSide - logicalLeftSide;
-    LayoutUnit logicalHeight = lastTextBox()->logicalBottomVisualOverflow() - logicalTop;
-    
-    LayoutRect rect(logicalLeftSide, logicalTop, logicalWidth, logicalHeight);
-    if (!style()->isHorizontalWritingMode())
-        rect = rect.transposedRect();
-    return rect;
+    return m_lineBoxes.visualOverflowBoundingBox(*this);
 }
 
 LayoutRect RenderText::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
@@ -1528,34 +1487,17 @@ LayoutRect RenderText::selectionRectForRepaint(const RenderLayerModelObject* rep
 
 int RenderText::caretMinOffset() const
 {
-    InlineTextBox* box = firstTextBox();
-    if (!box)
-        return 0;
-    int minOffset = box->start();
-    for (box = box->nextTextBox(); box; box = box->nextTextBox())
-        minOffset = min<int>(minOffset, box->start());
-    return minOffset;
+    return m_lineBoxes.caretMinOffset();
 }
 
 int RenderText::caretMaxOffset() const
 {
-    InlineTextBox* box = lastTextBox();
-    if (!lastTextBox())
-        return textLength();
-
-    int maxOffset = box->start() + box->len();
-    for (box = box->prevTextBox(); box; box = box->prevTextBox())
-        maxOffset = max<int>(maxOffset, box->start() + box->len());
-    return maxOffset;
+    return m_lineBoxes.caretMaxOffset(*this);
 }
 
 bool RenderText::hasRenderedText() const
 {
-    for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
-        if (box->len())
-            return true;
-    }
-    return false;
+    return m_lineBoxes.hasRenderedText();
 }
 
 int RenderText::previousOffset(int current) const
index e0b1dac..fecea2e 100644 (file)
@@ -174,7 +174,6 @@ private:
 
     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction) OVERRIDE FINAL { ASSERT_NOT_REACHED(); return false; }
 
-    void deleteTextBoxes() { m_lineBoxes.deleteAll(*this); }
     bool containsOnlyWhitespace(unsigned from, unsigned len) const;
     float widthFromCache(const Font&, int start, int len, float xPos, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*) const;
     bool isAllASCII() const { return m_isAllASCII; }
index b16e396..76185b3 100644 (file)
@@ -27,6 +27,7 @@
 #include "RenderTextLineBoxes.h"
 
 #include "InlineTextBox.h"
+#include "RenderStyle.h"
 
 namespace WebCore {
 
@@ -106,7 +107,7 @@ void RenderTextLineBoxes::deleteAll(RenderText& renderer)
 {
     if (!m_first)
         return;
-    RenderArena& arena = renderer.renderArena();
+    auto& arena = renderer.renderArena();
     InlineTextBox* next;
     for (auto current = m_first; current; current = next) {
         next = current->nextTextBox();
@@ -132,6 +133,85 @@ InlineTextBox* RenderTextLineBoxes::findNext(int offset, int& position) const
     return current;
 }
 
+IntRect RenderTextLineBoxes::boundingBox(const RenderText& renderer) const
+{
+    if (!m_first)
+        return IntRect();
+
+    // Return the width of the minimal left side and the maximal right side.
+    float logicalLeftSide = 0;
+    float logicalRightSide = 0;
+    for (auto current = m_first; current; current = current->nextTextBox()) {
+        if (current == m_first || current->logicalLeft() < logicalLeftSide)
+            logicalLeftSide = current->logicalLeft();
+        if (current == m_first || current->logicalRight() > logicalRightSide)
+            logicalRightSide = current->logicalRight();
+    }
+    
+    bool isHorizontal = renderer.style()->isHorizontalWritingMode();
+    
+    float x = isHorizontal ? logicalLeftSide : m_first->x();
+    float y = isHorizontal ? m_first->y() : logicalLeftSide;
+    float width = isHorizontal ? logicalRightSide - logicalLeftSide : m_last->logicalBottom() - x;
+    float height = isHorizontal ? m_last->logicalBottom() - y : logicalRightSide - logicalLeftSide;
+    return enclosingIntRect(FloatRect(x, y, width, height));
+}
+
+LayoutRect RenderTextLineBoxes::visualOverflowBoundingBox(const RenderText& renderer) const
+{
+    if (!m_first)
+        return LayoutRect();
+
+    // Return the width of the minimal left side and the maximal right side.
+    auto logicalLeftSide = LayoutUnit::max();
+    auto logicalRightSide = LayoutUnit::min();
+    for (auto current = m_first; current; current = current->nextTextBox()) {
+        logicalLeftSide = std::min(logicalLeftSide, current->logicalLeftVisualOverflow());
+        logicalRightSide = std::max(logicalRightSide, current->logicalRightVisualOverflow());
+    }
+    
+    auto logicalTop = m_first->logicalTopVisualOverflow();
+    auto logicalWidth = logicalRightSide - logicalLeftSide;
+    auto logicalHeight = m_last->logicalBottomVisualOverflow() - logicalTop;
+    
+    LayoutRect rect(logicalLeftSide, logicalTop, logicalWidth, logicalHeight);
+    if (!renderer.style()->isHorizontalWritingMode())
+        rect = rect.transposedRect();
+    return rect;
+}
+
+bool RenderTextLineBoxes::hasRenderedText() const
+{
+    for (auto box = m_first; box; box = box->nextTextBox()) {
+        if (box->len())
+            return true;
+    }
+    return false;
+}
+
+int RenderTextLineBoxes::caretMinOffset() const
+{
+    auto box = m_first;
+    if (!box)
+        return 0;
+    int minOffset = box->start();
+    for (box = box->nextTextBox(); box; box = box->nextTextBox())
+        minOffset = std::min<int>(minOffset, box->start());
+    return minOffset;
+}
+
+int RenderTextLineBoxes::caretMaxOffset(const RenderText& renderer) const
+{
+    auto box = m_last;
+    if (!box)
+        return renderer.textLength();
+
+    int maxOffset = box->start() + box->len();
+    for (box = box->prevTextBox(); box; box = box->prevTextBox())
+        maxOffset = std::max<int>(maxOffset, box->start() + box->len());
+    return maxOffset;
+}
+
 #if !ASSERT_DISABLED
 RenderTextLineBoxes::~RenderTextLineBoxes()
 {
index 9d8c36a..acc770b 100644 (file)
 #ifndef RenderTextLineBoxes_h
 #define RenderTextLineBoxes_h
 
+#include "LayoutRect.h"
+
 namespace WebCore {
 
 class InlineTextBox;
+class RenderStyle;
 class RenderText;
 
 class RenderTextLineBoxes {
@@ -48,6 +51,13 @@ public:
 
     InlineTextBox* findNext(int offset, int& position) const;
 
+    bool hasRenderedText() const;
+    int caretMinOffset() const;
+    int caretMaxOffset(const RenderText&) const;
+
+    IntRect boundingBox(const RenderText&) const;
+    LayoutRect visualOverflowBoundingBox(const RenderText&) const;
+
 #if !ASSERT_DISABLED
     ~RenderTextLineBoxes();
 #endif