Changeset 163475 in webkit


Ignore:
Timestamp:
Feb 5, 2014 1:50:55 PM (10 years ago)
Author:
Antti Koivisto
Message:

ElementRuleCollector should not use StyleResolver::State
https://bugs.webkit.org/show_bug.cgi?id=128247

Source/WebCore:

Reviewed by Andreas Kling.

Make ElementRuleCollector more reusable.

  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::collectMatchingRules):
(WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
(WebCore::ElementRuleCollector::matchAuthorRules):
(WebCore::ElementRuleCollector::matchUARules):
(WebCore::ElementRuleCollector::ruleMatches):
(WebCore::ElementRuleCollector::collectMatchingRulesForList):
(WebCore::ElementRuleCollector::matchAllRules):

  • css/ElementRuleCollector.h:

(WebCore::ElementRuleCollector::ElementRuleCollector):

Pass the objects that are actually needed rather than the entire State.

LayoutTests:

Reviewed by Andreas Kling.

  • platform/mac/fast/parser/xhtml-alternate-entities-expected.png:
  • platform/mac/fast/parser/xhtml-alternate-entities-expected.txt: This is a progression.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r163469 r163475  
     12014-02-05  Antti Koivisto  <antti@apple.com>
     2
     3        ElementRuleCollector should not use StyleResolver::State
     4        https://bugs.webkit.org/show_bug.cgi?id=128247
     5
     6        Reviewed by Andreas Kling.
     7
     8        * platform/mac/fast/parser/xhtml-alternate-entities-expected.png:
     9        * platform/mac/fast/parser/xhtml-alternate-entities-expected.txt: This is a progression.
     10
    1112014-02-05  Yuki Sekiguchi  <yuki.sekiguchi@access-company.com>
    212
  • trunk/LayoutTests/platform/mac/fast/parser/xhtml-alternate-entities-expected.txt

    r161884 r163475  
    1919      RenderText {#text} at (0,0) size 0x0
    2020      RenderText {#text} at (0,0) size 0x0
    21       RenderInline {p} at (0,0) size 489x18
     21      RenderInline {p} at (0,0) size 489x18 [color=#FF0000]
    2222        RenderInline {font} at (0,0) size 489x18
    2323          RenderText {#text} at (0,0) size 489x18
  • trunk/Source/WebCore/ChangeLog

    r163472 r163475  
     12014-02-05  Antti Koivisto  <antti@apple.com>
     2
     3        ElementRuleCollector should not use StyleResolver::State
     4        https://bugs.webkit.org/show_bug.cgi?id=128247
     5
     6        Reviewed by Andreas Kling.
     7       
     8        Make ElementRuleCollector more reusable.
     9
     10        * css/ElementRuleCollector.cpp:
     11        (WebCore::ElementRuleCollector::collectMatchingRules):
     12        (WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
     13        (WebCore::ElementRuleCollector::matchAuthorRules):
     14        (WebCore::ElementRuleCollector::matchUARules):
     15        (WebCore::ElementRuleCollector::ruleMatches):
     16        (WebCore::ElementRuleCollector::collectMatchingRulesForList):
     17        (WebCore::ElementRuleCollector::matchAllRules):
     18        * css/ElementRuleCollector.h:
     19        (WebCore::ElementRuleCollector::ElementRuleCollector):
     20       
     21            Pass the objects that are actually needed rather than the entire State.
     22
    1232014-02-05  Brent Fulgham  <bfulgham@apple.com>
    224
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r163440 r163475  
    33 *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
    44 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
    5  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
     5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Apple Inc. All rights reserved.
    66 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
    77 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
     
    146146{
    147147    ASSERT(matchRequest.ruleSet);
    148     ASSERT(m_state.element());
    149 
    150     const StyleResolver::State& state = m_state;
    151     Element* element = state.element();
    152     const StyledElement* styledElement = state.styledElement();
    153     const AtomicString& pseudoId = element->shadowPseudoId();
    154     if (!pseudoId.isEmpty()) {
    155         ASSERT(styledElement);
     148
     149    const AtomicString& pseudoId = m_element.shadowPseudoId();
     150    if (!pseudoId.isEmpty())
    156151        collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
    157     }
    158152
    159153#if ENABLE(VIDEO_TRACK)
    160     if (element->isWebVTTElement())
     154    if (m_element.isWebVTTElement())
    161155        collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), matchRequest, ruleRange);
    162156#endif
     
    166160    // c) the rules comes from a scoped style sheet within the same tree scope
    167161    if (!MatchingUARulesScope::isMatchingUARules()
    168         && !element->treeScope().applyAuthorStyles())
     162        && !m_element.treeScope().applyAuthorStyles())
    169163        return;
    170164
    171165    // We need to collect the rules for id, class, tag, and everything else into a buffer and
    172166    // then sort the buffer.
    173     if (element->hasID())
    174         collectMatchingRulesForList(matchRequest.ruleSet->idRules(element->idForStyleResolution().impl()), matchRequest, ruleRange);
    175     if (styledElement && styledElement->hasClass()) {
    176         for (size_t i = 0; i < styledElement->classNames().size(); ++i)
    177             collectMatchingRulesForList(matchRequest.ruleSet->classRules(styledElement->classNames()[i].impl()), matchRequest, ruleRange);
    178     }
    179 
    180     if (element->isLink())
     167    if (m_element.hasID())
     168        collectMatchingRulesForList(matchRequest.ruleSet->idRules(m_element.idForStyleResolution().impl()), matchRequest, ruleRange);
     169    if (m_element.hasClass()) {
     170        for (size_t i = 0; i < m_element.classNames().size(); ++i)
     171            collectMatchingRulesForList(matchRequest.ruleSet->classRules(m_element.classNames()[i].impl()), matchRequest, ruleRange);
     172    }
     173
     174    if (m_element.isLink())
    181175        collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
    182     if (SelectorChecker::matchesFocusPseudoClass(element))
     176    if (SelectorChecker::matchesFocusPseudoClass(&m_element))
    183177        collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
    184     collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element->localName().impl()), matchRequest, ruleRange);
     178    collectMatchingRulesForList(matchRequest.ruleSet->tagRules(m_element.localName().impl()), matchRequest, ruleRange);
    185179    collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), matchRequest, ruleRange);
    186180}
     
    204198void ElementRuleCollector::sortAndTransferMatchedRules()
    205199{
    206     const StyleResolver::State& state = m_state;
    207 
    208200    if (!m_matchedRules || m_matchedRules->isEmpty())
    209201        return;
     
    220212    // Now transfer the set of matched rules over to our list of declarations.
    221213    for (unsigned i = 0; i < matchedRules.size(); i++) {
    222         if (state.style() && matchedRules[i]->containsUncommonAttributeSelector())
    223             state.style()->setUnique();
     214        if (m_style && matchedRules[i]->containsUncommonAttributeSelector())
     215            m_style->setUnique();
    224216        m_result.addMatchedProperties(matchedRules[i]->rule()->properties(), matchedRules[i]->rule(), matchedRules[i]->linkMatchType(), matchedRules[i]->propertyWhitelistType(MatchingUARulesScope::isMatchingUARules()));
    225217    }
     
    230222    clearMatchedRules();
    231223    m_result.ranges.lastAuthorRule = m_result.matchedProperties.size() - 1;
    232 
    233     if (!m_state.element())
    234         return;
    235224
    236225    // Match global author rules.
     
    271260
    272261    // In quirks mode, we match rules from the quirks user agent sheet.
    273     if (document().inQuirksMode())
     262    if (m_element.document().inQuirksMode())
    274263        matchUARules(CSSDefaultStyleSheets::defaultQuirksStyle);
    275264
    276265    // If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet.
    277     if (document().isViewSource())
     266    if (m_element.document().isViewSource())
    278267        matchUARules(CSSDefaultStyleSheets::viewSourceStyle());
    279268}
     
    292281inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, PseudoId& dynamicPseudo)
    293282{
    294     const StyleResolver::State& state = m_state;
    295 
    296283    bool fastCheckableSelector = ruleData.hasFastCheckableSelector();
    297284    if (fastCheckableSelector) {
     
    301288        // We know a sufficiently simple single part selector matches simply because we found it from the rule hash.
    302289        // This is limited to HTML only so we don't need to check the namespace.
    303         if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() && state.element()->isHTMLElement()) {
     290        if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() && m_element.isHTMLElement()) {
    304291            if (!ruleData.hasMultipartSelector())
    305292                return true;
     
    310297    void* compiledSelectorChecker = ruleData.compiledSelectorCodeRef().code().executableAddress();
    311298    if (!compiledSelectorChecker && ruleData.compilationStatus() == SelectorCompilationStatus::NotCompiled) {
    312         JSC::VM* vm = document().scriptExecutionContext()->vm();
     299        JSC::VM* vm = m_element.document().scriptExecutionContext()->vm();
    313300        SelectorCompilationStatus compilationStatus;
    314301        JSC::MacroAssemblerCodeRef compiledSelectorCodeRef;
     
    324311        if (ruleData.compilationStatus() == SelectorCompilationStatus::SimpleSelectorChecker) {
    325312            SelectorCompiler::SimpleSelectorChecker selectorChecker = SelectorCompiler::simpleSelectorCheckerFunction(compiledSelectorChecker, ruleData.compilationStatus());
    326             return selectorChecker(state.element());
     313            return selectorChecker(&m_element);
    327314        }
    328315        ASSERT(ruleData.compilationStatus() == SelectorCompilationStatus::SelectorCheckerWithCheckingContext);
     
    330317        SelectorCompiler::SelectorCheckerWithCheckingContext selectorChecker = SelectorCompiler::selectorCheckerFunctionWithCheckingContext(compiledSelectorChecker, ruleData.compilationStatus());
    331318        SelectorCompiler::CheckingContext context;
    332         context.elementStyle = state.style();
     319        context.elementStyle = m_style;
    333320        context.resolvingMode = m_mode;
    334         return selectorChecker(state.element(), &context);
     321        return selectorChecker(&m_element, &context);
    335322    }
    336323#endif // ENABLE(CSS_SELECTOR_JIT)
    337324
    338325    if (fastCheckableSelector) {
    339         if (ruleData.selector()->m_match == CSSSelector::Tag && !SelectorChecker::tagMatches(state.element(), ruleData.selector()->tagQName()))
     326        if (ruleData.selector()->m_match == CSSSelector::Tag && !SelectorChecker::tagMatches(&m_element, ruleData.selector()->tagQName()))
    340327            return false;
    341         SelectorCheckerFastPath selectorCheckerFastPath(ruleData.selector(), state.element());
     328        SelectorCheckerFastPath selectorCheckerFastPath(ruleData.selector(), &m_element);
    342329        if (!selectorCheckerFastPath.matchesRightmostAttributeSelector())
    343330            return false;
     
    347334
    348335    // Slow path.
    349     SelectorChecker selectorChecker(document(), m_mode);
    350     SelectorChecker::SelectorCheckingContext context(ruleData.selector(), state.element(), SelectorChecker::VisitedMatchEnabled);
    351     context.elementStyle = state.style();
     336    SelectorChecker selectorChecker(m_element.document(), m_mode);
     337    SelectorChecker::SelectorCheckingContext context(ruleData.selector(), &m_element, SelectorChecker::VisitedMatchEnabled);
     338    context.elementStyle = m_style;
    352339    context.pseudoId = m_pseudoStyleRequest.pseudoId;
    353340    context.scrollbar = m_pseudoStyleRequest.scrollbar;
     
    364351    if (!rules)
    365352        return;
    366 
    367     const StyleResolver::State& state = m_state;
    368353
    369354    for (unsigned i = 0, size = rules->size(); i < size; ++i) {
     
    393378                if (m_mode == SelectorChecker::CollectingRules)
    394379                    continue;
    395                 if (dynamicPseudo < FIRST_INTERNAL_PSEUDOID)
    396                     state.style()->setHasPseudoStyle(dynamicPseudo);
     380                if (dynamicPseudo < FIRST_INTERNAL_PSEUDOID && m_style)
     381                    m_style->setHasPseudoStyle(dynamicPseudo);
    397382            } else {
    398383                // Update our first/last rule indices in the matched rules array.
     
    431416
    432417    // Now check author rules, beginning first with presentational attributes mapped from HTML.
    433     if (m_state.styledElement()) {
    434         addElementStyleProperties(m_state.styledElement()->presentationAttributeStyle());
     418    if (m_element.isStyledElement()) {
     419        StyledElement& styledElement = toStyledElement(m_element);
     420        addElementStyleProperties(styledElement.presentationAttributeStyle());
    435421
    436422        // Now we check additional mapped declarations.
    437423        // Tables and table cells share an additional mapped rule that must be applied
    438424        // after all attributes, since their mapped style depends on the values of multiple attributes.
    439         addElementStyleProperties(m_state.styledElement()->additionalPresentationAttributeStyle());
    440 
    441         if (m_state.styledElement()->isHTMLElement()) {
     425        addElementStyleProperties(styledElement.additionalPresentationAttributeStyle());
     426
     427        if (styledElement.isHTMLElement()) {
    442428            bool isAuto;
    443             TextDirection textDirection = toHTMLElement(m_state.styledElement())->directionalityIfhasDirAutoAttribute(isAuto);
     429            TextDirection textDirection = toHTMLElement(styledElement).directionalityIfhasDirAutoAttribute(isAuto);
    444430            if (isAuto)
    445431                m_result.addMatchedProperties(textDirection == LTR ? leftToRightDeclaration() : rightToLeftDeclaration());
     
    451437        matchAuthorRules(false);
    452438
    453     // Now check our inline style attribute.
    454     if (matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->inlineStyle()) {
    455         // Inline style is immutable as long as there is no CSSOM wrapper.
    456         // FIXME: Media control shadow trees seem to have problems with caching.
    457         bool isInlineStyleCacheable = !m_state.styledElement()->inlineStyle()->isMutable() && !m_state.styledElement()->isInShadowTree();
    458         // FIXME: Constify.
    459         addElementStyleProperties(m_state.styledElement()->inlineStyle(), isInlineStyleCacheable);
    460     }
    461 
    462     // Now check SMIL animation override style.
    463     if (includeSMILProperties && matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->isSVGElement())
    464         addElementStyleProperties(toSVGElement(m_state.styledElement())->animatedSMILStyleProperties(), false /* isCacheable */);
     439    if (matchAuthorAndUserStyles && m_element.isStyledElement()) {
     440        StyledElement& styledElement = toStyledElement(m_element);
     441        // Now check our inline style attribute.
     442        if (styledElement.inlineStyle()) {
     443            // Inline style is immutable as long as there is no CSSOM wrapper.
     444            // FIXME: Media control shadow trees seem to have problems with caching.
     445            bool isInlineStyleCacheable = !styledElement.inlineStyle()->isMutable() && !styledElement.isInShadowTree();
     446            // FIXME: Constify.
     447            addElementStyleProperties(styledElement.inlineStyle(), isInlineStyleCacheable);
     448        }
     449
     450        // Now check SMIL animation override style.
     451        if (includeSMILProperties && styledElement.isSVGElement())
     452            addElementStyleProperties(toSVGElement(styledElement).animatedSMILStyleProperties(), false /* isCacheable */);
     453    }
    465454}
    466455
  • trunk/Source/WebCore/css/ElementRuleCollector.h

    r163263 r163475  
    11/*
    22 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    3  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013 Apple Inc. All rights reserved.
     3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014 Apple Inc. All rights reserved.
    44 *
    55 * This library is free software; you can redistribute it and/or
     
    4141class ElementRuleCollector {
    4242public:
    43     ElementRuleCollector(StyleResolver* styleResolver, const StyleResolver::State& state)
    44         : m_state(state)
    45         , m_ruleSets(styleResolver->ruleSets())
    46         , m_selectorFilter(styleResolver->selectorFilter())
     43    ElementRuleCollector(Element& element, RenderStyle* style, const DocumentRuleSets& ruleSets, const SelectorFilter& selectorFilter)
     44        : m_element(element)
     45        , m_style(style)
     46        , m_ruleSets(ruleSets)
     47        , m_selectorFilter(selectorFilter)
    4748        , m_isPrintStyle(false)
    4849        , m_regionForStyling(0)
     
    5051        , m_sameOriginOnly(false)
    5152        , m_mode(SelectorChecker::ResolvingStyle)
    52         , m_canUseFastReject(m_selectorFilter.parentStackIsConsistent(state.parentNode()))
     53        , m_canUseFastReject(m_selectorFilter.parentStackIsConsistent(element.parentNode()))
    5354    {
    5455    }
     
    7172
    7273private:
    73     Document& document() { return m_state.document(); }
    7474    void addElementStyleProperties(const StyleProperties*, bool isCacheable = true);
    7575
     
    8787    void clearMatchedRules();
    8888
    89     const StyleResolver::State& m_state;
    90     DocumentRuleSets& m_ruleSets;
    91     SelectorFilter& m_selectorFilter;
     89    Element& m_element;
     90    RenderStyle* m_style;
     91    const DocumentRuleSets& m_ruleSets;
     92    const SelectorFilter& m_selectorFilter;
    9293
    9394    bool m_isPrintStyle;
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r163440 r163475  
    487487        return false;
    488488
    489     ElementRuleCollector collector(this, m_state);
     489    ElementRuleCollector collector(*m_state.element(), m_state.style(), m_ruleSets, m_selectorFilter);
    490490    return collector.hasAnyMatchingRules(ruleSet);
    491491}
     
    797797        m_ruleSets.collectFeatures(document().isViewSource());
    798798
    799     ElementRuleCollector collector(this, state);
     799    ElementRuleCollector collector(*element, state.style(), m_ruleSets, m_selectorFilter);
    800800    collector.setRegionForStyling(regionForStyling);
    801801    collector.setMedium(m_medium.get());
     
    940940}
    941941
    942 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle)
     942PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* element, const PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle)
    943943{
    944944    ASSERT(parentStyle);
    945     if (!e)
     945    if (!element)
    946946        return 0;
    947947
    948948    State& state = m_state;
    949949
    950     initElement(e);
    951 
    952     state.initForStyleResolve(document(), e, parentStyle);
     950    initElement(element);
     951
     952    state.initForStyleResolve(document(), element, parentStyle);
    953953
    954954    if (m_state.parentStyle()) {
     
    964964
    965965    // Check UA, user and author rules.
    966     ElementRuleCollector collector(this, state);
     966    ElementRuleCollector collector(*element, m_state.style(), m_ruleSets, m_selectorFilter);
    967967    collector.setPseudoStyleRequest(pseudoStyleRequest);
    968968    collector.setMedium(m_medium.get());
     
    979979    state.style()->setStyleType(pseudoStyleRequest.pseudoId);
    980980
    981     applyMatchedProperties(collector.matchedResult(), e);
     981    applyMatchedProperties(collector.matchedResult(), element);
    982982
    983983    // Clean up our style object's display and text decorations (among other fixups).
     
    14531453}
    14541454
    1455 Vector<RefPtr<StyleRuleBase>> StyleResolver::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, unsigned rulesToInclude)
    1456 {
    1457     if (!e || !e->document().haveStylesheetsLoaded())
     1455Vector<RefPtr<StyleRuleBase>> StyleResolver::pseudoStyleRulesForElement(Element* element, PseudoId pseudoId, unsigned rulesToInclude)
     1456{
     1457    if (!element || !element->document().haveStylesheetsLoaded())
    14581458        return Vector<RefPtr<StyleRuleBase>>();
    14591459
    1460     initElement(e);
    1461     m_state.initForStyleResolve(document(), e, 0);
    1462 
    1463     ElementRuleCollector collector(this, m_state);
     1460    initElement(element);
     1461    m_state.initForStyleResolve(document(), element, 0);
     1462
     1463    ElementRuleCollector collector(*element, m_state.style(), m_ruleSets, m_selectorFilter);
    14641464    collector.setMode(SelectorChecker::CollectingRules);
    14651465    collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
Note: See TracChangeset for help on using the changeset viewer.