Changeset 190323 in webkit


Ignore:
Timestamp:
Sep 29, 2015 1:22:18 PM (9 years ago)
Author:
rniwa@webkit.org
Message:

Update style/layout when a slot is added or removed
https://bugs.webkit.org/show_bug.cgi?id=149593

Reviewed by Antti Koivisto.

Source/WebCore:

Fixed the bug by forcing the render tree reconstruction on the shadow host when a slot is inserted or removed.
We should optimize these reconstructions by only triggering them on the affected slot elements in the future.

Also fixed a bug that we were not invalidating the slot assignments when a default slot is introduced dynamically
after the slot assignment algorithm had run.

Test (existing): fast/shadow-dom/shadow-layout-after-slot-changes.html

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::addSlotElementByName): Passes in ShadowRoot.
(WebCore::ShadowRoot::removeSlotElementByName): Ditto.

  • dom/SlotAssignment.cpp:

(WebCore::SlotAssignment::addSlotElementByName): Call setNeedsStyleRecalc.
(WebCore::SlotAssignment::removeSlotElementByName): Call setNeedsStyleRecalc if the host is still alive since this
function can be called while the host is being destructed in which case shadowRoot.host() would be nullptr.

  • dom/SlotAssignment.h:

LayoutTests:

Removed failing test expectations from fast/shadow-dom/shadow-layout-after-slot-changes.html

