Changeset 206951 in webkit


Ignore:
Timestamp:
Oct 8, 2016 1:42:03 AM (7 years ago)
Author:
Antti Koivisto
Message:

Move StyleResolver ownership from Document/ShadowRoot to Style::Scope
https://bugs.webkit.org/show_bug.cgi?id=163148

Reviewed by Andreas Kling.

Reduce duplication between Document and ShadowRoot.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::propertyValue):

  • css/CSSStyleSheet.cpp:

(WebCore::CSSStyleSheet::didMutateRules):

  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::matchHostPseudoClassRules):
(WebCore::ElementRuleCollector::matchSlottedPseudoElementRules):

  • css/MediaQueryMatcher.cpp:

(WebCore::MediaQueryMatcher::documentElementUserAgentStyle):

  • css/StyleMedia.cpp:

(WebCore::StyleMedia::matchMedium):

  • css/parser/SizesAttributeParser.cpp:

(WebCore::SizesAttributeParser::mediaConditionMatches):

  • dom/Document.cpp:

(WebCore::Document::~Document):
(WebCore::Document::childrenChanged):
(WebCore::Document::isPageBoxVisible):
(WebCore::Document::pageSizeAndMarginsInPixels):
(WebCore::Document::userAgentShadowTreeStyleResolver):
(WebCore::Document::fontsNeedUpdate):
(WebCore::Document::didClearStyleResolver):
(WebCore::Document::updateViewportUnitsOnResize):
(WebCore::Document::createStyleResolver): Deleted.
(WebCore::Document::clearStyleResolver): Deleted.

  • dom/Document.h:

(WebCore::Document::styleResolverIfExists): Deleted.
(WebCore::Document::ensureStyleResolver): Deleted.

  • dom/Element.cpp:

(WebCore::Element::styleResolver):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::styleResolver): Deleted.
(WebCore::ShadowRoot::styleResolverIfExists): Deleted.
(WebCore::ShadowRoot::resetStyleResolver): Deleted.

  • dom/ShadowRoot.h:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::getMatchedCSSRules):

  • page/FrameView.cpp:

(WebCore::FrameView::layout):

  • page/Page.cpp:

(WebCore::Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment):

  • page/PrintContext.cpp:

(WebCore::PrintContext::pageProperty):

  • platform/MemoryPressureHandler.cpp:

(WebCore::MemoryPressureHandler::releaseCriticalMemory):

  • style/AttributeChangeInvalidation.cpp:

(WebCore::Style::mayBeAffectedByHostStyle):

  • style/ClassChangeInvalidation.cpp:

(WebCore::Style::mayBeAffectedByHostStyle):

  • style/IdChangeInvalidation.cpp:

(WebCore::Style::mayBeAffectedByHostStyle):

  • style/StyleScope.cpp:

(WebCore::Style::Scope::resolver):
(WebCore::Style::Scope::resolverIfExists):
(WebCore::Style::Scope::clearResolver):
(WebCore::Style::Scope::analyzeStyleSheetChange):
(WebCore::Style::Scope::updateActiveStyleSheets):
(WebCore::Style::Scope::updateStyleResolver):
(WebCore::Style::Scope::styleResolver): Deleted.
(WebCore::Style::Scope::styleResolverIfExists): Deleted.

  • style/StyleScope.h:
  • style/StyleSharingResolver.cpp:

(WebCore::Style::SharingResolver::resolve):
(WebCore::Style::SharingResolver::canShareStyleWithElement):

  • style/StyleTreeResolver.cpp:

(WebCore::Style::TreeResolver::Scope::Scope):
(WebCore::Style::TreeResolver::resolve):

