Source/WebCore/ChangeLog

 12019-10-30 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 NOBODY (OOPS!).
 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 Existing 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 * css/CSSFontSelector.cpp:
 18 (WebCore::CSSFontSelector::beginLoadTimerFired): Fixed the flakiness in SVG animation tests observed
 19 after this patch was landed previously. The issue was that this code was calling FrameLoader's
 20 checkLoadComplete before checkCompleted. checkCompleted starts SVG animations in Document::implicitClose
 21 whereas checkLoadComplete can cause DumpRenderTree to end the test. As a result, depending on when this
 22 function was called relative to other work being done in the main thread, DumpRenderTree could prematurely
 23 end and dump the test result even though SVG animation would have immediately started in either scenario.
 24 Unfortunately I couldn't come up with a new deterministic test for this issue since the exact condition
 25 under which this problem comes up seems quite racy (which makes sense given this only manifested as flaky
 26 failures in existing tests).
 27 * dom/Document.cpp:
 28 (WebCore::Document::setNeedsDOMWindowResizeEvent): Added.
 29 (WebCore::Document::setNeedsVisualViewportResize): Added.
 30 (WebCore::Document::runResizeSteps): Added. https://drafts.csswg.org/cssom-view/#run-the-resize-steps
 31 * dom/Document.h:
 32 * page/FrameView.cpp:
 33 (WebCore::FrameView::sendResizeEventIfNeeded): Now sets m_needsDOMWindowResizeEvent on Document instead of
 34 enqueuing a resize event.
 35 * page/Page.cpp:
 36 (WebCore::Page::updateRendering): Call runResizeSteps on each document.
 37 (WebCore::Page::collectDocuments): Added.
 38 * page/Page.h:
 39 * page/VisualViewport.cpp:
 40 (WebCore::VisualViewport::enqueueResizeEvent):
 41
1422019-10-30 Alex Christensen <achristensen@webkit.org>
243
344 Prevent Mac CMake build from bit rotting
251831

Source/WebCore/css/CSSFontSelector.cpp

@@void CSSFontSelector::beginLoadTimerFire
397397 // Balances incrementRequestCount() in beginLoadingFontSoon().
398398 cachedResourceLoader.decrementRequestCount(*fontHandle);
399399 }
 400 // FIXME: Use SubresourceLoader instead.
 401 // Call FrameLoader::loadDone before FrameLoader::subresourceLoadDone to match the order in SubresourceLoader::notifyDone.
 402 cachedResourceLoader.loadDone(LoadCompletionType::Finish);
400403 // Ensure that if the request count reaches zero, the frame loader will know about it.
401404 // New font loads may be triggered by layout after the document load is complete but before we have dispatched
402405 // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
403406 if (m_document && m_document->frame())
404407 m_document->frame()->loader().checkLoadComplete();
405  cachedResourceLoader.loadDone(LoadCompletionType::Finish);
406408}
407409
408410
251673

Source/WebCore/dom/Document.cpp

224224#include "ValidationMessageClient.h"
225225#include "VisibilityChangeClient.h"
226226#include "VisitedLinkState.h"
 227#include "VisualViewport.h"
227228#include "WebAnimation.h"
228229#include "WheelEvent.h"
229230#include "WindowEventLoop.h"

