Changeset 130089 in webkit


Ignore:
Timestamp:
Oct 1, 2012 3:54:29 PM (12 years ago)
Author:
Dimitri Glazkov
Message:

Kill transitive effects of SelectorChecker::checkOneSelector.
https://bugs.webkit.org/show_bug.cgi?id=97953

Reviewed by Eric Seidel.

The dynamicPseudo/hasUnknownPseudoelements by-ref parameters that are passed into checkOneSelector make the logic harder to understand and aren't needed. Refactor the code to rid of them, replacing them instead with two flags in SelectorCheckingContext.

No change in behavior, covered by existing tests.

  • css/SelectorChecker.cpp:

(WebCore::SelectorChecker::checkSelector): Rolled pseudo-element-checking code out of checkOneSelector into here, since that is where t
(WebCore::SelectorChecker::checkOneSelector): Changed to use SelectorCheckingContext rather than transitive params.

  • css/SelectorChecker.h:

(WebCore::SelectorChecker::SelectorCheckingContext::SelectorCheckingContext): Added two new flags.
(SelectorCheckingContext): Ditto.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r130088 r130089  
     12012-10-01  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        Kill transitive effects of SelectorChecker::checkOneSelector.
     4        https://bugs.webkit.org/show_bug.cgi?id=97953
     5
     6        Reviewed by Eric Seidel.
     7
     8        The dynamicPseudo/hasUnknownPseudoelements by-ref parameters that are passed into checkOneSelector make the logic harder to understand and aren't needed. Refactor the code to rid of them, replacing them instead with two flags in SelectorCheckingContext.
     9
     10        No change in behavior, covered by existing tests.
     11
     12        * css/SelectorChecker.cpp:
     13        (WebCore::SelectorChecker::checkSelector): Rolled pseudo-element-checking code out of checkOneSelector into here, since that is where t
     14        (WebCore::SelectorChecker::checkOneSelector): Changed to use SelectorCheckingContext rather than transitive params.
     15        * css/SelectorChecker.h:
     16        (WebCore::SelectorChecker::SelectorCheckingContext::SelectorCheckingContext): Added two new flags.
     17        (SelectorCheckingContext): Ditto.
     18
     19
    1202012-10-01  Andreas Kling  <kling@webkit.org>
    221
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r129974 r130089  
    267267    }
    268268
    269     PseudoId dynamicPseudo = NOPSEUDO;
     269    PseudoId ignoreDynamicPseudo = NOPSEUDO;
    270270    bool hasUnknownPseudoElements = false;
    271     return checkSelector(SelectorCheckingContext(sel, element, SelectorChecker::VisitedMatchDisabled), dynamicPseudo, hasUnknownPseudoElements) == SelectorMatches;
     271    return checkSelector(SelectorCheckingContext(sel, element, SelectorChecker::VisitedMatchDisabled), ignoreDynamicPseudo, hasUnknownPseudoElements) == SelectorMatches;
    272272}
    273273
     
    443443{
    444444    // first selector has to match
    445     if (!checkOneSelector(context, dynamicPseudo, hasUnknownPseudoElements))
     445    if (!checkOneSelector(context))
    446446        return SelectorFailsLocally;
     447
     448    if (context.selector->m_match == CSSSelector::PseudoElement) {
     449        if (context.selector->isUnknownPseudoElement()) {
     450            hasUnknownPseudoElements = true;
     451            if (context.element->shadowPseudoId() != context.selector->value())
     452                return SelectorFailsLocally;
     453        } else {
     454            if ((!context.elementStyle && m_mode == ResolvingStyle) || m_mode == QueryingRules)
     455                return SelectorFailsLocally;
     456
     457            PseudoId pseudoId = CSSSelector::pseudoId(context.selector->pseudoType());
     458            if (pseudoId == FIRST_LETTER) {
     459                if (Document* document = context.element->document())
     460                    document->styleSheetCollection()->setUsesFirstLetterRules(true);
     461            }
     462            if (pseudoId != NOPSEUDO)
     463                dynamicPseudo = pseudoId;
     464        }
     465    }
    447466
    448467    // The rest of the selectors has to match
     
    533552        // We make an exception for scrollbar pseudo elements and allow a set of pseudo classes (but nothing else)
    534553        // to follow the pseudo elements.
    535         if ((context.elementStyle || m_mode == CollectingRules || m_mode == QueryingRules) && dynamicPseudo != NOPSEUDO && dynamicPseudo != SELECTION
    536              && !((RenderScrollbar::scrollbarForStyleResolve() || dynamicPseudo == SCROLLBAR_CORNER || dynamicPseudo == RESIZER) && nextContext.selector->m_match == CSSSelector::PseudoClass))
     554        nextContext.hasScrollbarPseudo = RenderScrollbar::scrollbarForStyleResolve() || dynamicPseudo == SCROLLBAR_CORNER || dynamicPseudo == RESIZER;
     555        nextContext.hasSelectionPseudo = dynamicPseudo == SELECTION;
     556        if ((context.elementStyle || m_mode == CollectingRules || m_mode == QueryingRules) && dynamicPseudo != NOPSEUDO
     557            && !nextContext.hasSelectionPseudo
     558            && !(nextContext.hasScrollbarPseudo && nextContext.selector->m_match == CSSSelector::PseudoClass))
    537559            return SelectorFailsCompletely;
    538560        nextContext.isSubSelector = true;
     
    705727}
    706728
    707 bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context, PseudoId& dynamicPseudo, bool& hasUnknownPseudoElements) const
     729bool SelectorChecker::checkOneSelector(const SelectorCheckingContext& context) const
    708730{
    709731    Element* const & element = context.element;
     
    752774                if (subContext.selector->pseudoType() == CSSSelector::PseudoVisited || (subContext.selector->pseudoType() == CSSSelector::PseudoLink && subContext.visitedMatchType == VisitedMatchEnabled))
    753775                    return true;
    754                 if (!checkOneSelector(subContext, dynamicPseudo, hasUnknownPseudoElements))
     776                if (!checkOneSelector(subContext))
    755777                    return true;
    756778            }
    757         } else if (dynamicPseudo != NOPSEUDO && (RenderScrollbar::scrollbarForStyleResolve() || dynamicPseudo == SCROLLBAR_CORNER || dynamicPseudo == RESIZER)) {
     779        } else if (context.hasScrollbarPseudo) {
    758780            // CSS scrollbars match a specific subset of pseudo classes, and they have specialized rules for each
    759781            // (since there are no elements involved).
    760782            return checkScrollbarPseudoClass(selector);
    761         } else if (dynamicPseudo == SELECTION) {
     783        } else if (context.hasSelectionPseudo) {
    762784            if (selector->pseudoType() == CSSSelector::PseudoWindowInactive)
    763785                return !m_document->page()->focusController()->isActive();
     
    10011023                SelectorCheckingContext subContext(context);
    10021024                subContext.isSubSelector = true;
     1025                bool hasUnknownPseudoElements = false;
     1026                PseudoId ignoreDynamicPseudo = NOPSEUDO;
    10031027                for (subContext.selector = selector->selectorList()->first(); subContext.selector; subContext.selector = CSSSelectorList::next(subContext.selector)) {
    1004                     if (checkSelector(subContext, dynamicPseudo, hasUnknownPseudoElements) == SelectorMatches)
     1028                    if (checkSelector(subContext, ignoreDynamicPseudo, hasUnknownPseudoElements) == SelectorMatches)
    10051029                        return true;
    10061030                }
     
    11751199        }
    11761200        return false;
    1177     }
    1178     if (selector->m_match == CSSSelector::PseudoElement) {
    1179         if (selector->isUnknownPseudoElement()) {
    1180             hasUnknownPseudoElements = true;
    1181             return element->shadowPseudoId() == selector->value();
    1182         }
    1183 
    1184         if ((!context.elementStyle && m_mode == ResolvingStyle) || m_mode == QueryingRules)
    1185             return false;
    1186 
    1187         PseudoId pseudoId = CSSSelector::pseudoId(selector->pseudoType());
    1188         if (pseudoId == FIRST_LETTER) {
    1189             if (Document* document = element->document())
    1190                 document->styleSheetCollection()->setUsesFirstLetterRules(true);
    1191         }
    1192         if (pseudoId != NOPSEUDO)
    1193             dynamicPseudo = pseudoId;
    11941201    }
    11951202    // ### add the rest of the checks...
  • trunk/Source/WebCore/css/SelectorChecker.h

    r129963 r130089  
    6666            , isSubSelector(false)
    6767            , pseudoStyle(NOPSEUDO)
     68            , hasScrollbarPseudo(false)
     69            , hasSelectionPseudo(false)
    6870        { }
    6971
     
    7678        bool isSubSelector;
    7779        PseudoId pseudoStyle;
     80        bool hasScrollbarPseudo;
     81        bool hasSelectionPseudo;
    7882    };
    7983
     
    118122
    119123private:
    120     bool checkOneSelector(const SelectorCheckingContext&, PseudoId&, bool& hasUnknownPseudoElements) const;
     124    bool checkOneSelector(const SelectorCheckingContext&) const;
    121125    bool checkScrollbarPseudoClass(CSSSelector*) const;
    122126    static bool isFrameFocused(const Element*);
Note: See TracChangeset for help on using the changeset viewer.