Changeset 208616 in webkit


Ignore:
Timestamp:
Nov 11, 2016 3:08:34 PM (7 years ago)
Author:
Antti Koivisto
Message:

Updating class name doesn't update the slotted content's style
https://bugs.webkit.org/show_bug.cgi?id=164577
<rdar://problem/29205873>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: fast/shadow-dom/css-scoping-slotted-invalidation.html

Teach style invalidation code for attribute/class/id mutations about slotted rules.

  • dom/ShadowRoot.cpp:

(WebCore::assignedShadowRootsIfSlotted):

Helper to find all assigned shadow roots (there may be more than one if slots are assigned to slots).

  • dom/ShadowRoot.h:
  • style/AttributeChangeInvalidation.cpp:

(WebCore::Style::mayBeAffectedByAttributeChange):
(WebCore::Style::mayBeAffectedByHostRules):
(WebCore::Style::mayBeAffectedBySlottedRules):
(WebCore::Style::AttributeChangeInvalidation::invalidateStyle):
(WebCore::Style::mayBeAffectedByHostStyle): Deleted.

  • style/ClassChangeInvalidation.cpp:

(WebCore::Style::mayBeAffectedByHostRules):
(WebCore::Style::mayBeAffectedBySlottedRules):
(WebCore::Style::ClassChangeInvalidation::invalidateStyle):
(WebCore::Style::mayBeAffectedByHostStyle): Deleted.

  • style/ClassChangeInvalidation.h:
  • style/IdChangeInvalidation.cpp:

(WebCore::Style::mayBeAffectedByHostRules):
(WebCore::Style::mayBeAffectedBySlottedRules):
(WebCore::Style::IdChangeInvalidation::invalidateStyle):
(WebCore::Style::mayBeAffectedByHostStyle): Deleted.

  • style/StyleSharingResolver.cpp:

(WebCore::Style::SharingResolver::canShareStyleWithElement):

Fix a bug in style sharing where we were checking wrong element for host rules.
Tested by the included test too (the last empty div).