@@void Document::updateViewportUnitsOnResi
39603961 }
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_WITH_STREAM(Events, stream << "Document" << this << "sending resize events to window");
 3982 m_needsDOMWindowResizeEvent = false;
 3983 dispatchWindowEvent(Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No));
 3984 }
 3985 if (m_needsVisualViewportResizeEvent) {
 3986 LOG_WITH_STREAM(Events, stream << "Document" << this << "sending resize events to visualViewport");
 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{
39653995 m_audioProducers.add(audioProducer);
251673

Source/WebCore/dom/Document.h

@@public:
13601360 bool hasStyleWithViewportUnits() const { return m_hasStyleWithViewportUnits; }
13611361 void updateViewportUnitsOnResize();
13621362
 1363 void setNeedsDOMWindowResizeEvent();
 1364 void setNeedsVisualViewportResize();
 1365 void runResizeSteps();
 1366
13631367 WEBCORE_EXPORT void addAudioProducer(MediaProducer&);
13641368 WEBCORE_EXPORT void removeAudioProducer(MediaProducer&);
13651369 MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }

@@private:
20162020 bool m_hasPreparedForDestruction { false };
20172021
20182022 bool m_hasStyleWithViewportUnits { false };
 2023 bool m_needsDOMWindowResizeEvent { false };
 2024 bool m_needsVisualViewportResizeEvent { false };
20192025 bool m_isTimerThrottlingEnabled { false };
20202026 bool m_isSuspended { false };
20212027
251673

Source/WebCore/page/FrameView.cpp

@@void FrameView::sendResizeEventIfNeeded(
34223422 }
34233423#endif
34243424
3425  bool isMainFrame = frame().isMainFrame();
3426  bool canSendResizeEventSynchronously = isMainFrame && !m_shouldAutoSize;
3427 
3428  LOG(Events, "FrameView %p sendResizeEventIfNeeded sending resize event, size %dx%d (canSendResizeEventSynchronously %d)", this, currentSize.width(), currentSize.height(), canSendResizeEventSynchronously);
3429 
3430  Ref<Event> resizeEvent = Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No);
3431  if (canSendResizeEventSynchronously)
3432  frame().document()->dispatchWindowEvent(resizeEvent);
3433  else {
3434  // FIXME: Queueing this event for an unpredictable time in the future seems
3435  // intrinsically racy. By the time this resize event fires, the frame might
3436  // be resized again, so we could end up with two resize events for the same size.
3437  frame().document()->enqueueWindowEvent(WTFMove(resizeEvent));
3438  }
 3425 LOG_WITH_STREAM(Events, stream << "FrameView" << this << "sendResizeEventIfNeeded scheduling resize event for document" << frame().document() << ", size " << currentSize.width() << currentSize.height());
 3426 frame().document()->setNeedsDOMWindowResizeEvent();
34393427
 3428 bool isMainFrame = frame().isMainFrame();
34403429 if (InspectorInstrumentation::hasFrontends() && isMainFrame) {
34413430 if (Page* page = frame().page()) {
34423431 if (InspectorClient* inspectorClient = page->inspectorController().inspectorClient())
251673

Source/WebCore/page/Page.cpp

@@void Page::updateRendering()
12941294
12951295 SetForScope<bool> change(m_inUpdateRendering, true);
12961296
1297  Vector<RefPtr<Document>> documents;
 1297 layoutIfNeeded();
12981298
1299  // The requestAnimationFrame callbacks may change the frame hierarchy of the page
1300  forEachDocument([&documents] (Document& document) {
1301  documents.append(&document);
 1299 forEachDocument([&] (Document& document) {
 1300 document.runResizeSteps();
13021301 });
13031302
1304  // FIXME: Run the resize steps
1305 
13061303 // FIXME: Run the scroll steps
13071304
13081305 // FIXME: Evaluate media queries and report changes.
13091306
 1307 Vector<Ref<Document>> documents = collectDocuments(); // The requestAnimationFrame callbacks may change the frame hierarchy of the page
13101308 for (auto& document : documents) {
13111309 DOMHighResTimeStamp timestamp = document->domWindow()->nowTimestamp();
13121310 document->updateAnimationsAndSendEvents(timestamp);
251673

Tools/DumpRenderTree/mac/DumpRenderTree.mm

@@static void updateDisplay()
17271727
17281728void dump()
17291729{
 1730 fprintf(stderr, "DumpRenderTree dump\n");
 1731 WTFReportBacktrace();
17301732#if PLATFORM(IOS_FAMILY)
17311733 WebThreadLock();
17321734#endif
251673

LayoutTests/ChangeLog

 12019-10-30 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 NOBODY (OOPS!).
 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-28 Yusuke Suzuki <ysuzuki@apple.com>
215
316 [JSC] Optimize Promise runtime functions
251673

LayoutTests/fast/shadow-dom/trusted-event-scoped-flags.html

@@function testResizeEvent() {
110110 iframe.style.height = '100px';
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
126128 document.body.appendChild(iframe);
251673