From b6b868b1bda0d82b85647f3e9ff2ab1f788eeb46 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 16 Sep 2020 19:39:33 +0000 Subject: Issue #1643 - Part 4: Hook up all the plumbing. --- dom/base/ResizeObserver.cpp | 4 ++-- dom/base/nsDocument.cpp | 26 ++++++++++++++++++++++++++ dom/base/nsDocument.h | 8 ++++++++ dom/base/nsIDocument.h | 5 +++++ 4 files changed, 41 insertions(+), 2 deletions(-) (limited to 'dom/base') diff --git a/dom/base/ResizeObserver.cpp b/dom/base/ResizeObserver.cpp index aefcddd9d..37d940c2b 100644 --- a/dom/base/ResizeObserver.cpp +++ b/dom/base/ResizeObserver.cpp @@ -61,7 +61,7 @@ ResizeObserver::Constructor(const GlobalObject& aGlobal, } RefPtr observer = new ResizeObserver(window.forget(), aCb); - // TODO: Add the new ResizeObserver to document here in the later patch. + document->AddResizeObserver(observer); return observer.forget(); } @@ -86,7 +86,7 @@ ResizeObserver::Observe(Element* aTarget, // Per the spec, we need to trigger notification in event loop that // contains ResizeObserver observe call even when resize/reflow does // not happen. - // TODO: Implement the notification scheduling in the later patch. + aTarget->OwnerDoc()->ScheduleResizeObserversNotification(); } } diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 76490e6b4..5bf89f26a 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1681,6 +1681,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) cb.NoteXPCOMChild(mql); } } + + if (tmp->mResizeObserverController) { + tmp->mResizeObserverController->Traverse(cb); + } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_CLASS(nsDocument) @@ -1786,6 +1790,10 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) } tmp->mInUnlinkOrDeletion = false; + + if (tmp->mResizeObserverController) { + tmp->mResizeObserverController->Unlink(); + } NS_IMPL_CYCLE_COLLECTION_UNLINK_END nsresult @@ -11823,6 +11831,24 @@ nsDocument::QuerySelectorAll(const nsAString& aSelector, nsIDOMNodeList **aRetur return nsINode::QuerySelectorAll(aSelector, aReturn); } +void +nsDocument::AddResizeObserver(ResizeObserver* aResizeObserver) +{ + if (!mResizeObserverController) { + mResizeObserverController = MakeUnique(this); + } + + mResizeObserverController->AddResizeObserver(aResizeObserver); +} + +void +nsDocument::ScheduleResizeObserversNotification() const +{ + if (mResizeObserverController) { + mResizeObserverController->ScheduleNotification(); + } +} + already_AddRefed nsIDocument::Constructor(const GlobalObject& aGlobal, ErrorResult& rv) diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 502ba0f13..017879b1f 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -60,6 +60,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/PendingAnimationTracker.h" #include "mozilla/dom/DOMImplementation.h" +#include "mozilla/dom/ResizeObserverController.h" #include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/StyleSheetList.h" #include "nsDataHashtable.h" @@ -1024,6 +1025,10 @@ public: virtual void UnblockDOMContentLoaded() override; + void AddResizeObserver(mozilla::dom::ResizeObserver* aResizeObserver) override; + + void ScheduleResizeObserversNotification() const override; + protected: friend class nsNodeUtils; friend class nsDocumentOnStack; @@ -1160,6 +1165,9 @@ protected: nsTArray mCharSetObservers; + mozilla::UniquePtr + mResizeObserverController; + PLDHashTable *mSubDocuments; // Array of owning references to all children diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 21cd0aaf7..5684490aa 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -153,6 +153,7 @@ class ProcessingInstruction; class Promise; class Selection; class ScriptLoader; +class ResizeObserver; class StyleSheetList; class SVGDocument; class SVGSVGElement; @@ -2853,6 +2854,10 @@ public: bool ModuleScriptsEnabled(); + virtual void AddResizeObserver(mozilla::dom::ResizeObserver* aResizeObserver) = 0; + + virtual void ScheduleResizeObserversNotification() const = 0; + protected: bool GetUseCounter(mozilla::UseCounter aUseCounter) { -- cgit v1.2.3