Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp |
| diff --git a/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp b/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp |
| index dd1ec1e8d8c81e2fb8b27cf5a7c3c0f4fc475fc0..27c010c7d18c6f1b6e37be007117b84ee976716d 100644 |
| --- a/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp |
| +++ b/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp |
| @@ -44,6 +44,7 @@ |
| #include "core/css/CSSCalculationValue.h" |
| #include "core/css/CSSDefaultStyleSheets.h" |
| #include "core/css/CSSFontSelector.h" |
| +#include "core/css/CSSImportRule.h" |
| #include "core/css/CSSKeyframeRule.h" |
| #include "core/css/CSSKeyframesRule.h" |
| #include "core/css/CSSReflectValue.h" |
| @@ -880,6 +881,28 @@ PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::cssRulesForElement(Element* e |
| return pseudoCSSRulesForElement(element, NOPSEUDO, rulesToInclude); |
| } |
| +PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::keyframesRulesForElement(Element* element) |
| +{ |
| + ASSERT(element); |
| + RefPtrWillBeRawPtr<StaticCSSRuleList> ruleList = StaticCSSRuleList::create(); |
| + |
| + // TODO(samli): Repeat for all pseudo elements. |
| + RefPtr<ComputedStyle> style = styleForElement(element); |
| + if (!style) |
| + return ruleList; |
| + const CSSAnimationData* animationData = style->animations(); |
| + for (size_t i = 0; animationData && i < animationData->nameList().size(); ++i) { |
| + AtomicString animationName(animationData->nameList()[i]); |
| + if (animationName == CSSAnimationData::initialName()) |
| + continue; |
| + RefPtrWillBeRawPtr<CSSKeyframesRule> keyframesRule = findCSSKeyframesRule(element, animationName); |
|
alancutter (OOO until 2018)
2015/10/15 00:11:53
It seems like a lot of added complexity to find th
samli
2015/10/15 00:16:07
Yes but with one caveat. I think when we later hav
|
| + if (!keyframesRule) |
| + continue; |
| + ruleList->rules().append(keyframesRule); |
| + } |
| + return ruleList; |
| +} |
| + |
| void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCollector& collector, PseudoId pseudoId, unsigned rulesToInclude) |
| { |
| collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); |
| @@ -953,6 +976,46 @@ StyleRuleKeyframes* StyleResolver::findKeyframesRule(const Element* element, con |
| return nullptr; |
| } |
| +CSSKeyframesRule* StyleResolver::findCSSKeyframesRule(const Element* element, const AtomicString& animationName) |
| +{ |
| + WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers; |
| + collectScopedResolversForHostedShadowTrees(element, resolvers); |
| + if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleResolver()) |
| + resolvers.append(scopedResolver); |
| + |
| + for (size_t i = 0; i < resolvers.size(); ++i) { |
| + if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForAnimation(animationName.impl())) { |
| + CSSStyleSheet* styleSheet = resolvers[i]->styleSheetForAnimation(animationName.impl()); |
| + if (!styleSheet) |
| + continue; |
| + return findCSSKeyframesRule(styleSheet->cssRules(), keyframesRule); |
| + } |
| + } |
| + return nullptr; |
| +} |
| + |
| +CSSKeyframesRule* StyleResolver::findCSSKeyframesRule(PassRefPtrWillBeRawPtr<CSSRuleList> cssRules, StyleRuleKeyframes* keyframesRule) |
| +{ |
| + if (!cssRules) |
| + return nullptr; |
| + CSSKeyframesRule* result = 0; |
| + for (unsigned i = 0; i < cssRules->length() && !result; ++i) { |
| + CSSRule* cssRule = cssRules->item(i); |
| + CSSRule::Type cssRuleType = cssRule->type(); |
| + if (cssRuleType == CSSRule::KEYFRAMES_RULE) { |
| + CSSKeyframesRule* cssKeyframesRule = toCSSKeyframesRule(cssRule); |
| + if (cssKeyframesRule->keyframesRule() == keyframesRule) |
| + return cssKeyframesRule; |
| + } else if (cssRuleType == CSSRule::IMPORT_RULE) { |
| + CSSImportRule* cssImportRule = toCSSImportRule(cssRule); |
| + result = findCSSKeyframesRule(cssImportRule->styleSheet()->cssRules(), keyframesRule); |
| + } else if (cssRuleType != CSSRule::STYLE_RULE) { |
| + result = findCSSKeyframesRule(cssRule->cssRules(), keyframesRule); |
| + } |
| + } |
| + return result; |
| +} |
| + |
| template <CSSPropertyPriority priority> |
| void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const ActiveInterpolationsMap& activeInterpolationsMap) |
| { |