Chromium Code Reviews| Index: sky/engine/core/css/resolver/SharedStyleFinder.cpp |
| diff --git a/sky/engine/core/css/resolver/SharedStyleFinder.cpp b/sky/engine/core/css/resolver/SharedStyleFinder.cpp |
| index 5f4ee61d7d4d403c57b3be2c146f403b1f3447cb..d27ad6b233d7196c97a56df0b4cfb99a5b21d65f 100644 |
| --- a/sky/engine/core/css/resolver/SharedStyleFinder.cpp |
| +++ b/sky/engine/core/css/resolver/SharedStyleFinder.cpp |
| @@ -48,8 +48,9 @@ |
| namespace blink { |
| -bool SharedStyleFinder::classNamesAffectedByRules(const SpaceSplitString& classNames) const |
| +bool SharedStyleFinder::classNamesAffectedByRules(const Element& element) const |
| { |
| + const SpaceSplitString& classNames = element.classNames(); |
| unsigned count = classNames.size(); |
| for (unsigned i = 0; i < count; ++i) { |
| if (m_features.hasSelectorForClass(classNames[i])) |
| @@ -58,6 +59,17 @@ bool SharedStyleFinder::classNamesAffectedByRules(const SpaceSplitString& classN |
| return false; |
| } |
| +bool SharedStyleFinder::attributesAffectedByRules(const Element& element) const |
| +{ |
| + AttributeCollection attributes = element.attributesWithoutUpdate(); |
| + AttributeCollection::iterator end = attributes.end(); |
| + for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it) { |
|
ojan
2014/12/10 23:22:58
Can you use C++11 iterators here? I think the synt
|
| + if (m_features.hasSelectorForAttribute(it->localName())) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| bool SharedStyleFinder::sharingCandidateHasIdenticalStyleAffectingAttributes(Element& candidate) const |
| { |
| if (element().sharesSameElementData(candidate)) |
| @@ -66,7 +78,7 @@ bool SharedStyleFinder::sharingCandidateHasIdenticalStyleAffectingAttributes(Ele |
| return false; |
| if (!m_elementAffectedByClassRules) { |
| - if (candidate.hasClass() && classNamesAffectedByRules(candidate.classNames())) |
| + if (candidate.hasClass() && classNamesAffectedByRules(candidate)) |
| return false; |
| } else if (candidate.hasClass()) { |
| if (element().classNames() != candidate.classNames()) |
| @@ -176,14 +188,6 @@ inline Element* SharedStyleFinder::findElementForStyleSharing() const |
| return 0; |
| } |
| -bool SharedStyleFinder::matchesRuleSet(RuleSet* ruleSet) |
| -{ |
| - if (!ruleSet) |
| - return false; |
| - ElementRuleCollector collector(m_context); |
| - return collector.hasAnyMatchingRules(ruleSet); |
| -} |
| - |
| RenderStyle* SharedStyleFinder::findSharedStyle() |
| { |
| INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleLookups); |
| @@ -191,8 +195,13 @@ RenderStyle* SharedStyleFinder::findSharedStyle() |
| if (!element().supportsStyleSharing()) |
| return 0; |
| + if (attributesAffectedByRules(element())) { |
| + INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttributeRules); |
| + return 0; |
| + } |
| + |
| // Cache whether context.element() is affected by any known class selectors. |
| - m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedByRules(element().classNames()); |
| + m_elementAffectedByClassRules = element().hasClass() && classNamesAffectedByRules(element()); |
| Element* shareElement = findElementForStyleSharing(); |
| @@ -204,7 +213,7 @@ RenderStyle* SharedStyleFinder::findSharedStyle() |
| INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleFound); |
| - if (matchesRuleSet(m_attributeRuleSet)) { |
| + if (attributesAffectedByRules(*shareElement)) { |
| INCREMENT_STYLE_STATS_COUNTER(m_styleResolver, sharedStyleRejectedByAttributeRules); |
| return 0; |
| } |