[RenderTreeBuilder] Move RenderButton::addChild() tree mutation to RenderTreeBuilder
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Dec 2017 16:28:50 +0000 (16:28 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Dec 2017 16:28:50 +0000 (16:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181109
<rdar://problem/36188262>

Reviewed by Antti Koivisto.

Covered by existing tests.

* rendering/RenderButton.cpp:
(WebCore::RenderButton::setInnerRenderer):
(WebCore::RenderButton::updateAnonymousChildStyle const):
(WebCore::RenderButton::addChild): Deleted.
* rendering/RenderButton.h:
* rendering/RenderElement.cpp:
(WebCore::RenderElement::propagateStyleToAnonymousChildren):
* rendering/RenderElement.h:
(WebCore::RenderElement::updateAnonymousChildStyle const):
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::insertChild):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderButton.cpp
Source/WebCore/rendering/RenderButton.h
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderElement.h
Source/WebCore/rendering/updating/RenderTreeBuilder.cpp

index cd6b7a8..fbdd319 100644 (file)
@@ -1,3 +1,25 @@
+2017-12-22  Zalan Bujtas  <zalan@apple.com>
+
+        [RenderTreeBuilder] Move RenderButton::addChild() tree mutation to RenderTreeBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=181109
+        <rdar://problem/36188262>
+
+        Reviewed by Antti Koivisto.
+
+        Covered by existing tests.
+
+        * rendering/RenderButton.cpp:
+        (WebCore::RenderButton::setInnerRenderer):
+        (WebCore::RenderButton::updateAnonymousChildStyle const):
+        (WebCore::RenderButton::addChild): Deleted.
+        * rendering/RenderButton.h:
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::propagateStyleToAnonymousChildren):
+        * rendering/RenderElement.h:
+        (WebCore::RenderElement::updateAnonymousChildStyle const):
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::insertChild):
+
 2017-12-22  Ms2ger  <Ms2ger@igalia.com>
 
         REGRESSION(r226228) Build error with unqualified isfinite() in MediaCapabilities.cpp
index df3e5c7..50c15ac 100644 (file)
@@ -63,17 +63,10 @@ bool RenderButton::hasLineIfEmpty() const
     return is<HTMLInputElement>(formControlElement());
 }
 
-void RenderButton::addChild(RenderTreeBuilder& builder, RenderPtr<RenderObject> newChild, RenderObject* beforeChild)
+void RenderButton::setInnerRenderer(RenderBlock& innerRenderer)
 {
-    if (!m_inner) {
-        // Create an anonymous block.
-        ASSERT(!firstChild());
-        auto newInner = createAnonymousBlock(style().display());
-        updateAnonymousChildStyle(*newInner, newInner->mutableStyle());
-        m_inner = makeWeakPtr(*newInner);
-        RenderFlexibleBox::addChild(builder, WTFMove(newInner));
-    }    
-    builder.insertChild(*m_inner, WTFMove(newChild), beforeChild);
+    ASSERT(!m_inner.get());
+    m_inner = makeWeakPtr(innerRenderer);
 }
 
 RenderPtr<RenderObject> RenderButton::takeChild(RenderObject& oldChild)
@@ -88,9 +81,8 @@ RenderPtr<RenderObject> RenderButton::takeChild(RenderObject& oldChild)
     return m_inner->takeChild(oldChild);
 }
     
-void RenderButton::updateAnonymousChildStyle(const RenderObject& child, RenderStyle& childStyle) const
+void RenderButton::updateAnonymousChildStyle(RenderStyle& childStyle) const
 {
-    ASSERT_UNUSED(child, !m_inner || &child == m_inner);
     childStyle.setFlexGrow(1.0f);
     // min-width: 0; is needed for correct shrinking.
     childStyle.setMinWidth(Length(0, Fixed));
index 6ef043d..537f376 100644 (file)
@@ -41,7 +41,6 @@ public:
 
     bool canBeSelectionLeaf() const override;
 
-    void addChild(RenderTreeBuilder&, RenderPtr<RenderObject> newChild, RenderObject *beforeChild = 0) override;
     RenderPtr<RenderObject> takeChild(RenderObject&) override;
     void removeLeftoverAnonymousBlock(RenderBlock*) override { }
     bool createsAnonymousWrapper() const override { return true; }
@@ -52,7 +51,7 @@ public:
     bool hasControlClip() const override { return true; }
     LayoutRect controlClipRect(const LayoutPoint&) const override;
 
-    void updateAnonymousChildStyle(const RenderObject& anonymousChild, RenderStyle&) const override;
+    void updateAnonymousChildStyle(RenderStyle&) const override;
 
     void setText(const String&);
     String text() const;
@@ -61,6 +60,9 @@ public:
     void layout() override;
 #endif
 
+    RenderBlock* innerRenderer() const { return m_inner.get(); }
+    void setInnerRenderer(RenderBlock&);
+
 private:
     void element() const = delete;
 
index 879631f..04d5840 100644 (file)
@@ -828,7 +828,7 @@ void RenderElement::propagateStyleToAnonymousChildren(StylePropagationType propa
         if (elementChild.isInFlowPositioned() && elementChild.isContinuation())
             newStyle.setPosition(elementChild.style().position());
 
-        updateAnonymousChildStyle(elementChild, newStyle);
+        updateAnonymousChildStyle(newStyle);
         
         elementChild.setStyle(WTFMove(newStyle));
     }
index 18c8f57..a04168a 100644 (file)
@@ -220,7 +220,7 @@ public:
 
     // Called before anonymousChild.setStyle(). Override to set custom styles for
     // the child.
-    virtual void updateAnonymousChildStyle(const RenderObject&, RenderStyle&) const { };
+    virtual void updateAnonymousChildStyle(RenderStyle&) const { };
 
     void removeAnonymousWrappersForInlinesIfNecessary();
 
index a2f941c..480fe31 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "RenderTreeBuilder.h"
 
+#include "RenderButton.h"
 #include "RenderElement.h"
 #include "RenderRuby.h"
 #include "RenderRubyBase.h"
@@ -60,6 +61,19 @@ RenderTreeBuilder::~RenderTreeBuilder()
     s_current = m_previous;
 }
 
+static RenderBlock& createInnerRendererForButtonIfNeeded(RenderButton& button, RenderTreeBuilder& builder)
+{
+    auto* innerRenderer = button.innerRenderer();
+    if (innerRenderer)
+        return *innerRenderer;
+    auto wrapper = button.createAnonymousBlock(button.style().display());
+    innerRenderer = wrapper.get();
+    button.updateAnonymousChildStyle(wrapper->mutableStyle());
+    button.RenderFlexibleBox::addChild(builder, WTFMove(wrapper));
+    button.setInnerRenderer(*innerRenderer);
+    return *innerRenderer;
+}
+
 void RenderTreeBuilder::insertChild(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
 {
     auto insertRecursiveIfNeeded = [&](RenderElement& parentCandidate) {
@@ -107,6 +121,10 @@ void RenderTreeBuilder::insertChild(RenderElement& parent, RenderPtr<RenderObjec
         return;
     }
 
+    if (is<RenderButton>(parent)) {
+        insertRecursiveIfNeeded(createInnerRendererForButtonIfNeeded(downcast<RenderButton>(parent), *this));
+        return;
+    }
     parent.addChild(*this, WTFMove(child), beforeChild);
 }