Changeset 139817 in webkit


Ignore:
Timestamp:
Jan 15, 2013 6:06:05 PM (11 years ago)
Author:
hayato@chromium.org
Message:

Group all request parameters which are used to match CSS Rules into a parameter object.
https://bugs.webkit.org/show_bug.cgi?id=106879

Reviewed by Dimitri Glazkov.

Introduces a MatchRequest which groups all request parameters to match CSS rules.

Factoring, no change in behavior.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::collectMatchingRules):
(WebCore::StyleResolver::collectMatchingRulesForRegion):
(WebCore::StyleResolver::matchScopedAuthorRules):
(WebCore::StyleResolver::matchHostRules):
(WebCore::StyleResolver::matchAuthorRules):
(WebCore::StyleResolver::matchUserRules):
(WebCore::StyleResolver::matchUARules):
(WebCore::StyleResolver::collectMatchingRulesForList):
(WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):

  • css/StyleResolver.h:

(WebCore::StyleResolver::MatchRequest::MatchRequest):
(MatchRequest):
(StyleResolver):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r139815 r139817  
     12013-01-15  Hayato Ito  <hayato@chromium.org>
     2
     3        Group all request parameters which are used to match CSS Rules into a parameter object.
     4        https://bugs.webkit.org/show_bug.cgi?id=106879
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        Introduces a MatchRequest which groups all request parameters to match CSS rules.
     9
     10        Factoring, no change in behavior.
     11
     12        * css/StyleResolver.cpp:
     13        (WebCore::StyleResolver::collectMatchingRules):
     14        (WebCore::StyleResolver::collectMatchingRulesForRegion):
     15        (WebCore::StyleResolver::matchScopedAuthorRules):
     16        (WebCore::StyleResolver::matchHostRules):
     17        (WebCore::StyleResolver::matchAuthorRules):
     18        (WebCore::StyleResolver::matchUserRules):
     19        (WebCore::StyleResolver::matchUARules):
     20        (WebCore::StyleResolver::collectMatchingRulesForList):
     21        (WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
     22        * css/StyleResolver.h:
     23        (WebCore::StyleResolver::MatchRequest::MatchRequest):
     24        (MatchRequest):
     25        (StyleResolver):
     26
    1272013-01-15  Simon Fraser  <simon.fraser@apple.com>
    228
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r139639 r139817  
    643643bool MatchingUARulesScope::m_matchingUARules = false;
    644644
    645 void StyleResolver::collectMatchingRules(RuleSet* rules, int& firstRuleIndex, int& lastRuleIndex, const MatchOptions& options)
    646 {
    647     ASSERT(rules);
     645void StyleResolver::collectMatchingRules(const MatchRequest& matchRequest, int& firstRuleIndex, int& lastRuleIndex)
     646{
     647    ASSERT(matchRequest.ruleSet);
    648648    ASSERT(m_element);
    649649
     
    651651    if (!pseudoId.isEmpty()) {
    652652        ASSERT(m_styledElement);
    653         collectMatchingRulesForList(rules->shadowPseudoElementRules(pseudoId.impl()), firstRuleIndex, lastRuleIndex, options);
     653        collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, firstRuleIndex, lastRuleIndex);
    654654    }
    655655
    656656#if ENABLE(VIDEO_TRACK)
    657657    if (m_element->webVTTNodeType())
    658         collectMatchingRulesForList(rules->cuePseudoRules(), firstRuleIndex, lastRuleIndex, options);
     658        collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), matchRequest, firstRuleIndex, lastRuleIndex);
    659659#endif
    660660    // Check whether other types of rules are applicable in the current tree scope. Criteria for this:
     
    665665    if (!MatchingUARulesScope::isMatchingUARules()
    666666        && !treeScope->applyAuthorStyles()
    667         && (!options.scope || options.scope->treeScope() != treeScope))
     667        && (!matchRequest.scope || matchRequest.scope->treeScope() != treeScope))
    668668        return;
    669669
     
    671671    // then sort the buffer.
    672672    if (m_element->hasID())
    673         collectMatchingRulesForList(rules->idRules(m_element->idForStyleResolution().impl()), firstRuleIndex, lastRuleIndex, options);
     673        collectMatchingRulesForList(matchRequest.ruleSet->idRules(m_element->idForStyleResolution().impl()), matchRequest, firstRuleIndex, lastRuleIndex);
    674674    if (m_styledElement && m_styledElement->hasClass()) {
    675675        for (size_t i = 0; i < m_styledElement->classNames().size(); ++i)
    676             collectMatchingRulesForList(rules->classRules(m_styledElement->classNames()[i].impl()), firstRuleIndex, lastRuleIndex, options);
     676            collectMatchingRulesForList(matchRequest.ruleSet->classRules(m_styledElement->classNames()[i].impl()), matchRequest, firstRuleIndex, lastRuleIndex);
    677677    }
    678678
    679679    if (m_element->isLink())
    680         collectMatchingRulesForList(rules->linkPseudoClassRules(), firstRuleIndex, lastRuleIndex, options);
     680        collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, firstRuleIndex, lastRuleIndex);
    681681    if (m_selectorChecker.matchesFocusPseudoClass(m_element))
    682         collectMatchingRulesForList(rules->focusPseudoClassRules(), firstRuleIndex, lastRuleIndex, options);
    683     collectMatchingRulesForList(rules->tagRules(m_element->localName().impl()), firstRuleIndex, lastRuleIndex, options);
    684     collectMatchingRulesForList(rules->universalRules(), firstRuleIndex, lastRuleIndex, options);
    685 }
    686 
    687 void StyleResolver::collectMatchingRulesForRegion(RuleSet* rules, int& firstRuleIndex, int& lastRuleIndex, const MatchOptions& options)
     682        collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, firstRuleIndex, lastRuleIndex);
     683    collectMatchingRulesForList(matchRequest.ruleSet->tagRules(m_element->localName().impl()), matchRequest, firstRuleIndex, lastRuleIndex);
     684    collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), matchRequest, firstRuleIndex, lastRuleIndex);
     685}
     686
     687void StyleResolver::collectMatchingRulesForRegion(const MatchRequest& matchRequest, int& firstRuleIndex, int& lastRuleIndex)
    688688{
    689689    if (!m_regionForStyling)
    690690        return;
    691691
    692     unsigned size = rules->m_regionSelectorsAndRuleSets.size();
     692    unsigned size = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.size();
    693693    for (unsigned i = 0; i < size; ++i) {
    694         CSSSelector* regionSelector = rules->m_regionSelectorsAndRuleSets.at(i).selector;
     694        CSSSelector* regionSelector = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).selector;
    695695        if (checkRegionSelector(regionSelector, static_cast<Element*>(m_regionForStyling->node()))) {
    696             RuleSet* regionRules = rules->m_regionSelectorsAndRuleSets.at(i).ruleSet.get();
     696            RuleSet* regionRules = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).ruleSet.get();
    697697            ASSERT(regionRules);
    698             collectMatchingRules(regionRules, firstRuleIndex, lastRuleIndex, options);
     698            collectMatchingRules(MatchRequest(regionRules, matchRequest.includeEmptyRules, matchRequest.scope), firstRuleIndex, lastRuleIndex);
    699699        }
    700700    }
     
    754754            }
    755755
    756             MatchOptions options(includeEmptyRules, frame.m_scope);
    757             collectMatchingRules(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
    758             collectMatchingRulesForRegion(frame.m_ruleSet, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
     756            MatchRequest matchRequest(frame.m_ruleSet, includeEmptyRules, frame.m_scope);
     757            collectMatchingRules(matchRequest, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule);
     758            collectMatchingRulesForRegion(matchRequest, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule);
    759759            sortAndTransferMatchedRules(result);
    760760        }
     
    790790        return;
    791791
    792     MatchOptions options(includeEmptyRules, m_element);
    793792    for (unsigned i = matchedRules.size(); i > 0; --i)
    794         collectMatchingRules(matchedRules.at(i-1), result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
     793        collectMatchingRules(MatchRequest(matchedRules.at(i-1), includeEmptyRules, m_element), result.ranges.firstAuthorRule, result.ranges.lastAuthorRule);
    795794    sortAndTransferMatchedRules(result);
    796795#else
     
    809808
    810809    // Match global author rules.
    811     MatchOptions options(includeEmptyRules);
    812     collectMatchingRules(m_authorStyle.get(), result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
    813     collectMatchingRulesForRegion(m_authorStyle.get(), result.ranges.firstAuthorRule, result.ranges.lastAuthorRule, options);
     810    MatchRequest matchRequest(m_authorStyle.get(), includeEmptyRules);
     811    collectMatchingRules(matchRequest, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule);
     812    collectMatchingRulesForRegion(matchRequest, result.ranges.firstAuthorRule, result.ranges.lastAuthorRule);
    814813    sortAndTransferMatchedRules(result);
    815814
     
    825824
    826825    result.ranges.lastUserRule = result.matchedProperties.size() - 1;
    827     collectMatchingRules(m_userStyle.get(), result.ranges.firstUserRule, result.ranges.lastUserRule, includeEmptyRules);
    828     collectMatchingRulesForRegion(m_userStyle.get(), result.ranges.firstUserRule, result.ranges.lastUserRule, includeEmptyRules);
     826    MatchRequest matchRequest(m_userStyle.get(), includeEmptyRules);
     827    collectMatchingRules(matchRequest, result.ranges.firstUserRule, result.ranges.lastUserRule);
     828    collectMatchingRulesForRegion(matchRequest, result.ranges.firstUserRule, result.ranges.lastUserRule);
    829829
    830830    sortAndTransferMatchedRules(result);
     
    836836   
    837837    result.ranges.lastUARule = result.matchedProperties.size() - 1;
    838     collectMatchingRules(rules, result.ranges.firstUARule, result.ranges.lastUARule, false);
     838    collectMatchingRules(MatchRequest(rules), result.ranges.firstUARule, result.ranges.lastUARule);
    839839
    840840    sortAndTransferMatchedRules(result);
    841841}
    842842
    843 void StyleResolver::collectMatchingRulesForList(const Vector<RuleData>* rules, int& firstRuleIndex, int& lastRuleIndex, const MatchOptions& options)
     843void StyleResolver::collectMatchingRulesForList(const Vector<RuleData>* rules, const MatchRequest& matchRequest, int& firstRuleIndex, int& lastRuleIndex)
    844844{
    845845    if (!rules)
     
    858858        StyleRule* rule = ruleData.rule();
    859859        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willMatchRule(document(), rule, this);
    860         if (ruleMatches(ruleData, options.scope)) {
     860        if (ruleMatches(ruleData, matchRequest.scope)) {
    861861            // If the rule has no properties to apply, then ignore it in the non-debug mode.
    862862            const StylePropertySet* properties = rule->properties();
    863             if (!properties || (properties->isEmpty() && !options.includeEmptyRules)) {
     863            if (!properties || (properties->isEmpty() && !matchRequest.includeEmptyRules)) {
    864864                InspectorInstrumentation::didMatchRule(cookie, false);
    865865                continue;
     
    10621062    int firstRuleIndex = -1, lastRuleIndex = -1;
    10631063    m_selectorChecker.setMode(SelectorChecker::SharingRules);
    1064     collectMatchingRules(ruleSet, firstRuleIndex, lastRuleIndex, false);
     1064    collectMatchingRules(MatchRequest(ruleSet), firstRuleIndex, lastRuleIndex);
    10651065    m_selectorChecker.setMode(SelectorChecker::ResolvingStyle);
    10661066    if (m_matchedRules.isEmpty())
  • trunk/Source/WebCore/css/StyleResolver.h

    r139406 r139817  
    343343    };
    344344
    345     struct MatchOptions {
    346         MatchOptions(bool includeEmptyRules, const ContainerNode* scope = 0) : scope(scope), includeEmptyRules(includeEmptyRules) { }
     345    struct MatchRequest {
     346        MatchRequest(RuleSet* ruleSet, bool includeEmptyRules = false, const ContainerNode* scope = 0)
     347            : ruleSet(ruleSet)
     348            , includeEmptyRules(includeEmptyRules)
     349            , scope(scope) { }
     350        const RuleSet* ruleSet;
     351        const bool includeEmptyRules;
    347352        const ContainerNode* scope;
    348         bool includeEmptyRules;
    349353    };
    350354
     
    359363    void matchScopedAuthorRules(MatchResult&, bool includeEmptyRules);
    360364    void matchHostRules(MatchResult&, bool includeEmptyRules);
    361     void collectMatchingRules(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, const MatchOptions&);
    362     void collectMatchingRulesForRegion(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, const MatchOptions&);
    363     void collectMatchingRulesForList(const Vector<RuleData>*, int& firstRuleIndex, int& lastRuleIndex, const MatchOptions&);
     365
     366    void collectMatchingRules(const MatchRequest&, int& firstRuleIndex, int& lastRuleIndex);
     367    void collectMatchingRulesForRegion(const MatchRequest&, int& firstRuleIndex, int& lastRuleIndex);
     368    void collectMatchingRulesForList(const Vector<RuleData>*, const MatchRequest&, int& firstRuleIndex, int& lastRuleIndex);
     369
    364370    bool fastRejectSelector(const RuleData&) const;
    365371    void sortMatchedRules();
Note: See TracChangeset for help on using the changeset viewer.