[RenderTreeBuilder] Move RenderBoxModelObject::willBeRemoved() mutation logic to...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Feb 2018 22:27:00 +0000 (22:27 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Feb 2018 22:27:00 +0000 (22:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183014
<rdar://problem/37757428>

Reviewed by Antti Koivisto.

No change in functionality.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::~RenderBoxModelObject):
(WebCore::RenderBoxModelObject::willBeDestroyed):
(WebCore::RenderBoxModelObject::continuationChainNode const):
(): Deleted.
(WebCore::RenderBoxModelObject::removeAndDestroyAllContinuations): Deleted.
* rendering/RenderBoxModelObject.h:
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::RenderTreeBuilder):
(WebCore::RenderTreeBuilder::removeAndDestroy):
* rendering/updating/RenderTreeBuilder.h:
(WebCore::RenderTreeBuilder::continuationBuilder):
* rendering/updating/RenderTreeBuilderContinuation.cpp: Added.
(WebCore::RenderTreeBuilder::Continuation::Continuation):
(WebCore::RenderTreeBuilder::Continuation::cleanupOnDestroy):
* rendering/updating/RenderTreeBuilderContinuation.h: Added.

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

Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderBoxModelObject.h
Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
Source/WebCore/rendering/updating/RenderTreeBuilder.h
Source/WebCore/rendering/updating/RenderTreeBuilderContinuation.cpp [new file with mode: 0644]
Source/WebCore/rendering/updating/RenderTreeBuilderContinuation.h [new file with mode: 0644]

index 75023dd..b08ee01 100644 (file)
@@ -1,3 +1,32 @@
+2018-02-21  Zalan Bujtas  <zalan@apple.com>
+
+        [RenderTreeBuilder] Move RenderBoxModelObject::willBeRemoved() mutation logic to RenderTreeBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=183014
+        <rdar://problem/37757428>
+
+        Reviewed by Antti Koivisto.
+
+        No change in functionality.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::~RenderBoxModelObject):
+        (WebCore::RenderBoxModelObject::willBeDestroyed):
+        (WebCore::RenderBoxModelObject::continuationChainNode const):
+        (): Deleted.
+        (WebCore::RenderBoxModelObject::removeAndDestroyAllContinuations): Deleted.
+        * rendering/RenderBoxModelObject.h:
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::RenderTreeBuilder):
+        (WebCore::RenderTreeBuilder::removeAndDestroy):
+        * rendering/updating/RenderTreeBuilder.h:
+        (WebCore::RenderTreeBuilder::continuationBuilder):
+        * rendering/updating/RenderTreeBuilderContinuation.cpp: Added.
+        (WebCore::RenderTreeBuilder::Continuation::Continuation):
+        (WebCore::RenderTreeBuilder::Continuation::cleanupOnDestroy):
+        * rendering/updating/RenderTreeBuilderContinuation.h: Added.
+
 2018-02-21  Youenn Fablet  <youenn@apple.com>
 
         ServiceWorkerJob::m_lastResponse is unneeded
index 94bdc4f..0ba2bb3 100644 (file)
@@ -2014,6 +2014,7 @@ rendering/svg/SVGTextQuery.cpp
 rendering/updating/RenderTreeBuilder.cpp
 rendering/updating/RenderTreeBuilderBlock.cpp
 rendering/updating/RenderTreeBuilderBlockFlow.cpp
+rendering/updating/RenderTreeBuilderContinuation.cpp
 rendering/updating/RenderTreeBuilderFirstLetter.cpp
 rendering/updating/RenderTreeBuilderFormControls.cpp
 rendering/updating/RenderTreeBuilderFullScreen.cpp
index 8bf54a1..9ba7293 100644 (file)
                0FFD4D6118651FA300512F6E /* AsyncScrollingCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FFD4D5F18651FA300512F6E /* AsyncScrollingCoordinator.h */; settings = {ATTRIBUTES = (Private, ); }; };
                10FB084B14E15C7E00A3DB98 /* PublicURLManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 10FB084A14E15C7E00A3DB98 /* PublicURLManager.h */; };
                112B34D51E60B98300BB310A /* SimpleLineLayoutPagination.h in Headers */ = {isa = PBXBuildFile; fileRef = 112B34D41E60B98300BB310A /* SimpleLineLayoutPagination.h */; };
