Changeset 285211 in webkit


Ignore:
Timestamp:
Nov 3, 2021 9:59:48 AM (9 months ago)
Author:
Antti Koivisto
Message:

::slotted element style not invalidated correctly in nested case
https://bugs.webkit.org/show_bug.cgi?id=232665

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-scoping/slotted-nested-expected.txt:

Source/WebCore:

We fail to invalidate ::slotted style if the assigned node is not from the current host scope.

  • style/StyleInvalidator.cpp:

(WebCore::Style::invalidateAssignedElements):

Invalidate more accurately by following assigned node chain recursively instead of just invalidating all host children.

(WebCore::Style::Invalidator::invalidateIfNeeded):

Remove the unnecessary and incorrect m_didInvalidateHostChildren optimization.

  • style/StyleInvalidator.h:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r285209 r285211  
     12021-11-03  Antti Koivisto  <antti@apple.com>
     2
     3        ::slotted element style not invalidated correctly in nested case
     4        https://bugs.webkit.org/show_bug.cgi?id=232665
     5
     6        Reviewed by Simon Fraser.
     7
     8        * web-platform-tests/css/css-scoping/slotted-nested-expected.txt:
     9
    1102021-11-03  Antti Koivisto  <antti@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scoping/slotted-nested-expected.txt

    r267650 r285211  
    33
    44PASS Slotted matches rules against the slot in the right tree
    5 FAIL Style invalidation works correctly for nested slots assert_not_equals: got disallowed value "rgb(0, 128, 0)"
     5PASS Style invalidation works correctly for nested slots
    66
  • trunk/Source/WebCore/ChangeLog

    r285210 r285211  
     12021-11-03  Antti Koivisto  <antti@apple.com>
     2
     3        ::slotted element style not invalidated correctly in nested case
     4        https://bugs.webkit.org/show_bug.cgi?id=232665
     5
     6        Reviewed by Simon Fraser.
     7
     8        We fail to invalidate ::slotted style if the assigned node is not from the current host scope.
     9
     10        * style/StyleInvalidator.cpp:
     11        (WebCore::Style::invalidateAssignedElements):
     12
     13        Invalidate more accurately by following assigned node chain recursively instead of just invalidating all host children.
     14
     15        (WebCore::Style::Invalidator::invalidateIfNeeded):
     16
     17        Remove the unnecessary and incorrect m_didInvalidateHostChildren optimization.
     18
     19        * style/StyleInvalidator.h:
     20
    1212021-11-03  Jer Noble  <jer.noble@apple.com>
    222
  • trunk/Source/WebCore/style/StyleInvalidator.cpp

    r283552 r285211  
    129129}
    130130
     131static void invalidateAssignedElements(HTMLSlotElement& slot)
     132{
     133    auto* assignedNodes = slot.assignedNodes();
     134    if (!assignedNodes)
     135        return;
     136    for (auto& node : *assignedNodes) {
     137        if (!is<Element>(node.get()))
     138            continue;
     139        if (is<HTMLSlotElement>(*node) && node->containingShadowRoot()) {
     140            invalidateAssignedElements(downcast<HTMLSlotElement>(*node));
     141            continue;
     142        }
     143        downcast<Element>(*node).invalidateStyleInternal();
     144    }
     145}
     146
    131147Invalidator::CheckDescendants Invalidator::invalidateIfNeeded(Element& element, const SelectorFilter* filter)
    132148{
    133149    invalidateInShadowTreeIfNeeded(element);
    134150
    135     bool shouldCheckForSlots = m_ruleInformation.hasSlottedPseudoElementRules && !m_didInvalidateHostChildren;
    136     if (shouldCheckForSlots && is<HTMLSlotElement>(element)) {
    137         auto* containingShadowRoot = element.containingShadowRoot();
    138         if (containingShadowRoot && containingShadowRoot->host()) {
    139             for (auto& possiblySlotted : childrenOfType<Element>(*containingShadowRoot->host()))
    140                 possiblySlotted.invalidateStyleInternal();
    141         }
    142         // No need to do this again.
    143         m_didInvalidateHostChildren = true;
    144     }
     151    if (m_ruleInformation.hasSlottedPseudoElementRules && is<HTMLSlotElement>(element))
     152        invalidateAssignedElements(downcast<HTMLSlotElement>(element));
    145153
    146154    switch (element.styleValidity()) {
     
    162170    case Style::Validity::SubtreeInvalid:
    163171    case Style::Validity::SubtreeAndRenderersInvalid:
    164         if (shouldCheckForSlots)
    165             return CheckDescendants::Yes;
    166172        return CheckDescendants::No;
    167173    }
  • trunk/Source/WebCore/style/StyleInvalidator.h

    r284857 r285211  
    9191
    9292    bool m_dirtiesAllStyle { false };
    93     bool m_didInvalidateHostChildren { false };
    9493};
    9594
Note: See TracChangeset for help on using the changeset viewer.