WebKit Bugzilla
Attachment 359876 Details for
Bug 157743
: Implement ResizeObserver
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Data structure and management
ro-upload-1.diff (text/plain), 31.94 KB, created by
cathiechen
on 2019-01-23 06:55:54 PST
(
hide
)
Description:
Data structure and management
Filename:
MIME Type:
Creator:
cathiechen
Created:
2019-01-23 06:55:54 PST
Size:
31.94 KB
patch
obsolete
>diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt >index 0de5943666..48eef54b12 100644 >--- a/Source/WebCore/CMakeLists.txt >+++ b/Source/WebCore/CMakeLists.txt >@@ -924,6 +924,9 @@ set(WebCore_NON_SVG_IDL_FILES > page/PerformanceServerTiming.idl > page/PerformanceTiming.idl > page/RemoteDOMWindow.idl >+ page/ResizeObserver.idl >+ page/ResizeObserverCallback.idl >+ page/ResizeObserverEntry.idl > page/Screen.idl > page/ScrollIntoViewOptions.idl > page/ScrollLogicalPosition.idl >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index d2adb0e540..9ec0bfd74b 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -1526,6 +1526,8 @@ page/ProcessWarming.cpp > page/Quirks.cpp > page/RemoteDOMWindow.cpp > page/RemoteFrame.cpp >+page/ResizeObservation.cpp >+page/ResizeObserver.cpp > page/ResourceUsageOverlay.cpp > page/ResourceUsageThread.cpp > page/RuntimeEnabledFeatures.cpp >diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp >index 5db71f516f..a54605d827 100644 >--- a/Source/WebCore/dom/Document.cpp >+++ b/Source/WebCore/dom/Document.cpp >@@ -161,6 +161,7 @@ > #include "RenderView.h" > #include "RenderWidget.h" > #include "RequestAnimationFrameCallback.h" >+#include "ResizeObserver.h" > #include "ResourceLoadObserver.h" > #include "RuntimeApplicationChecks.h" > #include "RuntimeEnabledFeatures.h" >@@ -8035,6 +8036,19 @@ void Document::notifyIntersectionObserversTimerFired() > } > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+void Document::addResizeObserver(ResizeObserver& observer) >+{ >+ ASSERT(m_resizeObservers.find(&observer) == notFound); >+ m_resizeObservers.append(makeWeakPtr(&observer)); >+} >+ >+void Document::removeResizeObserver(ResizeObserver& observer) >+{ >+ m_resizeObservers.removeFirst(&observer); >+} >+#endif >+ > const AtomicString& Document::dir() const > { > auto* documentElement = this->documentElement(); >diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h >index bb5c1c0466..c2a237f1e8 100644 >--- a/Source/WebCore/dom/Document.h >+++ b/Source/WebCore/dom/Document.h >@@ -246,6 +246,10 @@ class HTMLAttachmentElement; > class IntersectionObserver; > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+class ResizeObserver; >+#endif >+ > namespace Style { > class Scope; > }; >@@ -1415,6 +1419,11 @@ public: > void updateIntersectionObservations(); > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+ void addResizeObserver(ResizeObserver&); >+ void removeResizeObserver(ResizeObserver&); >+#endif >+ > #if ENABLE(MEDIA_STREAM) > void setHasCaptureMediaStreamTrack() { m_hasHadCaptureMediaStreamTrack = true; } > bool hasHadCaptureMediaStreamTrack() const { return m_hasHadCaptureMediaStreamTrack; } >@@ -1861,6 +1870,10 @@ private: > Timer m_intersectionObserversNotifyTimer; > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+ Vector<WeakPtr<ResizeObserver>> m_resizeObservers; >+#endif >+ > Timer m_loadEventDelayTimer; > > ViewportArguments m_viewportArguments; >diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp >index b2f13d022c..af51d09d1b 100644 >--- a/Source/WebCore/dom/Element.cpp >+++ b/Source/WebCore/dom/Element.cpp >@@ -194,6 +194,10 @@ Element::~Element() > disconnectFromIntersectionObservers(); > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+ disconnectFromResizeObservers(); >+#endif >+ > removeShadowRoot(); > > if (hasSyntheticAttrChildNodes()) >@@ -1835,6 +1839,17 @@ void Element::didMoveToNewDocument(Document& oldDocument, Document& newDocument) > } > } > #endif >+ >+#if ENABLE(RESIZE_OBSERVER) >+ if (auto* observerData = resizeObserverData()) { >+ for (const auto& observer : observerData->observers) { >+ if (observer->hasObservations()) { >+ oldDocument.removeResizeObserver(*observer); >+ newDocument.addResizeObserver(*observer); >+ } >+ } >+ } >+#endif > } > > bool Element::hasAttributes() const >@@ -3468,6 +3483,32 @@ IntersectionObserverData* Element::intersectionObserverData() > } > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+void Element::disconnectFromResizeObservers() >+{ >+ auto* observerData = resizeObserverData(); >+ if (!observerData) >+ return; >+ >+ for (const auto& observer : observerData->observers) >+ observer->targetDestroyed(*this); >+ observerData->observers.clear(); >+} >+ >+ResizeObserverData& Element::ensureResizeObserverData() >+{ >+ auto& rareData = ensureElementRareData(); >+ if (!rareData.resizeObserverData()) >+ rareData.setResizeObserverData(std::make_unique<ResizeObserverData>()); >+ return *rareData.resizeObserverData(); >+} >+ >+ResizeObserverData* Element::resizeObserverData() >+{ >+ return hasRareData() ? elementRareData()->resizeObserverData() : nullptr; >+} >+#endif >+ > SpellcheckAttributeState Element::spellcheckAttributeState() const > { > const AtomicString& value = attributeWithoutSynchronization(HTMLNames::spellcheckAttr); >diff --git a/Source/WebCore/dom/Element.h b/Source/WebCore/dom/Element.h >index c5eb6cb8c4..d080dd290c 100644 >--- a/Source/WebCore/dom/Element.h >+++ b/Source/WebCore/dom/Element.h >@@ -63,6 +63,10 @@ struct ScrollIntoViewOptions; > struct IntersectionObserverData; > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+struct ResizeObserverData; >+#endif >+ > enum SpellcheckAttributeState { > SpellcheckAttributeTrue, > SpellcheckAttributeFalse, >@@ -583,6 +587,11 @@ public: > IntersectionObserverData* intersectionObserverData(); > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+ ResizeObserverData& ensureResizeObserverData(); >+ ResizeObserverData* resizeObserverData(); >+#endif >+ > Element* findAnchorElementForLink(String& outAnchorName); > > ExceptionOr<Ref<WebAnimation>> animate(JSC::ExecState&, JSC::Strong<JSC::JSObject>&&, Optional<Variant<double, KeyframeAnimationOptions>>&&); >@@ -669,6 +678,10 @@ private: > void disconnectFromIntersectionObservers(); > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+ void disconnectFromResizeObservers(); >+#endif >+ > // The cloneNode function is private so that non-virtual cloneElementWith/WithoutChildren are used instead. > Ref<Node> cloneNodeInternal(Document&, CloningOperation) override; > virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&); >diff --git a/Source/WebCore/dom/ElementRareData.cpp b/Source/WebCore/dom/ElementRareData.cpp >index 4dd60eb84f..140b898900 100644 >--- a/Source/WebCore/dom/ElementRareData.cpp >+++ b/Source/WebCore/dom/ElementRareData.cpp >@@ -50,6 +50,9 @@ struct SameSizeAsElementRareData : NodeRareData { > #if ENABLE(CSS_TYPED_OM) > void* typedOMData; > #endif >+#if ENABLE(RESIZE_OBSERVER) >+ void* resizeObserverData; >+#endif > > }; > >diff --git a/Source/WebCore/dom/ElementRareData.h b/Source/WebCore/dom/ElementRareData.h >index fe80e331d5..8e106fb8a5 100644 >--- a/Source/WebCore/dom/ElementRareData.h >+++ b/Source/WebCore/dom/ElementRareData.h >@@ -29,6 +29,7 @@ > #include "NodeRareData.h" > #include "PseudoElement.h" > #include "RenderElement.h" >+#include "ResizeObserver.h" > #include "ShadowRoot.h" > #include "StylePropertyMap.h" > >@@ -128,6 +129,11 @@ public: > void setIntersectionObserverData(std::unique_ptr<IntersectionObserverData>&& data) { m_intersectionObserverData = WTFMove(data); } > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+ ResizeObserverData* resizeObserverData() { return m_resizeObserverData.get(); } >+ void setResizeObserverData(std::unique_ptr<ResizeObserverData>&& data) { m_resizeObserverData = WTFMove(data); } >+#endif >+ > #if ENABLE(CSS_TYPED_OM) > StylePropertyMap* attributeStyleMap() { return m_attributeStyleMap.get(); } > void setAttributeStyleMap(Ref<StylePropertyMap>&& map) { m_attributeStyleMap = WTFMove(map); } >@@ -162,6 +168,8 @@ public: > result.add(UseType::AttributeMap); > if (m_intersectionObserverData) > result.add(UseType::InteractionObserver); >+ if (m_resizeObserverData) >+ result.add(UseType::ResizeObserver); > if (m_beforePseudoElement || m_afterPseudoElement) > result.add(UseType::PseudoElements); > return result; >@@ -205,6 +213,10 @@ private: > std::unique_ptr<IntersectionObserverData> m_intersectionObserverData; > #endif > >+#if ENABLE(RESIZE_OBSERVER) >+ std::unique_ptr<ResizeObserverData> m_resizeObserverData; >+#endif >+ > RefPtr<PseudoElement> m_beforePseudoElement; > RefPtr<PseudoElement> m_afterPseudoElement; > >diff --git a/Source/WebCore/page/ResizeObservation.cpp b/Source/WebCore/page/ResizeObservation.cpp >new file mode 100644 >index 0000000000..1aaae5b746 >--- /dev/null >+++ b/Source/WebCore/page/ResizeObservation.cpp >@@ -0,0 +1,50 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+ >+#if ENABLE(RESIZE_OBSERVER) >+#include "ResizeObservation.h" >+ >+namespace WebCore { >+ >+ResizeObservation::ResizeObservation(Element* element) >+ : m_target(element) >+ , m_observationSize(0, 0) >+{ >+} >+ >+ResizeObservation::~ResizeObservation() >+{ >+} >+ >+void ResizeObservation::setObservationSize(const LayoutSize& size) >+{ >+ m_observationSize = size; >+} >+ >+} // namespace WebCore >+ >+#endif // ENABLE(RESIZE_OBSERVER) >diff --git a/Source/WebCore/page/ResizeObservation.h b/Source/WebCore/page/ResizeObservation.h >new file mode 100644 >index 0000000000..522f4bb38b >--- /dev/null >+++ b/Source/WebCore/page/ResizeObservation.h >@@ -0,0 +1,55 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(RESIZE_OBSERVER) >+#include "LayoutSize.h" >+ >+#include <wtf/RefCounted.h> >+ >+namespace WebCore { >+ >+class Element; >+ >+class ResizeObservation : public RefCounted<ResizeObservation> { >+ WTF_MAKE_FAST_ALLOCATED; >+public: >+ ResizeObservation(Element* target); >+ ~ResizeObservation(); >+ void setObservationSize(const LayoutSize&); >+ Element* target() { return m_target; } >+ LayoutSize observationSize() { return m_observationSize; } >+ >+private: >+ >+ Element* m_target; >+ // target size in last observation >+ LayoutSize m_observationSize; >+}; >+ >+} // namespace WebCore >+ >+#endif // ENABLE(RESIZE_OBSERVER) >diff --git a/Source/WebCore/page/ResizeObserver.cpp b/Source/WebCore/page/ResizeObserver.cpp >new file mode 100644 >index 0000000000..799be05d3c >--- /dev/null >+++ b/Source/WebCore/page/ResizeObserver.cpp >@@ -0,0 +1,146 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+ >+#if ENABLE(RESIZE_OBSERVER) >+#include "ResizeObserver.h" >+ >+#include "Element.h" >+ >+namespace WebCore { >+Ref<ResizeObserver> ResizeObserver::create(Document& document, Ref<ResizeObserverCallback>&& callback) >+{ >+ return WTF::adoptRef(*new ResizeObserver(document, WTFMove(callback))); >+} >+ >+ResizeObserver::ResizeObserver(Document& document, Ref<ResizeObserverCallback>&& callback) >+ : ActiveDOMObject(downcast<Document>(callback->scriptExecutionContext())) >+ , m_callback(WTFMove(callback)) >+{ >+ m_implicitRootDocument = makeWeakPtr(document); >+ suspendIfNeeded(); >+} >+ >+ResizeObserver::~ResizeObserver() >+{ >+ disconnect(); >+} >+ >+void ResizeObserver::observe(Element& target) >+{ >+ if (!m_callback) >+ return; >+ >+ for (auto observation : m_observations) { >+ if (observation->target() == &target) >+ return; >+ } >+ >+ auto& observerData = target.ensureResizeObserverData(); >+ observerData.observers.append(makeWeakPtr(this)); >+ >+ m_observations.append(WTF::adoptRef(new ResizeObservation(&target))); >+ >+ m_implicitRootDocument->addResizeObserver(*this); >+} >+ >+void ResizeObserver::unobserve(Element& target) >+{ >+ if (!removeTarget(target)) >+ return; >+ >+ removeObservation(target); >+} >+ >+void ResizeObserver::disconnect() >+{ >+ removeAllTargets(); >+ m_implicitRootDocument->removeResizeObserver(*this); >+} >+ >+bool ResizeObserver::hasPendingActivity() const >+{ >+ // TODO: cc. Need add the conditions when ResizeObserver is complete. >+ return hasObservations() && m_implicitRootDocument; >+} >+ >+const char* ResizeObserver::activeDOMObjectName() const >+{ >+ return "ResizeObserver"; >+} >+ >+bool ResizeObserver::canSuspendForDocumentSuspension() const >+{ >+ return true; >+} >+ >+void ResizeObserver::stop() >+{ >+ disconnect(); >+ m_callback = nullptr; >+} >+ >+void ResizeObserver::removeAllTargets() >+{ >+ for (auto observation : m_observations) { >+ bool removed = removeTarget(*observation->target()); >+ ASSERT_UNUSED(removed, removed); >+ } >+ m_observations.clear(); >+} >+ >+bool ResizeObserver::removeTarget(Element& target) >+{ >+ auto* observerData = target.resizeObserverData(); >+ if (!observerData) >+ return false; >+ >+ auto& observers = observerData->observers; >+ return observers.removeFirst(this); >+} >+ >+void ResizeObserver::targetDestroyed(Element& target) >+{ >+ removeObservation(target); >+ if (!hasObservations()) >+ m_implicitRootDocument->removeResizeObserver(*this); >+} >+ >+bool ResizeObserver::removeObservation(Element& target) >+{ >+ for (size_t position = 0; position < m_observations.size(); position++) { >+ auto observation = m_observations[position]; >+ if (observation->target() == &target) { >+ m_observations.remove(position); >+ return true; >+ } >+ } >+ return false; >+} >+ >+} // namespace WebCore >+ >+#endif // ENABLE(RESIZE_OBSERVER) >diff --git a/Source/WebCore/page/ResizeObserver.h b/Source/WebCore/page/ResizeObserver.h >new file mode 100644 >index 0000000000..40a03dcefc >--- /dev/null >+++ b/Source/WebCore/page/ResizeObserver.h >@@ -0,0 +1,80 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(RESIZE_OBSERVER) >+ >+#include "ActiveDOMObject.h" >+#include "ResizeObservation.h" >+#include "ResizeObserverCallback.h" >+#include <wtf/RefCounted.h> >+#include <wtf/WeakPtr.h> >+ >+namespace WebCore { >+ >+class Document; >+class Element; >+ >+struct ResizeObserverData { >+ Vector<WeakPtr<ResizeObserver>> observers; >+}; >+ >+class ResizeObserver : public RefCounted<ResizeObserver>, public ActiveDOMObject, public CanMakeWeakPtr<ResizeObserver> { >+ WTF_MAKE_FAST_ALLOCATED; >+public: >+ static Ref<ResizeObserver> create(Document&, Ref<ResizeObserverCallback>&&); >+ ~ResizeObserver(); >+ >+ const Vector<RefPtr<ResizeObservation>> observations() const { return m_observations; } >+ bool hasObservations() const { return m_observations.size(); } >+ >+ void observe(Element&); >+ void unobserve(Element&); >+ void disconnect(); >+ >+ void targetDestroyed(Element&); >+ >+ // ActiveDOMObject. >+ bool hasPendingActivity() const override; >+ const char* activeDOMObjectName() const override; >+ bool canSuspendForDocumentSuspension() const override; >+ void stop() override; >+ >+private: >+ ResizeObserver(Document&, Ref<ResizeObserverCallback>&&); >+ >+ void removeAllTargets(); >+ bool removeTarget(Element&); >+ bool removeObservation(Element&); >+ >+ WeakPtr<Document> m_implicitRootDocument; >+ RefPtr<ResizeObserverCallback> m_callback; >+ Vector<RefPtr<ResizeObservation>> m_observations; >+}; >+ >+} // namespace WebCore >+ >+#endif // ENABLE(RESIZE_OBSERVER) >diff --git a/Source/WebCore/page/ResizeObserver.idl b/Source/WebCore/page/ResizeObserver.idl >new file mode 100644 >index 0000000000..bf185da9eb >--- /dev/null >+++ b/Source/WebCore/page/ResizeObserver.idl >@@ -0,0 +1,37 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+// https://wicg.github.io/ResizeObserver/ >+ >+[ >+ ActiveDOMObject, >+ Conditional=RESIZE_OBSERVER, >+ Constructor(ResizeObserverCallback callback), >+ ConstructorCallWith=Document >+] interface ResizeObserver { >+ void observe(Element target); >+ void unobserve(Element target); >+ void disconnect(); >+}; >diff --git a/Source/WebCore/page/ResizeObserverCallback.h b/Source/WebCore/page/ResizeObserverCallback.h >new file mode 100644 >index 0000000000..d91f9f7f05 >--- /dev/null >+++ b/Source/WebCore/page/ResizeObserverCallback.h >@@ -0,0 +1,47 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(RESIZE_OBSERVER) >+ >+#include "ActiveDOMCallback.h" >+#include "CallbackResult.h" >+#include <wtf/RefCounted.h> >+ >+namespace WebCore { >+ >+class ResizeObserver; >+class ResizeObserverEntry; >+ >+class ResizeObserverCallback : public RefCounted<ResizeObserverCallback>, public ActiveDOMCallback { >+public: >+ using ActiveDOMCallback::ActiveDOMCallback; >+ virtual CallbackResult<void> handleEvent(const Vector<Ref<ResizeObserverEntry>>&, ResizeObserver&) = 0; >+}; >+ >+} // namespace WebCore >+ >+#endif // ENABLE(RESIZE_OBSERVER) >diff --git a/Source/WebCore/page/ResizeObserverCallback.idl b/Source/WebCore/page/ResizeObserverCallback.idl >new file mode 100644 >index 0000000000..9a438cde71 >--- /dev/null >+++ b/Source/WebCore/page/ResizeObserverCallback.idl >@@ -0,0 +1,30 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+// https://wicg.github.io/ResizeObserver/ >+ >+[ >+ Conditional=RESIZE_OBSERVER >+] callback ResizeObserverCallback = void (sequence<ResizeObserverEntry> entries, ResizeObserver observer); >diff --git a/Source/WebCore/page/ResizeObserverEntry.h b/Source/WebCore/page/ResizeObserverEntry.h >new file mode 100644 >index 0000000000..0c46e3963f >--- /dev/null >+++ b/Source/WebCore/page/ResizeObserverEntry.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(RESIZE_OBSERVER) >+ >+#include "DOMRectReadOnly.h" >+#include "Element.h" >+#include "FloatRect.h" >+#include <wtf/RefCounted.h> >+ >+namespace WebCore { >+ >+class Element; >+ >+class ResizeObserverEntry : public RefCounted<ResizeObserverEntry> { >+ WTF_MAKE_FAST_ALLOCATED; >+public: >+ static Ref<ResizeObserverEntry> create(Element* target, const FloatRect& contentRect) >+ { >+ return WTF::adoptRef(*new ResizeObserverEntry(target, contentRect)); >+ } >+ >+ Element* target() { return m_target.get(); } >+ DOMRectReadOnly* contentRect() { return m_contentRect.get(); } >+ >+private: >+ ResizeObserverEntry(Element* target, const FloatRect& contentRect) >+ : m_target(target) >+ { >+ m_contentRect = DOMRectReadOnly::create(contentRect.x(), contentRect.y(), contentRect.width(), contentRect.height()); >+ } >+ >+ RefPtr<Element> m_target; >+ RefPtr<DOMRectReadOnly> m_contentRect; >+}; >+ >+} // namespace WebCore >+#endif // ENABLE(RESIZE_OBSERVER) >diff --git a/Source/WebCore/page/ResizeObserverEntry.idl b/Source/WebCore/page/ResizeObserverEntry.idl >new file mode 100644 >index 0000000000..0093f81813 >--- /dev/null >+++ b/Source/WebCore/page/ResizeObserverEntry.idl >@@ -0,0 +1,34 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+// https://wicg.github.io/ResizeObserver/ >+ >+[ >+ Conditional=RESIZE_OBSERVER, >+ ImplementationLacksVTable >+] interface ResizeObserverEntry { >+ readonly attribute Element target; >+ readonly attribute DOMRectReadOnly contentRect; >+}; >\ No newline at end of file >diff --git a/Source/WebCore/page/Settings.yaml b/Source/WebCore/page/Settings.yaml >index 9b9a6e87c6..4590d2f242 100644 >--- a/Source/WebCore/page/Settings.yaml >+++ b/Source/WebCore/page/Settings.yaml >@@ -788,3 +788,6 @@ videoQualityIncludesDisplayCompositingEnabled: > > editableImagesEnabled: > initial: false >+ >+ResizeObserverEnabled: >+ initial: false >diff --git a/Source/WebKit/Shared/WebPreferences.yaml b/Source/WebKit/Shared/WebPreferences.yaml >index c6145b1255..02287ba068 100644 >--- a/Source/WebKit/Shared/WebPreferences.yaml >+++ b/Source/WebKit/Shared/WebPreferences.yaml >@@ -1543,3 +1543,11 @@ CSSLogicalEnabled: > humanReadableDescription: "Enable CSS Logical Properties and Values" > webcoreBinding: RuntimeEnabledFeatures > category: internal >+ >+ResizeObserverEnabled: >+ type: bool >+ defaultValue: true >+ humanReadableName: "Resize Observer" >+ humanReadableDescription: "Enable Resize Observer support" >+ category: experimental >+ condition: ENABLE(RESIZE_OBSERVER) >diff --git a/Source/cmake/WebKitFeatures.cmake b/Source/cmake/WebKitFeatures.cmake >index 041ab32d2b..77daba09ad 100644 >--- a/Source/cmake/WebKitFeatures.cmake >+++ b/Source/cmake/WebKitFeatures.cmake >@@ -177,6 +177,7 @@ macro(WEBKIT_OPTION_BEGIN) > WEBKIT_OPTION_DEFINE(ENABLE_PUBLIC_SUFFIX_LIST "Toggle public suffix list support" PRIVATE ON) > WEBKIT_OPTION_DEFINE(ENABLE_QUOTA "Toggle Quota support" PRIVATE OFF) > WEBKIT_OPTION_DEFINE(ENABLE_REMOTE_INSPECTOR "Toggle remote inspector support" PRIVATE ON) >+ WEBKIT_OPTION_DEFINE(ENABLE_RESIZE_OBSERVER "Enable Resize Observer support" PRIVATE ON) > WEBKIT_OPTION_DEFINE(ENABLE_RESOLUTION_MEDIA_QUERY "Toggle resolution media query support" PRIVATE OFF) > WEBKIT_OPTION_DEFINE(ENABLE_RESOURCE_LOAD_STATISTICS "Toggle resource load statistics support" PRIVATE OFF) > WEBKIT_OPTION_DEFINE(ENABLE_RESOURCE_USAGE "Toggle resource usage support" PRIVATE OFF)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 157743
:
359876
|
360287
|
360290
|
360291
|
361796
|
361805
|
361897
|
361903
|
361999
|
362000
|
362001
|
363087
|
363219
|
363505
|
363506
|
365042
|
365051
|
365064
|
365112
|
365120
|
365126
|
365128
|
365133
|
365144
|
365145
|
365146
|
365148
|
365149
|
365171
|
365187
|
365191
|
365209
|
365285
|
365301
|
365315
|
365319
|
365349
|
365479
|
365487
|
365493
|
365494
|
365510
|
365518
|
365522
|
365702
|
365711
|
365717
|
365720
|
365737
|
365953
|
365954
|
365969
|
365972
|
366015
|
366064
|
366073