Changeset 142591 in webkit


Ignore:
Timestamp:
Feb 12, 2013 12:07:54 AM (11 years ago)
Author:
tasak@google.com
Message:

[Refactoring] Make m_selectorChecker in StyleResolver an on-stack object.
https://bugs.webkit.org/show_bug.cgi?id=108595

Reviewed by Eric Seidel.

StyleResolver uses SelectorChecker's mode to change its resolving mode.
However it is a state of StyleResolver. StyleResolver should have the
mode and make SelectorChecker instance on a stack while required.

No new tests, just refactoring.

  • css/SelectorChecker.cpp:

(WebCore::SelectorChecker::fastCheckRightmostSelector):
(WebCore::SelectorChecker::fastCheck):
(WebCore::SelectorChecker::commonPseudoClassSelectorMatches):
(WebCore::SelectorChecker::matchesFocusPseudoClass):
Changed to static class function, because these methods never use
"this".
(WebCore):

  • css/SelectorChecker.h:

(SelectorChecker):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::collectMatchingRules):
Now, matchesFocusPseudoClass is not a static method of
SelectorChecker, so replaced "m_selectorChecker." with
"SelectorChecker::".
(WebCore::StyleResolver::sortAndTransferMatchedRules):
(WebCore::StyleResolver::collectMatchingRulesForList):
(WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
(WebCore::StyleResolver::matchUARules):
(WebCore::StyleResolver::adjustRenderStyle):
(WebCore::StyleResolver::pseudoStyleRulesForElement):
Use m_mode instead of m_selectorChecker.mode().
Also use document()->inQuirksMode() instead of
m_selectoChecker.strictParsing().
(WebCore::StyleResolver::ruleMatches):
(WebCore::StyleResolver::checkRegionSelector):
Created an on-stack SelectorChecker object and used it to check
selectors.

  • css/StyleResolver.h:

(WebCore::StyleResolver::State::State):
Added m_mode, this keeps m_selectorChecker's mode.
(State):
(StyleResolver):
Removed m_selectorChecker.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142587 r142591  
     12013-02-12  Takashi Sakamoto  <tasak@google.com>
     2
     3        [Refactoring] Make m_selectorChecker in StyleResolver an on-stack object.
     4        https://bugs.webkit.org/show_bug.cgi?id=108595
     5
     6        Reviewed by Eric Seidel.
     7
     8        StyleResolver uses SelectorChecker's mode to change its resolving mode.
     9        However it is a state of StyleResolver. StyleResolver should have the
     10        mode and make SelectorChecker instance on a stack while required.
     11
     12        No new tests, just refactoring.
     13
     14        * css/SelectorChecker.cpp:
     15        (WebCore::SelectorChecker::fastCheckRightmostSelector):
     16        (WebCore::SelectorChecker::fastCheck):
     17        (WebCore::SelectorChecker::commonPseudoClassSelectorMatches):
     18        (WebCore::SelectorChecker::matchesFocusPseudoClass):
     19        Changed to static class function, because these methods never use
     20        "this".
     21        (WebCore):
     22        * css/SelectorChecker.h:
     23        (SelectorChecker):
     24        * css/StyleResolver.cpp:
     25        (WebCore::StyleResolver::StyleResolver):
     26        (WebCore::StyleResolver::collectMatchingRules):
     27        Now, matchesFocusPseudoClass is not a static method of
     28        SelectorChecker, so replaced "m_selectorChecker." with
     29        "SelectorChecker::".
     30        (WebCore::StyleResolver::sortAndTransferMatchedRules):
     31        (WebCore::StyleResolver::collectMatchingRulesForList):
     32        (WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
     33        (WebCore::StyleResolver::matchUARules):
     34        (WebCore::StyleResolver::adjustRenderStyle):
     35        (WebCore::StyleResolver::pseudoStyleRulesForElement):
     36        Use m_mode instead of m_selectorChecker.mode().
     37        Also use document()->inQuirksMode() instead of
     38        m_selectoChecker.strictParsing().
     39        (WebCore::StyleResolver::ruleMatches):
     40        (WebCore::StyleResolver::checkRegionSelector):
     41        Created an on-stack SelectorChecker object and used it to check
     42        selectors.
     43        * css/StyleResolver.h:
     44        (WebCore::StyleResolver::State::State):
     45        Added m_mode, this keeps m_selectorChecker's mode.
     46        (State):
     47        (StyleResolver):
     48        Removed m_selectorChecker.
     49
    1502013-02-11  Viatcheslav Ostapenko  <sl.ostapenko@samsung.com>
    251
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r142043 r142591  
    140140}
    141141
    142 inline bool SelectorChecker::fastCheckRightmostSelector(const CSSSelector* selector, const Element* element, VisitedMatchType visitedMatchType) const
    143 {
    144     ASSERT(isFastCheckableSelector(selector));
     142bool SelectorChecker::fastCheckRightmostSelector(const CSSSelector* selector, const Element* element, SelectorChecker::VisitedMatchType visitedMatchType)
     143{
     144    ASSERT(SelectorChecker::isFastCheckableSelector(selector));
    145145
    146146    switch (selector->m_match) {
     
    162162}
    163163
    164 bool SelectorChecker::fastCheck(const CSSSelector* selector, const Element* element) const
     164bool SelectorChecker::fastCheck(const CSSSelector* selector, const Element* element)
    165165{
    166166    ASSERT(fastCheckRightmostSelector(selector, element, VisitedMatchEnabled));
     
    10001000}
    10011001
    1002 bool SelectorChecker::commonPseudoClassSelectorMatches(const Element* element, const CSSSelector* selector, VisitedMatchType visitedMatchType) const
     1002bool SelectorChecker::commonPseudoClassSelectorMatches(const Element* element, const CSSSelector* selector, VisitedMatchType visitedMatchType)
    10031003{
    10041004    ASSERT(isCommonPseudoClassSelector(selector));
     
    10671067}
    10681068
     1069bool SelectorChecker::matchesFocusPseudoClass(const Element* element)
     1070{
     1071    if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(element), CSSSelector::PseudoFocus))
     1072        return true;
     1073    return element->focused() && isFrameFocused(element);
     1074}
     1075
    10691076template
    10701077SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, PseudoId&, const DOMSiblingTraversalStrategy&) const;
  • trunk/Source/WebCore/css/SelectorChecker.h

    r140531 r142591  
    8383
    8484    static bool isFastCheckableSelector(const CSSSelector*);
    85     bool fastCheck(const CSSSelector*, const Element*) const;
     85    static bool fastCheck(const CSSSelector*, const Element*);
    8686
    8787    bool strictParsing() const { return m_strictParsing; }
     
    9292    static bool tagMatches(const Element*, const QualifiedName&);
    9393    static bool isCommonPseudoClassSelector(const CSSSelector*);
    94     bool matchesFocusPseudoClass(const Element*) const;
     94    static bool matchesFocusPseudoClass(const Element*);
    9595    static bool fastCheckRightmostAttributeSelector(const Element*, const CSSSelector*);
    9696    static bool checkExactAttribute(const Element*, const QualifiedName& selectorAttributeName, const AtomicStringImpl* value);
     
    101101private:
    102102    bool checkScrollbarPseudoClass(Document*, const CSSSelector*) const;
     103
    103104    static bool isFrameFocused(const Element*);
    104105
    105     bool fastCheckRightmostSelector(const CSSSelector*, const Element*, VisitedMatchType) const;
    106     bool commonPseudoClassSelectorMatches(const Element*, const CSSSelector*, VisitedMatchType) const;
     106    static bool fastCheckRightmostSelector(const CSSSelector*, const Element*, VisitedMatchType);
     107    static bool commonPseudoClassSelectorMatches(const Element*, const CSSSelector*, VisitedMatchType);
    107108
    108109    bool m_strictParsing;
     
    120121        || pseudoType == CSSSelector::PseudoVisited
    121122        || pseudoType == CSSSelector::PseudoFocus;
    122 }
    123 
    124 inline bool SelectorChecker::matchesFocusPseudoClass(const Element* element) const
    125 {
    126     if (InspectorInstrumentation::forcePseudoState(const_cast<Element*>(element), CSSSelector::PseudoFocus))
    127         return true;
    128     return element->focused() && isFrameFocused(element);
    129123}
    130124
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r142573 r142591  
    229229    , m_matchedPropertiesCacheSweepTimer(this, &StyleResolver::sweepMatchedPropertiesCache)
    230230    , m_document(document)
    231     , m_selectorChecker(document)
    232231    , m_matchAuthorAndUserStyles(matchAuthorAndUserStyles)
    233232    , m_fontSelector(CSSFontSelector::create(document))
     
    459458    if (element->isLink())
    460459        collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
    461     if (m_selectorChecker.matchesFocusPseudoClass(element))
     460    if (SelectorChecker::matchesFocusPseudoClass(element))
    462461        collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
    463462    collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element->localName().impl()), matchRequest, ruleRange);
     
    489488    sortMatchedRules();
    490489
    491     if (m_selectorChecker.mode() == SelectorChecker::CollectingRules) {
     490    if (state.mode == SelectorChecker::CollectingRules) {
    492491        if (!state.ruleList)
    493492            state.ruleList = StaticCSSRuleList::create();
     
    656655            // we really just matched a pseudo-element.
    657656            if (state.dynamicPseudo != NOPSEUDO && state.pseudoStyle == NOPSEUDO) {
    658                 if (m_selectorChecker.mode() == SelectorChecker::CollectingRules) {
     657                if (state.mode == SelectorChecker::CollectingRules) {
    659658                    InspectorInstrumentation::didMatchRule(cookie, false);
    660659                    continue;
     
    852851    m_state.matchedRules.clear();
    853852
    854     m_selectorChecker.setMode(SelectorChecker::SharingRules);
     853    m_state.mode = SelectorChecker::SharingRules;
    855854    int firstRuleIndex = -1, lastRuleIndex = -1;
    856855    RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
    857856    collectMatchingRules(MatchRequest(ruleSet), ruleRange);
    858     m_selectorChecker.setMode(SelectorChecker::ResolvingStyle);
     857    m_state.mode = SelectorChecker::ResolvingStyle;
    859858    if (m_state.matchedRules.isEmpty())
    860859        return false;
     
    11381137
    11391138    // In quirks mode, we match rules from the quirks user agent sheet.
    1140     if (!m_selectorChecker.strictParsing())
     1139    if (document()->inQuirksMode())
    11411140        matchUARules(result, CSSDefaultStyleSheets::defaultQuirksStyle);
    11421141
     
    17301729        // Sites also commonly use display:inline/block on <td>s and <table>s. In quirks mode we force
    17311730        // these tags to retain their display types.
    1732         if (!m_selectorChecker.strictParsing() && e) {
     1731        if (document()->inQuirksMode() && e) {
    17331732            if (e->hasTagName(tdTag)) {
    17341733                style->setDisplay(TABLE_CELL);
     
    17771776        // Absolute/fixed positioned elements, floating elements and the document element need block-like outside display.
    17781777        if (style->hasOutOfFlowPosition() || style->isFloating() || (e && e->document()->documentElement() == e))
    1779             style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), m_selectorChecker.strictParsing()));
     1778            style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), !document()->inQuirksMode()));
    17801779
    17811780        // FIXME: Don't support this mutation for pseudo styles like first-letter or first-line, since it's not completely
     
    18071806        if (isDisplayFlexibleBox(parentStyle->display())) {
    18081807            style->setFloating(NoFloat);
    1809             style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), m_selectorChecker.strictParsing()));
     1808            style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), !document()->inQuirksMode()));
    18101809        }
    18111810
     
    20262025        return 0;
    20272026
    2028     m_selectorChecker.setMode(SelectorChecker::CollectingRules);
     2027    m_state.mode = SelectorChecker::CollectingRules;
    20292028
    20302029    initElement(e);
     
    20502049    }
    20512050
    2052     m_selectorChecker.setMode(SelectorChecker::ResolvingStyle);
     2051    m_state.mode = SelectorChecker::ResolvingStyle;
    20532052
    20542053    return m_state.ruleList.release();
     
    20752074            return false;
    20762075
    2077         return m_selectorChecker.fastCheck(ruleData.selector(), state.element);
     2076        return SelectorChecker::fastCheck(ruleData.selector(), state.element);
    20782077    }
    20792078
    20802079    // Slow path.
     2080    SelectorChecker selectorChecker(document());
     2081    selectorChecker.setMode(state.mode);
    20812082    SelectorChecker::SelectorCheckingContext context(ruleData.selector(), state.element, SelectorChecker::VisitedMatchEnabled);
    20822083    context.elementStyle = state.style.get();
    20832084    context.scope = scope;
    20842085    context.pseudoStyle = state.pseudoStyle;
    2085     SelectorChecker::Match match = m_selectorChecker.match(context, state.dynamicPseudo, DOMSiblingTraversalStrategy());
     2086    SelectorChecker::Match match = selectorChecker.match(context, state.dynamicPseudo, DOMSiblingTraversalStrategy());
    20862087    if (match != SelectorChecker::SelectorMatches)
    20872088        return false;
     
    20982099    m_state.pseudoStyle = NOPSEUDO;
    20992100
     2101    SelectorChecker selectorChecker(document());
    21002102    for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s))
    2101         if (m_selectorChecker.matches(s, regionElement))
     2103        if (selectorChecker.matches(s, regionElement))
    21022104            return true;
    21032105
  • trunk/Source/WebCore/css/StyleResolver.h

    r142573 r142591  
    444444        , distributedToInsertionPoint(false)
    445445        , elementAffectedByClassRules(false)
     446        , mode(SelectorChecker::ResolvingStyle)
    446447        , applyPropertyToRegularStyle(true)
    447448        , applyPropertyToVisitedLinkStyle(false)
     
    477478        PseudoId dynamicPseudo;
    478479
     480        SelectorChecker::Mode mode;
     481
    479482        // A buffer used to hold the set of matched rules for an element,
    480483        // and a temporary buffer used for merge sorting.
     
    568571
    569572    Document* m_document;
    570     // FIXME: Make SelectorChecker an on-stack object and
    571     // move selectorChecker.mode() to State.
    572     // selectorChecker.stringParsing() can be replaced with
    573     // !document.inQuirksMode().
    574     SelectorChecker m_selectorChecker;
    575573    SelectorFilter m_selectorFilter;
    576574
Note: See TracChangeset for help on using the changeset viewer.