Apply more unique_ptr to line box management.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Nov 2013 04:47:12 +0000 (04:47 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Nov 2013 04:47:12 +0000 (04:47 +0000)
<https://webkit.org/b/123857>

Make all of the functions that return newly-created line boxes
return them packed up in std::unique_ptrs.

There is one exception in RenderBlockLineLayout where the function
createInlineBoxForRenderer() is inconsistent about the ownership of
the returned object. This will be addressed by a subsequent patch.

We now "release" the line boxes into their various home structures,
so the pointer smartness doesn't go end-to-end just yet.

Reviewed by Anders Carlsson.

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

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlockFlow.h
Source/WebCore/rendering/RenderBlockLineLayout.cpp
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBox.h
Source/WebCore/rendering/RenderInline.cpp
Source/WebCore/rendering/RenderInline.h
Source/WebCore/rendering/RenderLineBoxList.cpp
Source/WebCore/rendering/RenderLineBoxList.h
Source/WebCore/rendering/RenderLineBreak.cpp
Source/WebCore/rendering/RenderLineBreak.h
Source/WebCore/rendering/RenderListMarker.cpp
Source/WebCore/rendering/RenderListMarker.h
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderText.h
Source/WebCore/rendering/RenderTextLineBoxes.cpp
Source/WebCore/rendering/svg/RenderSVGInline.cpp
Source/WebCore/rendering/svg/RenderSVGInline.h
Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
Source/WebCore/rendering/svg/RenderSVGInlineText.h
Source/WebCore/rendering/svg/RenderSVGText.cpp
Source/WebCore/rendering/svg/RenderSVGText.h

index 9a667bb..a8d43c9 100644 (file)
@@ -1,3 +1,20 @@
+2013-11-05  Andreas Kling  <akling@apple.com>
+
+        Apply more unique_ptr to line box management.
+        <https://webkit.org/b/123857>
+
+        Make all of the functions that return newly-created line boxes
+        return them packed up in std::unique_ptrs.
+
+        There is one exception in RenderBlockLineLayout where the function
+        createInlineBoxForRenderer() is inconsistent about the ownership of
+        the returned object. This will be addressed by a subsequent patch.
+
+        We now "release" the line boxes into their various home structures,
+        so the pointer smartness doesn't go end-to-end just yet.
+
+        Reviewed by Anders Carlsson.
+
 2013-11-05  Ryosuke Niwa  <rniwa@webkit.org>
 
         getComputedStyle(x).lineHeight is affected by zooming
index f27d3f6..6c612ba 100644 (file)
@@ -461,7 +461,7 @@ private:
     void layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom);
     void layoutSimpleLines(LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom);
 
-    virtual RootInlineBox* createRootInlineBox(); // Subclassed by SVG and Ruby.
+    virtual std::unique_ptr<RootInlineBox> createRootInlineBox(); // Subclassed by RenderSVGText.
     InlineFlowBox* createLineBoxes(RenderObject*, const LineInfo&, InlineBox* childBox, bool startsNewSegment);
     RootInlineBox* constructLine(BidiRunList<BidiRun>&, const LineInfo&);
     void setMarginsForRubyRun(BidiRun*, RenderRubyRun&, RenderObject*, const LineInfo&);
index 9d0825b..1bb24b5 100644 (file)
@@ -283,15 +283,16 @@ void RenderBlockFlow::appendRunsForObject(BidiRunList<BidiRun>& runs, int start,
     }
 }
 
