Diff
Modified: trunk/LayoutTests/ChangeLog (224534 => 224535)
--- trunk/LayoutTests/ChangeLog 2017-11-07 17:41:05 UTC (rev 224534)
+++ trunk/LayoutTests/ChangeLog 2017-11-07 18:10:40 UTC (rev 224535)
@@ -1,3 +1,14 @@
+2017-11-07 Antti Koivisto <[email protected]>
+
+ Dynamic media queries don't update in shadow tree stylesheets
+ https://bugs.webkit.org/show_bug.cgi?id=179324
+
+ Reviewed by Ryosuke Niwa.
+
+ * fast/shadow-dom/media-query-in-shadow-style-expected.html: Added.
+ * fast/shadow-dom/media-query-in-shadow-style.html: Added.
+ * fast/shadow-dom/resources/media-query-in-shadow-style-frame.html: Added.
+
2017-11-07 Youenn Fablet <[email protected]>
Support the case of fetch events that are not responded
Added: trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style-expected.html (0 => 224535)
--- trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style-expected.html (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style-expected.html 2017-11-07 18:10:40 UTC (rev 224535)
@@ -0,0 +1,4 @@
+<iframe src="" style='color:red'>Text</span>" width=150 height=50></iframe><br>
+<iframe src="" style='color:green'>Text</span>" width=300 height=50></iframe><br>
+<iframe src="" style='color:red'>Text</span>" width=150 height=50></iframe><br>
+<iframe src="" style='color:green'>Text</span>" width=300 height=50></iframe><br>
Added: trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style.html (0 => 224535)
--- trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style.html (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/media-query-in-shadow-style.html 2017-11-07 18:10:40 UTC (rev 224535)
@@ -0,0 +1,19 @@
+<iframe src="" width=150 height=50></iframe><br>
+<iframe src="" width=300 height=50></iframe><br>
+<iframe src="" width=300 height=50 _onload_='resize(event.target, 150)'></iframe><br>
+<iframe src="" width=150 height=50 _onload_='resize(event.target, 300)'></iframe><br>
+<script>
+if (window.testRunner)
+ testRunner.waitUntilDone();
+
+let resizeCount = 2;
+
+function resize(frame, size)
+{
+ setTimeout(() => {
+ frame.width = size;
+ if (!--resizeCount)
+ testRunner.notifyDone();
+ }, 10);
+}
+</script>
Added: trunk/LayoutTests/fast/shadow-dom/resources/media-query-in-shadow-style-frame.html (0 => 224535)
--- trunk/LayoutTests/fast/shadow-dom/resources/media-query-in-shadow-style-frame.html (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/resources/media-query-in-shadow-style-frame.html 2017-11-07 18:10:40 UTC (rev 224535)
@@ -0,0 +1,15 @@
+<div id=test></div>
+<script>
+const shadow = test.attachShadow({mode: 'open'});
+shadow.innerHTML = `
+ <style>
+ @media (min-width:200px) {
+ div { color: green }
+ }
+ @media (max-width:200px) {
+ div { color: red }
+ }
+ </style>
+ <div>Text</div>
+`;
+</script>
Modified: trunk/Source/WebCore/ChangeLog (224534 => 224535)
--- trunk/Source/WebCore/ChangeLog 2017-11-07 17:41:05 UTC (rev 224534)
+++ trunk/Source/WebCore/ChangeLog 2017-11-07 18:10:40 UTC (rev 224535)
@@ -1,3 +1,34 @@
+2017-11-07 Antti Koivisto <[email protected]>
+
+ Dynamic media queries don't update in shadow tree stylesheets
+ https://bugs.webkit.org/show_bug.cgi?id=179324
+
+ Reviewed by Ryosuke Niwa.
+
+ Viewport and accessibility queries should work dynamically also in shadow trees.
+
+ Test: fast/shadow-dom/media-query-in-shadow-style.html
+
+ * page/LayoutContext.cpp:
+ (WebCore::LayoutContext::updateStyleForLayout):
+ * page/Page.cpp:
+ (WebCore::Page::accessibilitySettingsDidChange):
+
+ Evaluate media query list (JS API) unconditionally as it is independent from style queries.
+ Remove some logging.
+
+ * style/StyleScope.cpp:
+ (WebCore::Style::Scope::evaluateMediaQueriesForViewportChange):
+ (WebCore::Style::Scope::evaluateMediaQueriesForAccessibilitySettingsChange):
+
+ Factor into functions in style scope.
+
+ (WebCore::Style::Scope::evaluateMediaQueries):
+
+ Evaluate queries in all shadow trees too.
+
+ * style/StyleScope.h:
+
2017-11-07 Ryosuke Niwa <[email protected]>
Release-assert NoEventDispatchAssertion in canExecute, updateLayout, and updateStyle
Modified: trunk/Source/WebCore/page/LayoutContext.cpp (224534 => 224535)
--- trunk/Source/WebCore/page/LayoutContext.cpp 2017-11-07 17:41:05 UTC (rev 224534)
+++ trunk/Source/WebCore/page/LayoutContext.cpp 2017-11-07 18:10:40 UTC (rev 224535)
@@ -479,13 +479,8 @@
{
Document& document = *frame().document();
// Viewport-dependent media queries may cause us to need completely different style information.
- auto* styleResolver = document.styleScope().resolverIfExists();
- if (!styleResolver || styleResolver->hasMediaQueriesAffectedByViewportChange()) {
- LOG(Layout, " hasMediaQueriesAffectedByViewportChange, enqueueing style recalc");
- document.styleScope().didChangeStyleSheetEnvironment();
- // FIXME: This instrumentation event is not strictly accurate since cached media query results do not persist across StyleResolver rebuilds.
- InspectorInstrumentation::mediaQueryResultChanged(document);
- }
+ document.styleScope().evaluateMediaQueriesForViewportChange();
+
document.evaluateMediaQueryList();
// If there is any pagination to apply, it will affect the RenderView's style, so we should
// take care of that now.
Modified: trunk/Source/WebCore/page/Page.cpp (224534 => 224535)
--- trunk/Source/WebCore/page/Page.cpp 2017-11-07 17:41:05 UTC (rev 224534)
+++ trunk/Source/WebCore/page/Page.cpp 2017-11-07 18:10:40 UTC (rev 224535)
@@ -2280,23 +2280,12 @@
void Page::accessibilitySettingsDidChange()
{
- bool neededRecalc = false;
-
for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
- if (Document* document = frame->document()) {
- auto* styleResolver = document->styleScope().resolverIfExists();
- if (styleResolver && styleResolver->hasMediaQueriesAffectedByAccessibilitySettingsChange()) {
- document->styleScope().didChangeStyleSheetEnvironment();
- document->evaluateMediaQueryList();
- neededRecalc = true;
- // FIXME: This instrumentation event is not strictly accurate since cached media query results do not persist across StyleResolver rebuilds.
- InspectorInstrumentation::mediaQueryResultChanged(*document);
- }
+ if (auto* document = frame->document()) {
+ document->styleScope().evaluateMediaQueriesForAccessibilitySettingsChange();
+ document->evaluateMediaQueryList();
}
}
-
- if (neededRecalc)
- LOG(Layout, "hasMediaQueriesAffectedByAccessibilitySettingsChange, enqueueing style recalc");
}
void Page::setUnobscuredSafeAreaInsets(const FloatBoxExtent& insets)
Modified: trunk/Source/WebCore/style/StyleScope.cpp (224534 => 224535)
--- trunk/Source/WebCore/style/StyleScope.cpp 2017-11-07 17:41:05 UTC (rev 224534)
+++ trunk/Source/WebCore/style/StyleScope.cpp 2017-11-07 18:10:40 UTC (rev 224535)
@@ -600,6 +600,36 @@
m_pendingUpdateTimer.startOneShot(0_s);
}
+void Scope::evaluateMediaQueriesForViewportChange()
+{
+ evaluateMediaQueries([] (StyleResolver& resolver) {
+ return resolver.hasMediaQueriesAffectedByViewportChange();
+ });
+}
+
+void Scope::evaluateMediaQueriesForAccessibilitySettingsChange()
+{
+ evaluateMediaQueries([] (StyleResolver& resolver) {
+ return resolver.hasMediaQueriesAffectedByAccessibilitySettingsChange();
+ });
+}
+
+template <typename TestFunction>
+void Scope::evaluateMediaQueries(TestFunction&& testFunction)
+{
+ if (!m_shadowRoot) {
+ for (auto* descendantShadowRoot : m_document.inDocumentShadowRoots())
+ descendantShadowRoot->styleScope().evaluateMediaQueries(testFunction);
+ }
+ auto* resolver = resolverIfExists();
+ if (!resolver)
+ return;
+ if (!testFunction(*resolver))
+ return;
+ scheduleUpdate(UpdateType::ContentsOrInterpretation);
+ InspectorInstrumentation::mediaQueryResultChanged(m_document);
+}
+
void Scope::didChangeActiveStyleSheetCandidates()
{
scheduleUpdate(UpdateType::ActiveSet);
Modified: trunk/Source/WebCore/style/StyleScope.h (224534 => 224535)
--- trunk/Source/WebCore/style/StyleScope.h 2017-11-07 17:41:05 UTC (rev 224534)
+++ trunk/Source/WebCore/style/StyleScope.h 2017-11-07 18:10:40 UTC (rev 224535)
@@ -97,6 +97,9 @@
bool activeStyleSheetsContains(const CSSStyleSheet*) const;
+ void evaluateMediaQueriesForViewportChange();
+ void evaluateMediaQueriesForAccessibilitySettingsChange();
+
// This is called when some stylesheet becomes newly enabled or disabled.
void didChangeActiveStyleSheetCandidates();
// This is called when contents of a stylesheet is mutated.
@@ -130,6 +133,8 @@
void updateActiveStyleSheets(UpdateType);
void scheduleUpdate(UpdateType);
+ template <typename TestFunction> void evaluateMediaQueries(TestFunction&&);
+
WEBCORE_EXPORT void flushPendingSelfUpdate();
WEBCORE_EXPORT void flushPendingDescendantUpdates();