+               113409DA203E038000C66915 /* RenderTreeBuilderContinuation.h in Headers */ = {isa = PBXBuildFile; fileRef = 113409D8203E038000C66915 /* RenderTreeBuilderContinuation.h */; };
                113D0B521F9FDD2B00F611BB /* LayoutContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 113D0B501F9FDD2B00F611BB /* LayoutContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
                119340791FE8B92300935F1E /* RenderTreeBuilderTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340771FE8B92300935F1E /* RenderTreeBuilderTable.h */; };
                1193408A1FEB355D00935F1E /* RenderTreeBuilderRuby.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340881FEB355D00935F1E /* RenderTreeBuilderRuby.h */; };
                1100FC6E1FDB3C4D00DD961B /* TrailingFloatsRootInlineBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TrailingFloatsRootInlineBox.cpp; sourceTree = "<group>"; };
                112B34D01E60B8A700BB310A /* SimpleLineLayoutPagination.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleLineLayoutPagination.cpp; sourceTree = "<group>"; };
                112B34D41E60B98300BB310A /* SimpleLineLayoutPagination.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayoutPagination.h; sourceTree = "<group>"; };
+               113409D7203E038000C66915 /* RenderTreeBuilderContinuation.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderContinuation.cpp; sourceTree = "<group>"; };
+               113409D8203E038000C66915 /* RenderTreeBuilderContinuation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderContinuation.h; sourceTree = "<group>"; };
                113D0B4F1F9FDD2B00F611BB /* LayoutContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutContext.cpp; sourceTree = "<group>"; };
                113D0B501F9FDD2B00F611BB /* LayoutContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutContext.h; sourceTree = "<group>"; };
                119340761FE8B92300935F1E /* RenderTreeBuilderTable.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderTable.cpp; sourceTree = "<group>"; };
                                119340A11FEE024000935F1E /* RenderTreeBuilderBlock.h */,
                                11C5F11F2003F69F0001AE60 /* RenderTreeBuilderBlockFlow.cpp */,
                                11C5F11D2003F69E0001AE60 /* RenderTreeBuilderBlockFlow.h */,
+                               113409D7203E038000C66915 /* RenderTreeBuilderContinuation.cpp */,
+                               113409D8203E038000C66915 /* RenderTreeBuilderContinuation.h */,
                                E47C39211FE6E0DA00BBBC6B /* RenderTreeBuilderFirstLetter.cpp */,
                                E47C39261FE6E0DC00BBBC6B /* RenderTreeBuilderFirstLetter.h */,
                                119340941FED715500935F1E /* RenderTreeBuilderFormControls.cpp */,
                                93F1998C08245E59001E9ABC /* RenderTreeAsText.h in Headers */,
                                E47C392D1FE6E0F300BBBC6B /* RenderTreeBuilder.h in Headers */,
                                119340A31FEE024000935F1E /* RenderTreeBuilderBlock.h in Headers */,
+                               113409DA203E038000C66915 /* RenderTreeBuilderContinuation.h in Headers */,
                                E47C39301FE6E0FD00BBBC6B /* RenderTreeBuilderFirstLetter.h in Headers */,
                                119340971FED715500935F1E /* RenderTreeBuilderFormControls.h in Headers */,
                                11CB2789203BA570004A1DC9 /* RenderTreeBuilderFullScreen.h in Headers */,
index 6c223ee..2d555ef 100644 (file)
@@ -81,20 +81,6 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(RenderBoxModelObject);
 // an anonymous block (that houses other blocks) or it will be an inline flow.
 // <b><i><p>Hello</p></i></b>. In this example the <i> will have a block as
 // its continuation but the <b> will just have an inline as its continuation.