Also added an explicit test case for when a default slot is introduced dynamically after
calling getDistributedNodes() once, thereby forcing the slot assignments.

  • fast/shadow-dom/HTMLSlotElement-interface-expected.txt:
  • fast/shadow-dom/HTMLSlotElement-interface.html:
  • fast/shadow-dom/shadow-layout-after-slot-changes.html:
  • platform/mac/TestExpectations:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190322 r190323  
     12015-09-29  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Update style/layout when a slot is added or removed
     4        https://bugs.webkit.org/show_bug.cgi?id=149593
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Removed failing test expectations from fast/shadow-dom/shadow-layout-after-slot-changes.html
     9
     10        Also added an explicit test case for when a default slot is introduced dynamically after
     11        calling getDistributedNodes() once, thereby forcing the slot assignments.
     12
     13        * fast/shadow-dom/HTMLSlotElement-interface-expected.txt:
     14        * fast/shadow-dom/HTMLSlotElement-interface.html:
     15        * fast/shadow-dom/shadow-layout-after-slot-changes.html:
     16        * platform/mac/TestExpectations:
     17
    1182015-09-29  Ryan Haddad  <ryanhaddad@apple.com>
    219
  • trunk/LayoutTests/fast/shadow-dom/HTMLSlotElement-interface-expected.txt

    r189950 r190323  
    44PASS getDistributedNodes method on HTMLSlotElement must return the list of distributed nodes
    55PASS getDistributedNodes must update when slot and name attributes are modified
     6PASS getDistributedNodes must update when a default slot is introduced dynamically by a slot rename
    67PASS getDistributedNodes must update when slot elements are inserted or removed
    78
  • trunk/LayoutTests/fast/shadow-dom/HTMLSlotElement-interface.html

    r189950 r190323  
    9393test(function () {
    9494    var shadowHost = document.createElement('div');
     95    var child = document.createElement('span');
     96    shadowHost.appendChild(child);
     97
     98    var shadowRoot = shadowHost.attachShadow({mode: 'open'});
     99    var slotElement = document.createElement('slot');
     100    slotElement.name = 'foo';
     101    shadowRoot.appendChild(slotElement);
     102
     103    assert_array_equals(slotElement.getDistributedNodes(), [], 'getDistributedNodes must be empty when there are no matching elements for the slot name');
     104
     105    slotElement.name = null;
     106    assert_array_equals(slotElement.getDistributedNodes(), [child], 'getDistributedNodes must be empty when there are no matching elements for the slot name');
     107
     108}, 'getDistributedNodes must update when a default slot is introduced dynamically by a slot rename');
     109
     110test(function () {
     111    var shadowHost = document.createElement('div');
    95112    var p = document.createElement('p');
    96113    var text = document.createTextNode('');
  • trunk/LayoutTests/platform/mac/TestExpectations

    r190320 r190323  
    13311331webkit.org/b/149441 fast/shadow-dom/css-scoping-shadow-slotted-rule.html [ ImageOnlyFailure ]
    13321332webkit.org/b/149441 fast/shadow-dom/css-scoping-shadow-slot-display-override.html [ ImageOnlyFailure ]
    1333 webkit.org/b/149593 fast/shadow-dom/shadow-layout-after-slot-changes.html [ ImageOnlyFailure ]
    13341333
    13351334webkit.org/b/149510 accessibility/mac/aria-expanded-notifications.html [ Pass Failure ]
  • trunk/Source/WebCore/ChangeLog

    r190314 r190323  
     12015-09-29  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Update style/layout when a slot is added or removed
     4        https://bugs.webkit.org/show_bug.cgi?id=149593
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Fixed the bug by forcing the render tree reconstruction on the shadow host when a slot is inserted or removed.
     9        We should optimize these reconstructions by only triggering them on the affected slot elements in the future.
     10
     11        Also fixed a bug that we were not invalidating the slot assignments when a default slot is introduced dynamically
     12        after the slot assignment algorithm had run.
     13
     14        Test (existing): fast/shadow-dom/shadow-layout-after-slot-changes.html
     15
     16        * dom/ShadowRoot.cpp:
     17        (WebCore::ShadowRoot::addSlotElementByName): Passes in ShadowRoot.
     18        (WebCore::ShadowRoot::removeSlotElementByName): Ditto.
     19        * dom/SlotAssignment.cpp:
     20        (WebCore::SlotAssignment::addSlotElementByName): Call setNeedsStyleRecalc.
     21        (WebCore::SlotAssignment::removeSlotElementByName): Call setNeedsStyleRecalc if the host is still alive since this
     22        function can be called while the host is being destructed in which case shadowRoot.host() would be nullptr.
     23        * dom/SlotAssignment.h:
     24
    1252015-09-29  Youenn Fablet  <youenn.fablet@crf.canon.fr>
    226
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r190256 r190323  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    190191        m_slotAssignments = std::make_unique<SlotAssignment>();
    191192
    192     return m_slotAssignments->addSlotElementByName(name, slot);
     193    return m_slotAssignments->addSlotElementByName(name, slot, *this);
    193194}
    194195
    195196void ShadowRoot::removeSlotElementByName(const AtomicString& name, HTMLSlotElement& slot)
    196197{
    197     return m_slotAssignments->removeSlotElementByName(name, slot);
     198    return m_slotAssignments->removeSlotElementByName(name, slot, *this);
    198199}
    199200
  • trunk/Source/WebCore/dom/SlotAssignment.cpp

    r190109 r190323  
    5252}
    5353
    54 void SlotAssignment::addSlotElementByName(const AtomicString& name, HTMLSlotElement& slotElement)
     54void SlotAssignment::addSlotElementByName(const AtomicString& name, HTMLSlotElement& slotElement, ShadowRoot& shadowRoot)
    5555{
    5656#ifndef NDEBUG
     
    5959#endif
    6060
    61     auto addResult = m_slots.add(treatNullAsEmpty(name), std::unique_ptr<SlotInfo>());
     61    // FIXME: We should be able to do a targeted reconstruction.
     62    shadowRoot.host()->setNeedsStyleRecalc(ReconstructRenderTree);
     63
     64    const AtomicString& key = treatNullAsEmpty(name);
     65    auto addResult = m_slots.add(key, std::unique_ptr<SlotInfo>());
    6266    if (addResult.isNewEntry) {
    6367        addResult.iterator->value = std::make_unique<SlotInfo>(slotElement);
     68        if (key == emptyAtom) // Because assignSlots doesn't collect nodes assgined to the default slot as an optimzation.
     69            m_slotAssignmentsIsValid = false;
    6470        return;
    6571    }
     
    7884}
    7985
    80 void SlotAssignment::removeSlotElementByName(const AtomicString& name, HTMLSlotElement& slotElement)
     86void SlotAssignment::removeSlotElementByName(const AtomicString& name, HTMLSlotElement& slotElement, ShadowRoot& shadowRoot)
    8187{
    8288#ifndef NDEBUG
     
    8490    m_slotElementsForConsistencyCheck.remove(&slotElement);
    8591#endif
     92
     93    if (auto* host = shadowRoot.host()) // FIXME: We should be able to do a targeted reconstruction.
     94        host->setNeedsStyleRecalc(ReconstructRenderTree);
    8695
    8796    auto it = m_slots.find(treatNullAsEmpty(name));
  • trunk/Source/WebCore/dom/SlotAssignment.h

    r190109 r190323  
    4848    HTMLSlotElement* findAssignedSlot(const Node&, ShadowRoot&);
    4949
    50     void addSlotElementByName(const AtomicString&, HTMLSlotElement&);
    51     void removeSlotElementByName(const AtomicString&, HTMLSlotElement&);
     50    void addSlotElementByName(const AtomicString&, HTMLSlotElement&, ShadowRoot&);
     51    void removeSlotElementByName(const AtomicString&, HTMLSlotElement&, ShadowRoot&);
    5252
    5353    const Vector<Node*>* assignedNodesForSlot(const HTMLSlotElement&, ShadowRoot&);
Note: See TracChangeset for help on using the changeset viewer.