Location:
trunk/Source/WebCore
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206949 r206951  
     12016-10-08  Antti Koivisto  <antti@apple.com>
     2
     3        Move StyleResolver ownership from Document/ShadowRoot to Style::Scope
     4        https://bugs.webkit.org/show_bug.cgi?id=163148
     5
     6        Reviewed by Andreas Kling.
     7
     8        Reduce duplication between Document and ShadowRoot.
     9
     10        * css/CSSComputedStyleDeclaration.cpp:
     11        (WebCore::ComputedStyleExtractor::propertyValue):
     12        * css/CSSStyleSheet.cpp:
     13        (WebCore::CSSStyleSheet::didMutateRules):
     14        * css/ElementRuleCollector.cpp:
     15        (WebCore::ElementRuleCollector::matchHostPseudoClassRules):
     16        (WebCore::ElementRuleCollector::matchSlottedPseudoElementRules):
     17        * css/MediaQueryMatcher.cpp:
     18        (WebCore::MediaQueryMatcher::documentElementUserAgentStyle):
     19        * css/StyleMedia.cpp:
     20        (WebCore::StyleMedia::matchMedium):
     21        * css/parser/SizesAttributeParser.cpp:
     22        (WebCore::SizesAttributeParser::mediaConditionMatches):
     23        * dom/Document.cpp:
     24        (WebCore::Document::~Document):
     25        (WebCore::Document::childrenChanged):
     26        (WebCore::Document::isPageBoxVisible):
     27        (WebCore::Document::pageSizeAndMarginsInPixels):
     28        (WebCore::Document::userAgentShadowTreeStyleResolver):
     29        (WebCore::Document::fontsNeedUpdate):
     30        (WebCore::Document::didClearStyleResolver):
     31        (WebCore::Document::updateViewportUnitsOnResize):
     32        (WebCore::Document::createStyleResolver): Deleted.
     33        (WebCore::Document::clearStyleResolver): Deleted.
     34        * dom/Document.h:
     35        (WebCore::Document::styleResolverIfExists): Deleted.
     36        (WebCore::Document::ensureStyleResolver): Deleted.
     37        * dom/Element.cpp:
     38        (WebCore::Element::styleResolver):
     39        * dom/ShadowRoot.cpp:
     40        (WebCore::ShadowRoot::styleResolver): Deleted.
     41        (WebCore::ShadowRoot::styleResolverIfExists): Deleted.
     42        (WebCore::ShadowRoot::resetStyleResolver): Deleted.
     43        * dom/ShadowRoot.h:
     44        * page/DOMWindow.cpp:
     45        (WebCore::DOMWindow::getMatchedCSSRules):
     46        * page/FrameView.cpp:
     47        (WebCore::FrameView::layout):
     48        * page/Page.cpp:
     49        (WebCore::Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment):
     50        * page/PrintContext.cpp:
     51        (WebCore::PrintContext::pageProperty):
     52        * platform/MemoryPressureHandler.cpp:
     53        (WebCore::MemoryPressureHandler::releaseCriticalMemory):
     54        * style/AttributeChangeInvalidation.cpp:
     55        (WebCore::Style::mayBeAffectedByHostStyle):
     56        * style/ClassChangeInvalidation.cpp:
     57        (WebCore::Style::mayBeAffectedByHostStyle):
     58        * style/IdChangeInvalidation.cpp:
     59        (WebCore::Style::mayBeAffectedByHostStyle):
     60        * style/StyleScope.cpp:
     61        (WebCore::Style::Scope::resolver):
     62        (WebCore::Style::Scope::resolverIfExists):
     63        (WebCore::Style::Scope::clearResolver):
     64        (WebCore::Style::Scope::analyzeStyleSheetChange):
     65        (WebCore::Style::Scope::updateActiveStyleSheets):
     66        (WebCore::Style::Scope::updateStyleResolver):
     67        (WebCore::Style::Scope::styleResolver): Deleted.
     68        (WebCore::Style::Scope::styleResolverIfExists): Deleted.
     69        * style/StyleScope.h:
     70        * style/StyleSharingResolver.cpp:
     71        (WebCore::Style::SharingResolver::resolve):
     72        (WebCore::Style::SharingResolver::canShareStyleWithElement):
     73        * style/StyleTreeResolver.cpp:
     74        (WebCore::Style::TreeResolver::Scope::Scope):
     75        (WebCore::Style::TreeResolver::resolve):
     76
    1772016-10-07  Chris Dumez  <cdumez@apple.com>
    278
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r206839 r206951  
    7171#include "StylePropertyShorthandFunctions.h"
    7272#include "StyleResolver.h"
     73#include "StyleScope.h"
    7374#include "WebKitCSSFilterValue.h"
    7475#include "WebKitCSSTransformValue.h"
     
    24952496        forceFullLayout = isLayoutDependent(propertyID, style, renderer)
    24962497            || styledNode->isInShadowTree()
    2497             || (document.styleResolverIfExists() && document.styleResolverIfExists()->hasViewportDependentMediaQueries() && document.ownerElement());
     2498            || (document.styleScope().resolverIfExists() && document.styleScope().resolverIfExists()->hasViewportDependentMediaQueries() && document.ownerElement());
    24982499
    24992500        if (forceFullLayout) {
  • trunk/Source/WebCore/css/CSSStyleSheet.cpp

    r206917 r206951  
    178178    if (mutationType == RuleInsertion && !contentsWereClonedForMutation && !scope->activeStyleSheetsContains(this)) {
    179179        if (insertedKeyframesRule) {
    180             if (auto* resolver = scope->styleResolverIfExists())
     180            if (auto* resolver = scope->resolverIfExists())
    181181                resolver->addKeyframeStyle(*insertedKeyframesRule);
    182182            return;
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r204543 r206951  
    4646#include "ShadowRoot.h"
    4747#include "StyleProperties.h"
     48#include "StyleScope.h"
    4849#include "StyledElement.h"
    4950
     
    235236    matchRequest.treeContextOrdinal++;
    236237
    237     auto& shadowAuthorStyle = m_element.shadowRoot()->styleResolver().ruleSets().authorStyle();
     238    auto& shadowAuthorStyle = m_element.shadowRoot()->styleScope().resolver().ruleSets().authorStyle();
    238239    auto& shadowHostRules = shadowAuthorStyle.hostPseudoClassRules();
    239240    if (shadowHostRules.isEmpty())
     
    266267        // In nested case the slot may itself be assigned to a slot. Collect ::slotted rules from all the nested trees.
    267268        maybeSlotted = slot;
    268         if (!hostShadowRoot->styleResolver().ruleSets().isAuthorStyleDefined())
     269        if (!hostShadowRoot->styleScope().resolver().ruleSets().isAuthorStyleDefined())
    269270            continue;
    270271        // Find out if there are any ::slotted rules in the shadow tree matching the current slot.
    271272        // FIXME: This is really part of the slot style and could be cached when resolving it.
    272         ElementRuleCollector collector(*slot, hostShadowRoot->styleResolver().ruleSets().authorStyle(), nullptr);
     273        ElementRuleCollector collector(*slot, hostShadowRoot->styleScope().resolver().ruleSets().authorStyle(), nullptr);
    273274        auto slottedPseudoElementRules = collector.collectSlottedPseudoElementRulesForSlot(matchRequest.includeEmptyRules);
    274275        if (!slottedPseudoElementRules)
  • trunk/Source/WebCore/css/MediaQueryMatcher.cpp

    r202658 r206951  
    3131#include "RenderElement.h"
    3232#include "StyleResolver.h"
     33#include "StyleScope.h"
    3334
    3435namespace WebCore {
     
    6667        return nullptr;
    6768
    68     return m_document->ensureStyleResolver().styleForElement(*documentElement, m_document->renderStyle(), MatchOnlyUserAgentRules).renderStyle;
     69    return m_document->styleScope().resolver().styleForElement(*documentElement, m_document->renderStyle(), MatchOnlyUserAgentRules).renderStyle;
    6970}
    7071
  • trunk/Source/WebCore/css/StyleMedia.cpp

    r202167 r206951  
    3535#include "RenderElement.h"
    3636#include "StyleResolver.h"
     37#include "StyleScope.h"
    3738
    3839namespace WebCore {
     
    6364        return false;
    6465
    65     auto rootStyle = document->ensureStyleResolver().styleForElement(*documentElement, document->renderStyle(), MatchOnlyUserAgentRules).renderStyle;
     66    auto rootStyle = document->styleScope().resolver().styleForElement(*documentElement, document->renderStyle(), MatchOnlyUserAgentRules).renderStyle;
    6667
    6768    auto media = MediaQuerySet::create();
  • trunk/Source/WebCore/css/parser/SizesAttributeParser.cpp

    r205905 r206951  
    3737#include "RenderView.h"
    3838#include "SizesCalcParser.h"
     39#include "StyleScope.h"
    3940
    4041namespace WebCore {
     
    111112        return false;
    112113    auto& style = renderer->style();
    113     return MediaQueryEvaluator { "screen", m_document, &style }.evaluate(mediaCondition, m_document.styleResolverIfExists());
     114    return MediaQueryEvaluator { "screen", m_document, &style }.evaluate(mediaCondition, const_cast<Style::Scope&>(m_document.styleScope()).resolverIfExists());
    114115}
    115116
  • trunk/Source/WebCore/dom/Document.cpp

    r206917 r206951  
    632632    extensionStyleSheets().detachFromDocument();
    633633
    634     clearStyleResolver(); // We need to destroy CSSFontSelector before destroying m_cachedResourceLoader.
     634    styleScope().clearResolver(); // We need to destroy CSSFontSelector before destroying m_cachedResourceLoader.
    635635    m_fontSelector->clearDocument();
    636636    m_fontSelector->unregisterForInvalidationCallbacks(*this);
     
    864864    m_documentElement = newDocumentElement;
    865865    // The root style used for media query matching depends on the document element.
    866     clearStyleResolver();
     866    styleScope().clearResolver();
    867867}
    868868
     
    20982098bool Document::isPageBoxVisible(int pageIndex)
    20992099{
    2100     std::unique_ptr<RenderStyle> pageStyle(ensureStyleResolver().styleForPage(pageIndex));
     2100    std::unique_ptr<RenderStyle> pageStyle(styleScope().resolver().styleForPage(pageIndex));
    21012101    return pageStyle->visibility() != HIDDEN; // display property doesn't apply to @page.
    21022102}
     
    21042104void Document::pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft)
    21052105{
    2106     std::unique_ptr<RenderStyle> style = ensureStyleResolver().styleForPage(pageIndex);
     2106    std::unique_ptr<RenderStyle> style = styleScope().resolver().styleForPage(pageIndex);
    21072107
    21082108    int width = pageSize.width();
     
    21402140}
    21412141
    2142 void Document::createStyleResolver()
    2143 {
    2144     m_styleResolver = std::make_unique<StyleResolver>(*this);
    2145     m_styleResolver->appendAuthorStyleSheets(styleScope().activeStyleSheets());
    2146 }
    2147 
    21482142StyleResolver& Document::userAgentShadowTreeStyleResolver()
    21492143{
     
    21522146
    21532147        // FIXME: Filter out shadow pseudo elements we don't want to expose to authors.
    2154         auto& documentAuthorStyle = ensureStyleResolver().ruleSets().authorStyle();
     2148        auto& documentAuthorStyle = styleScope().resolver().ruleSets().authorStyle();
    21552149        if (documentAuthorStyle.hasShadowPseudoElementRules())
    21562150            m_userAgentShadowTreeStyleResolver->ruleSets().authorStyle().copyShadowPseudoElementRulesFrom(documentAuthorStyle);
     
    21622156void Document::fontsNeedUpdate(FontSelector&)
    21632157{
    2164     if (m_styleResolver)
    2165         m_styleResolver->invalidateMatchedPropertiesCache();
     2158    if (auto* resolver = styleScope().resolverIfExists())
     2159        resolver->invalidateMatchedPropertiesCache();
    21662160    if (pageCacheState() != NotInPageCache || !renderView())
    21672161        return;
     
    21692163}
    21702164
    2171 void Document::clearStyleResolver()
    2172 {
    2173     m_styleResolver = nullptr;
     2165void Document::didClearStyleResolver()
     2166{
    21742167    m_userAgentShadowTreeStyleResolver = nullptr;
    21752168
     
    34923485        return;
    34933486
    3494     ensureStyleResolver().clearCachedPropertiesAffectedByViewportUnits();
     3487    styleScope().resolver().clearCachedPropertiesAffectedByViewportUnits();
    34953488
    34963489    // FIXME: Ideally, we should save the list of elements that have viewport units and only iterate over those.
  • trunk/Source/WebCore/dom/Document.h

    r206917 r206951  
    488488    bool isSrcdocDocument() const { return m_isSrcdocDocument; }
    489489
    490     StyleResolver* styleResolverIfExists() const { return m_styleResolver.get(); }
    491 
    492490    bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }
    493491
    494     StyleResolver& ensureStyleResolver()
    495     {
    496         if (!m_styleResolver)
    497             createStyleResolver();
    498         return *m_styleResolver;
    499     }
    500492    StyleResolver& userAgentShadowTreeStyleResolver();
    501493
     
    12311223    void didRemoveAllPendingStylesheet();
    12321224    void setNeedsNotifyRemoveAllPendingStylesheet() { m_needsNotifyRemoveAllPendingStylesheet = true; }
    1233     void clearStyleResolver();
     1225    void didClearStyleResolver();
    12341226
    12351227    bool inStyleRecalc() const { return m_inStyleRecalc; }
     
    13531345    void buildAccessKeyMap(TreeScope* root);
    13541346
    1355     void createStyleResolver();
    1356 
    13571347    void loadEventDelayTimerFired();
    13581348
     
    13981388    unsigned m_referencingNodeCount;
    13991389
    1400     std::unique_ptr<StyleResolver> m_styleResolver;
    14011390    std::unique_ptr<StyleResolver> m_userAgentShadowTreeStyleResolver;
    14021391    bool m_hasNodesWithPlaceholderStyle;
  • trunk/Source/WebCore/dom/Element.cpp

    r206308 r206951  
    9898#include "StyleProperties.h"
    9999#include "StyleResolver.h"
     100#include "StyleScope.h"
    100101#include "StyleTreeResolver.h"
    101102#include "TextIterator.h"
     
    14301431{
    14311432    if (auto* shadowRoot = containingShadowRoot())
    1432         return shadowRoot->styleResolver();
    1433 
    1434     return document().ensureStyleResolver();
     1433        return shadowRoot->styleScope().resolver();
     1434
     1435    return document().styleScope().resolver();
    14351436}
    14361437
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r206917 r206951  
    4242struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope {
    4343    unsigned countersAndFlags[1];
    44     void* styleResolver;
    4544    void* styleScope;
    4645    void* host;
     
    8180}
    8281
    83 StyleResolver& ShadowRoot::styleResolver()
    84 {
    85     if (m_type == Mode::UserAgent)
    86         return document().userAgentShadowTreeStyleResolver();
    87 
    88     if (!m_styleResolver) {
    89         // FIXME: We could share style resolver with shadow roots that have identical style.
    90         m_styleResolver = std::make_unique<StyleResolver>(document());
    91         if (m_styleScope)
    92             m_styleResolver->appendAuthorStyleSheets(m_styleScope->activeStyleSheets());
    93     }
    94     return *m_styleResolver;
    95 }
    96 
    97 StyleResolver* ShadowRoot::styleResolverIfExists()
    98 {
    99     if (m_type == Mode::UserAgent)
    100         return &document().userAgentShadowTreeStyleResolver();
    101 
    102     return m_styleResolver.get();
    103 }
    104 
    105 void ShadowRoot::resetStyleResolver()
    106 {
    107     m_styleResolver = nullptr;
    108 }
    109 
    11082Style::Scope& ShadowRoot::styleScope()
    11183{
     
    11385        m_styleScope = std::make_unique<Style::Scope>(*this);
    11486    return *m_styleScope;
    115 }
    116 
    117 void ShadowRoot::updateStyle()
    118 {
    119     if (!m_styleScope)
    120         return;
    121     // FIXME: Make optimized updated work.
    122     m_styleScope->didChangeContentsOrInterpretation();
    12387}
    12488
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r206917 r206951  
    6262    using TreeScope::rootNode;
    6363
    64     StyleResolver& styleResolver();
    65     StyleResolver* styleResolverIfExists();
    6664    Style::Scope& styleScope();
    67 
    68     void updateStyle();
    69     void resetStyleResolver();
    7065
    7166    bool resetStyleInheritance() const { return m_resetStyleInheritance; }
     
    115110    Element* m_host { nullptr };
    116111
    117     std::unique_ptr<StyleResolver> m_styleResolver;
    118112    std::unique_ptr<Style::Scope> m_styleScope;
    119113
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r206917 r206951  
    14431443    PseudoId pseudoId = CSSSelector::pseudoId(pseudoType);
    14441444
    1445     auto matchedRules = m_frame->document()->ensureStyleResolver().pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
     1445    auto matchedRules = m_frame->document()->styleScope().resolver().pseudoStyleRulesForElement(element, pseudoId, rulesToInclude);
    14461446    if (matchedRules.isEmpty())
    14471447        return nullptr;
  • trunk/Source/WebCore/page/FrameView.cpp

    r206917 r206951  
    13331333
    13341334        // Viewport-dependent media queries may cause us to need completely different style information.
    1335         StyleResolver* styleResolver = document.styleResolverIfExists();
     1335        auto* styleResolver = document.styleScope().resolverIfExists();
    13361336        if (!styleResolver || styleResolver->hasMediaQueriesAffectedByViewportChange()) {
    13371337            LOG(Layout, "  hasMediaQueriesAffectedByViewportChange, enqueueing style recalc");
  • trunk/Source/WebCore/page/Page.cpp

    r206917 r206951  
    492492            if (!frame->document())
    493493                continue;
    494             if (StyleResolver* styleResolver = frame->document()->styleResolverIfExists())
     494            if (StyleResolver* styleResolver = frame->document()->styleScope().resolverIfExists())
    495495                styleResolver->invalidateMatchedPropertiesCache();
    496496            frame->document()->scheduleForcedStyleRecalc();
  • trunk/Source/WebCore/page/PrintContext.cpp

    r201884 r206951  
    2828#include "StyleInheritedData.h"
    2929#include "StyleResolver.h"
     30#include "StyleScope.h"
    3031#include <wtf/text/WTFString.h>
    3132
     
    252253    printContext.begin(800); // Any width is OK here.
    253254    document->updateLayout();
    254     std::unique_ptr<RenderStyle> style = document->ensureStyleResolver().styleForPage(pageNumber);
     255    std::unique_ptr<RenderStyle> style = document->styleScope().resolver().styleForPage(pageNumber);
    255256
    256257    // Implement formatters for properties we care about.
  • trunk/Source/WebCore/platform/MemoryPressureHandler.cpp

    r205275 r206951  
    4040#include "PageCache.h"
    4141#include "ScrollingThread.h"
     42#include "StyleScope.h"
    4243#include "StyledElement.h"
    4344#include "WorkerThread.h"
     
    129130        copyToVector(Document::allDocuments(), documents);
    130131        for (auto& document : documents)
    131             document->clearStyleResolver();
     132            document->styleScope().clearResolver();
    132133    }
    133134
  • trunk/Source/WebCore/style/AttributeChangeInvalidation.cpp

    r204220 r206951  
    3232#include "StyleInvalidationAnalysis.h"
    3333#include "StyleResolver.h"
     34#include "StyleScope.h"
    3435
    3536namespace WebCore {
     
    3839static bool mayBeAffectedByHostStyle(ShadowRoot& shadowRoot, bool isHTML, const QualifiedName& attributeName)
    3940{
    40     auto& shadowRuleSets = shadowRoot.styleResolver().ruleSets();
     41    auto& shadowRuleSets = shadowRoot.styleScope().resolver().ruleSets();
    4142    if (shadowRuleSets.authorStyle().hostPseudoClassRules().isEmpty())
    4243        return false;
  • trunk/Source/WebCore/style/ClassChangeInvalidation.cpp

    r204220 r206951  
    3333#include "StyleInvalidationAnalysis.h"
    3434#include "StyleResolver.h"
     35#include "StyleScope.h"
    3536#include <wtf/BitVector.h>
    3637
     
    8889static bool mayBeAffectedByHostStyle(ShadowRoot& shadowRoot, AtomicStringImpl* changedClass)
    8990{
    90     auto& shadowRuleSets = shadowRoot.styleResolver().ruleSets();
     91    auto& shadowRuleSets = shadowRoot.styleScope().resolver().ruleSets();
    9192    if (shadowRuleSets.authorStyle().hostPseudoClassRules().isEmpty())
    9293        return false;
  • trunk/Source/WebCore/style/IdChangeInvalidation.cpp

    r204220 r206951  
    3131#include "ShadowRoot.h"
    3232#include "StyleResolver.h"
     33#include "StyleScope.h"
    3334
    3435namespace WebCore {
     
    3738static bool mayBeAffectedByHostStyle(ShadowRoot& shadowRoot, const AtomicString& changedId)
    3839{
    39     auto& shadowRuleSets = shadowRoot.styleResolver().ruleSets();
     40    auto& shadowRuleSets = shadowRoot.styleScope().resolver().ruleSets();
    4041    if (shadowRuleSets.authorStyle().hostPseudoClassRules().isEmpty())
    4142        return false;
  • trunk/Source/WebCore/style/StyleScope.cpp

    r206917 r206951  
    7272}
    7373
    74 StyleResolver& Scope::styleResolver()
    75 {
    76     if (m_shadowRoot)
    77         return m_shadowRoot->styleResolver();
    78 
    79     return m_document.ensureStyleResolver();
    80 }
    81 
    82 StyleResolver* Scope::styleResolverIfExists()
    83 {
    84     if (m_shadowRoot)
    85         return m_shadowRoot->styleResolverIfExists();
    86 
    87     return m_document.styleResolverIfExists();
     74StyleResolver& Scope::resolver()
     75{
     76    if (m_shadowRoot && m_shadowRoot->mode() == ShadowRoot::Mode::UserAgent)
     77        return m_document.userAgentShadowTreeStyleResolver();
     78
     79    if (!m_resolver) {
     80        m_resolver = std::make_unique<StyleResolver>(m_document);
     81        m_resolver->appendAuthorStyleSheets(m_activeStyleSheets);
     82    }
     83    return *m_resolver;
     84}
     85
     86StyleResolver* Scope::resolverIfExists()
     87{
     88    if (m_shadowRoot && m_shadowRoot->mode() == ShadowRoot::Mode::UserAgent)
     89        return &m_document.userAgentShadowTreeStyleResolver();
     90
     91    return m_resolver.get();
     92}
     93
     94void Scope::clearResolver()
     95{
     96    m_resolver = nullptr;
     97
     98    if (!m_shadowRoot)
     99        m_document.didClearStyleResolver();
    88100}
    89101
     
    119131
    120132    if (m_shadowRoot) {
    121         m_shadowRoot->updateStyle();
     133        // FIXME: Make optimized updates work.
     134        didChangeContentsOrInterpretation();
    122135        return;
    123136    }
     
    249262    unsigned newStylesheetCount = newStylesheets.size();
    250263
    251     if (!styleResolverIfExists())
     264    if (!resolverIfExists())
    252265        return Reconstruct;
    253266
    254     StyleResolver& styleResolver = *styleResolverIfExists();
     267    auto& styleResolver = *resolverIfExists();
    255268
    256269    // Find out which stylesheets are new.
     
    324337
    325338    if (!m_document.hasLivingRenderTree()) {
    326         m_document.clearStyleResolver();
     339        clearResolver();
    327340        return;
    328341    }
     
    331344    // and haven't calculated the style resolver for the first time.
    332345    if (!m_shadowRoot && !m_didUpdateActiveStyleSheets && m_pendingStyleSheetCount) {
    333         m_document.clearStyleResolver();
     346        clearResolver();
    334347        return;
    335348    }
     
    379392{
    380393    if (updateType == Reconstruct) {
    381         if (m_shadowRoot)
    382             m_shadowRoot->resetStyleResolver();
    383         else
    384             m_document.clearStyleResolver();
    385         return;
    386     }
    387     auto& styleResolver = this->styleResolver();
     394        clearResolver();
     395        return;
     396    }
     397    auto& styleResolver = resolver();
    388398
    389399    if (updateType == Reset) {
  • trunk/Source/WebCore/style/StyleScope.h

    r206917 r206951  
    9090    void flushPendingUpdate();
    9191
    92     StyleResolver& styleResolver();
    93     StyleResolver* styleResolverIfExists();
     92    StyleResolver& resolver();
     93    StyleResolver* resolverIfExists();
     94    void clearResolver();
    9495
    9596    static Scope& forNode(Node&);
     
    114115    Document& m_document;
    115116    ShadowRoot* m_shadowRoot { nullptr };
     117
     118    std::unique_ptr<StyleResolver> m_resolver;
    116119
    117120    Vector<RefPtr<StyleSheet>> m_styleSheetsForStyleSheetList;
  • trunk/Source/WebCore/style/StyleSharingResolver.cpp

    r206916 r206951  
    3535#include "SVGElement.h"
    3636#include "ShadowRoot.h"
     37#include "StyleScope.h"
    3738#include "StyleUpdate.h"
    3839#include "StyledElement.h"
     
    9899    if (elementHasDirectionAuto(element))
    99100        return nullptr;
    100     if (element.shadowRoot() && !element.shadowRoot()->styleResolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
     101    if (element.shadowRoot() && !element.shadowRoot()->styleScope().resolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
    101102        return nullptr;
    102103
     
    288289        return false;
    289290
    290     if (element.shadowRoot() && !element.shadowRoot()->styleResolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
     291    if (element.shadowRoot() && !element.shadowRoot()->styleScope().resolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
    291292        return false;
    292293
  • trunk/Source/WebCore/style/StyleTreeResolver.cpp

    r206917 r206951  
    8484
    8585TreeResolver::Scope::Scope(Document& document)
    86     : styleResolver(document.ensureStyleResolver())
     86    : styleResolver(document.styleScope().resolver())
    8787    , sharingResolver(document, styleResolver.ruleSets(), selectorFilter)
    8888{
     
    9090
    9191TreeResolver::Scope::Scope(ShadowRoot& shadowRoot, Scope& enclosingScope)
    92     : styleResolver(shadowRoot.styleResolver())
     92    : styleResolver(shadowRoot.styleScope().resolver())
    9393    , sharingResolver(shadowRoot.documentScope(), styleResolver.ruleSets(), selectorFilter)
    9494    , shadowRoot(&shadowRoot)
     
    441441    Element* documentElement = m_document.documentElement();
    442442    if (!documentElement) {
    443         m_document.ensureStyleResolver();
     443        m_document.styleScope().resolver();
    444444        return nullptr;
    445445    }
Note: See TracChangeset for help on using the changeset viewer.