Implement ResizeObserver.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Mar 2019 08:37:46 +0000 (08:37 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Mar 2019 08:37:46 +0000 (08:37 +0000)
commit50122838f07e023d21f9da73cd0233473f64cfda
treea89bdd20dbb580308db3df6dfe1e2b44ac22742c
parent9e84357e7a68c0c4558fcb75d01529ad6a513b8f
Implement ResizeObserver.
https://bugs.webkit.org/show_bug.cgi?id=157743

Patch by Cathie Chen <cathiechen@igalia.com> on 2019-03-29
Reviewed by Simon Fraser.

.:

Add ENABLE_RESIZE_OBSERVER.

* Source/cmake/WebKitFeatures.cmake:

LayoutTests/imported/w3c:

Set ResizeObserverEnabled for test runner and update expectations.

* web-platform-tests/interfaces/ResizeObserver.idl: Added.
* web-platform-tests/resize-observer/eventloop-expected.txt:
* web-platform-tests/resize-observer/eventloop.html:
* web-platform-tests/resize-observer/idlharness.window-expected.txt:
* web-platform-tests/resize-observer/idlharness.window.html:
* web-platform-tests/resize-observer/notify-expected.txt:
* web-platform-tests/resize-observer/notify.html:
* web-platform-tests/resize-observer/observe-expected.txt:
* web-platform-tests/resize-observer/observe.html:
* web-platform-tests/resize-observer/svg-expected.txt:
* web-platform-tests/resize-observer/svg.html:

Source/JavaScriptCore:

Add ENABLE_RESIZE_OBSERVER.

* Configurations/FeatureDefines.xcconfig:

Source/WebCore:

Tests: resize-observer/modify-frametree-in-callback.html
       resize-observer/multi-frames.html
       resize-observer/observe-element-from-other-frame.html
       Imported from WPT by https://bugs.webkit.org/show_bug.cgi?id=193821

The data structure: Document has a ResizeObserver slot. ResizeObserver has a ResizeObservation slot.
ResizeObservation is related to one Element and the last reported size.
On the other hand, Element has a ResizeObservation slot.

At the beginning of willDisplayPage, it will check resize observations for current page if:
1. There is FrameView be layout and there are ResizeObservers in this page.
2. m_resizeObserverTimer has been started by observe() or hasSkippedResizeObservers().
During checkResizeObservations(), we'll gatherDocumentsNeedingResizeObservationCheck() first,
then notifyResizeObservers() for each document. During notifyResizeObservers(), it will gather
the m_activeObservations whose size changed and target element deeper than require depth.
The size changed shallower observations are skipped observations which will be delivered
in the next time. And an ErrorEvent will be reported.
After gathering, deliverResizeObservations create entries and invoke the callbacks with them.

The Element from other document could be observed.

* CMakeLists.txt:
* Configurations/FeatureDefines.xcconfig:
* DerivedSources.make:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:
* dom/Document.cpp:
(WebCore::Document::getParserLocation const):
(WebCore::Document::addResizeObserver):
(WebCore::Document::removeResizeObserver):
(WebCore::Document::hasResizeObservers):
(WebCore::Document::gatherResizeObservations): Gather m_activeObservations at depth and return the shallowest depth.
(WebCore::Document::deliverResizeObservations): Deliver m_activeObservations, generate ResizeObserverEntries, and invoke the m_callbacks.
(WebCore::Document::hasSkippedResizeObservations const): To determine if Document has the size changed but not delivered observations.
(WebCore::Document::setHasSkippedResizeObservations):
(WebCore::Document::scheduleResizeObservations):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::~Element):
(WebCore::Element::disconnectFromResizeObservers):
(WebCore::Element::ensureResizeObserverData):
(WebCore::Element::resizeObserverData):
* dom/Element.h:
* dom/ElementRareData.cpp:
* dom/ElementRareData.h:
(WebCore::ElementRareData::resizeObserverData):
(WebCore::ElementRareData::setResizeObserverData):
(WebCore::ElementRareData::useTypes const):
* page/FrameView.cpp:
(WebCore::FrameView::didLayout):
* page/FrameViewLayoutContext.cpp:
(WebCore::FrameViewLayoutContext::layoutTimerFired): We need to start a ResizeObserver timer here, because for WK1 this might not trigger flushCompositingChanges.
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::willDisplayPage):
(WebCore::Page::hasResizeObservers const):
(WebCore::Page::gatherDocumentsNeedingResizeObservationCheck): Gather the documents with resize observers.
(WebCore::Page::checkResizeObservations): Gather documents then notifyResizeObservers for each document.
(WebCore::Page::scheduleResizeObservations):
(WebCore::Page::notifyResizeObservers): Gather m_activeObservations and deliver them. Report ErrorEvent if it has skipped observations.
* page/Page.h:
(WebCore::Page::setNeedsCheckResizeObservations): Page needs to check ResizeObservations if FrameView layout or m_resizeObserverTimer has been started.
(WebCore::Page::needsCheckResizeObservations const):
* page/PageConsoleClient.cpp:
(WebCore::PageConsoleClient::addMessage):
(WebCore::getParserLocationForConsoleMessage): Deleted.
* page/ResizeObservation.cpp: Added.
(WebCore::ResizeObservation::create):
(WebCore::ResizeObservation::ResizeObservation):
(WebCore::ResizeObservation::~ResizeObservation):
(WebCore::ResizeObservation::updateObservationSize):
(WebCore::ResizeObservation::computeObservedSize const):
(WebCore::ResizeObservation::computeTargetLocation const):
(WebCore::ResizeObservation::computeContentRect const):
(WebCore::ResizeObservation::elementSizeChanged const):
(WebCore::ResizeObservation::targetElementDepth const):
* page/ResizeObservation.h: Copied from Tools/DumpRenderTree/TestOptions.h.
(WebCore::ResizeObservation::target const):
* page/ResizeObserver.cpp: Added.
(WebCore::ResizeObserver::create):
(WebCore::ResizeObserver::ResizeObserver):
(WebCore::ResizeObserver::~ResizeObserver):
(WebCore::ResizeObserver::scheduleObservations):
(WebCore::ResizeObserver::observe):
(WebCore::ResizeObserver::unobserve):
(WebCore::ResizeObserver::disconnect):
(WebCore::ResizeObserver::targetDestroyed):
(WebCore::ResizeObserver::gatherObservations):
(WebCore::ResizeObserver::deliverObservations):
(WebCore::ResizeObserver::removeTarget):
(WebCore::ResizeObserver::removeAllTargets):
(WebCore::ResizeObserver::removeObservation):
(WebCore::ResizeObserver::hasPendingActivity const):
(WebCore::ResizeObserver::activeDOMObjectName const):
(WebCore::ResizeObserver::canSuspendForDocumentSuspension const):
(WebCore::ResizeObserver::stop):
* page/ResizeObserver.h: Added.
(WebCore::ResizeObserver::hasObservations const):
(WebCore::ResizeObserver::hasActiveObservations const):
(WebCore::ResizeObserver::maxElementDepth):
(WebCore::ResizeObserver::hasSkippedObservations const):
(WebCore::ResizeObserver::setHasSkippedObservations):
* page/ResizeObserver.idl: Copied from Tools/DumpRenderTree/TestOptions.h.
* page/ResizeObserverCallback.h: Copied from Tools/DumpRenderTree/TestOptions.h.
* page/ResizeObserverCallback.idl: Copied from Tools/DumpRenderTree/TestOptions.h.
* page/ResizeObserverEntry.h: Copied from Tools/DumpRenderTree/TestOptions.h.
(WebCore::ResizeObserverEntry::create):
(WebCore::ResizeObserverEntry::target const):
(WebCore::ResizeObserverEntry::contentRect const):
(WebCore::ResizeObserverEntry::ResizeObserverEntry):
* page/ResizeObserverEntry.idl: Copied from Tools/DumpRenderTree/TestOptions.h.
* page/Settings.yaml:

Source/WebCore/PAL:

Add ENABLE_RESIZE_OBSERVER.

* Configurations/FeatureDefines.xcconfig:

Source/WebKit:

Add WebPreferences and FeatureDefines for ResizeObserver.

* Configurations/FeatureDefines.xcconfig:
* Shared/WebPreferences.yaml:

Source/WebKitLegacy/mac:

* Configurations/FeatureDefines.xcconfig:
* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
(-[WebPreferences resizeObserverEnabled]):
(-[WebPreferences setResizeObserverEnabled:]):
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):
(-[WebView _flushCompositingChanges]): checkResizeObservations() in the begining.

Source/WebKitLegacy/win:

* Interfaces/IWebPreferencesPrivate.idl:
* WebPreferenceKeysPrivate.h:
* WebPreferences.cpp:
(WebPreferences::initializeDefaultSettings):
(WebPreferences::resizeObserverEnabled):
(WebPreferences::setResizeObserverEnabled):
* WebPreferences.h:
* WebView.cpp:
(WebView::notifyPreferencesChanged):

Tools:

Support resizeObserverEnabled webPreferences.

* DumpRenderTree/TestOptions.cpp:
(TestOptions::TestOptions):
* DumpRenderTree/TestOptions.h:
* DumpRenderTree/mac/DumpRenderTree.mm:
(setWebPreferencesForTestOptions):
* DumpRenderTree/win/DumpRenderTree.cpp:
(enableExperimentalFeatures):
* Scripts/webkitperl/FeatureList.pm:
* TestWebKitAPI/Configurations/FeatureDefines.xcconfig:

LayoutTests:

Add tests for resize-observer of multiframe.

* resize-observer/modify-frametree-in-callback-expected.txt: Added.
* resize-observer/modify-frametree-in-callback.html: Added.
* resize-observer/multi-frames-expected.txt: Added.
* resize-observer/multi-frames.html: Added.
* resize-observer/observe-element-from-other-frame-expected.txt: Added.
* resize-observer/observe-element-from-other-frame.html: Added.
* resize-observer/resources/frame1.html: Added.
* resize-observer/resources/frame2.html: Added.
* resize-observer/resources/frame3.html: Added.
* resize-observer/resources/frame4.html: Added.
* resize-observer/resources/frameset1.html: Added.
* resize-observer/resources/frameset2.html: Added.
* resize-observer/resources/iframe1.html: Added.
* resize-observer/resources/resizeTestHelper.js: Added.
(ResizeTestHelper):
(ResizeTestHelper.prototype.get _currentStep):
(ResizeTestHelper.prototype._nextStep):
(ResizeTestHelper.prototype._handleNotification):
(ResizeTestHelper.prototype._handleTimeout):
(ResizeTestHelper.prototype._done):
(ResizeTestHelper.prototype.start):
(ResizeTestHelper.prototype.get rafCount):
(ResizeTestHelper.prototype._incrementRaf):
(ResizeTestHelper.prototype.startCountingRaf):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243643 268f45cc-cd09-0410-ab3c-d52691b4dbfc
83 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/interfaces/ResizeObserver.idl [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/resize-observer/eventloop-expected.txt
LayoutTests/imported/w3c/web-platform-tests/resize-observer/eventloop.html
LayoutTests/imported/w3c/web-platform-tests/resize-observer/idlharness.window-expected.txt
LayoutTests/imported/w3c/web-platform-tests/resize-observer/idlharness.window.html
LayoutTests/imported/w3c/web-platform-tests/resize-observer/notify-expected.txt
LayoutTests/imported/w3c/web-platform-tests/resize-observer/notify.html
LayoutTests/imported/w3c/web-platform-tests/resize-observer/observe-expected.txt
LayoutTests/imported/w3c/web-platform-tests/resize-observer/observe.html
LayoutTests/imported/w3c/web-platform-tests/resize-observer/svg-expected.txt
LayoutTests/imported/w3c/web-platform-tests/resize-observer/svg.html
LayoutTests/resize-observer/modify-frametree-in-callback-expected.txt [new file with mode: 0644]
LayoutTests/resize-observer/modify-frametree-in-callback.html [new file with mode: 0644]
LayoutTests/resize-observer/multi-frames-expected.txt [new file with mode: 0644]
LayoutTests/resize-observer/multi-frames.html [new file with mode: 0644]
LayoutTests/resize-observer/observe-element-from-other-frame-expected.txt [new file with mode: 0644]
LayoutTests/resize-observer/observe-element-from-other-frame.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/frame1.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/frame2.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/frame3.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/frame4.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/frameset1.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/frameset2.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/iframe1.html [new file with mode: 0644]
LayoutTests/resize-observer/resources/resizeTestHelper.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Configurations/FeatureDefines.xcconfig
Source/WebCore/DerivedSources.make
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/Configurations/FeatureDefines.xcconfig
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/WebCoreBuiltinNames.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementRareData.cpp
Source/WebCore/dom/ElementRareData.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameViewLayoutContext.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/PageConsoleClient.cpp
Source/WebCore/page/ResizeObservation.cpp [new file with mode: 0644]
Source/WebCore/page/ResizeObservation.h [new file with mode: 0644]
Source/WebCore/page/ResizeObserver.cpp [new file with mode: 0644]
Source/WebCore/page/ResizeObserver.h [new file with mode: 0644]
Source/WebCore/page/ResizeObserver.idl [new file with mode: 0644]
Source/WebCore/page/ResizeObserverCallback.h [new file with mode: 0644]
Source/WebCore/page/ResizeObserverCallback.idl [new file with mode: 0644]
Source/WebCore/page/ResizeObserverEntry.h [new file with mode: 0644]
Source/WebCore/page/ResizeObserverEntry.idl [new file with mode: 0644]
Source/WebCore/page/Settings.yaml
Source/WebKit/ChangeLog
Source/WebKit/Configurations/FeatureDefines.xcconfig
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/Configurations/FeatureDefines.xcconfig
Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h
Source/WebKitLegacy/mac/WebView/WebView.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl
Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h
Source/WebKitLegacy/win/WebPreferences.cpp
Source/WebKitLegacy/win/WebPreferences.h
Source/WebKitLegacy/win/WebView.cpp
Source/cmake/WebKitFeatures.cmake
Tools/ChangeLog
Tools/DumpRenderTree/TestOptions.cpp
Tools/DumpRenderTree/TestOptions.h
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/DumpRenderTree/win/DumpRenderTree.cpp
Tools/Scripts/webkitperl/FeatureList.pm
Tools/TestWebKitAPI/Configurations/FeatureDefines.xcconfig