Changeset 238758 in webkit


Ignore:
Timestamp:
Nov 30, 2018 3:33:39 PM (5 years ago)
Author:
rniwa@webkit.org
Message:

ShadowRoot should have styleSheets property
https://bugs.webkit.org/show_bug.cgi?id=191311
LayoutTests/imported/w3c:

Reviewed by Antti Koivisto.

Rebaselined the tests.

  • web-platform-tests/css/css-scoping/stylesheet-title-002-expected.txt: Rebaselined. The test now

doesn't throw but fails with the actual check the test is intending to check.

  • web-platform-tests/css/cssom/selectorText-modification-restyle-002-expected.txt: Rebaselined

now that all test cases pass.

  • web-platform-tests/shadow-dom/ShadowRoot-interface-expected.txt: Ditto.

Source/WebCore:

Reviewed by Antti Koivisto.

Added the support for ShadowRoot.prototype.styleSheets by making StyleSheetList refer to either
a document or a shadow root. We don't support the named getter in shadow root since that's not
a standard feature: https://drafts.csswg.org/cssom/#the-stylesheetlist-interface

Tests: fast/shadow-dom/shadowroot-stylesheets-wrapper-gc.html

imported/w3c/web-platform-tests/shadow-dom/ShadowRoot-interface.html

  • css/StyleSheetList.cpp:

(WebCore::StyleSheetList::StyleSheetList): Added a variant which takes ShadowRoot.
(WebCore::StyleSheetList::styleSheets const):
(WebCore::StyleSheetList::ownerNode): Added. The replacement for document() since now the opaque
root could be either a Document or a ShadowRoot.
(WebCore::StyleSheetList::detach): Renamed from detachFromDocument.
(WebCore::StyleSheetList::namedItem const): Added a comment that the named getter is only supported
for Document since it's not in the standard.

  • css/StyleSheetList.h:

(WebCore::StyleSheetList::create): Added a variant which takes ShadowRoot.
(WebCore::StyleSheetList::document): Deleted. Replaced by StyleSheetList::ownerNode in .cpp file.

  • css/StyleSheetList.idl:
  • dom/Document.cpp:

(WebCore::Document::~Document):
(WebCore::Document::styleSheets):

  • dom/Document.idl:
  • dom/DocumentOrShadowRoot.idl: Moved the declaration of styleSheets here from Document.idl.
  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::~ShadowRoot): Call detach.
(WebCore::ShadowRoot::styleSheets):

  • dom/ShadowRoot.h:

LayoutTests:

<rdar://problem/46333290>

Reviewed by Antti Koivisto.

