Title: [251867] trunk
Revision
251867
Author
[email protected]
Date
2019-10-31 12:26:10 -0700 (Thu, 31 Oct 2019)

Log Message

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

Reviewed by Geoffrey Garen and Simon Fraser.

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

Existing 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

* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::beginLoadTimerFired): Fixed the flakiness in SVG animation tests observed
after this patch was landed previously. The issue was that this code was calling FrameLoader's
checkLoadComplete before checkCompleted. checkCompleted starts SVG animations in Document::implicitClose
whereas checkLoadComplete can cause DumpRenderTree to end the test. As a result, depending on when this
function was called relative to other work being done in the main thread, DumpRenderTree could prematurely
end and dump the test result even though SVG animation would have immediately started in either scenario.
Unfortunately I couldn't come up with a new deterministic test for this issue since the exact condition
under which this problem comes up seems quite racy (which makes sense given this only manifested as flaky
failures in existing tests).
* 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/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:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (251866 => 251867)


--- trunk/LayoutTests/ChangeLog	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/LayoutTests/ChangeLog	2019-10-31 19:26:10 UTC (rev 251867)
@@ -1,3 +1,16 @@
+2019-10-31  Ryosuke Niwa  <[email protected]>
+
+        Integrate resize event with HTML5 event loop
+        https://bugs.webkit.org/show_bug.cgi?id=202964
+
+        Reviewed by Geoffrey Garen and Simon Fraser.
+
+        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:
+
 2019-10-31  Truitt Savell  <[email protected]>
 
         Update results for fast/css/hsl-color.html on win

Added: trunk/LayoutTests/fast/events/resize-subframe-in-rendering-update-expected.txt (0 => 251867)


--- trunk/LayoutTests/fast/events/resize-subframe-in-rendering-update-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/resize-subframe-in-rendering-update-expected.txt	2019-10-31 19:26:10 UTC (rev 251867)
@@ -0,0 +1,16 @@
+This tests that resize event is not dispatched as a part of updateLayout
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+iframeB.style.width = "200px"; updateLayout(iframeB)
+iframeA.style.width = "200px"; updateLayout(iframeA)
+iframeAA.style.width = "200px"; updateLayout(iframeAA)
+PASS logs.length is 0
+After requestAnimationFrame
+PASS logs.length is 3
+PASS logs.join(", ") is "A, AA, B"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/events/resize-subframe-in-rendering-update.html (0 => 251867)


--- trunk/LayoutTests/fast/events/resize-subframe-in-rendering-update.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/resize-subframe-in-rendering-update.html	2019-10-31 19:26:10 UTC (rev 251867)
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+
+description('This tests that resize event is not dispatched as a part of updateLayout');
+jsTestIsAsync = true;
+
+function createIframe(parentDocument)
+{
+    const iframe = document.createElement('iframe');
+    iframe.style.width = '100px';
+    iframe.style.height = '100px';
+    parentDocument.body.appendChild(iframe);
+    iframe.contentDocument.body.innerHTML = '<span>hello, world</span>';
+    return iframe;
+}
+
+function updateLayout(iframe)
+{
+    iframe.contentDocument.querySelector("span").getBoundingClientRect();
+}
+
+const iframeA = createIframe(document);
+const iframeAA = createIframe(iframeA.contentDocument);
+const iframeB = createIframe(document);
+
+const logs = [];
+requestAnimationFrame(() => {
+    setTimeout(() => {
+        iframeAA.contentWindow.addEventListener('resize', () => logs.push('AA'));
+        iframeA.contentWindow.addEventListener('resize', () => logs.push('A'));
+        iframeB.contentWindow.addEventListener('resize', () => logs.push('B'));
+
+        evalAndLog('iframeB.style.width = "200px"; updateLayout(iframeB)');
+        evalAndLog('iframeA.style.width = "200px"; updateLayout(iframeA)');
+        evalAndLog('iframeAA.style.width = "200px"; updateLayout(iframeAA)');
+        shouldBe('logs.length', '0');
+        setTimeout(() => {
+            requestAnimationFrame(() => {
+                debug('After requestAnimationFrame');
+                shouldBe('logs.length', '3');
+                shouldBeEqualToString('logs.join(", ")', 'A, AA, B');
+                iframeA.remove();
+                iframeB.remove();
+                finishJSTest();
+            });
+        }, 0);
+    }, 0);
+});
+
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/fast/shadow-dom/trusted-event-scoped-flags.html (251866 => 251867)


