Title: [251322] trunk
Revision
251322
Author
[email protected]
Date
2019-10-19 01:31:00 -0700 (Sat, 19 Oct 2019)

Log Message

Integrate media query evaluation into HTML5 event loop
https://bugs.webkit.org/show_bug.cgi?id=203134
<rdar://problem/56396316>

Reviewed by Antti Koivisto.

Source/WebCore:

Moved the code to call media query listeners to HTML5 event loop's step to update the rendering:
https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering

Tests: fast/media/mq-inverted-colors-live-update-for-listener.html
       fast/media/mq-prefers-reduced-motion-live-update-for-listener.html

* css/MediaQueryMatcher.cpp:
(WebCore::MediaQueryMatcher::evaluateAll): Renamed from styleResolverChanged.
* css/MediaQueryMatcher.h:
* dom/Document.cpp:
(WebCore::Document::updateElementsAffectedByMediaQueries): Split from evaluateMediaQueryList.
This function is still called right after each layout update so that picture element may start
requesting newly selected image resources without having to wait for a rendering update.
But this function will no longer execute arbitrary scripts.
(WebCore::Document::evaluateMediaQueriesAndReportChanges): Split from evaluateMediaQueryList.
Evaluates media query listeners.
* dom/Document.h:
* inspector/agents/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::setEmulatedMedia): Force the evaluation of media queries for now
but this code should really be scheduling a rendering update instead so added a FIXME.
* page/Frame.cpp:
(WebCore::Frame::setPrinting): Evaluate media queries. We should consider invoking the full
algorithm to update the rendering here. e.g. intersection observer may add more contents.
* page/Page.cpp:
(WebCore::Page::updateRendering): Call evaluateMediaQueriesAndReportChanges.

LayoutTests:

Added tests for listening to accessiblity related media queries without having any style rules
get affected by those media queries so that we can catch any future regressions. For now,
changing accessiblity settings seem to always schedule a rendering update so there is nothing to do
when these accessibility settings do change.

* fast/media/media-query-list-07.html: Fixed the test to be compatible with new behavior.
* fast/media/mq-inverted-colors-live-update-for-listener-expected.txt: Added.
* fast/media/mq-inverted-colors-live-update-for-listener.html: Added.
* fast/media/mq-prefers-reduced-motion-live-update-for-listener-expected.txt: Added.
* fast/media/mq-prefers-reduced-motion-live-update-for-listener.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (251321 => 251322)


--- trunk/LayoutTests/ChangeLog	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/LayoutTests/ChangeLog	2019-10-19 08:31:00 UTC (rev 251322)
@@ -1,3 +1,22 @@
+2019-10-19  Ryosuke Niwa  <[email protected]>
+
+        Integrate media query evaluation into HTML5 event loop
+        https://bugs.webkit.org/show_bug.cgi?id=203134
+        <rdar://problem/56396316>
+
+        Reviewed by Antti Koivisto.
+
+        Added tests for listening to accessiblity related media queries without having any style rules
+        get affected by those media queries so that we can catch any future regressions. For now,
+        changing accessiblity settings seem to always schedule a rendering update so there is nothing to do
+        when these accessibility settings do change.
+
+        * fast/media/media-query-list-07.html: Fixed the test to be compatible with new behavior.
+        * fast/media/mq-inverted-colors-live-update-for-listener-expected.txt: Added.
+        * fast/media/mq-inverted-colors-live-update-for-listener.html: Added.
+        * fast/media/mq-prefers-reduced-motion-live-update-for-listener-expected.txt: Added.
+        * fast/media/mq-prefers-reduced-motion-live-update-for-listener.html: Added.
+
 2019-10-18  Said Abou-Hallawa  <[email protected]>
 
         [SVG2]: Remove the SVGExternalResourcesRequired interface

Modified: trunk/LayoutTests/fast/media/media-query-list-07.html (251321 => 251322)


--- trunk/LayoutTests/fast/media/media-query-list-07.html	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/LayoutTests/fast/media/media-query-list-07.html	2019-10-19 08:31:00 UTC (rev 251322)
@@ -25,6 +25,8 @@
         if (!window.testRunner)
             return;
 