Added a regression test for testing that the JS wrapper of a StyleSheetList does not get collected
as long as its shadow root is alive.

  • fast/shadow-dom/shadowroot-stylesheets-wrapper-gc-expected.txt: Added.
  • fast/shadow-dom/shadowroot-stylesheets-wrapper-gc.html: Added.
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r238751 r238758  
     12018-11-30  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        ShadowRoot should have styleSheets property
     4        https://bugs.webkit.org/show_bug.cgi?id=191311
     5        <rdar://problem/46333290>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Added a regression test for testing that the JS wrapper of a StyleSheetList does not get collected
     10        as long as its shadow root is alive.
     11
     12        * fast/shadow-dom/shadowroot-stylesheets-wrapper-gc-expected.txt: Added.
     13        * fast/shadow-dom/shadowroot-stylesheets-wrapper-gc.html: Added.
     14
    1152018-11-30  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r238692 r238758  
     12018-11-30  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        ShadowRoot should have styleSheets property
     4        https://bugs.webkit.org/show_bug.cgi?id=191311
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Rebaselined the tests.
     9
     10        * web-platform-tests/css/css-scoping/stylesheet-title-002-expected.txt: Rebaselined. The test now
     11        doesn't throw but fails with the actual check the test is intending to check.
     12        * web-platform-tests/css/cssom/selectorText-modification-restyle-002-expected.txt: Rebaselined
     13        now that all test cases pass.
     14        * web-platform-tests/shadow-dom/ShadowRoot-interface-expected.txt: Ditto.
     15
    1162018-11-28  Ryosuke Niwa  <rniwa@webkit.org>
    217
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scoping/stylesheet-title-002-expected.txt

    r232903 r238758  
    11
    2 FAIL Title attribute in stylesheets not in the document tree is ignored undefined is not an object (evaluating 'host.shadowRoot.styleSheets.length')
     2FAIL Title attribute in stylesheets not in the document tree is ignored assert_equals: expected 3 but got 2
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom/selectorText-modification-restyle-002-expected.txt

    r232005 r238758  
    11
    22PASS Check initial color.
    3 FAIL Check that color changes correctly after shadow stylesheet selector and #container class is changed. undefined is not an object (evaluating 'root.styleSheets[0]')
     3PASS Check that color changes correctly after shadow stylesheet selector and #container class is changed.
    44
  • trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/ShadowRoot-interface-expected.txt

    r206463 r238758  
    1010PASS ShadowRoot.innerHTML must replace all with the result of invoking the fragment parsing algorithm when shadow root is open.
    1111PASS ShadowRoot.innerHTML must replace all with the result of invoking the fragment parsing algorithm when shadow root is closed.
    12 FAIL ShadowRoot.styleSheets must return a StyleSheetList sequence containing the shadow root style sheets when shadow root is open. undefined is not an object (evaluating 'shadowRoot.styleSheets.length')
    13 FAIL ShadowRoot.styleSheets must return a StyleSheetList sequence containing the shadow root style sheets when shadow root is closed. undefined is not an object (evaluating 'shadowRoot.styleSheets.length')
     12PASS ShadowRoot.styleSheets must return a StyleSheetList sequence containing the shadow root style sheets when shadow root is open.
     13PASS ShadowRoot.styleSheets must return a StyleSheetList sequence containing the shadow root style sheets when shadow root is closed.
    1414
  • trunk/Source/WebCore/ChangeLog

    r238755 r238758  
     12018-11-30  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        ShadowRoot should have styleSheets property
     4        https://bugs.webkit.org/show_bug.cgi?id=191311
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Added the support for ShadowRoot.prototype.styleSheets by making StyleSheetList refer to either
     9        a document or a shadow root. We don't support the named getter in shadow root since that's not
     10        a standard feature: https://drafts.csswg.org/cssom/#the-stylesheetlist-interface
     11
     12        Tests: fast/shadow-dom/shadowroot-stylesheets-wrapper-gc.html
     13               imported/w3c/web-platform-tests/shadow-dom/ShadowRoot-interface.html
     14
     15        * css/StyleSheetList.cpp:
     16        (WebCore::StyleSheetList::StyleSheetList): Added a variant which takes ShadowRoot.
     17        (WebCore::StyleSheetList::styleSheets const):
     18        (WebCore::StyleSheetList::ownerNode): Added. The replacement for document() since now the opaque
     19        root could be either a Document or a ShadowRoot.
     20        (WebCore::StyleSheetList::detach): Renamed from detachFromDocument.
     21        (WebCore::StyleSheetList::namedItem const): Added a comment that the named getter is only supported
     22        for Document since it's not in the standard.
     23        * css/StyleSheetList.h:
     24        (WebCore::StyleSheetList::create): Added a variant which takes ShadowRoot.
     25        (WebCore::StyleSheetList::document): Deleted. Replaced by StyleSheetList::ownerNode in .cpp file.
     26        * css/StyleSheetList.idl:
     27        * dom/Document.cpp:
     28        (WebCore::Document::~Document):
     29        (WebCore::Document::styleSheets):
     30        * dom/Document.idl:
     31        * dom/DocumentOrShadowRoot.idl: Moved the declaration of styleSheets here from Document.idl.
     32        * dom/ShadowRoot.cpp:
     33        (WebCore::ShadowRoot::~ShadowRoot): Call detach.
     34        (WebCore::ShadowRoot::styleSheets):
     35        * dom/ShadowRoot.h:
     36
    1372018-11-30  Chris Dumez  <cdumez@apple.com>
    238
  • trunk/Source/WebCore/css/StyleSheetList.cpp

    r223728 r238758  
    2626#include "HTMLNames.h"
    2727#include "HTMLStyleElement.h"
     28#include "ShadowRoot.h"
    2829#include "StyleScope.h"
    2930#include <wtf/text/WTFString.h>
     
    3334using namespace HTMLNames;
    3435
    35 StyleSheetList::StyleSheetList(Document* document)
    36     : m_document(document)
     36StyleSheetList::StyleSheetList(Document& document)
     37    : m_document(&document)
     38{
     39}
     40
     41StyleSheetList::StyleSheetList(ShadowRoot& shadowRoot)
     42    : m_shadowRoot(&shadowRoot)
    3743{
    3844}
     
    4248inline const Vector<RefPtr<StyleSheet>>& StyleSheetList::styleSheets() const
    4349{
    44     if (!m_document)
    45         return m_detachedStyleSheets;
    46     return m_document->styleScope().styleSheetsForStyleSheetList();
     50    if (m_document)
     51        return m_document->styleScope().styleSheetsForStyleSheetList();
     52    if (m_shadowRoot)
     53        return m_shadowRoot->styleScope().styleSheetsForStyleSheetList();
     54    return m_detachedStyleSheets;
    4755}
    4856
    49 void StyleSheetList::detachFromDocument()
     57Node* StyleSheetList::ownerNode() const
    5058{
    51     m_detachedStyleSheets = m_document->styleScope().styleSheetsForStyleSheetList();
    52     m_document = nullptr;
     59    if (m_document)
     60        return m_document;
     61    return m_shadowRoot;
     62}
     63
     64void StyleSheetList::detach()
     65{
     66    if (m_document) {
     67        ASSERT(!m_shadowRoot);
     68        m_detachedStyleSheets = m_document->styleScope().styleSheetsForStyleSheetList();
     69        m_document = nullptr;
     70    } else if (m_shadowRoot) {
     71        ASSERT(!m_document);
     72        m_detachedStyleSheets = m_shadowRoot->styleScope().styleSheetsForStyleSheetList();
     73        m_shadowRoot = nullptr;
     74    } else
     75        ASSERT_NOT_REACHED();
    5376}
    5477
     
    6689CSSStyleSheet* StyleSheetList::namedItem(const AtomicString& name) const
    6790{
     91    // Support the named getter on document for backwards compatibility.
    6892    if (!m_document)
    6993        return nullptr;
  • trunk/Source/WebCore/css/StyleSheetList.h

    r210667 r238758  
    2929class Document;
    3030class HTMLStyleElement;
     31class Node;
     32class ShadowRoot;
    3133class StyleSheet;
    3234class CSSStyleSheet;
     
    3436class StyleSheetList final : public RefCounted<StyleSheetList> {
    3537public:
    36     static Ref<StyleSheetList> create(Document* document) { return adoptRef(*new StyleSheetList(document)); }
     38    static Ref<StyleSheetList> create(Document& document) { return adoptRef(*new StyleSheetList(document)); }
     39    static Ref<StyleSheetList> create(ShadowRoot& shadowRoot) { return adoptRef(*new StyleSheetList(shadowRoot)); }
    3740    WEBCORE_EXPORT ~StyleSheetList();
    3841
     
    4346    Vector<AtomicString> supportedPropertyNames();
    4447
    45     Document* document() { return m_document; }
     48    Node* ownerNode() const;
    4649
    47     void detachFromDocument();
     50    void detach();
    4851
    4952private:
    50     StyleSheetList(Document*);
     53    StyleSheetList(Document&);
     54    StyleSheetList(ShadowRoot&);
    5155    const Vector<RefPtr<StyleSheet>>& styleSheets() const;
    5256
    53     Document* m_document;
     57    Document* m_document { nullptr };
     58    ShadowRoot* m_shadowRoot { nullptr };
    5459    Vector<RefPtr<StyleSheet>> m_detachedStyleSheets;
    5560};
  • trunk/Source/WebCore/css/StyleSheetList.idl

    r210667 r238758  
    2121[
    2222    ExportToWrappedFunction,
    23     GenerateIsReachable=ImplDocument,
     23    GenerateIsReachable=ImplOwnerNodeRoot,
    2424    ImplementationLacksVTable,
    2525] interface StyleSheetList {
  • trunk/Source/WebCore/dom/Document.cpp

    r238754 r238758  
    638638
    639639    if (m_styleSheetList)
    640         m_styleSheetList->detachFromDocument();
     640        m_styleSheetList->detach();
    641641
    642642    extensionStyleSheets().detachFromDocument();
     
    38313831{
    38323832    if (!m_styleSheetList)
    3833         m_styleSheetList = StyleSheetList::create(this);
     3833        m_styleSheetList = StyleSheetList::create(*this);
    38343834    return *m_styleSheetList;
    38353835}
  • trunk/Source/WebCore/dom/Document.idl

    r237306 r238758  
    131131    [LenientThis] attribute EventHandler onreadystatechange;
    132132
    133     // Extensions from the CSSOM specification (https://drafts.csswg.org/cssom/#extensions-to-the-document-interface).
    134     // FIXME: Should likely be moved to DocumentOrShadowRoot.
    135     readonly attribute StyleSheetList styleSheets; // FIXME: Should be [SameObject].
    136 
    137133    // Extensions from the CSSOM-View specification (https://drafts.csswg.org/cssom-view/#extensions-to-the-document-interface).
    138134    [ImplementedAs=scrollingElementForAPI] readonly attribute Element? scrollingElement;
  • trunk/Source/WebCore/dom/DocumentOrShadowRoot.idl

    r219961 r238758  
    3535    // CaretPosition? caretPositionFromPoint(double x, double y); // FIXME: Implement this.
    3636    readonly attribute Element? activeElement;
    37     // readonly attribute StyleSheetList styleSheets; // FIXME: Implement this.
     37
     38    // Extensions from the CSSOM specification (https://drafts.csswg.org/cssom/#extensions-to-the-document-interface).
     39    readonly attribute StyleSheetList styleSheets; // FIXME: Should be [SameObject].
    3840
    3941    // Extensions from Pointer Lock API (https://w3c.github.io/pointerlock/#extensions-to-the-documentorshadowroot-mixin).
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r236583 r238758  
    3737#include "StyleResolver.h"
    3838#include "StyleScope.h"
     39#include "StyleSheetList.h"
    3940#include "markup.h"
    4041#include <wtf/IsoMallocInlines.h>
     
    4748    unsigned countersAndFlags[1];
    4849    void* styleScope;
     50    void* styleSheetList;
    4951    void* host;
    5052    void* slotAssignment;
     
    7678    if (isConnected())
    7779        document().didRemoveInDocumentShadowRoot(*this);
     80
     81    if (m_styleSheetList)
     82        m_styleSheetList->detach();
    7883
    7984    // We cannot let ContainerNode destructor call willBeDeletedFrom()
     
    152157}
    153158
     159StyleSheetList& ShadowRoot::styleSheets()
     160{
     161    if (!m_styleSheetList)
     162        m_styleSheetList = StyleSheetList::create(*this);
     163    return *m_styleSheetList;
     164}
     165
    154166String ShadowRoot::innerHTML() const
    155167{
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r235917 r238758  
    3636class HTMLSlotElement;
    3737class SlotAssignment;
     38class StyleSheetList;
    3839
    3940class ShadowRoot final : public DocumentFragment, public TreeScope {
     
    5556
    5657    Style::Scope& styleScope();
     58    StyleSheetList& styleSheets();
    5759
    5860    bool resetStyleInheritance() const { return m_resetStyleInheritance; }
     
    111113
    112114    Element* m_host { nullptr };
     115    RefPtr<StyleSheetList> m_styleSheetList;
    113116
    114117    std::unique_ptr<Style::Scope> m_styleScope;
Note: See TracChangeset for help on using the changeset viewer.