Changeset 190347 in webkit


Ignore:
Timestamp:
Sep 30, 2015 8:39:15 AM (9 years ago)
Author:
Antti Koivisto
Message:

Use separate style resolver for user agent shadow trees
https://bugs.webkit.org/show_bug.cgi?id=149626

Reviewed by Andreas Kling.

We now support separate style resolvers for shadow trees. Use this mechanism to have a separate
per-document style resolver for user agent shadow trees. This isolates user agent shadow trees
from author style better and simplifies the style resolver. It can also avoid some unnecessary style recalcs.

  • css/DocumentRuleSets.cpp:

(WebCore::DocumentRuleSets::resetAuthorStyle):
(WebCore::DocumentRuleSets::appendAuthorStyleSheets):

Change interface so that only the new rules are provided.

  • css/DocumentRuleSets.h:
  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::addElementStyleProperties):
(WebCore::ElementRuleCollector::collectMatchingRules):

We can remove special bailout as shadow tree style resolver won't have other author style

(WebCore::ElementRuleCollector::sortAndTransferMatchedRules):

Remove the exception that disables property whitelists for UA stylesheets. We don't seem to use the feature.

(WebCore::ElementRuleCollector::matchUARules):
(WebCore::MatchingUARulesScope::MatchingUARulesScope): Deleted.
(WebCore::MatchingUARulesScope::~MatchingUARulesScope): Deleted.
(WebCore::MatchingUARulesScope::isMatchingUARules): Deleted.

Remove this unnecessary hack.

  • css/ElementRuleCollector.h:

(WebCore::ElementRuleCollector::ElementRuleCollector):

  • css/RuleSet.cpp:

(WebCore::RuleSet::addStyleRule):
(WebCore::RuleSet::copyShadowPseudoElementRulesFrom):

Also copy WebVTT rules. They are currently a sort of mixture of UA and author shadow tree.

(WebCore::shrinkMapVectorsToFit):

  • css/RuleSet.h:

(WebCore::RuleData::containsUncommonAttributeSelector):
(WebCore::RuleData::linkMatchType):
(WebCore::RuleData::hasDocumentSecurityOrigin):
(WebCore::RuleData::propertyWhitelistType):
(WebCore::RuleData::descendantSelectorIdentifierHashes):
(WebCore::RuleSet::ruleCount):
(WebCore::RuleSet::hasShadowPseudoElementRules):

  • css/StyleInvalidationAnalysis.cpp:

(WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
(WebCore::StyleInvalidationAnalysis::invalidateIfNeeded):

Don't invalidate the whole tree when author shadow pseudo element rules change. Just invalidate the shadow trees.

(WebCore::StyleInvalidationAnalysis::invalidateStyleForTree):
(WebCore::StyleInvalidationAnalysis::invalidateStyle):
(WebCore::invalidateIfNeeded): Deleted.
(WebCore::invalidateStyleForTree): Deleted.

  • css/StyleInvalidationAnalysis.h:

(WebCore::StyleInvalidationAnalysis::dirtiesAllStyle):
(WebCore::StyleInvalidationAnalysis::hasShadowPseudoElementRulesInAuthorSheet):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::MatchResult::addMatchedProperties):
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::appendAuthorStyleSheets):

Simpler interface.

  • css/StyleResolver.h:

(WebCore::StyleResolver::document):
(WebCore::StyleResolver::documentSettings):
(WebCore::StyleResolver::ruleSets):

  • dom/AuthorStyleSheets.cpp:

(WebCore::AuthorStyleSheets::collectActiveStyleSheets):
(WebCore::AuthorStyleSheets::analyzeStyleSheetChange):

Cleanups.

(WebCore::filterEnabledNonemptyCSSStyleSheets):
(WebCore::AuthorStyleSheets::updateActiveStyleSheets):
(WebCore::AuthorStyleSheets::updateStyleResolver):

Factor to a function.
Copy any author shadow pseudo elements to user agent shadow tree resolver.

(WebCore::AuthorStyleSheets::activeStyleSheetsForInspector):

  • dom/AuthorStyleSheets.h:
  • dom/Document.cpp:

(WebCore::Document::createStyleResolver):
(WebCore::Document::userAgentShadowTreeStyleResolver):

Use separate resolver.

(WebCore::Document::fontsNeedUpdate):
(WebCore::Document::clearStyleResolver):

  • dom/Document.h:

(WebCore::Document::ensureStyleResolver):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::styleResolver):

