Computing animated style should not require renderers
[WebKit-https.git] / Source / WebCore / style / RenderTreeUpdater.cpp
index f662a00..eca8818 100644 (file)
@@ -307,7 +307,10 @@ void RenderTreeUpdater::updateElementRenderer(Element& element, const Style::Ele
             // We may be tearing down a descendant renderer cached in renderTreePosition.
             renderTreePosition().invalidateNextSibling();
         }
-        tearDownRenderers(element, TeardownType::KeepHoverAndActive);
+
+        // display:none cancels animations.
+        auto teardownType = update.style->display() == NONE ? TeardownType::RendererUpdateCancelingAnimations : TeardownType::RendererUpdate;
+        tearDownRenderers(element, teardownType);
     }
 
     bool hasDisplayContents = update.style->display() == CONTENTS;
@@ -396,14 +399,6 @@ void RenderTreeUpdater::createRenderer(Element& element, RenderStyle&& style)
 
     element.setRenderer(newRenderer);
 
-    auto& initialStyle = newRenderer->style();
-    std::unique_ptr<RenderStyle> animatedStyle;
-    newRenderer->animation().updateAnimations(element, initialStyle, animatedStyle);
-    if (animatedStyle) {
-        newRenderer->setStyleInternal(WTFMove(*animatedStyle));
-        newRenderer->setHasInitialAnimatedStyle(true);
-    }
-
     newRenderer->initializeStyle();
 
 #if ENABLE(FULLSCREEN_API)
@@ -525,6 +520,11 @@ void RenderTreeUpdater::invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(
     }
 }
 
+void RenderTreeUpdater::tearDownRenderers(Element& root)
+{
+    tearDownRenderers(root, TeardownType::Full);
+}
+
 void RenderTreeUpdater::tearDownRenderers(Element& root, TeardownType teardownType)
 {
     WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
@@ -537,12 +537,18 @@ void RenderTreeUpdater::tearDownRenderers(Element& root, TeardownType teardownTy
         teardownStack.append(&element);
     };
 
+    auto& animationController = root.document().frame()->animation();
+
     auto pop = [&] (unsigned depth) {
         while (teardownStack.size() > depth) {
             auto& element = *teardownStack.takeLast();
 
-            if (teardownType != TeardownType::KeepHoverAndActive)
+            if (teardownType == TeardownType::Full || teardownType == TeardownType::RendererUpdateCancelingAnimations)
+                animationController.cancelAnimations(element);
+
+            if (teardownType == TeardownType::Full)
                 element.clearHoverAndActiveStatusBeforeDetachingRenderer();
+
             element.clearStyleDerivedDataBeforeDetachingRenderer();
 
             if (auto* renderer = element.renderer()) {