+        testRunner.waitUntilDone();
+
         var query = window.matchMedia("screen");
 
         query.addListener(callback1);
@@ -49,6 +51,7 @@
         query.addListener(callback2);
 
         window.internals.settings.setMediaTypeOverride("handheld");
+        requestAnimationFrame(() => testRunner.notifyDone());
     }
 
 </script>

Added: trunk/LayoutTests/fast/media/mq-inverted-colors-live-update-for-listener-expected.txt (0 => 251322)


--- trunk/LayoutTests/fast/media/mq-inverted-colors-live-update-for-listener-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-inverted-colors-live-update-for-listener-expected.txt	2019-10-19 08:31:00 UTC (rev 251322)
@@ -0,0 +1,11 @@
+This tests listeners on MediaQueryList get called when inverted color is turned on when there are no relevant style rules
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS didCallListener is true
+PASS matchMedia("(inverted-colors)").matches is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/media/mq-inverted-colors-live-update-for-listener.html (0 => 251322)


--- trunk/LayoutTests/fast/media/mq-inverted-colors-live-update-for-listener.html	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-inverted-colors-live-update-for-listener.html	2019-10-19 08:31:00 UTC (rev 251322)
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+description('This tests listeners on MediaQueryList get called when inverted color is turned on when there are no relevant style rules');
+
+jsTestIsAsync = true;
+
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+let didCallListener = false;
+let timer;
+
+window._onload_ = () => {
+    window.matchMedia('(inverted-colors)').addListener((e) => {
+        didCallListener = true;
+        finalize();
+    });
+
+    if (!window.internals || !testRunner.runUIScript) {
+        testFailed('This test requires runUIScript');
+        finishJSTest();
+        return;
+    }
+
+    window.internals.settings.forcedColorsAreInvertedAccessibilityValue = "on";
+    testRunner.runUIScript(`
+        uiController.simulateAccessibilitySettingsChangeNotification(() => {
+            uiController.uiScriptComplete("Done");
+        })`, () => {
+        timer = setTimeout(finalize, 1000);
+    });
+}
+
+function finalize() {
+    if (timer)
+        clearTimeout(timer);
+
+    shouldBeTrue('didCallListener');
+    shouldBeTrue('matchMedia("(inverted-colors)").matches');
+    finishJSTest();
+}
+
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/media/mq-prefers-reduced-motion-live-update-for-listener-expected.txt (0 => 251322)


--- trunk/LayoutTests/fast/media/mq-prefers-reduced-motion-live-update-for-listener-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-prefers-reduced-motion-live-update-for-listener-expected.txt	2019-10-19 08:31:00 UTC (rev 251322)
@@ -0,0 +1,11 @@
+This tests listeners on MediaQueryList get called when inverted color is turned on when there are no relevant style rules
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS didCallListener is true
+PASS matchMedia("(prefers-reduced-motion)").matches is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/media/mq-prefers-reduced-motion-live-update-for-listener.html (0 => 251322)


--- trunk/LayoutTests/fast/media/mq-prefers-reduced-motion-live-update-for-listener.html	                        (rev 0)
+++ trunk/LayoutTests/fast/media/mq-prefers-reduced-motion-live-update-for-listener.html	2019-10-19 08:31:00 UTC (rev 251322)
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+description('This tests listeners on MediaQueryList get called when inverted color is turned on when there are no relevant style rules');
+
+jsTestIsAsync = true;
+
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+let didCallListener = false;
+let timer;
+
+window._onload_ = () => {
+    window.matchMedia('(prefers-reduced-motion)').addListener((e) => {
+        didCallListener = true;
+        finalize();
+    });
+
+    if (!window.internals || !testRunner.runUIScript) {
+        testFailed('This test requires runUIScript');
+        finishJSTest();
+        return;
+    }
+
+    window.internals.settings.forcedPrefersReducedMotionAccessibilityValue = "on";
+    testRunner.runUIScript(`
+        uiController.simulateAccessibilitySettingsChangeNotification(() => {
+            uiController.uiScriptComplete("Done");
+        })`, () => {
+        timer = setTimeout(finalize, 1000);
+    });
+}
+
+function finalize() {
+    if (timer)
+        clearTimeout(timer);
+
+    shouldBeTrue('didCallListener');
+    shouldBeTrue('matchMedia("(prefers-reduced-motion)").matches');
+    finishJSTest();
+}
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (251321 => 251322)


