Changeset 224864 in webkit


Ignore:
Timestamp:
Nov 14, 2017, 5:15:21 PM (8 years ago)
Author:
Antti Koivisto
Message:

Media query with :host inside a custom elements doesn't get updated on window resize
https://bugs.webkit.org/show_bug.cgi?id=176101
<rdar://problem/34163850>

Reviewed by Simon Fraser.

Source/WebCore:

If a media query containing :host or ::slotted stops applying we fail to update the style.

  • style/StyleScope.cpp:

(WebCore::Style::invalidateHostAndSlottedStyleIfNeeded):

Factor into function.

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

Invalidate elements that may match :host and ::slotted before clearing style resolver for full update.

LayoutTests:

Expand the existing test case to cover :host and ::slotted.

  • fast/shadow-dom/media-query-in-shadow-style-expected.html:
  • fast/shadow-dom/resources/media-query-in-shadow-style-frame.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r224853 r224864  
     12017-11-14  Antti Koivisto  <antti@apple.com>
     2
     3        Media query with :host inside a custom elements doesn't get updated on window resize
     4        https://bugs.webkit.org/show_bug.cgi?id=176101
     5        <rdar://problem/34163850>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Expand the existing test case to cover :host and ::slotted.
     10
     11        * fast/shadow-dom/media-query-in-shadow-style-expected.html:
     12        * fast/shadow-dom/resources/media-query-in-shadow-style-frame.html:
     13
    1142017-11-14  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style-expected.html

    r224535 r224864  
    1 <iframe src="data:text/html,<span style='color:red'>Text</span>" width=150 height=50></iframe><br>
    2 <iframe src="data:text/html,<span style='color:green'>Text</span>" width=300 height=50></iframe><br>
    3 <iframe src="data:text/html,<span style='color:red'>Text</span>" width=150 height=50></iframe><br>
    4 <iframe src="data:text/html,<span style='color:green'>Text</span>" width=300 height=50></iframe><br>
     1<iframe src="data:text/html,<div style='color:red'>Text</div>" width=150 height=50></iframe><br>
     2<iframe src="data:text/html,<div style='color:green;background-color: lightgrey'>Text</div>" width=300 height=50></iframe><br>
     3<iframe src="data:text/html,<div style='color:red'>Text</div>" width=150 height=50></iframe><br>
     4<iframe src="data:text/html,<div style='color:green;background-color: lightgrey'>Text</div>" width=300 height=50></iframe><br>
  • trunk/LayoutTests/fast/shadow-dom/resources/media-query-in-shadow-style-frame.html

    r224535 r224864  
    1 <div id=test></div>
     1<div id=test><span>Text</span></div>
    22<script>
    33const shadow = test.attachShadow({mode: 'open'});
     
    66    @media (min-width:200px) {
    77        div { color: green }
     8        :host { background-color: lightgrey }
    89    }
    910    @media (max-width:200px) {
    10         div { color: red }
     11        ::slotted(*) { color: red }
    1112    }
    1213    </style>
    13     <div>Text</div>
     14    <div><slot></slot></div>
    1415`;
    1516</script>
  • trunk/Source/WebCore/ChangeLog

    r224863 r224864  
     12017-11-14  Antti Koivisto  <antti@apple.com>
     2
     3        Media query with :host inside a custom elements doesn't get updated on window resize
     4        https://bugs.webkit.org/show_bug.cgi?id=176101
     5        <rdar://problem/34163850>
     6
     7        Reviewed by Simon Fraser.
     8
     9        If a media query containing :host or ::slotted stops applying we fail to update the style.
     10
     11        * style/StyleScope.cpp:
     12        (WebCore::Style::invalidateHostAndSlottedStyleIfNeeded):
     13
     14            Factor into function.
     15
     16        (WebCore::Style::Scope::updateActiveStyleSheets):
     17        (WebCore::Style::Scope::scheduleUpdate):
     18
     19            Invalidate elements that may match :host and ::slotted before clearing style resolver for full update.
     20
    1212017-11-14  Carlos Garcia Campos  <cgarcia@igalia.com>
    222
  • trunk/Source/WebCore/style/StyleScope.cpp

    r224535 r224864  
    447447}
    448448
     449static void invalidateHostAndSlottedStyleIfNeeded(ShadowRoot& shadowRoot, StyleResolver& resolver)
     450{
     451    auto& host = *shadowRoot.host();
     452    if (!resolver.ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
     453        host.invalidateStyle();
     454
     455    if (!resolver.ruleSets().authorStyle().slottedPseudoElementRules().isEmpty()) {
     456        for (auto& shadowChild : childrenOfType<Element>(host))
     457            shadowChild.invalidateStyle();
     458    }
     459}
     460
    449461void Scope::updateActiveStyleSheets(UpdateType updateType)
    450462{
     
    494506            for (auto& shadowChild : childrenOfType<Element>(*m_shadowRoot))
    495507                shadowChild.invalidateStyleForSubtree();
    496             if (m_shadowRoot->host()) {
    497                 if (!resolver().ruleSets().authorStyle().hostPseudoClassRules().isEmpty())
    498                     m_shadowRoot->host()->invalidateStyle();
    499                 if (!resolver().ruleSets().authorStyle().slottedPseudoElementRules().isEmpty()) {
    500                     for (auto& shadowChild : childrenOfType<Element>(*m_shadowRoot->host()))
    501                         shadowChild.invalidateStyle();
    502                 }
    503             }
     508            invalidateHostAndSlottedStyleIfNeeded(*m_shadowRoot, resolver());
    504509        } else
    505510            m_document.scheduleForcedStyleRecalc();
     
    586591void Scope::scheduleUpdate(UpdateType update)
    587592{
    588     // FIXME: The m_isUpdatingStyleResolver test is here because extension stylesheets can get us here from StyleResolver::appendAuthorStyleSheets.
    589     if (update == UpdateType::ContentsOrInterpretation && !m_isUpdatingStyleResolver)
    590         clearResolver();
     593    if (update == UpdateType::ContentsOrInterpretation) {
     594        // :host and ::slotted rules might go away.
     595        if (m_shadowRoot && m_resolver)
     596            invalidateHostAndSlottedStyleIfNeeded(*m_shadowRoot, *m_resolver);
     597        // FIXME: The m_isUpdatingStyleResolver test is here because extension stylesheets can get us here from StyleResolver::appendAuthorStyleSheets.
     598        if (!m_isUpdatingStyleResolver)
     599            clearResolver();
     600    }
    591601
    592602    if (!m_pendingUpdate || *m_pendingUpdate < update) {
Note: See TracChangeset for help on using the changeset viewer.