--- trunk/LayoutTests/fast/shadow-dom/trusted-event-scoped-flags.html	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/LayoutTests/fast/shadow-dom/trusted-event-scoped-flags.html	2019-10-31 19:26:10 UTC (rev 251867)
@@ -110,17 +110,19 @@
     iframe.style.height = '100px';
 
     iframe._onload_ = function () {
-        iframe.contentDocument.body.getBoundingClientRect();
-        log(iframe.contentWindow, "resize");
-        setTimeout(function () {
-            iframe.style.width = '200px';
-            iframe.style.height = '200px';
-            iframe.contentDocument.body.getBoundingClientRect();
+        requestAnimationFrame(function () {
             setTimeout(function () {
-                checkFlags('', {eventType: 'resize', composed: false});
-                finishJSTest();
+                iframe.contentDocument.body.getBoundingClientRect();
+                log(iframe.contentWindow, "resize");
+                iframe.style.width = '200px';
+                iframe.style.height = '200px';
+                iframe.contentDocument.body.getBoundingClientRect();
+                requestAnimationFrame(function () {
+                    checkFlags('', {eventType: 'resize', composed: false});
+                    finishJSTest();
+                });
             }, 0);
-        }, 0);
+        });
     }
 
     document.body.appendChild(iframe);

Modified: trunk/Source/WebCore/ChangeLog (251866 => 251867)


--- trunk/Source/WebCore/ChangeLog	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/Source/WebCore/ChangeLog	2019-10-31 19:26:10 UTC (rev 251867)
@@ -1,3 +1,44 @@
+2019-10-31  Ryosuke Niwa  <[email protected]>
+
+        Integrate resize event with HTML5 event loop
+        https://bugs.webkit.org/show_bug.cgi?id=202964
+
+        Reviewed by Geoffrey Garen and Simon Fraser.
+
+        Dispatch resize events in "run the resize steps" during the "update the rendering":
+        https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering
+
+        Existing 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
+
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::beginLoadTimerFired): Fixed the flakiness in SVG animation tests observed
+        after this patch was landed previously. The issue was that this code was calling FrameLoader's
+        checkLoadComplete before checkCompleted. checkCompleted starts SVG animations in Document::implicitClose
+        whereas checkLoadComplete can cause DumpRenderTree to end the test. As a result, depending on when this
+        function was called relative to other work being done in the main thread, DumpRenderTree could prematurely
+        end and dump the test result even though SVG animation would have immediately started in either scenario.
+        Unfortunately I couldn't come up with a new deterministic test for this issue since the exact condition
+        under which this problem comes up seems quite racy (which makes sense given this only manifested as flaky
+        failures in existing tests).
+        * 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/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):
+
 2019-10-31  Jer Noble  <[email protected]>
 
         Unreviewed build fix; move PictureInPictureSupport.h include outside HAVE(AVKIT) check.

Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (251866 => 251867)


--- trunk/Source/WebCore/css/CSSFontSelector.cpp	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp	2019-10-31 19:26:10 UTC (rev 251867)
@@ -397,12 +397,14 @@
         // Balances incrementRequestCount() in beginLoadingFontSoon().
         cachedResourceLoader.decrementRequestCount(*fontHandle);
     }
+    // FIXME: Use SubresourceLoader instead.
+    // Call FrameLoader::loadDone before FrameLoader::subresourceLoadDone to match the order in SubresourceLoader::notifyDone.
+    cachedResourceLoader.loadDone(LoadCompletionType::Finish);
     // Ensure that if the request count reaches zero, the frame loader will know about it.
     // New font loads may be triggered by layout after the document load is complete but before we have dispatched
     // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
     if (m_document && m_document->frame())
         m_document->frame()->loader().checkLoadComplete();
-    cachedResourceLoader.loadDone(LoadCompletionType::Finish);
 }
 
 

Modified: trunk/Source/WebCore/dom/Document.cpp (251866 => 251867)


--- trunk/Source/WebCore/dom/Document.cpp	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/Source/WebCore/dom/Document.cpp	2019-10-31 19:26:10 UTC (rev 251867)
@@ -223,6 +223,7 @@
 #include "ValidationMessageClient.h"
 #include "VisibilityChangeClient.h"
 #include "VisitedLinkState.h"
+#include "VisualViewport.h"
 #include "WebAnimation.h"
 #include "WheelEvent.h"
 #include "WindowEventLoop.h"
@@ -3959,6 +3960,35 @@
     }
 }
 
+void Document::setNeedsDOMWindowResizeEvent()
+{
+    m_needsDOMWindowResizeEvent = true;
+    scheduleTimedRenderingUpdate();
+}
+
+void Document::setNeedsVisualViewportResize()
+{
+    m_needsVisualViewportResizeEvent = true;
+    scheduleTimedRenderingUpdate();
+}
+
+// https://drafts.csswg.org/cssom-view/#run-the-resize-steps
+void Document::runResizeSteps()
+{
+    // FIXME: The order of dispatching is not specified: https://github.com/WICG/visual-viewport/issues/65.
+    if (m_needsDOMWindowResizeEvent) {
+        LOG_WITH_STREAM(Events, stream << "Document" << this << "sending resize events to window");
+        m_needsDOMWindowResizeEvent = false;
+        dispatchWindowEvent(Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No));
+    }
+    if (m_needsVisualViewportResizeEvent) {
+        LOG_WITH_STREAM(Events, stream << "Document" << this << "sending resize events to visualViewport");
+        m_needsVisualViewportResizeEvent = false;
+        if (auto* window = domWindow())
+            window->visualViewport().dispatchEvent(Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No));
+    }
+}
+
 void Document::addAudioProducer(MediaProducer& audioProducer)
 {
     m_audioProducers.add(audioProducer);

Modified: trunk/Source/WebCore/dom/Document.h (251866 => 251867)


--- trunk/Source/WebCore/dom/Document.h	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/Source/WebCore/dom/Document.h	2019-10-31 19:26:10 UTC (rev 251867)
@@ -1360,6 +1360,10 @@
     bool hasStyleWithViewportUnits() const { return m_hasStyleWithViewportUnits; }
     void updateViewportUnitsOnResize();
 
+    void setNeedsDOMWindowResizeEvent();
+    void setNeedsVisualViewportResize();
+    void runResizeSteps();
+
     WEBCORE_EXPORT void addAudioProducer(MediaProducer&);
     WEBCORE_EXPORT void removeAudioProducer(MediaProducer&);
     MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
@@ -2013,6 +2017,8 @@
     bool m_hasPreparedForDestruction { false };
 
     bool m_hasStyleWithViewportUnits { false };
+    bool m_needsDOMWindowResizeEvent { false };
+    bool m_needsVisualViewportResizeEvent { false };
     bool m_isTimerThrottlingEnabled { false };
     bool m_isSuspended { false };
 

Modified: trunk/Source/WebCore/page/FrameView.cpp (251866 => 251867)


--- trunk/Source/WebCore/page/FrameView.cpp	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/Source/WebCore/page/FrameView.cpp	2019-10-31 19:26:10 UTC (rev 251867)
@@ -3422,21 +3422,10 @@
     }
 #endif
 
+    LOG_WITH_STREAM(Events, stream << "FrameView" << this << "sendResizeEventIfNeeded scheduling resize event for document" << frame().document() << ", size " << currentSize);
+    frame().document()->setNeedsDOMWindowResizeEvent();
+
     bool isMainFrame = frame().isMainFrame();
-    bool canSendResizeEventSynchronously = isMainFrame && !m_shouldAutoSize;
-
-    LOG(Events, "FrameView %p sendResizeEventIfNeeded sending resize event, size %dx%d (canSendResizeEventSynchronously %d)", this, currentSize.width(), currentSize.height(), canSendResizeEventSynchronously);
-
-    Ref<Event> resizeEvent = Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No);
-    if (canSendResizeEventSynchronously)
-        frame().document()->dispatchWindowEvent(resizeEvent);
-    else {
-        // FIXME: Queueing this event for an unpredictable time in the future seems
-        // intrinsically racy. By the time this resize event fires, the frame might
-        // be resized again, so we could end up with two resize events for the same size.
-        frame().document()->enqueueWindowEvent(WTFMove(resizeEvent));
-    }
-
     if (InspectorInstrumentation::hasFrontends() && isMainFrame) {
         if (Page* page = frame().page()) {
             if (InspectorClient* inspectorClient = page->inspectorController().inspectorClient())

Modified: trunk/Source/WebCore/page/Page.cpp (251866 => 251867)


--- trunk/Source/WebCore/page/Page.cpp	2019-10-31 19:23:24 UTC (rev 251866)
+++ trunk/Source/WebCore/page/Page.cpp	2019-10-31 19:26:10 UTC (rev 251867)
@@ -1294,19 +1294,17 @@
 
     SetForScope<bool> change(m_inUpdateRendering, true);
 
-    Vector<RefPtr<Document>> documents;
+    layoutIfNeeded();
 
-    // The requestAnimationFrame callbacks may change the frame hierarchy of the page
-    forEachDocument([&documents] (Document& document) {
-        documents.append(&document);
+    forEachDocument([&] (Document& document) {
+        document.runResizeSteps();
     });
 
-    // FIXME: Run the resize steps
-
     // FIXME: Run the scroll steps
 
     // FIXME: Evaluate media queries and report changes.
 
+    Vector<Ref<Document>> documents = collectDocuments(); // The requestAnimationFrame callbacks may change the frame hierarchy of the page
     for (auto& document : documents) {
         DOMHighResTimeStamp timestamp = document->domWindow()->nowTimestamp();
         document->updateAnimationsAndSendEvents(timestamp);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to