Changeset 251930 in webkit


Ignore:
Timestamp:
Nov 1, 2019 11:16:13 AM (4 years ago)
Author:
rniwa@webkit.org
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::updateStyleAfterChangeInEnvironment): Schedule a rendering update after
accessibility settings have changed.
(WebCore::Page::updateRendering): Call evaluateMediaQueriesAndReportChanges.
(WebCore::Page::accessibilitySettingsDidChange): Schedule a rendering update after accessibility
settings have changed.
(WebCore::Page::appearanceDidChange): Ditto.

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.
Location:
trunk
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r251924 r251930  
     12019-11-01  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Integrate media query evaluation into HTML5 event loop
     4        https://bugs.webkit.org/show_bug.cgi?id=203134
     5        <rdar://problem/56396316>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Added tests for listening to accessiblity related media queries without having any style rules
     10        get affected by those media queries so that we can catch any future regressions. For now,
     11        changing accessiblity settings seem to always schedule a rendering update so there is nothing to do
     12        when these accessibility settings do change.
     13
     14        * fast/media/media-query-list-07.html: Fixed the test to be compatible with new behavior.
     15        * fast/media/mq-inverted-colors-live-update-for-listener-expected.txt: Added.
     16        * fast/media/mq-inverted-colors-live-update-for-listener.html: Added.
     17        * fast/media/mq-prefers-reduced-motion-live-update-for-listener-expected.txt: Added.
     18        * fast/media/mq-prefers-reduced-motion-live-update-for-listener.html: Added.
     19
    1202019-11-01  Ryosuke Niwa  <rniwa@webkit.org>
    221
  • trunk/LayoutTests/fast/media/media-query-list-07.html

    r251605 r251930  
    2626            return;
    2727
     28        testRunner.waitUntilDone();
     29
    2830        var query = window.matchMedia("screen");
    2931
     
    5052
    5153        window.internals.settings.setMediaTypeOverride("handheld");
     54        requestAnimationFrame(() => testRunner.notifyDone());
    5255    }
    5356
  • trunk/Source/WebCore/ChangeLog

    r251926 r251930  
     12019-11-01  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Integrate media query evaluation into HTML5 event loop
     4        https://bugs.webkit.org/show_bug.cgi?id=203134
     5        <rdar://problem/56396316>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Moved the code to call media query listeners to HTML5 event loop's step to update the rendering:
     10        https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering
     11
     12        Tests: fast/media/mq-inverted-colors-live-update-for-listener.html
     13               fast/media/mq-prefers-reduced-motion-live-update-for-listener.html
     14
     15        * css/MediaQueryMatcher.cpp:
     16        (WebCore::MediaQueryMatcher::evaluateAll): Renamed from styleResolverChanged.
     17        * css/MediaQueryMatcher.h:
     18        * dom/Document.cpp:
     19        (WebCore::Document::updateElementsAffectedByMediaQueries): Split from evaluateMediaQueryList.
     20        This function is still called right after each layout update so that picture element may start
     21        requesting newly selected image resources without having to wait for a rendering update.
     22        But this function will no longer execute arbitrary scripts.
     23        (WebCore::Document::evaluateMediaQueriesAndReportChanges): Split from evaluateMediaQueryList.
     24        Evaluates media query listeners.
     25        * dom/Document.h:
     26        * inspector/agents/InspectorPageAgent.cpp:
     27        (WebCore::InspectorPageAgent::setEmulatedMedia): Force the evaluation of media queries for now
     28        but this code should really be scheduling a rendering update instead so added a FIXME.
     29        * page/Frame.cpp:
     30        (WebCore::Frame::setPrinting): Evaluate media queries. We should consider invoking the full
     31        algorithm to update the rendering here. e.g. intersection observer may add more contents.
     32        * page/Page.cpp:
     33        (WebCore::Page::updateStyleAfterChangeInEnvironment): Schedule a rendering update after
     34        accessibility settings have changed.
     35        (WebCore::Page::updateRendering): Call evaluateMediaQueriesAndReportChanges.
     36        (WebCore::Page::accessibilitySettingsDidChange): Schedule a rendering update after accessibility
     37        settings have changed.
     38        (WebCore::Page::appearanceDidChange): Ditto.
     39
    1402019-11-01  Tim Horton  <timothy_horton@apple.com>
    241
  • trunk/Source/WebCore/css/MediaQueryMatcher.cpp

    r251605 r251930  
    110110}
    111111
    112 void MediaQueryMatcher::styleResolverChanged()
     112void MediaQueryMatcher::evaluateAll()
    113113{
    114114    ASSERT(m_document);
  • trunk/Source/WebCore/css/MediaQueryMatcher.h

    r251605 r251930  
    5454    unsigned evaluationRound() const { return m_evaluationRound; }
    5555
    56     void styleResolverChanged();
     56    void evaluateAll();
    5757
    5858    bool evaluate(const MediaQuerySet&);
  • trunk/Source/WebCore/dom/Document.cpp

    r251924 r251930  
    39193919}
    39203920
    3921 void Document::evaluateMediaQueryList()
    3922 {
    3923     if (m_mediaQueryMatcher)
    3924         m_mediaQueryMatcher->styleResolverChanged();
    3925    
     3921void Document::updateElementsAffectedByMediaQueries()
     3922{
     3923    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
    39263924    checkViewportDependentPictures();
    39273925    checkAppearanceDependentPictures();
     3926}
     3927
     3928void Document::evaluateMediaQueriesAndReportChanges()
     3929{
     3930    if (!m_mediaQueryMatcher)
     3931        return;
     3932
     3933    m_mediaQueryMatcher->evaluateAll();
    39283934}
    39293935
  • trunk/Source/WebCore/dom/Document.h

    r251924 r251930  
    558558    void setGotoAnchorNeededAfterStylesheetsLoad(bool b) { m_gotoAnchorNeededAfterStylesheetsLoad = b; }
    559559
    560     void evaluateMediaQueryList();
     560    void updateElementsAffectedByMediaQueries();
     561    void evaluateMediaQueriesAndReportChanges();
    561562
    562563    FormController& formController();
  • trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp

    r251605 r251930  
    887887    m_emulatedMedia = media;
    888888
     889    // FIXME: Schedule a rendering update instead of synchronously updating the layout.
    889890    m_inspectedPage.updateStyleAfterChangeInEnvironment();
    890891
    891     if (auto* document = m_inspectedPage.mainFrame().document())
    892         document->updateLayout();
     892    auto document = makeRefPtr(m_inspectedPage.mainFrame().document());
     893    if (!document)
     894        return;
     895
     896    document->updateLayout();
     897    document->evaluateMediaQueriesAndReportChanges();
    893898}
    894899
  • trunk/Source/WebCore/page/Frame.cpp

    r251605 r251930  
    561561    frameView.adjustMediaTypeForPrinting(printing);
    562562
     563    // FIXME: Consider invoking Page::updateRendering or an equivalent.
    563564    m_doc->styleScope().didChangeStyleSheetEnvironment();
     565    m_doc->evaluateMediaQueriesAndReportChanges();
    564566    if (shouldUsePrintingLayout())
    565567        frameView.forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
  • trunk/Source/WebCore/page/FrameViewLayoutContext.cpp

    r251638 r251930  
    521521    document.styleScope().evaluateMediaQueriesForViewportChange();
    522522
    523     document.evaluateMediaQueryList();
     523    document.updateElementsAffectedByMediaQueries();
    524524    // If there is any pagination to apply, it will affect the RenderView's style, so we should
    525525    // take care of that now.
  • trunk/Source/WebCore/page/Page.cpp

    r251867 r251930  
    566566void Page::updateStyleAfterChangeInEnvironment()
    567567{
    568     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
    569         // If a change in the global environment has occurred, we need to
    570         // make sure all the properties a recomputed, therefore we invalidate
    571         // the properties cache.
    572         auto* document = frame->document();
    573         if (!document)
    574             continue;
    575 
    576         if (StyleResolver* styleResolver = document->styleScope().resolverIfExists())
     568    forEachDocument([](Document& document) {
     569        if (StyleResolver* styleResolver = document.styleScope().resolverIfExists())
    577570            styleResolver->invalidateMatchedPropertiesCache();
    578         document->scheduleFullStyleRebuild();
    579         document->styleScope().didChangeStyleSheetEnvironment();
    580     }
     571        document.scheduleFullStyleRebuild();
     572        document.styleScope().didChangeStyleSheetEnvironment();
     573        document.scheduleTimedRenderingUpdate();
     574    });
    581575}
    582576
     
    12971291    layoutIfNeeded();
    12981292
    1299     forEachDocument([&] (Document& document) {
     1293    forEachDocument([&](Document& document) {
    13001294        document.runResizeSteps();
    13011295    });
     
    13031297    // FIXME: Run the scroll steps
    13041298
    1305     // FIXME: Evaluate media queries and report changes.
     1299    forEachDocument([&](Document& document) {
     1300        document.evaluateMediaQueriesAndReportChanges();       
     1301    });
    13061302
    13071303    Vector<Ref<Document>> documents = collectDocuments(); // The requestAnimationFrame callbacks may change the frame hierarchy of the page
     
    26762672void Page::accessibilitySettingsDidChange()
    26772673{
    2678     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
    2679         if (auto* document = frame->document()) {
    2680             document->styleScope().evaluateMediaQueriesForAccessibilitySettingsChange();
    2681             document->evaluateMediaQueryList();
    2682         }
    2683     }
     2674    forEachDocument([](auto& document) {
     2675        document.styleScope().evaluateMediaQueriesForAccessibilitySettingsChange();
     2676        document.updateElementsAffectedByMediaQueries();
     2677        document.scheduleTimedRenderingUpdate();
     2678    });
    26842679}
    26852680
    26862681void Page::appearanceDidChange()
    26872682{
    2688     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
    2689         auto* document = frame->document();
    2690         if (!document)
    2691             continue;
    2692 
    2693         document->styleScope().didChangeStyleSheetEnvironment();
    2694         document->styleScope().evaluateMediaQueriesForAppearanceChange();
    2695         document->evaluateMediaQueryList();
    2696     }
     2683    forEachDocument([](auto& document) {
     2684        document.styleScope().didChangeStyleSheetEnvironment();
     2685        document.styleScope().evaluateMediaQueriesForAppearanceChange();
     2686        document.updateElementsAffectedByMediaQueries();
     2687        document.scheduleTimedRenderingUpdate();
     2688    });
    26972689}
    26982690
Note: See TracChangeset for help on using the changeset viewer.