LayoutTests:

  • fast/shadow-dom/css-scoping-slotted-invalidation-expected.html: Added.
  • fast/shadow-dom/css-scoping-slotted-invalidation.html: Added.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r208613 r208616  
     12016-11-11  Antti Koivisto  <antti@apple.com>
     2
     3        Updating class name doesn't update the slotted content's style
     4        https://bugs.webkit.org/show_bug.cgi?id=164577
     5        <rdar://problem/29205873>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        * fast/shadow-dom/css-scoping-slotted-invalidation-expected.html: Added.
     10        * fast/shadow-dom/css-scoping-slotted-invalidation.html: Added.
     11
    1122016-11-11  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r208615 r208616  
     12016-11-11  Antti Koivisto  <antti@apple.com>
     2
     3        Updating class name doesn't update the slotted content's style
     4        https://bugs.webkit.org/show_bug.cgi?id=164577
     5        <rdar://problem/29205873>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Test: fast/shadow-dom/css-scoping-slotted-invalidation.html
     10
     11        Teach style invalidation code for attribute/class/id mutations about slotted rules.
     12
     13        * dom/ShadowRoot.cpp:
     14        (WebCore::assignedShadowRootsIfSlotted):
     15
     16            Helper to find all assigned shadow roots (there may be more than one if slots are assigned to slots).
     17
     18        * dom/ShadowRoot.h:
     19        * style/AttributeChangeInvalidation.cpp:
     20        (WebCore::Style::mayBeAffectedByAttributeChange):
     21        (WebCore::Style::mayBeAffectedByHostRules):
     22        (WebCore::Style::mayBeAffectedBySlottedRules):
     23        (WebCore::Style::AttributeChangeInvalidation::invalidateStyle):
     24        (WebCore::Style::mayBeAffectedByHostStyle): Deleted.
     25        * style/ClassChangeInvalidation.cpp:
     26        (WebCore::Style::mayBeAffectedByHostRules):
     27        (WebCore::Style::mayBeAffectedBySlottedRules):
     28        (WebCore::Style::ClassChangeInvalidation::invalidateStyle):
     29        (WebCore::Style::mayBeAffectedByHostStyle): Deleted.
     30        * style/ClassChangeInvalidation.h:
     31        * style/IdChangeInvalidation.cpp:
     32        (WebCore::Style::mayBeAffectedByHostRules):
     33        (WebCore::Style::mayBeAffectedBySlottedRules):
     34        (WebCore::Style::IdChangeInvalidation::invalidateStyle):
     35        (WebCore::Style::mayBeAffectedByHostStyle): Deleted.
     36        * style/StyleSharingResolver.cpp:
     37        (WebCore::Style::SharingResolver::canShareStyleWithElement):
     38
     39            Fix a bug in style sharing where we were checking wrong element for host rules.
     40            Tested by the included test too (the last empty div).
     41
    1422016-11-11  Dave Hyatt  <hyatt@apple.com>
    243
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r208378 r208616  
    3232#include "ElementTraversal.h"
    3333#include "ExceptionCode.h"
     34#include "HTMLSlotElement.h"
    3435#include "RenderElement.h"
    3536#include "RuntimeEnabledFeatures.h"
     
    184185}
    185186
     187Vector<ShadowRoot*> assignedShadowRootsIfSlotted(const Node& node)
     188{
     189    Vector<ShadowRoot*> result;
     190    for (auto* slot = node.assignedSlot(); slot; slot = slot->assignedSlot()) {
     191        ASSERT(slot->containingShadowRoot());
     192        result.append(slot->containingShadowRoot());
     193    }
     194    return result;
     195}
    186196
    187197}
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r208118 r208616  
    134134}
    135135
     136Vector<ShadowRoot*> assignedShadowRootsIfSlotted(const Node&);
     137
    136138} // namespace WebCore
    137139
  • trunk/Source/WebCore/style/AttributeChangeInvalidation.cpp

    r207458 r208616  
    3737namespace Style {
    3838
    39 static bool mayBeAffectedByHostStyle(ShadowRoot& shadowRoot, bool isHTML, const QualifiedName& attributeName)
     39static bool mayBeAffectedByAttributeChange(DocumentRuleSets& ruleSets, bool isHTML, const QualifiedName& attributeName)
    4040{
    41     auto& shadowRuleSets = shadowRoot.styleScope().resolver().ruleSets();
     41    auto& nameSet = isHTML ? ruleSets.features().attributeCanonicalLocalNamesInRules : ruleSets.features().attributeLocalNamesInRules;
     42    return nameSet.contains(attributeName.localName().impl());
     43}
     44
     45static bool mayBeAffectedByHostRules(const Element& element, const QualifiedName& attributeName)
     46{
     47    auto* shadowRoot = element.shadowRoot();
     48    if (!shadowRoot)
     49        return false;
     50    auto& shadowRuleSets = shadowRoot->styleScope().resolver().ruleSets();
    4251    if (shadowRuleSets.authorStyle().hostPseudoClassRules().isEmpty())
    4352        return false;
    4453
    45     auto& nameSet = isHTML ? shadowRuleSets.features().attributeCanonicalLocalNamesInRules : shadowRuleSets.features().attributeLocalNamesInRules;
    46     return nameSet.contains(attributeName.localName().impl());
     54    return mayBeAffectedByAttributeChange(shadowRuleSets, element.isHTMLElement(), attributeName);
     55}
     56
     57static bool mayBeAffectedBySlottedRules(const Element& element, const QualifiedName& attributeName)
     58{
     59    for (auto* shadowRoot : assignedShadowRootsIfSlotted(element)) {
     60        auto& ruleSets = shadowRoot->styleScope().resolver().ruleSets();
     61        if (ruleSets.authorStyle().slottedPseudoElementRules().isEmpty())
     62            continue;
     63        if (mayBeAffectedByAttributeChange(ruleSets, element.isHTMLElement(), attributeName))
     64            return true;
     65    }
     66    return false;
    4767}
    4868
     
    5575    bool isHTML = m_element.isHTMLElement();
    5676
    57     auto& nameSet = isHTML ? ruleSets.features().attributeCanonicalLocalNamesInRules : ruleSets.features().attributeLocalNamesInRules;
    58     bool mayAffectStyle = nameSet.contains(attributeName.localName().impl());
    59 
    60     auto* shadowRoot = m_element.shadowRoot();
    61     if (!mayAffectStyle && shadowRoot && mayBeAffectedByHostStyle(*shadowRoot, isHTML, attributeName))
    62         mayAffectStyle = true;
     77    bool mayAffectStyle = mayBeAffectedByAttributeChange(ruleSets, isHTML, attributeName)
     78        || mayBeAffectedByHostRules(m_element, attributeName)
     79        || mayBeAffectedBySlottedRules(m_element, attributeName);
    6380
    6481    if (!mayAffectStyle)
  • trunk/Source/WebCore/style/ClassChangeInvalidation.cpp

    r207458 r208616  
    8787}
    8888
    89 static bool mayBeAffectedByHostStyle(ShadowRoot& shadowRoot, AtomicStringImpl* changedClass)
     89static bool mayBeAffectedByHostRules(ShadowRoot* shadowRoot, AtomicStringImpl* changedClass)
    9090{
    91     auto& shadowRuleSets = shadowRoot.styleScope().resolver().ruleSets();
     91    if (!shadowRoot)
     92        return false;
     93    auto& shadowRuleSets = shadowRoot->styleScope().resolver().ruleSets();
    9294    if (shadowRuleSets.authorStyle().hostPseudoClassRules().isEmpty())
    9395        return false;
    9496    return shadowRuleSets.features().classesInRules.contains(changedClass);
     97}
     98
     99static bool mayBeAffectedBySlottedRules(const Vector<ShadowRoot*>& assignedShadowRoots, AtomicStringImpl* changedClass)
     100{
     101    for (auto& assignedShadowRoot : assignedShadowRoots) {
     102        auto& ruleSets = assignedShadowRoot->styleScope().resolver().ruleSets();
     103        if (ruleSets.authorStyle().slottedPseudoElementRules().isEmpty())
     104            continue;
     105        if (ruleSets.features().classesInRules.contains(changedClass))
     106            return true;
     107    }
     108    return false;
    95109}
    96110
     
    101115    auto& ruleSets = m_element.styleResolver().ruleSets();
    102116    auto* shadowRoot = m_element.shadowRoot();
     117    auto assignedShadowRoots = assignedShadowRootsIfSlotted(m_element);
    103118
    104119    ClassChangeVector changedClassesAffectingStyle;
    105120    for (auto* changedClass : changedClasses) {
    106         bool mayAffectStyle = ruleSets.features().classesInRules.contains(changedClass);
    107 
    108         if (!mayAffectStyle && shadowRoot && mayBeAffectedByHostStyle(*shadowRoot, changedClass))
    109             mayAffectStyle = true;
    110 
     121        bool mayAffectStyle = ruleSets.features().classesInRules.contains(changedClass)
     122            || mayBeAffectedByHostRules(shadowRoot, changedClass)
     123            || mayBeAffectedBySlottedRules(assignedShadowRoots, changedClass);
    111124        if (mayAffectStyle)
    112125            changedClassesAffectingStyle.append(changedClass);
  • trunk/Source/WebCore/style/ClassChangeInvalidation.h

    r202167 r208616  
    7070    invalidateDescendantStyle();
    7171}
    72    
     72
    7373}
    7474}
  • trunk/Source/WebCore/style/IdChangeInvalidation.cpp

    r207458 r208616  
    3636namespace Style {
    3737
    38 static bool mayBeAffectedByHostStyle(ShadowRoot& shadowRoot, const AtomicString& changedId)
     38static bool mayBeAffectedByHostRules(const Element& element, const AtomicString& changedId)
    3939{
    40     auto& shadowRuleSets = shadowRoot.styleScope().resolver().ruleSets();
     40    auto* shadowRoot = element.shadowRoot();
     41    if (!shadowRoot)
     42        return false;
     43    auto& shadowRuleSets = shadowRoot->styleScope().resolver().ruleSets();
    4144    if (shadowRuleSets.authorStyle().hostPseudoClassRules().isEmpty())
    4245        return false;
     46    return shadowRuleSets.features().idsInRules.contains(changedId.impl());
     47}
    4348
    44     return shadowRuleSets.features().idsInRules.contains(changedId.impl());
     49static bool mayBeAffectedBySlottedRules(const Element& element, const AtomicString& changedId)
     50{
     51    for (auto* shadowRoot : assignedShadowRootsIfSlotted(element)) {
     52        auto& ruleSets = shadowRoot->styleScope().resolver().ruleSets();
     53        if (ruleSets.authorStyle().slottedPseudoElementRules().isEmpty())
     54            continue;
     55        if (ruleSets.features().idsInRules.contains(changedId.impl()))
     56            return true;
     57    }
     58    return false;
    4559}
    4660
     
    5266    auto& ruleSets = m_element.styleResolver().ruleSets();
    5367
    54     bool mayAffectStyle = ruleSets.features().idsInRules.contains(changedId.impl());
    55 
    56     auto* shadowRoot = m_element.shadowRoot();
    57     if (!mayAffectStyle && shadowRoot && mayBeAffectedByHostStyle(*shadowRoot, changedId))
    58         mayAffectStyle = true;
     68    bool mayAffectStyle = ruleSets.features().idsInRules.contains(changedId.impl())
     69        || mayBeAffectedByHostRules(m_element, changedId)
     70        || mayBeAffectedBySlottedRules(m_element, changedId);
    5971
    6072    if (!mayAffectStyle)
  • trunk/Source/WebCore/style/StyleSharingResolver.cpp

    r206951 r208616  
    289289        return false;
    290290
    291     if (element.shadowRoot() && !element.shadowRoot()->styleScope().resolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
     291    if (candidateElement.shadowRoot() && !candidateElement.shadowRoot()->styleScope().resolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
    292292        return false;
    293293
Note: See TracChangeset for help on using the changeset viewer.