Simplify ScopedStyleResolver keyframe handling.

Just linearly search for keyframes in the set of stylesheets.
Components rarely have many sheets, and sheets rarely have many
keyframes so this should be quite fast. It's also much simpler
than having to collect all the keyframes from all the rulesets.

R=ojan@chromium.org, rafaelw@chromium.org

Review URL: https://codereview.chromium.org/839473005
This commit is contained in:
Elliott Sprehn 2015-01-07 10:47:43 -08:00
parent f4546b7716
commit 8b97399df3
6 changed files with 12 additions and 40 deletions

View File

@ -86,7 +86,7 @@ static void resolveKeyframes(StyleResolver* resolver, Element* element, const El
{
// When the element is null, use its parent for scoping purposes.
const Element* elementForScoping = element ? element : &parentElement;
const StyleRuleKeyframes* keyframesRule = CSSAnimations::matchScopedKeyframesRule(resolver, elementForScoping, name.impl());
const StyleRuleKeyframes* keyframesRule = CSSAnimations::matchScopedKeyframesRule(resolver, elementForScoping, name);
if (!keyframesRule)
return;
@ -193,7 +193,7 @@ static void resolveKeyframes(StyleResolver* resolver, Element* element, const El
} // namespace
const StyleRuleKeyframes* CSSAnimations::matchScopedKeyframesRule(StyleResolver* resolver, const Element* element, const StringImpl* animationName)
const StyleRuleKeyframes* CSSAnimations::matchScopedKeyframesRule(StyleResolver* resolver, const Element* element, String animationName)
{
// FIXME: This is all implementation detail of style resolver, CSSAnimations shouldn't be reaching into any of it.
Vector<RawPtr<ScopedStyleResolver>, 8> stack;

View File

@ -154,7 +154,7 @@ public:
// FIXME: This method is only used here and in the legacy animations
// implementation. It should be made private or file-scope when the legacy
// engine is removed.
static const StyleRuleKeyframes* matchScopedKeyframesRule(StyleResolver*, const Element*, const StringImpl*);
static const StyleRuleKeyframes* matchScopedKeyframesRule(StyleResolver*, const Element*, String animationName);
static const StylePropertyShorthand& animatableProperties();
static bool isAllowedAnimation(CSSPropertyID);

View File

@ -61,34 +61,19 @@ void ScopedStyleResolver::addRulesFromSheet(CSSStyleSheet* cssSheet, StyleResolv
void ScopedStyleResolver::resetAuthorStyle()
{
m_authorStyleSheets.clear();
m_keyframesRuleMap.clear();
m_features.clear();
}
const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(const StringImpl* animationName)
const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(String animationName)
{
if (m_keyframesRuleMap.isEmpty())
return 0;
KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(animationName);
if (it == m_keyframesRuleMap.end())
return 0;
return it->value.get();
}
void ScopedStyleResolver::addKeyframeStyle(PassRefPtr<StyleRuleKeyframes> rule)
{
AtomicString s(rule->name());
if (rule->isVendorPrefixed()) {
KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(rule->name().impl());
if (it == m_keyframesRuleMap.end())
m_keyframesRuleMap.set(s.impl(), rule);
else if (it->value->isVendorPrefixed())
m_keyframesRuleMap.set(s.impl(), rule);
} else {
m_keyframesRuleMap.set(s.impl(), rule);
for (auto& sheet : m_authorStyleSheets) {
// TODO(esprehn): Maybe just store the keyframes in a map?
for (auto& rule : sheet->contents()->ruleSet().keyframesRules()) {
if (rule->name() == animationName)
return rule.get();
}
}
return nullptr;
}
void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& collector, bool includeEmptyRules, bool applyAuthorStyles, CascadeScope cascadeScope, CascadeOrder cascadeOrder)

View File

@ -54,8 +54,7 @@ public:
const TreeScope& treeScope() const { return *m_scope; }
public:
const StyleRuleKeyframes* keyframeStylesForAnimation(const StringImpl* animationName);
void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>);
const StyleRuleKeyframes* keyframeStylesForAnimation(String animationName);
void collectMatchingAuthorRules(ElementRuleCollector&, bool includeEmptyRules, bool applyAuthorStyles, CascadeScope, CascadeOrder = ignoreCascadeOrder);
void addRulesFromSheet(CSSStyleSheet*, StyleResolver*);
@ -70,9 +69,6 @@ private:
RawPtr<TreeScope> m_scope;
Vector<RawPtr<CSSStyleSheet> > m_authorStyleSheets;
typedef HashMap<const StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRuleMap;
KeyframesRuleMap m_keyframesRuleMap;
RuleFeatureSet m_features;
};

View File

@ -195,11 +195,6 @@ void StyleResolver::finishAppendAuthorStyleSheets()
void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet* parentStyleSheet, unsigned parentIndex, ContainerNode& scope)
{
const Vector<RawPtr<StyleRuleKeyframes> > keyframesRules = authorRules.keyframesRules();
ScopedStyleResolver* resolver = &scope.treeScope().scopedStyleResolver();
for (unsigned i = 0; i < keyframesRules.size(); ++i)
resolver->addKeyframeStyle(keyframesRules[i]);
// FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets for the moment.
if (scope.isDocumentNode()) {
const Vector<RawPtr<StyleRuleFontFace> > fontFaceRules = authorRules.fontFaceRules();

View File

@ -196,10 +196,6 @@ private:
template <StyleResolver::StyleApplicationPass pass>
void applyAllProperty(StyleResolverState&, CSSValue*);
// FIXME: This likely belongs on RuleSet.
typedef HashMap<StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRuleMap;
KeyframesRuleMap m_keyframesRuleMap;
static RenderStyle* s_styleNotYetAvailable;
MatchedPropertiesCache m_matchedPropertiesCache;