RenderBlock::clone() should return RenderPtr.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Jan 2014 10:39:36 +0000 (10:39 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Jan 2014 10:39:36 +0000 (10:39 +0000)
<https://webkit.org/b/126513>

Reviewed by Antti Koivisto.

* rendering/RenderBlock.h:
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::clone):

    Tweaked to return RenderPtr<RenderBlock>.

(WebCore::RenderBlock::splitBlocks):

    Store cloned RenderBlocks in RenderPtrs. Use leakPtr() to sink
    them into ownership-taking APIs that still use raw pointers.

* rendering/RenderPtr.h:

    Add a simple static_pointer_cast for RenderPtr&&.

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBlock.h
Source/WebCore/rendering/RenderPtr.h

index 17f113891f1aa96e565878cfe627ea9982df15a3..d50ae9463211b3751f805528568788596622891d 100644 (file)
@@ -1,3 +1,25 @@
+2014-01-06  Andreas Kling  <akling@apple.com>
+
+        RenderBlock::clone() should return RenderPtr.
+        <https://webkit.org/b/126513>
+
+        Reviewed by Antti Koivisto.
+
+        * rendering/RenderBlock.h:
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::clone):
+
+            Tweaked to return RenderPtr<RenderBlock>.
+
+        (WebCore::RenderBlock::splitBlocks):
+
+            Store cloned RenderBlocks in RenderPtrs. Use leakPtr() to sink
+            them into ownership-taking APIs that still use raw pointers.
+
+        * rendering/RenderPtr.h:
+
+            Add a simple static_pointer_cast for RenderPtr&&.
+
 2014-01-06  Andreas Kling  <akling@apple.com>
 
         RenderInline::clone() should return RenderPtr.
index d4e36e537b3a0e80e54862729192a7f301c3d91d..f157731c25841efd0fb66bb95ea47e017602660d 100644 (file)
@@ -504,15 +504,14 @@ RenderBlock* RenderBlock::containingColumnsBlock(bool allowAnonymousColumnBlock)
     return 0;
 }
 
-RenderBlock* RenderBlock::clone() const
+RenderPtr<RenderBlock> RenderBlock::clone() const
 {
-    RenderBlock* cloneBlock;
+    RenderPtr<RenderBlock> cloneBlock;
     if (isAnonymousBlock()) {
-        cloneBlock = createAnonymousBlock();
+        cloneBlock = RenderPtr<RenderBlock>(createAnonymousBlock());
         cloneBlock->setChildrenInline(childrenInline());
     } else {
-        auto cloneRenderer = element()->createElementRenderer(style());
-        cloneBlock = toRenderBlock(cloneRenderer.leakPtr());
+        cloneBlock = static_pointer_cast<RenderBlock>(element()->createElementRenderer(style()));
         cloneBlock->initializeStyle();
 
         // This takes care of setting the right value of childrenInline in case
@@ -529,7 +528,7 @@ void RenderBlock::splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock,
                               RenderObject* beforeChild, RenderBoxModelObject* oldCont)
 {
     // Create a clone of this inline.
-    RenderBlock* cloneBlock = clone();
+    RenderPtr<RenderBlock> cloneBlock = clone();
     if (!isAnonymousBlock())
         cloneBlock->setContinuation(oldCont);
 
@@ -543,11 +542,11 @@ void RenderBlock::splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock,
 
     // Now take all of the children from beforeChild to the end and remove
     // them from |this| and place them in the clone.
-    moveChildrenTo(cloneBlock, beforeChild, 0, true);
+    moveChildrenTo(cloneBlock.get(), beforeChild, 0, true);
     
     // Hook |clone| up as the continuation of the middle block.
     if (!cloneBlock->isAnonymousBlock())
-        middleBlock->setContinuation(cloneBlock);
+        middleBlock->setContinuation(cloneBlock.get());
 
     // We have been reparented and are now under the fromBlock.  We need
     // to walk up our block parent chain until we hit the containing anonymous columns block.
@@ -562,11 +561,11 @@ void RenderBlock::splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock,
         RenderBlock* blockCurr = toRenderBlock(curr);
         
         // Create a new clone.
-        RenderBlock* cloneChild = cloneBlock;
+        RenderPtr<RenderBlock> cloneChild = std::move(cloneBlock);
         cloneBlock = blockCurr->clone();
 
         // Insert our child clone as the first child.
-        cloneBlock->addChildIgnoringContinuation(cloneChild, 0);
+        cloneBlock->addChildIgnoringContinuation(cloneChild.leakPtr(), 0);
 
         // Hook the clone up as a continuation of |curr|.  Note we do encounter
         // anonymous blocks possibly as we walk up the block chain.  When we split an
@@ -574,13 +573,13 @@ void RenderBlock::splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock,
         // actually split a real element.
         if (!blockCurr->isAnonymousBlock()) {
             oldCont = blockCurr->continuation();
-            blockCurr->setContinuation(cloneBlock);
+            blockCurr->setContinuation(cloneBlock.get());
             cloneBlock->setContinuation(oldCont);
         }
 
         // Now we need to take all of the children starting from the first child
         // *after* currChild and append them all to the clone.
-        blockCurr->moveChildrenTo(cloneBlock, currChildNextSibling, 0, true);
+        blockCurr->moveChildrenTo(cloneBlock.get(), currChildNextSibling, 0, true);
 
         // Keep walking up the chain.
         currChild = curr;
@@ -589,7 +588,7 @@ void RenderBlock::splitBlocks(RenderBlock* fromBlock, RenderBlock* toBlock,
     }
 
     // Now we are at the columns block level. We need to put the clone into the toBlock.
-    toBlock->insertChildInternal(cloneBlock, nullptr, NotifyChildren);
+    toBlock->insertChildInternal(cloneBlock.leakPtr(), nullptr, NotifyChildren);
 
     // Now take all the children after currChild and remove them from the fromBlock
     // and put them in the toBlock.
index 73f9fc211628b99727ecf014bd39ca70a37f2c92..d027e6e12a9ff32f0d04f4ee688d48e155b27f24 100644 (file)
@@ -583,7 +583,7 @@ private:
                      RenderObject* beforeChild, RenderBoxModelObject* oldCont);
     void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
                    RenderObject* newChild, RenderBoxModelObject* oldCont);
-    RenderBlock* clone() const;
+    RenderPtr<RenderBlock> clone() const;
     RenderBlock* continuationBefore(RenderObject* beforeChild);
     RenderBlock* containingColumnsBlock(bool allowAnonymousColumnBlock = true);
     RenderBlock* columnsBlockForSpanningElement(RenderObject* newChild);
index 0723eeb8a565129f41c347bb83a988de070e4a8f..ef069226fde97b4f68f81b985b1fd4bceabe760f 100644 (file)
@@ -158,6 +158,11 @@ createRenderer(Args&&... args)
     return RenderPtr<T>(new T(std::forward<Args>(args)...));
 }
 
+template<typename T, typename U> inline RenderPtr<T> static_pointer_cast(RenderPtr<U>&& p)
+{
+    return RenderPtr<T>(static_cast<T*>(p.leakPtr()));
+}
+
 } // namespace WebCore
 
 namespace WTF {