-RootInlineBox* RenderBlockFlow::createRootInlineBox()
+std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox()
 {
-    return new RootInlineBox(*this);
+    return std::make_unique<RootInlineBox>(*this);
 }
 
 RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
 {
-    RootInlineBox* rootBox = createRootInlineBox();
-    m_lineBoxes.appendLineBox(rootBox);
+    auto newRootBox = createRootInlineBox();
+    RootInlineBox* rootBox = newRootBox.get();
+    m_lineBoxes.appendLineBox(std::move(newRootBox));
 
     if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && m_lineBoxes.firstLineBox() == rootBox) {
         if (AXObjectCache* cache = document().existingAXObjectCache())
@@ -310,11 +311,14 @@ static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRo
     if (obj->isText())
         return toRenderText(obj)->createInlineTextBox();
 
-    if (obj->isBox())
-        return toRenderBox(obj)->createInlineBox();
+    if (obj->isBox()) {
+        // FIXME: This is terrible. This branch returns an *owned* pointer!
+        return toRenderBox(obj)->createInlineBox().release();
+    }
 
     if (obj->isLineBreak()) {
-        InlineBox* inlineBox = toRenderLineBreak(obj)->createInlineBox();
+        // FIXME: This is terrible. This branch returns an *owned* pointer!
+        InlineBox* inlineBox = toRenderLineBreak(obj)->createInlineBox().release();
         // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
         // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
         inlineBox->setBehavesLikeText(isOnlyRun || obj->document().inNoQuirksMode() || obj->isLineBreakOpportunity());
@@ -1792,8 +1796,9 @@ void RenderBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState)
         if (layoutState.checkForFloatsFromLastLine()) {
             LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow();
             LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow();
-            TrailingFloatsRootInlineBox* trailingFloatsLineBox = new TrailingFloatsRootInlineBox(*this);
-            m_lineBoxes.appendLineBox(trailingFloatsLineBox);
+            auto newLineBox = std::make_unique<TrailingFloatsRootInlineBox>(*this);
+            auto trailingFloatsLineBox = newLineBox.get();
+            m_lineBoxes.appendLineBox(std::move(newLineBox));
             trailingFloatsLineBox->setConstructed();
             GlyphOverflowAndFallbackFontsMap textBoxDataMap;
             VerticalPositionCache verticalPositionCache;
index 3b09bb6..8d5d9d3 100644 (file)
@@ -1939,9 +1939,9 @@ LayoutSize RenderBox::offsetFromContainer(RenderObject* o, const LayoutPoint& po
     return offset;
 }
 
-InlineBox* RenderBox::createInlineBox()
+std::unique_ptr<InlineBox> RenderBox::createInlineBox()
 {
-    return new InlineBox(*this);
+    return std::make_unique<InlineBox>(*this);
 }
 
 void RenderBox::dirtyLineBoxes(bool fullLayout)
index 852cf36..65f9e44 100644 (file)
@@ -373,7 +373,7 @@ public:
     
     void positionLineBox(InlineBox*);
 
-    virtual InlineBox* createInlineBox();
+    virtual std::unique_ptr<InlineBox> createInlineBox();
     void dirtyLineBoxes(bool fullLayout);
 
     // For inline replaced elements, this function returns the inline box that owns us.  Enables
index 37b9d4a..324fde8 100644 (file)
@@ -1342,16 +1342,17 @@ void RenderInline::deleteLines()
     m_lineBoxes.deleteLineBoxTree();
 }
 
-InlineFlowBox* RenderInline::createInlineFlowBox() 
+std::unique_ptr<InlineFlowBox> RenderInline::createInlineFlowBox()
 {
-    return new InlineFlowBox(*this);
+    return std::make_unique<InlineFlowBox>(*this);
 }
 
 InlineFlowBox* RenderInline::createAndAppendInlineFlowBox()
 {
     setAlwaysCreateLineBoxes();
-    InlineFlowBox* flowBox = createInlineFlowBox();
-    m_lineBoxes.appendLineBox(flowBox);
+    auto newFlowBox = createInlineFlowBox();
+    auto flowBox = newFlowBox.get();
+    m_lineBoxes.appendLineBox(std::move(newFlowBox));
     return flowBox;
 }
 
index 26db866..71e45fe 100644 (file)
@@ -146,7 +146,7 @@ private:
         return IntRect(0, 0, boundingBox.width(), boundingBox.height());
     }
 
-    virtual InlineFlowBox* createInlineFlowBox(); // Subclassed by SVG and Ruby
+    virtual std::unique_ptr<InlineFlowBox> createInlineFlowBox(); // Subclassed by RenderSVGInline
 
     virtual void dirtyLinesFromChangedChild(RenderObject* child) OVERRIDE FINAL { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
 
index 28c24ce..c453a3d 100644 (file)
@@ -50,16 +50,19 @@ RenderLineBoxList::~RenderLineBoxList()
 }
 #endif
 
