Changeset 251269 in webkit


Ignore:
Timestamp:
Oct 17, 2019, 5:15:28 PM (6 years ago)
Author:
rniwa@webkit.org
Message:

Integrate resize event with HTML5 event loop
https://bugs.webkit.org/show_bug.cgi?id=202964

Reviewed by Geoffrey Garen.

Source/WebCore:

Dispatch resize events in "run the resize steps" during the "update the rendering":
https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering

Exisitng code in WebCore which was dispatching or scheduling dispatching of resize events now simply sets
a flag on document and schedules a rendering update. In Page::updateRendering, we fire resize events on
any documents with this flag set.

Test: fast/events/resize-subframe-in-rendering-update.html

  • dom/Document.cpp:

(WebCore::Document::setNeedsDOMWindowResizeEvent): Added.
(WebCore::Document::setNeedsVisualViewportResize): Added.
(WebCore::Document::runResizeSteps): Added. https://drafts.csswg.org/cssom-view/#run-the-resize-steps

  • dom/Document.h:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::resizeTo const):

  • page/FrameView.cpp:

(WebCore::FrameView::sendResizeEventIfNeeded): Now sets m_needsDOMWindowResizeEvent on Document instead of
enqueuing a resize event.

  • page/Page.cpp:

(WebCore::Page::updateRendering): Call runResizeSteps on each document.
(WebCore::Page::collectDocuments): Added.

  • page/Page.h:
  • page/VisualViewport.cpp:

(WebCore::VisualViewport::enqueueResizeEvent):

LayoutTests:

