Index: third_party/WebKit/Source/core/css/resolver/ScopedStyleResolver.cpp |
diff --git a/third_party/WebKit/Source/core/css/resolver/ScopedStyleResolver.cpp b/third_party/WebKit/Source/core/css/resolver/ScopedStyleResolver.cpp |
index ede3e41e6aab4baeb3d18af774d92350d35fd7fb..62938aad7228e6751c982301c2e2721604071301 100644 |
--- a/third_party/WebKit/Source/core/css/resolver/ScopedStyleResolver.cpp |
+++ b/third_party/WebKit/Source/core/css/resolver/ScopedStyleResolver.cpp |
@@ -27,6 +27,7 @@ |
#include "core/css/resolver/ScopedStyleResolver.h" |
#include "core/HTMLNames.h" |
+#include "core/animation/DocumentTimeline.h" |
#include "core/css/CSSFontSelector.h" |
#include "core/css/CSSStyleSheet.h" |
#include "core/css/FontFace.h" |
@@ -37,6 +38,7 @@ |
#include "core/css/resolver/MatchRequest.h" |
#include "core/css/resolver/ViewportStyleResolver.h" |
#include "core/dom/Document.h" |
+#include "core/dom/StyleChangeReason.h" |
#include "core/dom/StyleEngine.h" |
#include "core/dom/shadow/ElementShadow.h" |
#include "core/dom/shadow/ShadowRoot.h" |
@@ -144,6 +146,46 @@ void ScopedStyleResolver::addKeyframeStyle(StyleRuleKeyframes* rule) |
} |
} |
+static Node& invalidationRootFor(const TreeScope& treeScope) |
+{ |
+ if (treeScope.rootNode() == treeScope.document()) |
+ return treeScope.document(); |
+ return toShadowRoot(treeScope.rootNode()).host(); |
+} |
+ |
+void ScopedStyleResolver::keyframesRulesAdded(const TreeScope& treeScope) |
+{ |
+ // Called when @keyframes rules are about to be added/removed from a |
+ // TreeScope. @keyframes rules may apply to animations on elements in the |
+ // same TreeScope as the stylesheet, or the host element in the parent |
+ // TreeScope if the TreeScope is a shadow tree. |
+ |
+ ScopedStyleResolver* resolver = treeScope.scopedStyleResolver(); |
+ ScopedStyleResolver* parentResolver = treeScope.parentTreeScope() ? treeScope.parentTreeScope()->scopedStyleResolver() : nullptr; |
+ |
+ bool hadUnresolvedKeyframes = false; |
+ if (resolver && resolver->m_hasUnresolvedKeyframesRule) { |
+ resolver->m_hasUnresolvedKeyframesRule = false; |
+ hadUnresolvedKeyframes = true; |
+ } |
+ if (parentResolver && parentResolver->m_hasUnresolvedKeyframesRule) { |
+ parentResolver->m_hasUnresolvedKeyframesRule = false; |
+ hadUnresolvedKeyframes = true; |
+ } |
+ |
+ if (hadUnresolvedKeyframes) { |
+ // If an animation ended up not being started because no @keyframes |
+ // rules were found for the animation-name, we need to recalculate style |
+ // for the elements in the scope, including its shadow host if |
+ // applicable. |
+ invalidationRootFor(treeScope).setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::StyleSheetChange)); |
+ return; |
+ } |
+ |
+ // If we have animations running, added/removed @keyframes may affect these. |
+ treeScope.document().timeline().invalidateKeyframeEffects(treeScope); |
+} |
+ |
void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& collector, CascadeOrder cascadeOrder) |
{ |
for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { |