Bug 202964 - Integrate resize event with HTML5 event loop
Summary: Integrate resize event with HTML5 event loop
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on: 203140 203162 203384
Blocks: 202843
  Show dependency treegraph
 
Reported: 2019-10-14 19:07 PDT by Ryosuke Niwa
Modified: 2019-10-31 12:26 PDT (History)
16 users (show)

See Also:


Attachments
WIP (5.94 KB, patch)
2019-10-14 19:08 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WIP2 (6.95 KB, patch)
2019-10-15 19:05 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WIP3 (7.93 KB, patch)
2019-10-15 19:11 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WIP4 (8.09 KB, patch)
2019-10-15 20:08 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch (13.65 KB, patch)
2019-10-16 23:09 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews214 for win-future (13.65 MB, application/zip)
2019-10-17 01:08 PDT, EWS Watchlist
no flags Details
Windows test fix attempt (14.09 KB, patch)
2019-10-17 10:19 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed SVG animation tests (11.98 KB, patch)
2019-10-30 20:45 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed SVG animation tests (12.06 KB, patch)
2019-10-30 20:53 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch for landing (14.52 KB, patch)
2019-10-31 00:33 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2019-10-14 19:07:56 PDT
HTML5 specification says we should be fire resize event at step 10.5 during the step to update the rendering:
https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering

Do that.
Comment 1 Ryosuke Niwa 2019-10-14 19:08:43 PDT
Created attachment 380946 [details]
WIP
Comment 2 Ryosuke Niwa 2019-10-15 19:05:53 PDT
Created attachment 381047 [details]
WIP2
Comment 3 Ryosuke Niwa 2019-10-15 19:11:36 PDT
Created attachment 381048 [details]
WIP3
Comment 4 Ryosuke Niwa 2019-10-15 20:08:52 PDT
Created attachment 381049 [details]
WIP4
Comment 5 Ryosuke Niwa 2019-10-16 23:09:24 PDT
Created attachment 381171 [details]
Patch
Comment 6 EWS Watchlist 2019-10-17 01:08:20 PDT
Comment on attachment 381171 [details]
Patch

Attachment 381171 [details] did not pass win-ews (win):
Output: https://webkit-queues.webkit.org/results/13142433

New failing tests:
fast/shadow-dom/trusted-event-scoped-flags.html
Comment 7 EWS Watchlist 2019-10-17 01:08:23 PDT
Created attachment 381178 [details]
Archive of layout-test-results from ews214 for win-future

The attached test failures were seen while running run-webkit-tests on the win-ews.
Bot: ews214  Port: win-future  Platform: CYGWIN_NT-10.0-17763-3.0.5-338.x86_64-x86_64-64bit
Comment 8 Ryosuke Niwa 2019-10-17 10:19:48 PDT
Created attachment 381197 [details]
Windows test fix attempt
Comment 9 Ryosuke Niwa 2019-10-17 14:11:23 PDT
Ping reviews (EWS is all green except armv7 & i386 JSC bots).
Comment 10 Geoffrey Garen 2019-10-17 16:23:36 PDT
Comment on attachment 381197 [details]
Windows test fix attempt

View in context: https://bugs.webkit.org/attachment.cgi?id=381197&action=review

r=me

> Source/WebCore/page/Page.cpp:1297
> +    layoutIfNeeded();

Are the additional layoutIfNeeded() calls below also required? (Kind of sad to do up to three layouts just because certain events dirtied the DOM.)

> Source/WebCore/page/Page.cpp:2879
> +        auto* document = frame->document();
> +        if (!document)
> +            continue;

A frame always has a document, so you can skip this null check.
Comment 11 Ryosuke Niwa 2019-10-17 16:40:36 PDT
Comment on attachment 381197 [details]
Windows test fix attempt

View in context: https://bugs.webkit.org/attachment.cgi?id=381197&action=review

>> Source/WebCore/page/Page.cpp:1297
>> +    layoutIfNeeded();
> 
> Are the additional layoutIfNeeded() calls below also required? (Kind of sad to do up to three layouts just because certain events dirtied the DOM.)

Yes. Otherwise, we don't update the states for intersection observers & resize observers.
However, some of these layout updates are no-op if they don't make any changes.

Regardless, we can probably optimize away some of layouts needed here once we've fully moved to the new model.
Comment 12 Ryosuke Niwa 2019-10-17 17:01:34 PDT
(In reply to Geoffrey Garen from comment #10)
> Comment on attachment 381197 [details]
> Windows test fix attempt
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=381197&action=review
> 
> r=me
>
> > Source/WebCore/page/Page.cpp:2879
> > +        auto* document = frame->document();
> > +        if (!document)
> > +            continue;
> 
> A frame always has a document, so you can skip this null check.

Hm... I don't think this is true. FrameLoader::clear sets Frame::m_doc to nullptr. It's true that this function is currently not called within FrameLoader::clear but I think we should make this code future proof.
Comment 13 Simon Fraser (smfr) 2019-10-17 17:13:24 PDT
Comment on attachment 381197 [details]
Windows test fix attempt

View in context: https://bugs.webkit.org/attachment.cgi?id=381197&action=review

> Source/WebCore/ChangeLog:11
> +        Exisitng code in WebCore which was dispatching or scheduling dispatching of resize events now simply sets

Exisitng

> Source/WebCore/page/FrameView.cpp:3379
> +    LOG(Events, "FrameView %p sendResizeEventIfNeeded scheduling resize event for document %p, size %dx%d", this, frame().document(), currentSize.width(), currentSize.height());

LOG_WITH_STREAM will do size formatting for you. We could also make it print a human-readable thing for a Document&.

> Source/WebCore/page/Page.cpp:1306
> +    Vector<Ref<Document>> documents = collectDocuments(); // The requestAnimationFrame callbacks may change the frame hierarchy of the page

It's going to be really easy to make the mistake, when we extend this function, of re-using 'documents' from before a previous step, and thus using a stale list. Can we factor the code to make this less likely? Maybe a lambda for each step that goes into a vector, and a wrapper function that gathers documents each time?

> Source/WebCore/page/Page.h:753
>      void forEachDocument(const WTF::Function<void(Document&)>&);
> +    Vector<Ref<Document>> collectDocuments();

Why don't we use forEachDocument in the rendering steps?
Comment 14 Ryosuke Niwa 2019-10-17 17:15:30 PDT
Committed r251269: <https://trac.webkit.org/changeset/251269>
Comment 15 Radar WebKit Bug Importer 2019-10-17 17:16:23 PDT
<rdar://problem/56391539>
Comment 16 Truitt Savell 2019-10-18 09:21:32 PDT
It looks like the new test fast/events/resize-subframe-in-rendering-update.html

added in https://trac.webkit.org/changeset/251269/webkit

is a flakey failure on Mac and iOS:

https://results.webkit.org/?suite=layout-tests&test=fast%2Fevents%2Fresize-subframe-in-rendering-update.html

Diff:
--- /Volumes/Data/slave/mojave-release-tests-wk1/build/layout-test-results/fast/events/resize-subframe-in-rendering-update-expected.txt
+++ /Volumes/Data/slave/mojave-release-tests-wk1/build/layout-test-results/fast/events/resize-subframe-in-rendering-update-actual.txt
@@ -7,6 +7,8 @@
 iframeA.style.width = "200px"; updateLayout(iframeA)
 iframeAA.style.width = "200px"; updateLayout(iframeAA)
 PASS logs.length is 0
+After 0s setTimeout
+PASS logs.length is 0
 After requestAnimationFrame
 PASS logs.length is 3
 PASS logs.join(", ") is "A, AA, B"
Comment 17 WebKit Commit Bot 2019-10-24 15:37:22 PDT
Re-opened since this is blocked by bug 203384
Comment 18 Ryosuke Niwa 2019-10-30 20:38:05 PDT
Comment on attachment 381197 [details]
Windows test fix attempt

View in context: https://bugs.webkit.org/attachment.cgi?id=381197&action=review

>> Source/WebCore/page/Page.cpp:1306
>> +    Vector<Ref<Document>> documents = collectDocuments(); // The requestAnimationFrame callbacks may change the frame hierarchy of the page
> 
> It's going to be really easy to make the mistake, when we extend this function, of re-using 'documents' from before a previous step, and thus using a stale list. Can we factor the code to make this less likely? Maybe a lambda for each step that goes into a vector, and a wrapper function that gathers documents each time?

Well, the subsequent steps are using the same documents now.
Let me refactor that in a separate patch.
Comment 19 Ryosuke Niwa 2019-10-30 20:45:49 PDT
Created attachment 382415 [details]
Fixed SVG animation tests
Comment 20 Ryosuke Niwa 2019-10-30 20:52:08 PDT
(In reply to Simon Fraser (smfr) from comment #13)
> Comment on attachment 381197 [details]
> Windows test fix attempt
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=381197&action=review
> 
> > Source/WebCore/ChangeLog:11
> > +        Exisitng code in WebCore which was dispatching or scheduling dispatching of resize events now simply sets
> 
> Exisitng

Fixed.

> > Source/WebCore/page/FrameView.cpp:3379
> > +    LOG(Events, "FrameView %p sendResizeEventIfNeeded scheduling resize event for document %p, size %dx%d", this, frame().document(), currentSize.width(), currentSize.height());
> 
> LOG_WITH_STREAM will do size formatting for you. We could also make it print
> a human-readable thing for a Document&.

Sure, fixed.

> > Source/WebCore/page/Page.h:753
> >      void forEachDocument(const WTF::Function<void(Document&)>&);
> > +    Vector<Ref<Document>> collectDocuments();
> 
> Why don't we use forEachDocument in the rendering steps?

Sure, done.
Comment 21 Ryosuke Niwa 2019-10-30 20:53:49 PDT
Created attachment 382417 [details]
Fixed SVG animation tests
Comment 22 Simon Fraser (smfr) 2019-10-30 22:03:13 PDT
Comment on attachment 382417 [details]
Fixed SVG animation tests

View in context: https://bugs.webkit.org/attachment.cgi?id=382417&action=review

> Source/WebCore/page/FrameView.cpp:3425
> +    LOG_WITH_STREAM(Events, stream << "FrameView" << this << "sendResizeEventIfNeeded scheduling resize event for document" << frame().document() << ", size " << currentSize.width() << currentSize.height());

just " size " << currentSize

> Tools/DumpRenderTree/mac/DumpRenderTree.mm:1731
> +    fprintf(stderr, "DumpRenderTree dump\n");
> +    WTFReportBacktrace();

Remove.
Comment 23 Ryosuke Niwa 2019-10-31 00:33:55 PDT
Created attachment 382437 [details]
Patch for landing
Comment 24 Ryosuke Niwa 2019-10-31 12:26:12 PDT
Committed r251867: <https://trac.webkit.org/changeset/251867>