--- trunk/Source/WebCore/ChangeLog	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/ChangeLog	2019-10-19 08:31:00 UTC (rev 251322)
@@ -1,3 +1,37 @@
+2019-10-19  Ryosuke Niwa  <[email protected]>
+
+        Integrate media query evaluation into HTML5 event loop
+        https://bugs.webkit.org/show_bug.cgi?id=203134
+        <rdar://problem/56396316>
+
+        Reviewed by Antti Koivisto.
+
+        Moved the code to call media query listeners to HTML5 event loop's step to update the rendering:
+        https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering
+
+        Tests: fast/media/mq-inverted-colors-live-update-for-listener.html
+               fast/media/mq-prefers-reduced-motion-live-update-for-listener.html
+
+        * css/MediaQueryMatcher.cpp:
+        (WebCore::MediaQueryMatcher::evaluateAll): Renamed from styleResolverChanged.
+        * css/MediaQueryMatcher.h:
+        * dom/Document.cpp:
+        (WebCore::Document::updateElementsAffectedByMediaQueries): Split from evaluateMediaQueryList.
+        This function is still called right after each layout update so that picture element may start
+        requesting newly selected image resources without having to wait for a rendering update.
+        But this function will no longer execute arbitrary scripts.
+        (WebCore::Document::evaluateMediaQueriesAndReportChanges): Split from evaluateMediaQueryList.
+        Evaluates media query listeners.
+        * dom/Document.h:
+        * inspector/agents/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::setEmulatedMedia): Force the evaluation of media queries for now
+        but this code should really be scheduling a rendering update instead so added a FIXME.
+        * page/Frame.cpp:
+        (WebCore::Frame::setPrinting): Evaluate media queries. We should consider invoking the full
+        algorithm to update the rendering here. e.g. intersection observer may add more contents.
+        * page/Page.cpp:
+        (WebCore::Page::updateRendering): Call evaluateMediaQueriesAndReportChanges.
+
 2019-10-18  Tim Horton  <[email protected]>
 
         macCatalyst: Cursor should send mouse events, not touch events

Modified: trunk/Source/WebCore/css/MediaQueryMatcher.cpp (251321 => 251322)


--- trunk/Source/WebCore/css/MediaQueryMatcher.cpp	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/css/MediaQueryMatcher.cpp	2019-10-19 08:31:00 UTC (rev 251322)
@@ -109,7 +109,7 @@
     });
 }
 
-void MediaQueryMatcher::styleResolverChanged()
+void MediaQueryMatcher::evaluateAll()
 {
     ASSERT(m_document);
 

Modified: trunk/Source/WebCore/css/MediaQueryMatcher.h (251321 => 251322)


--- trunk/Source/WebCore/css/MediaQueryMatcher.h	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/css/MediaQueryMatcher.h	2019-10-19 08:31:00 UTC (rev 251322)
@@ -53,7 +53,7 @@
 
     unsigned evaluationRound() const { return m_evaluationRound; }
 
-    void styleResolverChanged();
+    void evaluateAll();
 
     bool evaluate(const MediaQuerySet&);
 

Modified: trunk/Source/WebCore/dom/Document.cpp (251321 => 251322)


--- trunk/Source/WebCore/dom/Document.cpp	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/dom/Document.cpp	2019-10-19 08:31:00 UTC (rev 251322)
@@ -3899,15 +3899,21 @@
     return *m_styleSheetList;
 }
 
-void Document::evaluateMediaQueryList()
+void Document::updateElementsAffectedByMediaQueries()
 {
-    if (m_mediaQueryMatcher)
-        m_mediaQueryMatcher->styleResolverChanged();
-    
+    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     checkViewportDependentPictures();
     checkAppearanceDependentPictures();
 }
 