-void RenderLineBoxList::appendLineBox(InlineFlowBox* box)
+void RenderLineBoxList::appendLineBox(std::unique_ptr<InlineFlowBox> box)
 {
     checkConsistency();
-    
-    if (!m_firstLineBox)
-        m_firstLineBox = m_lastLineBox = box;
-    else {
-        m_lastLineBox->setNextLineBox(box);
-        box->setPreviousLineBox(m_lastLineBox);
-        m_lastLineBox = box;
+
+    InlineFlowBox* boxPtr = box.release();
+
+    if (!m_firstLineBox) {
+        m_firstLineBox = boxPtr;
+        m_lastLineBox = boxPtr;
+    } else {
+        m_lastLineBox->setNextLineBox(boxPtr);
+        boxPtr->setPreviousLineBox(m_lastLineBox);
+        m_lastLineBox = boxPtr;
     }
 
     checkConsistency();
index 9eb53b9..615bcb5 100644 (file)
@@ -54,7 +54,7 @@ public:
 
     void checkConsistency() const;
 
-    void appendLineBox(InlineFlowBox*);
+    void appendLineBox(std::unique_ptr<InlineFlowBox>);
 
     void deleteLineBoxTree();
     void deleteLineBoxes();
index ba2f842..49238b5 100644 (file)
@@ -67,9 +67,9 @@ int RenderLineBreak::baselinePosition(FontBaseline baselineType, bool firstLine,
     return fontMetrics.ascent(baselineType) + (lineHeight(firstLine, direction, linePositionMode) - fontMetrics.height()) / 2;
 }
 
-InlineBox* RenderLineBreak::createInlineBox()
+std::unique_ptr<InlineBox> RenderLineBreak::createInlineBox()
 {
-    return new InlineBox(*this);
+    return std::make_unique<InlineBox>(*this);
 }
 
 void RenderLineBreak::setInlineBoxWrapper(InlineBox* inlineBox)
index 9d93d57..f55cecb 100644 (file)
@@ -39,7 +39,7 @@ public:
 
     virtual bool isWBR() const OVERRIDE { return m_isWBR; }
 
-    InlineBox* createInlineBox();
+    std::unique_ptr<InlineBox> createInlineBox();
     InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
     void setInlineBoxWrapper(InlineBox*);
     void deleteInlineBoxWrapper();
index c4e3db5..2edb0c5 100644 (file)
@@ -1148,11 +1148,11 @@ void RenderListMarker::styleDidChange(StyleDifference diff, const RenderStyle* o
     }
 }
 
-InlineBox* RenderListMarker::createInlineBox()
+std::unique_ptr<InlineBox> RenderListMarker::createInlineBox()
 {
-    InlineBox* result = RenderBox::createInlineBox();
-    result->setBehavesLikeText(isText());
-    return result;
+    auto box = RenderBox::createInlineBox();
+    box->setBehavesLikeText(isText());
+    return box;
 }
 
 bool RenderListMarker::isImage() const
index 8b0aba6..03a79de 100644 (file)
@@ -60,7 +60,7 @@ private:
 
     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
 
-    virtual InlineBox* createInlineBox() OVERRIDE;
+    virtual std::unique_ptr<InlineBox> createInlineBox() OVERRIDE;
 
     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
index ff1f650..2ccd76f 100644 (file)
@@ -1023,9 +1023,9 @@ void RenderText::dirtyLineBoxes(bool fullLayout)
     m_linesDirty = false;
 }
 
-InlineTextBox* RenderText::createTextBox()
+std::unique_ptr<InlineTextBox> RenderText::createTextBox()
 {
-    return new InlineTextBox(*this);
+    return std::make_unique<InlineTextBox>(*this);
 }
 
 void RenderText::positionLineBox(InlineBox* box)
index 1e1d11e..3f85057 100644 (file)
@@ -145,7 +145,7 @@ public:
 
     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
 
-    virtual InlineTextBox* createTextBox(); // Subclassed by RenderSVGInlineText.
+    virtual std::unique_ptr<InlineTextBox> createTextBox(); // Subclassed by RenderSVGInlineText.
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
     float candidateComputedTextSize() const { return m_candidateComputedTextSize; }