-
-struct RenderBoxModelObject::ContinuationChainNode {
-    WeakPtr<RenderBoxModelObject> renderer;
-    ContinuationChainNode* previous { nullptr };
-    ContinuationChainNode* next { nullptr };
-
-    ContinuationChainNode(RenderBoxModelObject&);
-    ~ContinuationChainNode();
-
-    void insertAfter(ContinuationChainNode&);
-
-    WTF_MAKE_FAST_ALLOCATED;
-};
-
 RenderBoxModelObject::ContinuationChainNode::ContinuationChainNode(RenderBoxModelObject& renderer)
     : renderer(makeWeakPtr(renderer))
 {
@@ -235,14 +221,11 @@ RenderBoxModelObject::RenderBoxModelObject(Document& document, RenderStyle&& sty
 RenderBoxModelObject::~RenderBoxModelObject()
 {
     // Do not add any code here. Add it to willBeDestroyed() instead.
+    ASSERT(!continuation());
 }
 
 void RenderBoxModelObject::willBeDestroyed(RenderTreeBuilder& builder)
 {
-    if (continuation() && !isContinuation()) {
-        removeAndDestroyAllContinuations(builder);
-        ASSERT(!continuation());
-    }
     if (hasContinuationChainNode())
         removeFromContinuationChain();
 
@@ -2525,6 +2508,10 @@ RenderInline* RenderBoxModelObject::inlineContinuation() const
     return nullptr;
 }
 
+RenderBoxModelObject::ContinuationChainNode* RenderBoxModelObject::continuationChainNode() const
+{
+    return continuationChainNodeMap().get(this);
+}
 
 void RenderBoxModelObject::insertIntoContinuationChainAfter(RenderBoxModelObject& afterRenderer)
 {
@@ -2551,17 +2538,6 @@ auto RenderBoxModelObject::ensureContinuationChainNode() -> ContinuationChainNod
     }).iterator->value;
 }
 