+void Document::evaluateMediaQueriesAndReportChanges()
+{
+    if (!m_mediaQueryMatcher)
+        return;
+
+    m_mediaQueryMatcher->evaluateAll();
+}
+
 void Document::checkViewportDependentPictures()
 {
     Vector<HTMLPictureElement*, 16> changedPictures;

Modified: trunk/Source/WebCore/dom/Document.h (251321 => 251322)


--- trunk/Source/WebCore/dom/Document.h	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/dom/Document.h	2019-10-19 08:31:00 UTC (rev 251322)
@@ -555,7 +555,8 @@
     bool gotoAnchorNeededAfterStylesheetsLoad() { return m_gotoAnchorNeededAfterStylesheetsLoad; }
     void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
 
-    void evaluateMediaQueryList();
+    void updateElementsAffectedByMediaQueries();
+    void evaluateMediaQueriesAndReportChanges();
 
     FormController& formController();
     Vector<String> formElementsState() const;

Modified: trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp (251321 => 251322)


--- trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2019-10-19 08:31:00 UTC (rev 251322)
@@ -872,10 +872,15 @@
 
     m_emulatedMedia = media;
 
+    // FIXME: Schedule a rendering update instead of synchronously updating the layout.
     m_inspectedPage.updateStyleAfterChangeInEnvironment();
 
-    if (auto* document = m_inspectedPage.mainFrame().document())
-        document->updateLayout();
+    auto document = makeRefPtr(m_inspectedPage.mainFrame().document());
+    if (!document)
+        return;
+
+    document->updateLayout();
+    document->evaluateMediaQueriesAndReportChanges();
 }
 
 void InspectorPageAgent::setForcedAppearance(ErrorString&, const String& appearance)

Modified: trunk/Source/WebCore/page/Frame.cpp (251321 => 251322)


--- trunk/Source/WebCore/page/Frame.cpp	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/page/Frame.cpp	2019-10-19 08:31:00 UTC (rev 251322)
@@ -560,7 +560,9 @@
     auto& frameView = *view();
     frameView.adjustMediaTypeForPrinting(printing);
 
+    // FIXME: Consider invoking Page::updateRendering or an equivalent.
     m_doc->styleScope().didChangeStyleSheetEnvironment();
+    m_doc->evaluateMediaQueriesAndReportChanges();
     if (shouldUsePrintingLayout())
         frameView.forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
     else {

Modified: trunk/Source/WebCore/page/FrameViewLayoutContext.cpp (251321 => 251322)


--- trunk/Source/WebCore/page/FrameViewLayoutContext.cpp	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/page/FrameViewLayoutContext.cpp	2019-10-19 08:31:00 UTC (rev 251322)
@@ -519,7 +519,7 @@
     // Viewport-dependent media queries may cause us to need completely different style information.
     document.styleScope().evaluateMediaQueriesForViewportChange();
 
-    document.evaluateMediaQueryList();
+    document.updateElementsAffectedByMediaQueries();
     // If there is any pagination to apply, it will affect the RenderView's style, so we should
     // take care of that now.
     view().applyPaginationToViewport();

Modified: trunk/Source/WebCore/page/Page.cpp (251321 => 251322)


--- trunk/Source/WebCore/page/Page.cpp	2019-10-19 06:31:27 UTC (rev 251321)
+++ trunk/Source/WebCore/page/Page.cpp	2019-10-19 08:31:00 UTC (rev 251322)
@@ -1301,7 +1301,8 @@
 
     // FIXME: Run the scroll steps
 
-    // FIXME: Evaluate media queries and report changes.
+    for (auto& document : collectDocuments())
+        document->evaluateMediaQueriesAndReportChanges();
 
     Vector<Ref<Document>> documents = collectDocuments(); // The requestAnimationFrame callbacks may change the frame hierarchy of the page
     for (auto& document : documents) {
@@ -2663,7 +2664,7 @@
     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (auto* document = frame->document()) {
             document->styleScope().evaluateMediaQueriesForAccessibilitySettingsChange();
-            document->evaluateMediaQueryList();
+            document->updateElementsAffectedByMediaQueries();
         }
     }
 }
@@ -2677,7 +2678,7 @@
 
         document->styleScope().didChangeStyleSheetEnvironment();
         document->styleScope().evaluateMediaQueriesForAppearanceChange();
-        document->evaluateMediaQueryList();
+        document->updateElementsAffectedByMediaQueries();
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to