index 7f36eac..be6276a 100644 (file)
@@ -44,14 +44,14 @@ InlineTextBox* RenderTextLineBoxes::createAndAppendLineBox(RenderText& renderTex
 {
     auto textBox = renderText.createTextBox();
     if (!m_first) {
-        m_first = textBox;
-        m_last = textBox;
+        m_first = textBox.get();
+        m_last = textBox.get();
     } else {
-        m_last->setNextTextBox(textBox);
+        m_last->setNextTextBox(textBox.get());
         textBox->setPreviousTextBox(m_last);
-        m_last = textBox;
+        m_last = textBox.get();
     }
-    return textBox;
+    return textBox.release();
 }
 
 void RenderTextLineBoxes::extract(InlineTextBox& box)
index 45546bd..b887641 100644 (file)
@@ -38,11 +38,11 @@ RenderSVGInline::RenderSVGInline(SVGGraphicsElement& element, PassRef<RenderStyl
     setAlwaysCreateLineBoxes();
 }
 
-InlineFlowBox* RenderSVGInline::createInlineFlowBox()
+std::unique_ptr<InlineFlowBox> RenderSVGInline::createInlineFlowBox()
 {
-    InlineFlowBox* box = new SVGInlineFlowBox(*this);
+    auto box = std::make_unique<SVGInlineFlowBox>(*this);
     box->setHasVirtualLogicalHeight();
-    return box;
+    return std::move(box);
 }
 
 FloatRect RenderSVGInline::objectBoundingBox() const
index b8aa8e3..22bd82e 100644 (file)
@@ -55,7 +55,7 @@ private:
     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE FINAL;
     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE FINAL;
 
-    virtual InlineFlowBox* createInlineFlowBox() OVERRIDE FINAL;
+    virtual std::unique_ptr<InlineFlowBox> createInlineFlowBox() OVERRIDE FINAL;
 
     virtual void willBeDestroyed() OVERRIDE FINAL;
     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE FINAL;
index a0210bf..a490a54 100644 (file)
@@ -106,11 +106,11 @@ void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle
         textRenderer->subtreeStyleDidChange(this);
 }
 
-InlineTextBox* RenderSVGInlineText::createTextBox()
+std::unique_ptr<InlineTextBox> RenderSVGInlineText::createTextBox()
 {
-    InlineTextBox* box = new SVGInlineTextBox(*this);
+    auto box = std::make_unique<SVGInlineTextBox>(*this);
     box->setHasVirtualLogicalHeight();
-    return box;
+    return std::move(box);
 }
 
 LayoutRect RenderSVGInlineText::localCaretRect(InlineBox* box, int caretOffset, LayoutUnit*)
index a82e7fc..f4f5ee5 100644 (file)
@@ -62,7 +62,7 @@ private:
     virtual VisiblePosition positionForPoint(const LayoutPoint&) OVERRIDE;
     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
     virtual IntRect linesBoundingBox() const OVERRIDE;
-    virtual InlineTextBox* createTextBox() OVERRIDE;
+    virtual std::unique_ptr<InlineTextBox> createTextBox() OVERRIDE;
 
     float m_scalingFactor;
     Font m_scaledFont;
index 36de50a..af3236e 100644 (file)
@@ -441,11 +441,11 @@ void RenderSVGText::layout()
     clearNeedsLayout();
 }
 
-RootInlineBox* RenderSVGText::createRootInlineBox() 
+std::unique_ptr<RootInlineBox> RenderSVGText::createRootInlineBox()
 {
-    RootInlineBox* box = new SVGRootInlineBox(*this);
+    auto box = std::make_unique<SVGRootInlineBox>(*this);
     box->setHasVirtualLogicalHeight();
-    return box;
+    return std::move(box);
 }
 
 bool RenderSVGText::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
index 27bc1d9..f298829 100644 (file)
@@ -90,7 +90,7 @@ private:
 
     virtual const AffineTransform& localToParentTransform() const { return m_localTransform; }
     virtual AffineTransform localTransform() const { return m_localTransform; }
-    virtual RootInlineBox* createRootInlineBox();
+    virtual std::unique_ptr<RootInlineBox> createRootInlineBox() OVERRIDE;
 
     virtual RenderBlock* firstLineBlock() const;
     virtual void updateFirstLetter();