Changeset 207077 in webkit


Ignore:
Timestamp:
Oct 11, 2016 3:24:07 AM (8 years ago)
Author:
Antti Koivisto
Message:

Stop copying author shadow pseudo rules into shadow tree style resolver
https://bugs.webkit.org/show_bug.cgi?id=163232

Reviewed by Darin Adler.

  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::collectMatchingRules):
(WebCore::ElementRuleCollector::matchAuthorRules):
(WebCore::ElementRuleCollector::matchAuthorShadowPseudoElementRules):

If we are resolving a user agent shadow tree also look up pseudo element rules from the host scope author sheet.
This is needed to keep web exposed ::-webkit-foo pseudo elements working.

(WebCore::ElementRuleCollector::collectMatchingShadowPseudoElementRules):

Factor to a function.

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

(WebCore::RuleSet::copyShadowPseudoElementRulesFrom): Deleted.

  • css/RuleSet.h:
  • dom/Document.cpp:

(WebCore::Document::userAgentShadowTreeStyleResolver):

  • style/StyleScope.cpp:

(WebCore::Style::Scope::updateStyleResolver):

No need to awkwardly copy these rules anymore.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207058 r207077  
     12016-10-10  Antti Koivisto  <antti@apple.com>
     2
     3        Stop copying author shadow pseudo rules into shadow tree style resolver
     4        https://bugs.webkit.org/show_bug.cgi?id=163232
     5
     6        Reviewed by Darin Adler.
     7
     8        * css/ElementRuleCollector.cpp:
     9        (WebCore::ElementRuleCollector::collectMatchingRules):
     10        (WebCore::ElementRuleCollector::matchAuthorRules):
     11        (WebCore::ElementRuleCollector::matchAuthorShadowPseudoElementRules):
     12
     13            If we are resolving a user agent shadow tree also look up pseudo element rules from the host scope author sheet.
     14            This is needed to keep web exposed ::-webkit-foo pseudo elements working.
     15
     16        (WebCore::ElementRuleCollector::collectMatchingShadowPseudoElementRules):
     17
     18            Factor to a function.
     19
     20        * css/ElementRuleCollector.h:
     21        * css/RuleSet.cpp:
     22        (WebCore::RuleSet::copyShadowPseudoElementRulesFrom): Deleted.
     23        * css/RuleSet.h:
     24        * dom/Document.cpp:
     25        (WebCore::Document::userAgentShadowTreeStyleResolver):
     26        * style/StyleScope.cpp:
     27        (WebCore::Style::Scope::updateStyleResolver):
     28
     29            No need to awkwardly copy these rules anymore.
     30
    1312016-10-11  Chris Dumez  <cdumez@apple.com>
    232
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r206951 r207077  
    144144    ASSERT_WITH_MESSAGE(!(m_mode == SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements && m_pseudoStyleRequest.pseudoId != NOPSEUDO), "When in StyleInvalidation or SharingRules, SelectorChecker does not try to match the pseudo ID. While ElementRuleCollector supports matching a particular pseudoId in this case, this would indicate a error at the call site since matching a particular element should be unnecessary.");
    145145
    146 #if ENABLE(VIDEO_TRACK)
    147     if (m_element.isWebVTTElement())
    148         collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), matchRequest, ruleRange);
    149 #endif
    150 
    151146    auto* shadowRoot = m_element.containingShadowRoot();
    152     if (shadowRoot && shadowRoot->mode() == ShadowRoot::Mode::UserAgent) {
    153         const AtomicString& pseudoId = m_element.shadowPseudoId();
    154         if (!pseudoId.isEmpty())
    155             collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
    156     }
     147    if (shadowRoot && shadowRoot->mode() == ShadowRoot::Mode::UserAgent)
     148        collectMatchingShadowPseudoElementRules(matchRequest, ruleRange);
    157149
    158150    // We need to collect the rules for id, class, tag, and everything else into a buffer and
     
    227219        matchHostPseudoClassRules(matchRequest, ruleRange);
    228220
     221    if (m_element.isInShadowTree())
     222        matchAuthorShadowPseudoElementRules(matchRequest, ruleRange);
     223
    229224    sortAndTransferMatchedRules();
     225}
     226
     227void ElementRuleCollector::matchAuthorShadowPseudoElementRules(const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
     228{
     229    ASSERT(m_element.isInShadowTree());
     230    auto& shadowRoot = *m_element.containingShadowRoot();
     231    if (shadowRoot.mode() != ShadowRoot::Mode::UserAgent)
     232        return;
     233    // Look up shadow pseudo elements also from the host scope author style as they are web-exposed.
     234    auto& hostAuthorRules = Style::Scope::forNode(*shadowRoot.host()).resolver().ruleSets().authorStyle();
     235    MatchRequest hostAuthorRequest { &hostAuthorRules, matchRequest.includeEmptyRules };
     236    collectMatchingShadowPseudoElementRules(hostAuthorRequest, ruleRange);
    230237}
    231238
     
    283290        m_keepAliveSlottedPseudoElementRules.append(WTFMove(slottedPseudoElementRules));
    284291    }
     292}
     293
     294void ElementRuleCollector::collectMatchingShadowPseudoElementRules(const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
     295{
     296    ASSERT(matchRequest.ruleSet);
     297    ASSERT(m_element.containingShadowRoot()->mode() == ShadowRoot::Mode::UserAgent);
     298
     299    auto& rules = *matchRequest.ruleSet;
     300#if ENABLE(VIDEO_TRACK)
     301    // FXIME: WebVTT should not be done by styling UA shadow trees like this.
     302    if (m_element.isWebVTTElement())
     303        collectMatchingRulesForList(rules.cuePseudoRules(), matchRequest, ruleRange);
     304#endif
     305    auto& pseudoId = m_element.shadowPseudoId();
     306    if (!pseudoId.isEmpty())
     307        collectMatchingRulesForList(rules.shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
    285308}
    286309
  • trunk/Source/WebCore/css/ElementRuleCollector.h

    r202091 r207077  
    7777
    7878    void matchUARules(RuleSet*);
     79    void matchAuthorShadowPseudoElementRules(const MatchRequest&, StyleResolver::RuleRange&);
    7980    void matchHostPseudoClassRules(MatchRequest&, StyleResolver::RuleRange&);
    8081    void matchSlottedPseudoElementRules(MatchRequest&, StyleResolver::RuleRange&);
     82
     83    void collectMatchingShadowPseudoElementRules(const MatchRequest&, StyleResolver::RuleRange&);
    8184    std::unique_ptr<RuleSet::RuleDataVector> collectSlottedPseudoElementRulesForSlot(bool includeEmptyRules);
    8285
  • trunk/Source/WebCore/css/RuleSet.cpp

    r202091 r207077  
    395395}
    396396
    397 void RuleSet::copyShadowPseudoElementRulesFrom(const RuleSet& other)
    398 {
    399     for (auto& keyValuePair : other.m_shadowPseudoElementRules)
    400         m_shadowPseudoElementRules.add(keyValuePair.key, std::make_unique<RuleDataVector>(*keyValuePair.value));
    401 
    402 #if ENABLE(VIDEO_TRACK)
    403     // FIXME: We probably shouldn't treat WebVTT as author stylable user agent shadow tree.
    404     for (auto& cue : other.m_cuePseudoRules)
    405         m_cuePseudoRules.append(cue);
    406 #endif
    407 }
    408 
    409397static inline void shrinkMapVectorsToFit(RuleSet::AtomRuleMap& map)
    410398{
  • trunk/Source/WebCore/css/RuleSet.h

    r204466 r207077  
    193193
    194194    bool hasShadowPseudoElementRules() const;
    195     void copyShadowPseudoElementRulesFrom(const RuleSet&);
    196195
    197196private:
  • trunk/Source/WebCore/dom/Document.cpp

    r206990 r207077  
    21452145StyleResolver& Document::userAgentShadowTreeStyleResolver()
    21462146{
    2147     if (!m_userAgentShadowTreeStyleResolver) {
     2147    if (!m_userAgentShadowTreeStyleResolver)
    21482148        m_userAgentShadowTreeStyleResolver = std::make_unique<StyleResolver>(*this);
    2149 
    2150         // FIXME: Filter out shadow pseudo elements we don't want to expose to authors.
    2151         auto& documentAuthorStyle = styleScope().resolver().ruleSets().authorStyle();
    2152         if (documentAuthorStyle.hasShadowPseudoElementRules())
    2153             m_userAgentShadowTreeStyleResolver->ruleSets().authorStyle().copyShadowPseudoElementRulesFrom(documentAuthorStyle);
    2154     }
    2155 
    21562149    return *m_userAgentShadowTreeStyleResolver;
    21572150}
  • trunk/Source/WebCore/style/StyleScope.cpp

    r206990 r207077  
    405405        styleResolver.appendAuthorStyleSheets(newStyleSheets);
    406406    }
    407 
    408     if (!m_shadowRoot) {
    409         auto& userAgentShadowTreeStyleResolver = m_document.userAgentShadowTreeStyleResolver();
    410         userAgentShadowTreeStyleResolver.ruleSets().resetAuthorStyle();
    411         auto& authorRuleSet = styleResolver.ruleSets().authorStyle();
    412         if (authorRuleSet.hasShadowPseudoElementRules())
    413             userAgentShadowTreeStyleResolver.ruleSets().authorStyle().copyShadowPseudoElementRulesFrom(authorRuleSet);
    414     }
    415407}
    416408
Note: See TracChangeset for help on using the changeset viewer.