Diff
Modified: trunk/Source/WebCore/ChangeLog (199055 => 199056)
--- trunk/Source/WebCore/ChangeLog 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/ChangeLog 2016-04-05 15:04:02 UTC (rev 199056)
@@ -1,3 +1,53 @@
+2016-04-05 Antti Koivisto <[email protected]>
+
+ Render tree teardown should be iterative
+ https://bugs.webkit.org/show_bug.cgi?id=156233
+
+ Reviewed by Andreas Kling.
+
+ * dom/ContainerNode.cpp:
+ (WebCore::destroyRenderTreeIfNeeded):
+ (WebCore::ContainerNode::takeAllChildrenFrom):
+ * dom/Document.cpp:
+ (WebCore::Document::destroyRenderTree):
+ * dom/Element.cpp:
+ (WebCore::disconnectPseudoElement):
+ * html/HTMLPlugInImageElement.cpp:
+ (WebCore::HTMLPlugInImageElement::prepareForDocumentSuspension):
+ * mathml/MathMLSelectElement.cpp:
+ (WebCore::MathMLSelectElement::updateSelectedChild):
+ * style/RenderTreeUpdater.cpp:
+ (WebCore::RenderTreeUpdater::updateElementRenderer):
+ (WebCore::RenderTreeUpdater::updateTextRenderer):
+ (WebCore::RenderTreeUpdater::updateBeforeOrAfterPseudoElement):
+ (WebCore::RenderTreeUpdater::tearDownRenderers):
+
+ Tear down render tree using ComposedTreeIterator for traversal.
+
+ (WebCore::RenderTreeUpdater::tearDownRenderer):
+
+ * style/RenderTreeUpdater.h:
+ * style/StyleTreeResolver.cpp:
+ (WebCore::Style::ensurePlaceholderStyle):
+ (WebCore::Style::TreeResolver::styleForElement):
+ (WebCore::Style::resetStyleForNonRenderedDescendants):
+ (WebCore::Style::affectsRenderedSubtree):
+ (WebCore::Style::SelectorFilterPusher::SelectorFilterPusher): Deleted.
+ (WebCore::Style::SelectorFilterPusher::push): Deleted.
+ (WebCore::Style::SelectorFilterPusher::~SelectorFilterPusher): Deleted.
+
+ Unused class.
+
+ (WebCore::Style::detachTextRenderer): Deleted.
+ (WebCore::Style::detachChildren): Deleted.
+ (WebCore::Style::detachShadowRoot): Deleted.
+ (WebCore::Style::detachSlotAssignees): Deleted.
+ (WebCore::Style::detachRenderTree): Deleted.
+
+ Remove the old recursive code.
+
+ * style/StyleTreeResolver.h:
+
2016-04-05 Antoine Quint <[email protected]>
[WebGL2] Allow enabling WebGL2 with a runtime flag
Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (199055 => 199056)
--- trunk/Source/WebCore/dom/ContainerNode.cpp 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp 2016-04-05 15:04:02 UTC (rev 199056)
@@ -49,13 +49,13 @@
#include "RadioNodeList.h"
#include "RenderBox.h"
#include "RenderTheme.h"
+#include "RenderTreeUpdater.h"
#include "RenderWidget.h"
#include "RootInlineBox.h"
#include "SVGDocumentExtensions.h"
#include "SVGElement.h"
#include "SVGNames.h"
#include "SelectorQuery.h"
-#include "StyleTreeResolver.h"
#include "TemplateContentDocumentFragment.h"
#include <algorithm>
#include <wtf/CurrentTime.h>
@@ -103,9 +103,9 @@
if (!child.renderer() && !child.isNamedFlowContentNode() && !is<HTMLSlotElement>(child))
return;
if (is<Element>(child))
- Style::detachRenderTree(downcast<Element>(child));
+ RenderTreeUpdater::tearDownRenderers(downcast<Element>(child));
else if (is<Text>(child))
- Style::detachTextRenderer(downcast<Text>(child));
+ RenderTreeUpdater::tearDownRenderer(downcast<Text>(child));
}
void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
Modified: trunk/Source/WebCore/dom/Document.cpp (199055 => 199056)
--- trunk/Source/WebCore/dom/Document.cpp 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-04-05 15:04:02 UTC (rev 199056)
@@ -2353,7 +2353,7 @@
m_activeElement = nullptr;
if (m_documentElement)
- Style::detachRenderTree(*m_documentElement);
+ RenderTreeUpdater::tearDownRenderers(*m_documentElement);
clearChildNeedsStyleRecalc();
Modified: trunk/Source/WebCore/dom/Element.cpp (199055 => 199056)
--- trunk/Source/WebCore/dom/Element.cpp 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/dom/Element.cpp 2016-04-05 15:04:02 UTC (rev 199056)
@@ -75,6 +75,7 @@
#include "RenderNamedFlowFragment.h"
#include "RenderRegion.h"
#include "RenderTheme.h"
+#include "RenderTreeUpdater.h"
#include "RenderView.h"
#include "RenderWidget.h"
#include "SVGDocumentExtensions.h"
@@ -2703,7 +2704,7 @@
if (!pseudoElement)
return;
if (pseudoElement->renderer())
- Style::detachRenderTree(*pseudoElement);
+ RenderTreeUpdater::tearDownRenderers(*pseudoElement);
ASSERT(pseudoElement->hostElement());
pseudoElement->clearHostElement();
}
Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp (199055 => 199056)
--- trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp 2016-04-05 15:04:02 UTC (rev 199056)
@@ -43,6 +43,7 @@
#include "RenderEmbeddedObject.h"
#include "RenderImage.h"
#include "RenderSnapshottedPlugIn.h"
+#include "RenderTreeUpdater.h"
#include "SchemeRegistry.h"
#include "ScriptController.h"
#include "SecurityOrigin.h"
@@ -322,7 +323,7 @@
void HTMLPlugInImageElement::prepareForDocumentSuspension()
{
if (renderer())
- Style::detachRenderTree(*this);
+ RenderTreeUpdater::tearDownRenderers(*this);
HTMLPlugInElement::prepareForDocumentSuspension();
}
Modified: trunk/Source/WebCore/mathml/MathMLSelectElement.cpp (199055 => 199056)
--- trunk/Source/WebCore/mathml/MathMLSelectElement.cpp 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/mathml/MathMLSelectElement.cpp 2016-04-05 15:04:02 UTC (rev 199056)
@@ -33,9 +33,9 @@
#include "HTMLNames.h"
#include "MathMLNames.h"
#include "RenderMathMLRow.h"
+#include "RenderTreeUpdater.h"
#include "SVGElement.h"
#include "SVGNames.h"
-#include "StyleTreeResolver.h"
namespace WebCore {
@@ -202,7 +202,7 @@
return;
if (m_selectedChild && m_selectedChild->renderer())
- Style::detachRenderTree(*m_selectedChild);
+ RenderTreeUpdater::tearDownRenderers(*m_selectedChild);
m_selectedChild = newSelectedChild;
setNeedsStyleRecalc();
Modified: trunk/Source/WebCore/style/RenderTreeUpdater.cpp (199055 => 199056)
--- trunk/Source/WebCore/style/RenderTreeUpdater.cpp 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/style/RenderTreeUpdater.cpp 2016-04-05 15:04:02 UTC (rev 199056)
@@ -242,7 +242,7 @@
{
bool shouldTearDownRenderers = update.change == Style::Detach && (element.renderer() || element.isNamedFlowContentNode());
if (shouldTearDownRenderers)
- detachRenderTree(element, Style::ReattachDetach);
+ tearDownRenderers(element, TeardownType::KeepHoverAndActive);
bool shouldCreateNewRenderer = !element.renderer() && update.style && !hasImplicitDisplayContents(element);
if (shouldCreateNewRenderer) {
@@ -409,7 +409,7 @@
if (hasRenderer) {
if (needsRenderer)
return;
- Style::detachTextRenderer(text);
+ tearDownRenderer(text);
invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(text);
return;
}
@@ -506,4 +506,59 @@
pseudoElement->didRecalcStyle(elementUpdate.change);
}
+void RenderTreeUpdater::tearDownRenderers(Element& root, TeardownType teardownType)
+{
+ WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
+
+ Vector<Element*, 30> teardownStack;
+
+ auto push = [&] (Element& element) {
+ if (element.hasCustomStyleResolveCallbacks())
+ element.willDetachRenderers();
+ if (teardownType != TeardownType::KeepHoverAndActive)
+ element.clearHoverAndActiveStatusBeforeDetachingRenderer();
+ element.clearStyleDerivedDataBeforeDetachingRenderer();
+
+ teardownStack.append(&element);
+ };
+
+ auto pop = [&] (unsigned depth) {
+ while (teardownStack.size() > depth) {
+ auto& element = *teardownStack.takeLast();
+
+ if (auto* renderer = element.renderer()) {
+ renderer->destroyAndCleanupAnonymousWrappers();
+ element.setRenderer(nullptr);
+ }
+ if (element.hasCustomStyleResolveCallbacks())
+ element.didDetachRenderers();
+ }
+ };
+
+ push(root);
+
+ auto descendants = composedTreeDescendants(root);
+ for (auto it = descendants.begin(), end = descendants.end(); it != end; ++it) {
+ pop(it.depth());
+
+ if (is<Text>(*it)) {
+ tearDownRenderer(downcast<Text>(*it));
+ continue;
+ }
+
+ push(downcast<Element>(*it));
+ }
+
+ pop(0);
}
+
+void RenderTreeUpdater::tearDownRenderer(Text& text)
+{
+ auto* renderer = text.renderer();
+ if (!renderer)
+ return;
+ renderer->destroyAndCleanupAnonymousWrappers();
+ text.setRenderer(nullptr);
+}
+
+}
Modified: trunk/Source/WebCore/style/RenderTreeUpdater.h (199055 => 199056)
--- trunk/Source/WebCore/style/RenderTreeUpdater.h 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/style/RenderTreeUpdater.h 2016-04-05 15:04:02 UTC (rev 199056)
@@ -50,6 +50,10 @@
void commit(std::unique_ptr<const Style::Update>);
+ enum class TeardownType { Normal, KeepHoverAndActive };
+ static void tearDownRenderers(Element&, TeardownType = TeardownType::Normal);
+ static void tearDownRenderer(Text&);
+
private:
void updateRenderTree(ContainerNode& root);
void updateTextRenderer(Text&);
Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (199055 => 199056)
--- trunk/Source/WebCore/style/StyleTreeResolver.cpp 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp 2016-04-05 15:04:02 UTC (rev 199056)
@@ -50,37 +50,6 @@
namespace Style {
-class SelectorFilterPusher {
-public:
- enum PushMode { Push, NoPush };
- SelectorFilterPusher(SelectorFilter& selectorFilter, Element& parent, PushMode pushMode = Push)
- : m_selectorFilter(selectorFilter)
- , m_parent(parent)
- {
- if (pushMode == Push)
- push();
- }
- void push()
- {
- if (m_didPush)
- return;
- m_didPush = true;
- m_selectorFilter.pushParent(&m_parent);
- }
- ~SelectorFilterPusher()
- {
- if (!m_didPush)
- return;
- m_selectorFilter.popParent();
- }
-
-private:
- SelectorFilter& m_selectorFilter;
- Element& m_parent;
- bool m_didPush { false };
-};
-
-
static RenderStyle* placeholderStyle;
static void ensurePlaceholderStyle(Document& document)
@@ -176,13 +145,6 @@
return WTFMove(elementStyle.renderStyle);
}
-void detachTextRenderer(Text& textNode)
-{
- if (textNode.renderer())
- textNode.renderer()->destroyAndCleanupAnonymousWrappers();
- textNode.setRenderer(0);
-}
-
static void resetStyleForNonRenderedDescendants(Element& current)
{
// FIXME: This is not correct with shadow trees. This should be done with ComposedTreeIterator.
@@ -204,72 +166,6 @@
}
}
-static void detachChildren(ContainerNode& current, DetachType detachType)
-{
- for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
- if (is<Text>(*child))
- detachTextRenderer(downcast<Text>(*child));
- else if (is<Element>(*child))
- detachRenderTree(downcast<Element>(*child), detachType);
- }
- current.clearChildNeedsStyleRecalc();
-}
-
-static void detachShadowRoot(ShadowRoot& shadowRoot, DetachType detachType)
-{
- detachChildren(shadowRoot, detachType);
-}
-
-#if ENABLE(SHADOW_DOM) || ENABLE(DETAILS_ELEMENT)
-static void detachSlotAssignees(HTMLSlotElement& slot, DetachType detachType)
-{
- ASSERT(!slot.renderer());
- if (auto* assignedNodes = slot.assignedNodes()) {
- for (auto* child : *assignedNodes) {
- if (is<Text>(*child))
- detachTextRenderer(downcast<Text>(*child));
- else if (is<Element>(*child))
- detachRenderTree(downcast<Element>(*child), detachType);
- }
- } else
- detachChildren(slot, detachType);
-
- slot.clearNeedsStyleRecalc();
- slot.clearChildNeedsStyleRecalc();
-}
-#endif
-
-void detachRenderTree(Element& current, DetachType detachType)
-{
- WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
-
- if (current.hasCustomStyleResolveCallbacks())
- current.willDetachRenderers();
-
- current.clearStyleDerivedDataBeforeDetachingRenderer();
-
- // Do not remove the element's hovered and active status
- // if performing a reattach.
- if (detachType != ReattachDetach)
- current.clearHoverAndActiveStatusBeforeDetachingRenderer();
-
-#if ENABLE(SHADOW_DOM) || ENABLE(DETAILS_ELEMENT)
- if (is<HTMLSlotElement>(current))
- detachSlotAssignees(downcast<HTMLSlotElement>(current), detachType);
-#endif
- else if (ShadowRoot* shadowRoot = current.shadowRoot())
- detachShadowRoot(*shadowRoot, detachType);
-
- detachChildren(current, detachType);
-
- if (current.renderer())
- current.renderer()->destroyAndCleanupAnonymousWrappers();
- current.setRenderer(nullptr);
-
- if (current.hasCustomStyleResolveCallbacks())
- current.didDetachRenderers();
-}
-
static bool affectsRenderedSubtree(Element& element, const RenderStyle& newStyle)
{
if (element.renderer())
Modified: trunk/Source/WebCore/style/StyleTreeResolver.h (199055 => 199056)
--- trunk/Source/WebCore/style/StyleTreeResolver.h 2016-04-05 11:22:17 UTC (rev 199055)
+++ trunk/Source/WebCore/style/StyleTreeResolver.h 2016-04-05 15:04:02 UTC (rev 199056)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -108,10 +108,6 @@
std::unique_ptr<Update> m_update;
};
-enum DetachType { NormalDetach, ReattachDetach };
-void detachRenderTree(Element&, DetachType = NormalDetach);
-void detachTextRenderer(Text&);
-
void queuePostResolutionCallback(std::function<void ()>);
bool postResolutionCallbacksAreSuspended();