Changeset 235458 in webkit


Ignore:
Timestamp:
Aug 28, 2018 10:31:57 PM (6 years ago)
Author:
rniwa@webkit.org
Message:

Changes to slot children should trigger slotchange
https://bugs.webkit.org/show_bug.cgi?id=169718
<rdar://problem/43317496>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaselined the test now that relevant test cases pass.

  • web-platform-tests/shadow-dom/slotchange-expected.txt:

Source/WebCore:

Fix the bug that slotchange event is not fired when a slot's fallback content is updated now that slotchange event
is more formally specified.

This particular behavior corresponds to step 7.5. of the concept *to insert a node* where it says:
"[I]f parent’s root is a shadow root, and parent is a slot whose assigned nodes is the empty list, then run signal
a slot change for parent."

See https://dom.spec.whatwg.org/#concept-node-insert

Tests: fast/shadow-dom/slotchange-in-fallback.html

imported/w3c/web-platform-tests/shadow-dom/slotchange.html

  • dom/Element.cpp:

(WebCore::Element::childrenChanged): Updated the comment.

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::addSlotElementByName): Added an assertion.
(WebCore::ShadowRoot::slotFallbackDidChange): Added.

  • dom/ShadowRoot.h:
  • dom/SlotAssignment.cpp:

(WebCore::SlotAssignment::slotFallbackDidChange): Added. When the assigned nodes is empty, we enqueue a slotchange.
Because assignedNodesForSlot invokes assignSlots, this can be O(n) but we don't expect mutating slot's fallback
contents and shadow host's children in turn to be a common scenario so this shouldn't be an issue in practice.

  • dom/SlotAssignment.h:
  • html/HTMLSlotElement.cpp:

(WebCore::HTMLSlotElement::insertedIntoAncestor): Be explicit about auto* being used here.
(WebCore::HTMLSlotElement::childrenChanged): Added. Invokes slotFallbackDidChange whenver child node is muated.

  • html/HTMLSlotElement.h:

LayoutTests:

Added a W3C style testharness.js test for firing slotchange event for the fallback content change
since web-platform-tests/shadow-dom/slotchange.html doesn't have adequate set of tests.

