Changeset 190256 in webkit


Ignore:
Timestamp:
Sep 25, 2015 3:06:09 PM (9 years ago)
Author:
Antti Koivisto
Message:

Implement scoped styling for shadow DOM
https://bugs.webkit.org/show_bug.cgi?id=149230

Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html

  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::collectMatchingRules):

Only use special path here for user agent shadow trees.

  • dom/AuthorStyleSheets.cpp:

(WebCore::AuthorStyleSheets::AuthorStyleSheets):
(WebCore::AuthorStyleSheets::removePendingSheet):
(WebCore::AuthorStyleSheets::updateActiveStyleSheets):

Basic support for ShadowRoot scoped stylesheets.

  • dom/AuthorStyleSheets.h:

(WebCore::AuthorStyleSheets::activeStyleSheets):

  • dom/InlineStyleSheetOwner.cpp:

(WebCore::InlineStyleSheetOwner::~InlineStyleSheetOwner):
(WebCore::authorStyleSheetsForElement):
(WebCore::InlineStyleSheetOwner::insertedIntoDocument):
(WebCore::InlineStyleSheetOwner::removedFromDocument):
(WebCore::InlineStyleSheetOwner::clearDocumentData):
(WebCore::InlineStyleSheetOwner::childrenChanged):
(WebCore::InlineStyleSheetOwner::createSheet):
(WebCore::InlineStyleSheetOwner::isLoading):
(WebCore::InlineStyleSheetOwner::sheetLoaded):
(WebCore::InlineStyleSheetOwner::startLoadingDynamicSheet):

Basic support for ShadowRoot scoped inline stylesheets.

  • dom/InlineStyleSheetOwner.h:

(WebCore::InlineStyleSheetOwner::sheet):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::styleResolver):

Create and initialize ShadowRoot scoped style resolver.

(WebCore::ShadowRoot::resetStyleResolver):
(WebCore::ShadowRoot::authorStyleSheets):

Collection of author stylesheets in the shadow tree.

(WebCore::ShadowRoot::updateStyle):

Trigger style recalc when stylesheets change.

(WebCore::ShadowRoot::cloneNode):

  • dom/ShadowRoot.h:

(WebCore::ShadowRoot::resetStyleInheritance):

  • html/HTMLStyleElement.h:
  • svg/SVGStyleElement.h:

LayoutTests:

  • fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html: Added.
  • fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html: Added.

Add a test that verifies that shadow DOM style doesn't affect normal DOM.

  • platform/mac/TestExpectations:

Enable fast/shadow-dom/css-scoping-shadow-with-rules.html

Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190254 r190256  
     12015-09-25  Antti Koivisto  <antti@apple.com>
     2
     3        Implement scoped styling for shadow DOM
     4        https://bugs.webkit.org/show_bug.cgi?id=149230
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak-expected.html: Added.
     9        * fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html: Added.
     10
     11            Add a test that verifies that shadow DOM style doesn't affect normal DOM.
     12
     13        * platform/mac/TestExpectations:
     14
     15            Enable fast/shadow-dom/css-scoping-shadow-with-rules.html
     16
    1172015-09-25  Tim Horton  <timothy_horton@apple.com>
    218
  • trunk/LayoutTests/platform/mac/TestExpectations

    r190245 r190256  
    13091309
    13101310webkit.org/b/148695 fast/shadow-dom [ Pass ]
    1311 
    1312 webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-with-rules.html [ ImageOnlyFailure ]
    13131311webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-host-rule.html [ ImageOnlyFailure ]
    13141312webkit.org/b/149328 fast/shadow-dom/css-scoping-shadow-host-functional-rule.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r190255 r190256  
     12015-09-25  Antti Koivisto  <antti@apple.com>
     2
     3        Implement scoped styling for shadow DOM
     4        https://bugs.webkit.org/show_bug.cgi?id=149230
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Test: fast/shadow-dom/css-scoping-shadow-with-rules-no-style-leak.html
     9
     10        * css/ElementRuleCollector.cpp:
     11        (WebCore::ElementRuleCollector::collectMatchingRules):
     12
     13            Only use special path here for user agent shadow trees.
     14
     15        * dom/AuthorStyleSheets.cpp:
     16        (WebCore::AuthorStyleSheets::AuthorStyleSheets):
     17        (WebCore::AuthorStyleSheets::removePendingSheet):
     18        (WebCore::AuthorStyleSheets::updateActiveStyleSheets):
     19
     20            Basic support for ShadowRoot scoped stylesheets.
     21
     22        * dom/AuthorStyleSheets.h:
     23        (WebCore::AuthorStyleSheets::activeStyleSheets):
     24        * dom/InlineStyleSheetOwner.cpp:
     25        (WebCore::InlineStyleSheetOwner::~InlineStyleSheetOwner):
     26        (WebCore::authorStyleSheetsForElement):
     27        (WebCore::InlineStyleSheetOwner::insertedIntoDocument):
     28        (WebCore::InlineStyleSheetOwner::removedFromDocument):
     29        (WebCore::InlineStyleSheetOwner::clearDocumentData):
     30        (WebCore::InlineStyleSheetOwner::childrenChanged):
     31        (WebCore::InlineStyleSheetOwner::createSheet):
     32        (WebCore::InlineStyleSheetOwner::isLoading):
     33        (WebCore::InlineStyleSheetOwner::sheetLoaded):
     34        (WebCore::InlineStyleSheetOwner::startLoadingDynamicSheet):
     35
     36            Basic support for ShadowRoot scoped inline stylesheets.
     37
     38        * dom/InlineStyleSheetOwner.h:
     39        (WebCore::InlineStyleSheetOwner::sheet):
     40        * dom/ShadowRoot.cpp:
     41        (WebCore::ShadowRoot::styleResolver):
     42
     43            Create and initialize ShadowRoot scoped style resolver.
     44
     45        (WebCore::ShadowRoot::resetStyleResolver):
     46        (WebCore::ShadowRoot::authorStyleSheets):
     47
     48            Collection of author stylesheets in the shadow tree.
     49
     50        (WebCore::ShadowRoot::updateStyle):
     51
     52            Trigger style recalc when stylesheets change.
     53
     54        (WebCore::ShadowRoot::cloneNode):
     55        * dom/ShadowRoot.h:
     56        (WebCore::ShadowRoot::resetStyleInheritance):
     57        * html/HTMLStyleElement.h:
     58        * svg/SVGStyleElement.h:
     59
    1602015-09-25  Alex Christensen  <achristensen@webkit.org>
    261
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r182130 r190256  
    4141#include "SVGElement.h"
    4242#include "SelectorCompiler.h"
     43#include "ShadowRoot.h"
    4344#include "StyleProperties.h"
    4445#include "StyledElement.h"
     
    153154#endif
    154155
    155     if (m_element.isInShadowTree()) {
     156    auto* shadowRoot = m_element.containingShadowRoot();
     157    if (shadowRoot && shadowRoot->type() == ShadowRoot::Type::UserAgent) {
    156158        const AtomicString& pseudoId = m_element.shadowPseudoId();
    157159        if (!pseudoId.isEmpty())
  • trunk/Source/WebCore/dom/AuthorStyleSheets.cpp

    r190169 r190256  
    4242#include "SVGStyleElement.h"
    4343#include "Settings.h"
     44#include "ShadowRoot.h"
    4445#include "StyleInvalidationAnalysis.h"
    4546#include "StyleResolver.h"
     
    5556using namespace HTMLNames;
    5657
    57 AuthorStyleSheets::AuthorStyleSheets(TreeScope& treeScope)
    58     : m_document(treeScope.documentScope())
     58AuthorStyleSheets::AuthorStyleSheets(Document& document)
     59    : m_document(document)
     60{
     61}
     62
     63AuthorStyleSheets::AuthorStyleSheets(ShadowRoot& shadowRoot)
     64    : m_document(shadowRoot.documentScope())
     65    , m_shadowRoot(&shadowRoot)
    5966{
    6067}
     
    8087        return;
    8188    }
    82    
     89
     90    if (m_shadowRoot) {
     91        m_shadowRoot->updateStyle();
     92        return;
     93    }
     94
    8395    m_document.didRemoveAllPendingStylesheet();
    8496}
     
    300312    analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
    301313
    302     if (styleResolverUpdateType == Reconstruct)
    303         m_document.clearStyleResolver();
    304     else {
     314    if (styleResolverUpdateType == Reconstruct) {
     315        if (m_shadowRoot)
     316            m_shadowRoot->resetStyleResolver();
     317        else
     318            m_document.clearStyleResolver();
     319    } else {
    305320        StyleResolver& styleResolver = m_document.ensureStyleResolver();
    306321        if (styleResolverUpdateType == Reset) {
  • trunk/Source/WebCore/dom/AuthorStyleSheets.h

    r190169 r190256  
    4646class StyleSheetContents;
    4747class StyleSheetList;
     48class ShadowRoot;
    4849class TreeScope;
    4950
     
    5152    WTF_MAKE_FAST_ALLOCATED;
    5253public:
    53     explicit AuthorStyleSheets(TreeScope&);
     54    explicit AuthorStyleSheets(Document&);
     55    explicit AuthorStyleSheets(ShadowRoot&);
    5456
    5557    const Vector<RefPtr<CSSStyleSheet>>& activeStyleSheets() const { return m_activeStyleSheets; }
     
    108110
    109111    Document& m_document;
     112    ShadowRoot* m_shadowRoot { nullptr };
    110113
    111114    Vector<RefPtr<StyleSheet>> m_styleSheetsForStyleSheetList;
  • trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp

    r190169 r190256  
    2828#include "MediaQueryEvaluator.h"
    2929#include "ScriptableDocumentParser.h"
     30#include "ShadowRoot.h"
    3031#include "StyleSheetContents.h"
    3132#include "TextNodeTraversal.h"
     
    4748}
    4849
    49 void InlineStyleSheetOwner::insertedIntoDocument(Document& document, Element& element)
     50static AuthorStyleSheets& authorStyleSheetsForElement(Element& element)
    5051{
    51     document.authorStyleSheets().addStyleSheetCandidateNode(element, m_isParsingChildren);
     52    auto* shadowRoot = element.containingShadowRoot();
     53    return shadowRoot ? shadowRoot->authorStyleSheets() : element.document().authorStyleSheets();
     54}
     55
     56void InlineStyleSheetOwner::insertedIntoDocument(Document&, Element& element)
     57{
     58    authorStyleSheetsForElement(element).addStyleSheetCandidateNode(element, m_isParsingChildren);
    5259
    5360    if (m_isParsingChildren)
     
    5865void InlineStyleSheetOwner::removedFromDocument(Document& document, Element& element)
    5966{
    60     document.authorStyleSheets().removeStyleSheetCandidateNode(element);
     67    authorStyleSheetsForElement(element).removeStyleSheetCandidateNode(element);
    6168
    6269    if (m_sheet)
     
    6875}
    6976
    70 void InlineStyleSheetOwner::clearDocumentData(Document& document, Element& element)
     77void InlineStyleSheetOwner::clearDocumentData(Document&, Element& element)
    7178{
    7279    if (m_sheet)
     
    7582    if (!element.inDocument())
    7683        return;
    77     document.authorStyleSheets().removeStyleSheetCandidateNode(element);
     84    authorStyleSheetsForElement(element).removeStyleSheetCandidateNode(element);
    7885}
    7986
     
    139146        return;
    140147
    141     document.authorStyleSheets().addPendingSheet();
     148    authorStyleSheetsForElement(element).addPendingSheet();
    142149
    143150    m_loading = true;
     
    161168}
    162169
    163 bool InlineStyleSheetOwner::sheetLoaded(Document& document)
     170bool InlineStyleSheetOwner::sheetLoaded(Element& element)
    164171{
    165172    if (isLoading())
    166173        return false;
    167174
    168     document.authorStyleSheets().removePendingSheet();
     175    authorStyleSheetsForElement(element).removePendingSheet();
    169176    return true;
    170177}
    171178
    172 void InlineStyleSheetOwner::startLoadingDynamicSheet(Document& document)
     179void InlineStyleSheetOwner::startLoadingDynamicSheet(Element& element)
    173180{
    174     document.authorStyleSheets().addPendingSheet();
     181    authorStyleSheetsForElement(element).addPendingSheet();
    175182}
    176183
  • trunk/Source/WebCore/dom/InlineStyleSheetOwner.h

    r181426 r190256  
    4242
    4343    bool isLoading() const;
    44     bool sheetLoaded(Document&);
    45     void startLoadingDynamicSheet(Document&);
     44    bool sheetLoaded(Element&);
     45    void startLoadingDynamicSheet(Element&);
    4646
    4747    void insertedIntoDocument(Document&, Element&);
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r190120 r190256  
    2828#include "ShadowRoot.h"
    2929
     30#include "AuthorStyleSheets.h"
     31#include "CSSStyleSheet.h"
    3032#include "ElementTraversal.h"
    3133#include "InsertionPoint.h"
     
    4143    unsigned countersAndFlags[1];
    4244    void* styleResolver;
     45    void* authorStyleSheets;
    4346    void* host;
    4447#if ENABLE(SHADOW_DOM)
     
    7477StyleResolver& ShadowRoot::styleResolver()
    7578{
    76     if (m_styleResolver)
    77         return *m_styleResolver;
    78 
    79     return document().ensureStyleResolver();
     79    // FIXME: Use isolated style resolver for user agent shadow roots.
     80    if (m_type == Type::UserAgent)
     81        return document().ensureStyleResolver();
     82
     83    if (!m_styleResolver) {
     84        // FIXME: We could share style resolver with shadow roots that have identical style.
     85        m_styleResolver = std::make_unique<StyleResolver>(document(), true);
     86        if (m_authorStyleSheets)
     87            m_styleResolver->appendAuthorStyleSheets(0, m_authorStyleSheets->activeStyleSheets());
     88    }
     89    return *m_styleResolver;
     90}
     91
     92void ShadowRoot::resetStyleResolver()
     93{
     94    m_styleResolver = nullptr;
     95}
     96
     97AuthorStyleSheets& ShadowRoot::authorStyleSheets()
     98{
     99    if (!m_authorStyleSheets)
     100        m_authorStyleSheets = std::make_unique<AuthorStyleSheets>(*this);
     101    return *m_authorStyleSheets;
     102}
     103
     104void ShadowRoot::updateStyle()
     105{
     106    bool shouldRecalcStyle = false;
     107
     108    if (m_authorStyleSheets) {
     109        // FIXME: Make optimized updated work.
     110        shouldRecalcStyle = m_authorStyleSheets->updateActiveStyleSheets(AuthorStyleSheets::FullUpdate);
     111    }
     112
     113    if (shouldRecalcStyle)
     114        setNeedsStyleRecalc();
    80115}
    81116
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r190109 r190256  
    3737namespace WebCore {
    3838
     39class AuthorStyleSheets;
    3940class ContentDistributor;
    4041class HTMLSlotElement;
     
    5758
    5859    StyleResolver& styleResolver();
     60    AuthorStyleSheets& authorStyleSheets();
     61   
     62    void updateStyle();
     63    void resetStyleResolver();
    5964
    6065    bool resetStyleInheritance() const { return m_resetStyleInheritance; }
     
    103108    Type m_type;
    104109
     110    Element* m_host;
     111
    105112    std::unique_ptr<StyleResolver> m_styleResolver;
    106 
    107     Element* m_host;
     113    std::unique_ptr<AuthorStyleSheets> m_authorStyleSheets;
    108114
    109115#if ENABLE(SHADOW_DOM)
  • trunk/Source/WebCore/html/HTMLStyleElement.h

    r177996 r190256  
    6060
    6161    bool isLoading() const { return m_styleSheetOwner.isLoading(); }
    62     virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(document()); }
     62    virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(*this); }
    6363    virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred) override;
    64     virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(document()); }
     64    virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(*this); }
    6565
    6666    virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
  • trunk/Source/WebCore/svg/SVGStyleElement.h

    r182121 r190256  
    6060
    6161    virtual bool isLoading() const { return m_styleSheetOwner.isLoading(); }
    62     virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(document()); }
    63     virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(document()); }
     62    virtual bool sheetLoaded() override { return m_styleSheetOwner.sheetLoaded(*this); }
     63    virtual void startLoadingDynamicSheet() override { m_styleSheetOwner.startLoadingDynamicSheet(*this); }
    6464    virtual Timer* svgLoadEventTimer() override { return &m_svgLoadEventTimer; }
    6565
Note: See TracChangeset for help on using the changeset viewer.