Added a regression test and fixed an existing test to work with the new behavior.

  • fast/events/resize-subframe-in-rendering-update-expected.txt: Added.
  • fast/events/resize-subframe-in-rendering-update.html: Added.
  • fast/shadow-dom/trusted-event-scoped-flags.html:
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/LayoutTests/ChangeLog

    r251266 r251269  
     12019-10-17  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Integrate resize event with HTML5 event loop
     4        https://bugs.webkit.org/show_bug.cgi?id=202964
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Added a regression test and fixed an existing test to work with the new behavior.
     9
     10        * fast/events/resize-subframe-in-rendering-update-expected.txt: Added.
     11        * fast/events/resize-subframe-in-rendering-update.html: Added.
     12        * fast/shadow-dom/trusted-event-scoped-flags.html:
     13
    1142019-10-17  Tim Horton  <timothy_horton@apple.com>
    215
  • TabularUnified trunk/LayoutTests/fast/shadow-dom/trusted-event-scoped-flags.html

    r202953 r251269  
    111111
    112112    iframe.onload = function () {
    113         iframe.contentDocument.body.getBoundingClientRect();
    114         log(iframe.contentWindow, "resize");
    115         setTimeout(function () {
    116             iframe.style.width = '200px';
    117             iframe.style.height = '200px';
    118             iframe.contentDocument.body.getBoundingClientRect();
     113        requestAnimationFrame(function () {
    119114            setTimeout(function () {
    120                 checkFlags('', {eventType: 'resize', composed: false});
    121                 finishJSTest();
     115                iframe.contentDocument.body.getBoundingClientRect();
     116                log(iframe.contentWindow, "resize");
     117                iframe.style.width = '200px';
     118                iframe.style.height = '200px';
     119                iframe.contentDocument.body.getBoundingClientRect();
     120                requestAnimationFrame(function () {
     121                    checkFlags('', {eventType: 'resize', composed: false});
     122                    finishJSTest();
     123                });
    122124            }, 0);
    123         }, 0);
     125        });
    124126    }
    125127
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r251267 r251269  
     12019-10-17  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Integrate resize event with HTML5 event loop
     4        https://bugs.webkit.org/show_bug.cgi?id=202964
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Dispatch resize events in "run the resize steps" during the "update the rendering":
     9        https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering
     10
     11        Exisitng code in WebCore which was dispatching or scheduling dispatching of resize events now simply sets
     12        a flag on document and schedules a rendering update. In Page::updateRendering, we fire resize events on
     13        any documents with this flag set.
     14
     15        Test: fast/events/resize-subframe-in-rendering-update.html
     16
     17        * dom/Document.cpp:
     18        (WebCore::Document::setNeedsDOMWindowResizeEvent): Added.
     19        (WebCore::Document::setNeedsVisualViewportResize): Added.
     20        (WebCore::Document::runResizeSteps): Added. https://drafts.csswg.org/cssom-view/#run-the-resize-steps
     21        * dom/Document.h:
     22        * page/DOMWindow.cpp:
     23        (WebCore::DOMWindow::resizeTo const):
     24        * page/FrameView.cpp:
     25        (WebCore::FrameView::sendResizeEventIfNeeded): Now sets m_needsDOMWindowResizeEvent on Document instead of
     26        enqueuing a resize event.
     27        * page/Page.cpp:
     28        (WebCore::Page::updateRendering): Call runResizeSteps on each document.
     29        (WebCore::Page::collectDocuments): Added.
     30        * page/Page.h:
     31        * page/VisualViewport.cpp:
     32        (WebCore::VisualViewport::enqueueResizeEvent):
     33
    1342019-10-17  Chris Dumez  <cdumez@apple.com>
    235
  • TabularUnified trunk/Source/WebCore/dom/Document.cpp

    r251220 r251269  
    223223#include "VisibilityChangeClient.h"
    224224#include "VisitedLinkState.h"
     225#include "VisualViewport.h"
    225226#include "WebAnimation.h"
    226227#include "WheelEvent.h"
     
    39613962}
    39623963
     3964void Document::setNeedsDOMWindowResizeEvent()
     3965{
     3966    m_needsDOMWindowResizeEvent = true;
     3967    scheduleTimedRenderingUpdate();
     3968}
     3969
     3970void Document::setNeedsVisualViewportResize()
     3971{
     3972    m_needsVisualViewportResizeEvent = true;
     3973    scheduleTimedRenderingUpdate();
     3974}
     3975
     3976// https://drafts.csswg.org/cssom-view/#run-the-resize-steps
     3977void Document::runResizeSteps()
     3978{
     3979    // FIXME: The order of dispatching is not specified: https://github.com/WICG/visual-viewport/issues/65.
     3980    if (m_needsDOMWindowResizeEvent) {
     3981        LOG(Events, "Document %p sending resize events to window", this);
     3982        m_needsDOMWindowResizeEvent = false;
     3983        dispatchWindowEvent(Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No));
     3984    }
     3985    if (m_needsVisualViewportResizeEvent) {
     3986        LOG(Events, "Document %p sending resize events to visualViewport", this);
     3987        m_needsVisualViewportResizeEvent = false;
     3988        if (auto* window = domWindow())
     3989            window->visualViewport().dispatchEvent(Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No));
     3990    }
     3991}
     3992
    39633993void Document::addAudioProducer(MediaProducer& audioProducer)
    39643994{
  • TabularUnified trunk/Source/WebCore/dom/Document.h

    r251258 r251269  
    13591359    void updateViewportUnitsOnResize();
    13601360
     1361    void setNeedsDOMWindowResizeEvent();
     1362    void setNeedsVisualViewportResize();
     1363    void runResizeSteps();
     1364
    13611365    WEBCORE_EXPORT void addAudioProducer(MediaProducer&);
    13621366    WEBCORE_EXPORT void removeAudioProducer(MediaProducer&);
     
    20082012
    20092013    bool m_hasStyleWithViewportUnits { false };
     2014    bool m_needsDOMWindowResizeEvent { false };
     2015    bool m_needsVisualViewportResizeEvent { false };
    20102016    bool m_isTimerThrottlingEnabled { false };
    20112017    bool m_isSuspended { false };
  • TabularUnified trunk/Source/WebCore/page/FrameView.cpp

    r251220 r251269  
    33773377#endif
    33783378
     3379    LOG(Events, "FrameView %p sendResizeEventIfNeeded scheduling resize event for document %p, size %dx%d", this, frame().document(), currentSize.width(), currentSize.height());
     3380    frame().document()->setNeedsDOMWindowResizeEvent();
     3381
    33793382    bool isMainFrame = frame().isMainFrame();
    3380     bool canSendResizeEventSynchronously = isMainFrame && !m_shouldAutoSize;
    3381 
    3382     LOG(Events, "FrameView %p sendResizeEventIfNeeded sending resize event, size %dx%d (canSendResizeEventSynchronously %d)", this, currentSize.width(), currentSize.height(), canSendResizeEventSynchronously);
    3383 
    3384     Ref<Event> resizeEvent = Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No);
    3385     if (canSendResizeEventSynchronously)
    3386         frame().document()->dispatchWindowEvent(resizeEvent);
    3387     else {
    3388         // FIXME: Queueing this event for an unpredictable time in the future seems
    3389         // intrinsically racy. By the time this resize event fires, the frame might
    3390         // be resized again, so we could end up with two resize events for the same size.
    3391         frame().document()->enqueueWindowEvent(WTFMove(resizeEvent));
    3392     }
    3393 
    33943383    if (InspectorInstrumentation::hasFrontends() && isMainFrame) {
    33953384        if (Page* page = frame().page()) {
  • TabularUnified trunk/Source/WebCore/page/Page.cpp

    r251220 r251269  
    12951295    SetForScope<bool> change(m_inUpdateRendering, true);
    12961296
    1297     Vector<RefPtr<Document>> documents;
    1298 
    1299     // The requestAnimationFrame callbacks may change the frame hierarchy of the page
    1300     forEachDocument([&documents] (Document& document) {
    1301         documents.append(&document);
    1302     });
    1303 
    1304     // FIXME: Run the resize steps
     1297    layoutIfNeeded();
     1298
     1299    for (auto& document : collectDocuments())
     1300        document->runResizeSteps();
    13051301
    13061302    // FIXME: Run the scroll steps
     
    13081304    // FIXME: Evaluate media queries and report changes.
    13091305
     1306    Vector<Ref<Document>> documents = collectDocuments(); // The requestAnimationFrame callbacks may change the frame hierarchy of the page
    13101307    for (auto& document : documents) {
    13111308        DOMHighResTimeStamp timestamp = document->domWindow()->nowTimestamp();
     
    28742871}
    28752872
     2873Vector<Ref<Document>> Page::collectDocuments()
     2874{
     2875    Vector<Ref<Document>> documents;
     2876    for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
     2877        auto* document = frame->document();
     2878        if (!document)
     2879            continue;
     2880        documents.append(*document);
     2881    }
     2882    return documents;
     2883}
     2884
    28762885void Page::applicationWillResignActive()
    28772886{
  • TabularUnified trunk/Source/WebCore/page/Page.h

    r251220 r251269  
    751751
    752752    void forEachDocument(const WTF::Function<void(Document&)>&);
     753    Vector<Ref<Document>> collectDocuments();
    753754
    754755    enum class TimerThrottlingState { Disabled, Enabled, EnabledIncreasing };
  • TabularUnified trunk/Source/WebCore/page/VisualViewport.cpp

    r246490 r251269  
    186186    if (!frame)
    187187        return;
    188 
    189     frame->document()->eventQueue().enqueueResizeEvent(*this, Event::CanBubble::No, Event::IsCancelable::No);
     188    frame->document()->setNeedsVisualViewportResize();
    190189}
    191190
Note: See TracChangeset for help on using the changeset viewer.