Chrome and Firefox pass all test cases. WebKit used to fail all test cases before this patch.

  • fast/shadow-dom/slotchange-in-fallback-expected.txt: Added.
  • fast/shadow-dom/slotchange-in-fallback.html: Added.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r235457 r235458  
     12018-08-28  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Changes to slot children should trigger slotchange
     4        https://bugs.webkit.org/show_bug.cgi?id=169718
     5        <rdar://problem/43317496>
     6
     7        Reviewed by Darin Adler.
     8
     9        Added a W3C style testharness.js test for firing slotchange event for the fallback content change
     10        since web-platform-tests/shadow-dom/slotchange.html doesn't have adequate set of tests.
     11
     12        Chrome and Firefox pass all test cases. WebKit used to fail all test cases before this patch.
     13
     14        * fast/shadow-dom/slotchange-in-fallback-expected.txt: Added.
     15        * fast/shadow-dom/slotchange-in-fallback.html: Added.
     16
    1172018-08-28  Don Olmstead  <don.olmstead@sony.com>
    218
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r235426 r235458  
     12018-08-28  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Changes to slot children should trigger slotchange
     4        https://bugs.webkit.org/show_bug.cgi?id=169718
     5        <rdar://problem/43317496>
     6
     7        Reviewed by Darin Adler.
     8
     9        Rebaselined the test now that relevant test cases pass.
     10
     11        * web-platform-tests/shadow-dom/slotchange-expected.txt:
     12
    1132018-08-28  Aditya Keerthi  <akeerthi@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slotchange-expected.txt

    r206463 r235458  
    1111PASS slotchange event: Add a fallback content.
    1212PASS slotchange event: Remove a fallback content.
    13 TIMEOUT slotchange event: Add a fallback content to nested slots. Test timed out
    14 TIMEOUT slotchange event: Remove a fallback content from nested slots. Test timed out
     13PASS slotchange event: Add a fallback content to nested slots.
     14PASS slotchange event: Remove a fallback content from nested slots.
    1515TIMEOUT slotchange event: Insert a slot before an existing slot. Test timed out
    1616TIMEOUT slotchange event: Remove a preceding slot. Test timed out
  • trunk/Source/WebCore/ChangeLog

    r235457 r235458  
     12018-08-28  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Changes to slot children should trigger slotchange
     4        https://bugs.webkit.org/show_bug.cgi?id=169718
     5        <rdar://problem/43317496>
     6
     7        Reviewed by Darin Adler.
     8
     9        Fix the bug that slotchange event is not fired when a slot's fallback content is updated now that slotchange event
     10        is more formally specified.
     11
     12        This particular behavior corresponds to step 7.5. of the concept *to insert a node* where it says:
     13        "[I]f parent’s root is a shadow root, and parent is a slot whose assigned nodes is the empty list, then run signal
     14        a slot change for parent."
     15
     16        See https://dom.spec.whatwg.org/#concept-node-insert
     17
     18        Tests: fast/shadow-dom/slotchange-in-fallback.html
     19               imported/w3c/web-platform-tests/shadow-dom/slotchange.html
     20
     21        * dom/Element.cpp:
     22        (WebCore::Element::childrenChanged): Updated the comment.
     23        * dom/ShadowRoot.cpp:
     24        (WebCore::ShadowRoot::addSlotElementByName): Added an assertion.
     25        (WebCore::ShadowRoot::slotFallbackDidChange): Added.
     26        * dom/ShadowRoot.h:
     27        * dom/SlotAssignment.cpp:
     28        (WebCore::SlotAssignment::slotFallbackDidChange): Added. When the assigned nodes is empty, we enqueue a slotchange.
     29        Because assignedNodesForSlot invokes assignSlots, this can be O(n) but we don't expect mutating slot's fallback
     30        contents and shadow host's children in turn to be a common scenario so this shouldn't be an issue in practice.
     31        * dom/SlotAssignment.h:
     32        * html/HTMLSlotElement.cpp:
     33        (WebCore::HTMLSlotElement::insertedIntoAncestor): Be explicit about auto* being used here.
     34        (WebCore::HTMLSlotElement::childrenChanged): Added. Invokes slotFallbackDidChange whenver child node is muated.
     35        * html/HTMLSlotElement.h:
     36
    1372018-08-28  Don Olmstead  <don.olmstead@sony.com>
    238
  • trunk/Source/WebCore/dom/Element.cpp

    r235331 r235458  
    21792179        case ElementInserted:
    21802180        case ElementRemoved:
    2181             // For elements, we notify shadowRoot in Element::insertedInto and Element::removedFrom.
     2181            // For elements, we notify shadowRoot in Element::insertedIntoAncestor and Element::removedFromAncestor.
    21822182            break;
    21832183        case AllChildrenRemoved:
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r229694 r235458  
    184184void ShadowRoot::addSlotElementByName(const AtomicString& name, HTMLSlotElement& slot)
    185185{
     186    ASSERT(&slot.rootNode() == this);
    186187    if (!m_slotAssignment)
    187188        m_slotAssignment = std::make_unique<SlotAssignment>();
     
    193194{
    194195    return m_slotAssignment->removeSlotElementByName(name, slot, *this);
     196}
     197
     198void ShadowRoot::slotFallbackDidChange(HTMLSlotElement& slot)
     199{
     200    ASSERT(&slot.rootNode() == this);
     201    return m_slotAssignment->slotFallbackDidChange(slot, *this);
    195202}
    196203
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r229694 r235458  
    7575    void addSlotElementByName(const AtomicString&, HTMLSlotElement&);
    7676    void removeSlotElementByName(const AtomicString&, HTMLSlotElement&);
     77    void slotFallbackDidChange(HTMLSlotElement&);
    7778
    7879    void didRemoveAllChildrenOfShadowHost();
     
    108109
    109110    std::unique_ptr<Style::Scope> m_styleScope;
    110 
    111111    std::unique_ptr<SlotAssignment> m_slotAssignment;
    112112};
  • trunk/Source/WebCore/dom/SlotAssignment.cpp

    r223728 r235458  
    124124}
    125125
     126void SlotAssignment::slotFallbackDidChange(HTMLSlotElement& slotElement, ShadowRoot& shadowRoot)
     127{
     128    if (shadowRoot.mode() == ShadowRootMode::UserAgent)
     129        return;
     130
     131    bool usesFallbackContent = !assignedNodesForSlot(slotElement, shadowRoot);
     132    if (usesFallbackContent)
     133        slotElement.enqueueSlotChangeEvent();
     134}
     135
    126136void SlotAssignment::didChangeSlot(const AtomicString& slotAttrValue, ShadowRoot& shadowRoot)
    127137{
  • trunk/Source/WebCore/dom/SlotAssignment.h

    r219237 r235458  
    5252    void addSlotElementByName(const AtomicString&, HTMLSlotElement&, ShadowRoot&);
    5353    void removeSlotElementByName(const AtomicString&, HTMLSlotElement&, ShadowRoot&);
     54    void slotFallbackDidChange(HTMLSlotElement&, ShadowRoot&);
    5455
    5556    void didChangeSlot(const AtomicString&, ShadowRoot&);
  • trunk/Source/WebCore/html/HTMLSlotElement.cpp

    r234995 r235458  
    5858
    5959    if (insertionType.treeScopeChanged && isInShadowTree()) {
    60         if (auto shadowRoot = containingShadowRoot())
     60        if (auto* shadowRoot = containingShadowRoot())
    6161            shadowRoot->addSlotElementByName(attributeWithoutSynchronization(nameAttr), *this);
    6262    }
     
    7474
    7575    HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
     76}
     77
     78void HTMLSlotElement::childrenChanged(const ChildChange& childChange)
     79{
     80    HTMLElement::childrenChanged(childChange);
     81
     82    if (isInShadowTree()) {
     83        if (auto* shadowRoot = containingShadowRoot())
     84            shadowRoot->slotFallbackDidChange(*this);
     85    }
    7686}
    7787
  • trunk/Source/WebCore/html/HTMLSlotElement.h

    r229694 r235458  
    5252    InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) final;
    5353    void removedFromAncestor(RemovalType, ContainerNode&) final;
     54    void childrenChanged(const ChildChange&) final;
    5455    void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason) final;
    5556
Note: See TracChangeset for help on using the changeset viewer.