-void RenderBoxModelObject::removeAndDestroyAllContinuations(RenderTreeBuilder& builder)
-{
-    ASSERT(!isContinuation());
-    ASSERT(hasContinuationChainNode());
-    ASSERT(continuationChainNodeMap().contains(this));
-    auto& continuationChainNode = *continuationChainNodeMap().get(this);
-    while (continuationChainNode.next)
-        builder.removeAndDestroy(*continuationChainNode.next->renderer);
-    removeFromContinuationChain();
-}
-
 RenderTextFragment* RenderBoxModelObject::firstLetterRemainingText() const
 {
     if (!isFirstLetter())
index 5c1fbb6..38c3cc0 100644 (file)
@@ -280,11 +280,23 @@ public:
 
     RenderBlock* containingBlockForAutoHeightDetection(Length logicalHeight) const;
 
-    struct ContinuationChainNode;
+    struct ContinuationChainNode {
+        WeakPtr<RenderBoxModelObject> renderer;
+        ContinuationChainNode* previous { nullptr };
+        ContinuationChainNode* next { nullptr };
+
+        ContinuationChainNode(RenderBoxModelObject&);
+        ~ContinuationChainNode();
+
+        void insertAfter(ContinuationChainNode&);
+
+        WTF_MAKE_FAST_ALLOCATED;
+    };
+
+    ContinuationChainNode* continuationChainNode() const;
 
 private:
     ContinuationChainNode& ensureContinuationChainNode();
-    void removeAndDestroyAllContinuations(RenderTreeBuilder&);
 
     LayoutUnit computedCSSPadding(const Length&) const;
     
index 46e5f2a..c82b43f 100644 (file)
@@ -50,6 +50,7 @@
 #include "RenderTextFragment.h"
 #include "RenderTreeBuilderBlock.h"
 #include "RenderTreeBuilderBlockFlow.h"
+#include "RenderTreeBuilderContinuation.h"
 #include "RenderTreeBuilderFirstLetter.h"
 #include "RenderTreeBuilderFormControls.h"
 #include "RenderTreeBuilderFullScreen.h"
@@ -130,6 +131,7 @@ RenderTreeBuilder::RenderTreeBuilder(RenderView& view)
     , m_inlineBuilder(std::make_unique<Inline>(*this))
     , m_svgBuilder(std::make_unique<SVG>(*this))
     , m_mathMLBuilder(std::make_unique<MathML>(*this))
+    , m_continuationBuilder(std::make_unique<Continuation>(*this))
 #if ENABLE(FULLSCREEN_API)
     , m_fullScreenBuilder(std::make_unique<FullScreen>(*this))
 #endif
@@ -157,6 +159,9 @@ void RenderTreeBuilder::removeAndDestroy(RenderObject& renderer)
     if (is<RenderTextFragment>(renderer))
         firstLetterBuilder().cleanupOnDestroy(downcast<RenderTextFragment>(renderer));
 
+    if (is<RenderBoxModelObject>(renderer))
+        continuationBuilder().cleanupOnDestroy(downcast<RenderBoxModelObject>(renderer));
+
     // We need to detach the subtree first so that the descendants don't have
     // access to previous/next sublings at takeChild().
     // FIXME: webkit.org/b/182909.
index 6bca18d..75671b7 100644 (file)
@@ -91,6 +91,7 @@ private:
     class Inline;
     class SVG;
     class MathML;
+    class Continuation;
 #if ENABLE(FULLSCREEN_API)
     class FullScreen;
 #endif
@@ -106,6 +107,7 @@ private:
     Inline& inlineBuilder() { return *m_inlineBuilder; }
     SVG& svgBuilder() { return *m_svgBuilder; }
     MathML& mathMLBuilder() { return *m_mathMLBuilder; }
+    Continuation& continuationBuilder() { return *m_continuationBuilder; }
 #if ENABLE(FULLSCREEN_API)
     FullScreen& fullScreenBuilder() { return *m_fullScreenBuilder; }
 #endif
@@ -125,6 +127,7 @@ private:
     std::unique_ptr<Inline> m_inlineBuilder;
     std::unique_ptr<SVG> m_svgBuilder;
     std::unique_ptr<MathML> m_mathMLBuilder;
+    std::unique_ptr<Continuation> m_continuationBuilder;
 #if ENABLE(FULLSCREEN_API)
     std::unique_ptr<FullScreen> m_fullScreenBuilder;
 #endif
diff --git a/Source/WebCore/rendering/updating/RenderTreeBuilderContinuation.cpp b/Source/WebCore/rendering/updating/RenderTreeBuilderContinuation.cpp
new file mode 100644 (file)
index 0000000..8d3cadc
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RenderTreeBuilderContinuation.h"
+
+#include "RenderBoxModelObject.h"
+
+namespace WebCore {
+
+RenderTreeBuilder::Continuation::Continuation(RenderTreeBuilder& builder)
+    : m_builder(builder)
+{
+}
+
+void RenderTreeBuilder::Continuation::cleanupOnDestroy(RenderBoxModelObject& renderer)
+{
+    if (!renderer.continuation() || renderer.isContinuation())
+        return;
+
+    ASSERT(renderer.hasContinuationChainNode());
+    ASSERT(renderer.continuationChainNode());
+    auto& continuationChainNode = *renderer.continuationChainNode();
+    while (continuationChainNode.next)
+        m_builder.removeAndDestroy(*continuationChainNode.next->renderer);
+    renderer.removeFromContinuationChain();
+}
+
+}
diff --git a/Source/WebCore/rendering/updating/RenderTreeBuilderContinuation.h b/Source/WebCore/rendering/updating/RenderTreeBuilderContinuation.h
new file mode 100644 (file)
index 0000000..a757916
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "RenderTreeBuilder.h"
+
+namespace WebCore {
+
+class RenderBoxModelObject;
+
+class RenderTreeBuilder::Continuation {
+public:
+    Continuation(RenderTreeBuilder&);
+
+    void cleanupOnDestroy(RenderBoxModelObject&);
+
+private:
+    RenderTreeBuilder& m_builder;
+};
+
+}