Changeset 208610 in webkit


Ignore:
Timestamp:
Nov 11, 2016 1:59:33 PM (7 years ago)
Author:
Antti Koivisto
Message:

Shadow DOM: Toggling class in .class ::slotted(*) does not trigger style recalc
https://bugs.webkit.org/show_bug.cgi?id=160864

Reviewed by Ryosuke Niwa.

Source/WebCore:

Also fix similar issue with ::host

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

  • css/StyleInvalidationAnalysis.cpp:

(WebCore::StyleInvalidationAnalysis::invalidateIfNeeded):

If we have ::slotted rules and encounter a <slot>, invalidate the slotted host children.

(WebCore::StyleInvalidationAnalysis::invalidateStyle):

Invalidate the shadow host if we have ::host rules.

  • css/StyleInvalidationAnalysis.h:
  • dom/InlineStyleSheetOwner.cpp:

(WebCore::InlineStyleSheetOwner::createSheet):

Fix a bug where it was possible to mutate stylesheets in the inline stylesheet cache.
The included test covers this.

  • style/StyleScope.cpp:

(WebCore::Style::Scope::updateActiveStyleSheets):

Handle the full invalidation case.

LayoutTests:

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

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r208606 r208610  
     12016-11-11  Antti Koivisto  <antti@apple.com>
     2
     3        Shadow DOM: Toggling class in `.class ::slotted(*)` does not trigger style recalc
     4        https://bugs.webkit.org/show_bug.cgi?id=160864
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * fast/shadow-dom/css-scoping-host-and-slotted-context-invalidation-expected.html: Added.
     9        * fast/shadow-dom/css-scoping-host-and-slotted-context-invalidation.html: Added.
     10
    1112016-11-11  Eric Carlson  <eric.carlson@apple.com>
    212
     
    12011211        * fast/shadow-dom/css-scoping-slot-with-id-expected.html: Added.
    12021212        * fast/shadow-dom/css-scoping-slot-with-id.html: Added.
     1213
    12031214
    120412152016-11-04  Brady Eidson  <beidson@apple.com>
  • trunk/Source/WebCore/ChangeLog

    r208609 r208610  
     12016-11-11  Antti Koivisto  <antti@apple.com>
     2
     3        Shadow DOM: Toggling class in `.class ::slotted(*)` does not trigger style recalc
     4        https://bugs.webkit.org/show_bug.cgi?id=160864
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Also fix similar issue with ::host
     9
     10        Test: fast/shadow-dom/css-scoping-host-and-slotted-context-invalidation.html
     11
     12        * css/StyleInvalidationAnalysis.cpp:
     13        (WebCore::StyleInvalidationAnalysis::invalidateIfNeeded):
     14
     15            If we have ::slotted rules and encounter a <slot>, invalidate the slotted host children.
     16
     17        (WebCore::StyleInvalidationAnalysis::invalidateStyle):
     18
     19            Invalidate the shadow host if we have ::host rules.
     20
     21        * css/StyleInvalidationAnalysis.h:
     22        * dom/InlineStyleSheetOwner.cpp:
     23        (WebCore::InlineStyleSheetOwner::createSheet):
     24
     25            Fix a bug where it was possible to mutate stylesheets in the inline stylesheet cache.
     26            The included test covers this.
     27
     28        * style/StyleScope.cpp:
     29        (WebCore::Style::Scope::updateActiveStyleSheets):
     30
     31            Handle the full invalidation case.
     32
    1332016-11-11  Brady Eidson  <beidson@apple.com>
    234
  • trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp

    r207458 r208610  
    3131#include "ElementIterator.h"
    3232#include "ElementRuleCollector.h"
     33#include "HTMLSlotElement.h"
    3334#include "SelectorFilter.h"
    3435#include "ShadowRoot.h"
     
    104105    }
    105106
     107    bool shouldCheckForSlots = !m_ruleSet.slottedPseudoElementRules().isEmpty() && !m_didInvalidateHostChildren;
     108    if (shouldCheckForSlots && is<HTMLSlotElement>(element)) {
     109        auto* containingShadowRoot = element.containingShadowRoot();
     110        if (containingShadowRoot && containingShadowRoot->host()) {
     111            for (auto& possiblySlotted : childrenOfType<Element>(*containingShadowRoot->host()))
     112                possiblySlotted.invalidateStyle();
     113        }
     114        // No need to do this again.
     115        m_didInvalidateHostChildren = true;
     116    }
     117
    106118    switch (element.styleValidity()) {
    107119    case Style::Validity::Valid: {
     
    118130    case Style::Validity::SubtreeInvalid:
    119131    case Style::Validity::SubtreeAndRenderersInvalid:
     132        if (shouldCheckForSlots)
     133            return CheckDescendants::Yes;
    120134        return CheckDescendants::No;
    121135    }
     
    173187    ASSERT(!m_dirtiesAllStyle);
    174188
     189    if (!m_ruleSet.hostPseudoClassRules().isEmpty() && shadowRoot.host())
     190        shadowRoot.host()->invalidateStyle();
     191
    175192    for (auto& child : childrenOfType<Element>(shadowRoot)) {
    176193        SelectorFilter filter;
  • trunk/Source/WebCore/css/StyleInvalidationAnalysis.h

    r206990 r208610  
    5959    bool m_dirtiesAllStyle { false };
    6060    bool m_hasShadowPseudoElementRulesInAuthorSheet { false };
     61    bool m_didInvalidateHostChildren { false };
    6162};
    6263
  • trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp

    r208001 r208610  
    214214
    215215    if (cacheKey && contents->isCacheable()) {
     216        m_sheet->contents().addedToMemoryCache();
    216217        inlineStyleSheetCache().add(*cacheKey, &m_sheet->contents());
    217218
    218219        // Prevent pathological growth.
    219220        const size_t maximumInlineStyleSheetCacheSize = 50;
    220         if (inlineStyleSheetCache().size() > maximumInlineStyleSheetCacheSize)
     221        if (inlineStyleSheetCache().size() > maximumInlineStyleSheetCacheSize) {
     222            inlineStyleSheetCache().begin()->value->removedFromMemoryCache();
    221223            inlineStyleSheetCache().remove(inlineStyleSheetCache().begin());
     224        }
    222225    }
    223226}
  • trunk/Source/WebCore/style/StyleScope.cpp

    r208001 r208610  
    408408    }
    409409
     410    // FIXME: Move this code somewhere else.
    410411    if (requiresFullStyleRecalc) {
    411412        if (m_shadowRoot) {
    412413            for (auto& shadowChild : childrenOfType<Element>(*m_shadowRoot))
    413414                shadowChild.invalidateStyleForSubtree();
     415            if (m_shadowRoot->host()) {
     416                if (!resolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
     417                    m_shadowRoot->host()->invalidateStyle();
     418                if (!resolver().ruleSets().authorStyle().slottedPseudoElementRules().isEmpty()) {
     419                    for (auto& shadowChild : childrenOfType<Element>(*m_shadowRoot->host()))
     420                        shadowChild.invalidateStyle();
     421                }
     422            }
    414423        } else
    415424            m_document.scheduleForcedStyleRecalc();
Note: See TracChangeset for help on using the changeset viewer.