Return document-global shadow tree resolver for ua trees.

  • style/StyleResolveTree.cpp:

(WebCore::Style::resolveShadowTree):

Take styleChange of shadow root into account.

Location:
trunk/Source/WebCore
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r190344 r190347  
     12015-09-29  Antti Koivisto  <antti@apple.com>
     2
     3        Use separate style resolver for user agent shadow trees
     4        https://bugs.webkit.org/show_bug.cgi?id=149626
     5
     6        Reviewed by Andreas Kling.
     7
     8        We now support separate style resolvers for shadow trees. Use this mechanism to have a separate
     9        per-document style resolver for user agent shadow trees. This isolates user agent shadow trees
     10        from author style better and simplifies the style resolver. It can also avoid some unnecessary style recalcs.
     11
     12        * css/DocumentRuleSets.cpp:
     13        (WebCore::DocumentRuleSets::resetAuthorStyle):
     14        (WebCore::DocumentRuleSets::appendAuthorStyleSheets):
     15
     16            Change interface so that only the new rules are provided.
     17
     18        * css/DocumentRuleSets.h:
     19        * css/ElementRuleCollector.cpp:
     20        (WebCore::ElementRuleCollector::addElementStyleProperties):
     21        (WebCore::ElementRuleCollector::collectMatchingRules):
     22
     23            We can remove special bailout as shadow tree style resolver won't have other author style
     24
     25        (WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
     26
     27            Remove the exception that disables property whitelists for UA stylesheets. We don't seem to use the feature.
     28
     29        (WebCore::ElementRuleCollector::matchUARules):
     30        (WebCore::MatchingUARulesScope::MatchingUARulesScope): Deleted.
     31        (WebCore::MatchingUARulesScope::~MatchingUARulesScope): Deleted.
     32        (WebCore::MatchingUARulesScope::isMatchingUARules): Deleted.
     33
     34            Remove this unnecessary hack.
     35
     36        * css/ElementRuleCollector.h:
     37        (WebCore::ElementRuleCollector::ElementRuleCollector):
     38        * css/RuleSet.cpp:
     39        (WebCore::RuleSet::addStyleRule):
     40        (WebCore::RuleSet::copyShadowPseudoElementRulesFrom):
     41
     42            Also copy WebVTT rules. They are currently a sort of mixture of UA and author shadow tree.
     43
     44        (WebCore::shrinkMapVectorsToFit):
     45        * css/RuleSet.h:
     46        (WebCore::RuleData::containsUncommonAttributeSelector):
     47        (WebCore::RuleData::linkMatchType):
     48        (WebCore::RuleData::hasDocumentSecurityOrigin):
     49        (WebCore::RuleData::propertyWhitelistType):
     50        (WebCore::RuleData::descendantSelectorIdentifierHashes):
     51        (WebCore::RuleSet::ruleCount):
     52        (WebCore::RuleSet::hasShadowPseudoElementRules):
     53        * css/StyleInvalidationAnalysis.cpp:
     54        (WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis):
     55        (WebCore::StyleInvalidationAnalysis::invalidateIfNeeded):
     56
     57            Don't invalidate the whole tree when author shadow pseudo element rules change. Just invalidate the shadow trees.
     58
     59        (WebCore::StyleInvalidationAnalysis::invalidateStyleForTree):
     60        (WebCore::StyleInvalidationAnalysis::invalidateStyle):
     61        (WebCore::invalidateIfNeeded): Deleted.
     62        (WebCore::invalidateStyleForTree): Deleted.
     63        * css/StyleInvalidationAnalysis.h:
     64        (WebCore::StyleInvalidationAnalysis::dirtiesAllStyle):
     65        (WebCore::StyleInvalidationAnalysis::hasShadowPseudoElementRulesInAuthorSheet):
     66        * css/StyleResolver.cpp:
     67        (WebCore::StyleResolver::MatchResult::addMatchedProperties):
     68        (WebCore::StyleResolver::StyleResolver):
     69        (WebCore::StyleResolver::appendAuthorStyleSheets):
     70
     71            Simpler interface.
     72
     73        * css/StyleResolver.h:
     74        (WebCore::StyleResolver::document):
     75        (WebCore::StyleResolver::documentSettings):
     76        (WebCore::StyleResolver::ruleSets):
     77        * dom/AuthorStyleSheets.cpp:
     78        (WebCore::AuthorStyleSheets::collectActiveStyleSheets):
     79        (WebCore::AuthorStyleSheets::analyzeStyleSheetChange):
     80
     81            Cleanups.
     82
     83        (WebCore::filterEnabledNonemptyCSSStyleSheets):
     84        (WebCore::AuthorStyleSheets::updateActiveStyleSheets):
     85        (WebCore::AuthorStyleSheets::updateStyleResolver):
     86
     87            Factor to a function.
     88            Copy any author shadow pseudo elements to user agent shadow tree resolver.
     89
     90        (WebCore::AuthorStyleSheets::activeStyleSheetsForInspector):
     91        * dom/AuthorStyleSheets.h:
     92        * dom/Document.cpp:
     93        (WebCore::Document::createStyleResolver):
     94        (WebCore::Document::userAgentShadowTreeStyleResolver):
     95
     96            Use separate resolver.
     97
     98        (WebCore::Document::fontsNeedUpdate):
     99        (WebCore::Document::clearStyleResolver):
     100        * dom/Document.h:
     101        (WebCore::Document::ensureStyleResolver):
     102        * dom/ShadowRoot.cpp:
     103        (WebCore::ShadowRoot::styleResolver):
     104
     105            Return document-global shadow tree resolver for ua trees.
     106
     107        * style/StyleResolveTree.cpp:
     108        (WebCore::Style::resolveShadowTree):
     109
     110            Take styleChange of shadow root into account.
     111
    11122015-09-30  Gwang Yoon Hwang  <yoon@igalia.com>
    2113
  • trunk/Source/WebCore/css/DocumentRuleSets.cpp

    r190169 r190347  
    8484}
    8585
    86 void DocumentRuleSets::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet>>& styleSheets, MediaQueryEvaluator* medium, InspectorCSSOMWrappers& inspectorCSSOMWrappers, StyleResolver* resolver)
     86void DocumentRuleSets::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& styleSheets, MediaQueryEvaluator* medium, InspectorCSSOMWrappers& inspectorCSSOMWrappers, StyleResolver* resolver)
    8787{
    8888    // This handles sheets added to the end of the stylesheet list only. In other cases the style resolver
    8989    // needs to be reconstructed. To handle insertions too the rule order numbers would need to be updated.
    90     unsigned size = styleSheets.size();
    91     for (unsigned i = firstNew; i < size; ++i) {
    92         CSSStyleSheet* cssSheet = styleSheets[i].get();
     90    for (auto& cssSheet : styleSheets) {
    9391        ASSERT(!cssSheet->disabled());
    9492        if (cssSheet->mediaQueries() && !medium->eval(cssSheet->mediaQueries(), resolver))
    9593            continue;
    9694        m_authorStyle->addRulesFromSheet(&cssSheet->contents(), *medium, resolver);
    97         inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet);
     95        inspectorCSSOMWrappers.collectFromStyleSheetIfNeeded(cssSheet.get());
    9896    }
    9997    m_authorStyle->shrinkToFit();
  • trunk/Source/WebCore/css/DocumentRuleSets.h

    r190171 r190347  
    5252    void initUserStyle(ExtensionStyleSheets&, const MediaQueryEvaluator&, StyleResolver&);
    5353    void resetAuthorStyle();
    54     void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet>>&, MediaQueryEvaluator*, InspectorCSSOMWrappers&, StyleResolver*);
     54    void appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>&, MediaQueryEvaluator*, InspectorCSSOMWrappers&, StyleResolver*);
    5555
    5656    void collectFeatures();
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r190256 r190347  
    114114}
    115115
    116 class MatchingUARulesScope {
    117 public:
    118     MatchingUARulesScope();
    119     ~MatchingUARulesScope();
    120 
    121     static bool isMatchingUARules();
    122 
    123 private:
    124     static bool m_matchingUARules;
    125 };
    126 
    127 MatchingUARulesScope::MatchingUARulesScope()
    128 {
    129     ASSERT(!m_matchingUARules);
    130     m_matchingUARules = true;
    131 }
    132 
    133 MatchingUARulesScope::~MatchingUARulesScope()
    134 {
    135     m_matchingUARules = false;
    136 }
    137 
    138 inline bool MatchingUARulesScope::isMatchingUARules()
    139 {
    140     return m_matchingUARules;
    141 }
    142 
    143 bool MatchingUARulesScope::m_matchingUARules = false;
    144 
    145116void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
    146117{
     
    159130        if (!pseudoId.isEmpty())
    160131            collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
    161 
    162         // Only match UA rules in shadow tree.
    163         if (!MatchingUARulesScope::isMatchingUARules())
    164             return;
    165132    }
    166133
     
    216183        if (m_style && matchedRule.ruleData->containsUncommonAttributeSelector())
    217184            m_style->setUnique();
    218         m_result.addMatchedProperties(matchedRule.ruleData->rule()->properties(), matchedRule.ruleData->rule(), matchedRule.ruleData->linkMatchType(), matchedRule.ruleData->propertyWhitelistType(MatchingUARulesScope::isMatchingUARules()));
     185        m_result.addMatchedProperties(matchedRule.ruleData->rule()->properties(), matchedRule.ruleData->rule(), matchedRule.ruleData->linkMatchType(), matchedRule.ruleData->propertyWhitelistType());
    219186    }
    220187}
     
    252219void ElementRuleCollector::matchUARules()
    253220{
    254     MatchingUARulesScope scope;
    255 
    256221    // First we match rules from the user agent sheet.
    257222    if (CSSDefaultStyleSheets::simpleDefaultStyleSheet)
  • trunk/Source/WebCore/css/ElementRuleCollector.h

    r178580 r190347  
    5151        , m_ruleSets(ruleSets)
    5252        , m_selectorFilter(selectorFilter)
    53         , m_isPrintStyle(false)
    54         , m_regionForStyling(nullptr)
    55         , m_pseudoStyleRequest(NOPSEUDO)
    56         , m_sameOriginOnly(false)
    57         , m_mode(SelectorChecker::Mode::ResolvingStyle)
    5853        , m_canUseFastReject(m_selectorFilter.parentStackIsConsistent(element.parentNode()))
    5954    {
     
    9994    const SelectorFilter& m_selectorFilter;
    10095
    101     bool m_isPrintStyle;
    102     const RenderRegion* m_regionForStyling;
    103     PseudoStyleRequest m_pseudoStyleRequest;
    104     bool m_sameOriginOnly;
    105     SelectorChecker::Mode m_mode;
     96    bool m_isPrintStyle { false };
     97    const RenderRegion* m_regionForStyling { nullptr };
     98    PseudoStyleRequest m_pseudoStyleRequest { NOPSEUDO };
     99    bool m_sameOriginOnly { false };
     100    SelectorChecker::Mode m_mode { SelectorChecker::Mode::ResolvingStyle };
    106101    bool m_canUseFastReject;
    107102
  • trunk/Source/WebCore/css/RuleSet.cpp

    r186388 r190347  
    378378}
    379379
     380bool RuleSet::hasShadowPseudoElementRules() const
     381{
     382    if (!m_shadowPseudoElementRules.isEmpty())
     383        return true;
     384#if ENABLE(VIDEO_TRACK)
     385    if (!m_cuePseudoRules.isEmpty())
     386        return true;
     387#endif
     388    return false;
     389}
     390
     391void RuleSet::copyShadowPseudoElementRulesFrom(const RuleSet& other)
     392{
     393    for (auto& keyValuePair : other.m_shadowPseudoElementRules)
     394        m_shadowPseudoElementRules.add(keyValuePair.key, std::make_unique<RuleDataVector>(*keyValuePair.value));
     395
     396#if ENABLE(VIDEO_TRACK)
     397    // FIXME: We probably shouldn't treat WebVTT as author stylable user agent shadow tree.
     398    for (auto& cue : other.m_cuePseudoRules)
     399        m_cuePseudoRules.append(cue);
     400#endif
     401}
     402
    380403static inline void shrinkMapVectorsToFit(RuleSet::AtomRuleMap& map)
    381404{
  • trunk/Source/WebCore/css/RuleSet.h

    r186388 r190347  
    8080    unsigned linkMatchType() const { return m_linkMatchType; }
    8181    bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
    82     PropertyWhitelistType propertyWhitelistType(bool isMatchingUARules = false) const { return isMatchingUARules ? PropertyWhitelistNone : static_cast<PropertyWhitelistType>(m_propertyWhitelistType); }
     82    PropertyWhitelistType propertyWhitelistType() const { return static_cast<PropertyWhitelistType>(m_propertyWhitelistType); }
    8383    // Try to balance between memory usage (there can be lots of RuleData objects) and good filtering performance.
    8484    static const unsigned maximumIdentifierCount = 4;
     
    188188    unsigned ruleCount() const { return m_ruleCount; }
    189189
    190     bool hasShadowPseudoElementRules() const { return !m_shadowPseudoElementRules.isEmpty(); }
     190    bool hasShadowPseudoElementRules() const;
     191    void copyShadowPseudoElementRulesFrom(const RuleSet&);
    191192
    192193private:
  • trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp

    r184615 r190347  
    3232#include "ElementRuleCollector.h"
    3333#include "SelectorFilter.h"
     34#include "ShadowRoot.h"
    3435#include "StyleRuleImport.h"
    3536#include "StyleSheetContents.h"
     
    8485        m_ruleSets.authorStyle()->addRulesFromSheet(sheet, mediaQueryEvaluator);
    8586
    86     // FIXME: We don't descent into shadow trees or otherwise handle shadow pseudo elements.
    87     if (m_ruleSets.authorStyle()->hasShadowPseudoElementRules())
    88         m_dirtiesAllStyle = true;
     87    m_hasShadowPseudoElementRulesInAuthorSheet = m_ruleSets.authorStyle()->hasShadowPseudoElementRules();
    8988}
    9089
    91 enum class CheckDescendants { Yes, No };
    92 static CheckDescendants invalidateIfNeeded(Element& element, SelectorFilter& filter, const DocumentRuleSets& ruleSets)
     90StyleInvalidationAnalysis::CheckDescendants StyleInvalidationAnalysis::invalidateIfNeeded(Element& element, SelectorFilter& filter)
    9391{
     92    if (m_hasShadowPseudoElementRulesInAuthorSheet) {
     93        // FIXME: This could do actual rule matching too.
     94        if (auto* shadowRoot = element.shadowRoot())
     95            shadowRoot->setNeedsStyleRecalc();
     96    }
     97
    9498    switch (element.styleChangeType()) {
    9599    case NoStyleChange: {
    96         ElementRuleCollector ruleCollector(element, nullptr, ruleSets, filter);
     100        ElementRuleCollector ruleCollector(element, nullptr, m_ruleSets, filter);
    97101        ruleCollector.setMode(SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements);
    98102        ruleCollector.matchAuthorRules(false);
     
    113117}
    114118
    115 static void invalidateStyleForTree(Element& root, SelectorFilter& filter, const DocumentRuleSets& ruleSets)
     119void StyleInvalidationAnalysis::invalidateStyleForTree(Element& root, SelectorFilter& filter)
    116120{
    117     if (invalidateIfNeeded(root, filter, ruleSets) == CheckDescendants::No)
     121    if (invalidateIfNeeded(root, filter) == CheckDescendants::No)
    118122        return;
    119123
     
    137141        previousElement = &descendant;
    138142
    139         if (invalidateIfNeeded(descendant, filter, ruleSets) == CheckDescendants::Yes)
     143        if (invalidateIfNeeded(descendant, filter) == CheckDescendants::Yes)
    140144            it.traverseNext();
    141145        else
     
    161165    SelectorFilter filter;
    162166    filter.setupParentStack(documentElement);
    163     invalidateStyleForTree(*documentElement, filter, m_ruleSets);
     167    invalidateStyleForTree(*documentElement, filter);
    164168}
    165169
  • trunk/Source/WebCore/css/StyleInvalidationAnalysis.h

    r165676 r190347  
    3434
    3535class Document;
     36class SelectorFilter;
    3637class StyleSheetContents;
    3738
     
    4142
    4243    bool dirtiesAllStyle() const { return m_dirtiesAllStyle; }
     44    bool hasShadowPseudoElementRulesInAuthorSheet() const { return m_hasShadowPseudoElementRulesInAuthorSheet; }
    4345    void invalidateStyle(Document&);
    4446
    4547private:
    46     bool m_dirtiesAllStyle;
     48    enum class CheckDescendants { Yes, No };
     49    CheckDescendants invalidateIfNeeded(Element&, SelectorFilter&);
     50    void invalidateStyleForTree(Element&, SelectorFilter&);
     51
     52    bool m_dirtiesAllStyle { false };
     53    bool m_hasShadowPseudoElementRulesInAuthorSheet { false };
    4754    DocumentRuleSets m_ruleSets;
    4855};
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r190231 r190347  
    272272}
    273273
    274 StyleResolver::StyleResolver(Document& document, bool matchAuthorAndUserStyles)
     274StyleResolver::StyleResolver(Document& document)
    275275    : m_matchedPropertiesCacheAdditionsSinceLastSweep(0)
    276276    , m_matchedPropertiesCacheSweepTimer(*this, &StyleResolver::sweepMatchedPropertiesCache)
    277277    , m_document(document)
    278     , m_matchAuthorAndUserStyles(matchAuthorAndUserStyles)
     278    , m_matchAuthorAndUserStyles(m_document.settings() ? m_document.settings()->authorAndUserStylesEnabled() : true)
    279279#if ENABLE(CSS_DEVICE_ADAPTATION)
    280280    , m_viewportStyleResolver(ViewportStyleResolver::create(&document))
     
    317317}
    318318
    319 void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet>>& styleSheets)
    320 {
    321     m_ruleSets.appendAuthorStyleSheets(firstNew, styleSheets, m_medium.get(), m_inspectorCSSOMWrappers, this);
     319void StyleResolver::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& styleSheets)
     320{
     321    m_ruleSets.appendAuthorStyleSheets(styleSheets, m_medium.get(), m_inspectorCSSOMWrappers, this);
    322322    if (auto renderView = document().renderView())
    323323        renderView->style().fontCascade().update(&document().fontSelector());
  • trunk/Source/WebCore/css/StyleResolver.h

    r189987 r190347  
    139139    WTF_MAKE_NONCOPYABLE(StyleResolver); WTF_MAKE_FAST_ALLOCATED;
    140140public:
    141     StyleResolver(Document&, bool matchAuthorAndUserStyles);
     141    StyleResolver(Document&);
    142142    ~StyleResolver();
    143143
     
    163163    Settings* documentSettings() { return m_document.settings(); }
    164164
    165     // FIXME: It could be better to call m_ruleSets.appendAuthorStyleSheets() directly after we factor StyleRsolver further.
    166     // https://bugs.webkit.org/show_bug.cgi?id=108890
    167     void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet>>&);
     165    void appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>&);
    168166
    169167    DocumentRuleSets& ruleSets() { return m_ruleSets; }
  • trunk/Source/WebCore/dom/AuthorStyleSheets.cpp

    r190256 r190347  
    212212}
    213213
    214 void AuthorStyleSheets::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, StyleResolverUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc)
    215 {
    216     styleResolverUpdateType = Reconstruct;
     214AuthorStyleSheets::StyleResolverUpdateType AuthorStyleSheets::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, bool& requiresFullStyleRecalc)
     215{
    217216    requiresFullStyleRecalc = true;
    218217   
     
    226225    if (m_hadActiveLoadingStylesheet && !hasActiveLoadingStylesheet) {
    227226        m_hadActiveLoadingStylesheet = false;
    228         return;
     227        return Reconstruct;
    229228    }
    230229    m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet;
    231230
    232231    if (updateFlag != OptimizedUpdate)
    233         return;
     232        return Reconstruct;
    234233    if (!m_document.styleResolverIfExists())
    235         return;
     234        return Reconstruct;
     235
    236236    StyleResolver& styleResolver = *m_document.styleResolverIfExists();
    237237
     
    239239    unsigned oldStylesheetCount = m_activeStyleSheets.size();
    240240    if (newStylesheetCount < oldStylesheetCount)
    241         return;
     241        return Reconstruct;
     242
    242243    Vector<StyleSheetContents*> addedSheets;
    243244    unsigned newIndex = 0;
    244245    for (unsigned oldIndex = 0; oldIndex < oldStylesheetCount; ++oldIndex) {
    245246        if (newIndex >= newStylesheetCount)
    246             return;
     247            return Reconstruct;
    247248        while (m_activeStyleSheets[oldIndex] != newStylesheets[newIndex]) {
    248249            addedSheets.append(&newStylesheets[newIndex]->contents());
    249250            ++newIndex;
    250251            if (newIndex == newStylesheetCount)
    251                 return;
     252                return Reconstruct;
    252253        }
    253254        ++newIndex;
     
    260261    // If all new sheets were added at the end of the list we can just add them to existing StyleResolver.
    261262    // If there were insertions we need to re-add all the stylesheets so rules are ordered correctly.
    262     styleResolverUpdateType = hasInsertions ? Reset : Additive;
     263    auto styleResolverUpdateType = hasInsertions ? Reset : Additive;
    263264
    264265    // If we are already parsing the body and so may have significant amount of elements, put some effort into trying to avoid style recalcs.
    265266    if (!m_document.bodyOrFrameset() || m_document.hasNodesWithPlaceholderStyle())
    266         return;
     267        return styleResolverUpdateType;
     268
    267269    StyleInvalidationAnalysis invalidationAnalysis(addedSheets, styleResolver.mediaQueryEvaluator());
    268270    if (invalidationAnalysis.dirtiesAllStyle())
    269         return;
     271        return styleResolverUpdateType;
    270272    invalidationAnalysis.invalidateStyle(m_document);
    271273    requiresFullStyleRecalc = false;
     274
     275    return styleResolverUpdateType;
    272276}
    273277
     
    308312    filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
    309313
    310     StyleResolverUpdateType styleResolverUpdateType;
    311314    bool requiresFullStyleRecalc;
    312     analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
    313 
    314     if (styleResolverUpdateType == Reconstruct) {
    315         if (m_shadowRoot)
    316             m_shadowRoot->resetStyleResolver();
    317         else
    318             m_document.clearStyleResolver();
    319     } else {
    320         StyleResolver& styleResolver = m_document.ensureStyleResolver();
    321         if (styleResolverUpdateType == Reset) {
    322             styleResolver.ruleSets().resetAuthorStyle();
    323             styleResolver.appendAuthorStyleSheets(0, activeCSSStyleSheets);
    324         } else {
    325             ASSERT(styleResolverUpdateType == Additive);
    326             styleResolver.appendAuthorStyleSheets(m_activeStyleSheets.size(), activeCSSStyleSheets);
    327         }
    328     }
     315    auto styleResolverUpdateType = analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, requiresFullStyleRecalc);
     316
     317    updateStyleResolver(activeCSSStyleSheets, styleResolverUpdateType);
    329318
    330319    m_weakCopyOfActiveStyleSheetListForFastLookup = nullptr;
     
    345334}
    346335
     336void AuthorStyleSheets::updateStyleResolver(Vector<RefPtr<CSSStyleSheet>>& activeStyleSheets, StyleResolverUpdateType updateType)
     337{
     338    if (updateType == Reconstruct) {
     339        if (m_shadowRoot)
     340            m_shadowRoot->resetStyleResolver();
     341        else
     342            m_document.clearStyleResolver();
     343        return;
     344    }
     345    auto& styleResolver = m_document.ensureStyleResolver();
     346    auto& userAgentShadowTreeStyleResolver = m_document.userAgentShadowTreeStyleResolver();
     347
     348    if (updateType == Reset) {
     349        styleResolver.ruleSets().resetAuthorStyle();
     350        styleResolver.appendAuthorStyleSheets(activeStyleSheets);
     351    } else {
     352        ASSERT(updateType == Additive);
     353        unsigned firstNewIndex = m_activeStyleSheets.size();
     354        Vector<RefPtr<CSSStyleSheet>> newStyleSheets;
     355        newStyleSheets.appendRange(activeStyleSheets.begin() + firstNewIndex, activeStyleSheets.end());
     356        styleResolver.appendAuthorStyleSheets(newStyleSheets);
     357    }
     358
     359    userAgentShadowTreeStyleResolver.ruleSets().resetAuthorStyle();
     360    auto& authorRuleSet = *styleResolver.ruleSets().authorStyle();
     361    if (authorRuleSet.hasShadowPseudoElementRules())
     362        userAgentShadowTreeStyleResolver.ruleSets().authorStyle()->copyShadowPseudoElementRulesFrom(authorRuleSet);
     363}
     364
    347365const Vector<RefPtr<CSSStyleSheet>> AuthorStyleSheets::activeStyleSheetsForInspector() const
    348366{
  • trunk/Source/WebCore/dom/AuthorStyleSheets.h

    r190256 r190347  
    107107        Additive
    108108    };
    109     void analyzeStyleSheetChange(UpdateFlag, const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, StyleResolverUpdateType&, bool& requiresFullStyleRecalc);
     109    StyleResolverUpdateType analyzeStyleSheetChange(UpdateFlag, const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, bool& requiresFullStyleRecalc);
     110    void updateStyleResolver(Vector<RefPtr<CSSStyleSheet>>&, StyleResolverUpdateType);
    110111
    111112    Document& m_document;
  • trunk/Source/WebCore/dom/Document.cpp

    r190272 r190347  
    21122112void Document::createStyleResolver()
    21132113{
    2114     bool matchAuthorAndUserStyles = true;
    2115     if (Settings* settings = this->settings())
    2116         matchAuthorAndUserStyles = settings->authorAndUserStylesEnabled();
    2117     m_styleResolver = std::make_unique<StyleResolver>(*this, matchAuthorAndUserStyles);
    2118     m_styleResolver->appendAuthorStyleSheets(0, authorStyleSheets().activeStyleSheets());
     2114    m_styleResolver = std::make_unique<StyleResolver>(*this);
     2115    m_styleResolver->appendAuthorStyleSheets(authorStyleSheets().activeStyleSheets());
     2116}
     2117
     2118StyleResolver& Document::userAgentShadowTreeStyleResolver()
     2119{
     2120    if (!m_userAgentShadowTreeStyleResolver) {
     2121        m_userAgentShadowTreeStyleResolver = std::make_unique<StyleResolver>(*this);
     2122
     2123        // FIXME: Filter out shadow pseudo elements we don't want to expose to authors.
     2124        auto& documentAuthorStyle = *ensureStyleResolver().ruleSets().authorStyle();
     2125        if (documentAuthorStyle.hasShadowPseudoElementRules())
     2126            m_userAgentShadowTreeStyleResolver->ruleSets().authorStyle()->copyShadowPseudoElementRulesFrom(documentAuthorStyle);
     2127    }
     2128
     2129    return *m_userAgentShadowTreeStyleResolver;
    21192130}
    21202131
     
    21402151{
    21412152    m_styleResolver = nullptr;
     2153    m_userAgentShadowTreeStyleResolver = nullptr;
    21422154
    21432155    // FIXME: It would be better if the FontSelector could survive this operation.
  • trunk/Source/WebCore/dom/Document.h

    r190272 r190347  
    496496        return *m_styleResolver;
    497497    }
     498    StyleResolver& userAgentShadowTreeStyleResolver();
    498499
    499500    CSSFontSelector& fontSelector();
     
    13951396
    13961397    std::unique_ptr<StyleResolver> m_styleResolver;
     1398    std::unique_ptr<StyleResolver> m_userAgentShadowTreeStyleResolver;
    13971399    bool m_didCalculateStyleResolver;
    13981400    bool m_hasNodesWithPlaceholderStyle;
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r190323 r190347  
    7878StyleResolver& ShadowRoot::styleResolver()
    7979{
    80     // FIXME: Use isolated style resolver for user agent shadow roots.
    8180    if (m_type == Type::UserAgent)
    82         return document().ensureStyleResolver();
     81        return document().userAgentShadowTreeStyleResolver();
    8382
    8483    if (!m_styleResolver) {
    8584        // FIXME: We could share style resolver with shadow roots that have identical style.
    86         m_styleResolver = std::make_unique<StyleResolver>(document(), true);
     85        m_styleResolver = std::make_unique<StyleResolver>(document());
    8786        if (m_authorStyleSheets)
    88             m_styleResolver->appendAuthorStyleSheets(0, m_authorStyleSheets->activeStyleSheets());
     87            m_styleResolver->appendAuthorStyleSheets(m_authorStyleSheets->activeStyleSheets());
    8988    }
    9089    return *m_styleResolver;
  • trunk/Source/WebCore/style/StyleResolveTree.cpp

    r190169 r190347  
    726726    ASSERT(shadowRoot.host() == &host);
    727727    ASSERT(host.renderer());
     728    if (shadowRoot.styleChangeType() >= FullStyleChange)
     729        change = Force;
    728730    RenderTreePosition renderTreePosition(*host.renderer());
    729731    for (Node* child = shadowRoot.firstChild(); child; child = child->nextSibling()) {
  • trunk/Source/WebCore/svg/SVGElement.cpp

    r189987 r190347  
    792792RefPtr<RenderStyle> SVGElement::customStyleForRenderer(RenderStyle& parentStyle)
    793793{
    794     if (!correspondingElement())
    795         return resolveStyle(&parentStyle);
    796 
    797     return styleResolver().styleForElement(correspondingElement(), &parentStyle, DisallowStyleSharing);
     794    // If the element is in a <use> tree we get the style from the definition tree.
     795    if (auto* styleElement = this->correspondingElement())
     796        return styleElement->styleResolver().styleForElement(styleElement, &parentStyle, DisallowStyleSharing);
     797
     798    return resolveStyle(&parentStyle);
    798799}
    799800
Note: See TracChangeset for help on using the changeset viewer.