summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-09-16 19:39:33 +0000
committerMoonchild <moonchild@palemoon.org>2020-09-21 11:04:31 +0000
commit075fa012868017c9cb49f1b92960bf02f4bf27ca (patch)
treebce03e7900f790b896f889c24a51814a4ade828d
parent32e0d2ca2369d4ee0658affde0e96bdf0f84455a (diff)
downloadUXP-075fa012868017c9cb49f1b92960bf02f4bf27ca.tar
UXP-075fa012868017c9cb49f1b92960bf02f4bf27ca.tar.gz
UXP-075fa012868017c9cb49f1b92960bf02f4bf27ca.tar.lz
UXP-075fa012868017c9cb49f1b92960bf02f4bf27ca.tar.xz
UXP-075fa012868017c9cb49f1b92960bf02f4bf27ca.zip
Issue #1643 - Part 4: Hook up all the plumbing.
-rw-r--r--dom/base/ResizeObserver.cpp4
-rw-r--r--dom/base/nsDocument.cpp26
-rw-r--r--dom/base/nsDocument.h8
-rw-r--r--dom/base/nsIDocument.h5
-rw-r--r--layout/base/nsPresShell.cpp5
5 files changed, 46 insertions, 2 deletions
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<ResizeObserver> 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 de793bfab..48d23e325 100644
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1727,6 +1727,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)
@@ -1832,6 +1836,10 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
}
tmp->mInUnlinkOrDeletion = false;
+
+ if (tmp->mResizeObserverController) {
+ tmp->mResizeObserverController->Unlink();
+ }
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
nsresult
@@ -12105,6 +12113,24 @@ nsDocument::QuerySelectorAll(const nsAString& aSelector, nsIDOMNodeList **aRetur
return nsINode::QuerySelectorAll(aSelector, aReturn);
}
+void
+nsDocument::AddResizeObserver(ResizeObserver* aResizeObserver)
+{
+ if (!mResizeObserverController) {
+ mResizeObserverController = MakeUnique<ResizeObserverController>(this);
+ }
+
+ mResizeObserverController->AddResizeObserver(aResizeObserver);
+}
+
+void
+nsDocument::ScheduleResizeObserversNotification() const
+{
+ if (mResizeObserverController) {
+ mResizeObserverController->ScheduleNotification();
+ }
+}
+
already_AddRefed<nsIDocument>
nsIDocument::Constructor(const GlobalObject& aGlobal,
ErrorResult& rv)
diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h
index a319ad13e..220f4152d 100644
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -59,6 +59,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"
@@ -1206,6 +1207,10 @@ public:
virtual void UnblockDOMContentLoaded() override;
+ void AddResizeObserver(mozilla::dom::ResizeObserver* aResizeObserver) override;
+
+ void ScheduleResizeObserversNotification() const override;
+
protected:
friend class nsNodeUtils;
friend class nsDocumentOnStack;
@@ -1342,6 +1347,9 @@ protected:
nsTArray<nsIObserver*> mCharSetObservers;
+ mozilla::UniquePtr<mozilla::dom::ResizeObserverController>
+ mResizeObserverController;
+
PLDHashTable *mSubDocuments;
// Array of owning references to all children
diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h
index 29afa5439..760048501 100644
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -152,6 +152,7 @@ class ProcessingInstruction;
class Promise;
class Selection;
class ScriptLoader;
+class ResizeObserver;
class StyleSheetList;
class SVGDocument;
class SVGSVGElement;
@@ -2874,6 +2875,10 @@ public:
bool ModuleScriptsEnabled();
+ virtual void AddResizeObserver(mozilla::dom::ResizeObserver* aResizeObserver) = 0;
+
+ virtual void ScheduleResizeObserversNotification() const = 0;
+
protected:
bool GetUseCounter(mozilla::UseCounter aUseCounter)
{
diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp
index 63f512af4..0544a69a4 100644
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -9090,6 +9090,11 @@ PresShell::DidDoReflow(bool aInterruptible)
docShell->NotifyReflowObservers(aInterruptible, mLastReflowStart, now);
}
+ // Notify resize observers on reflow.
+ if (!mPresContext->HasPendingInterrupt()) {
+ mDocument->ScheduleResizeObserversNotification();
+ }
+
if (sSynthMouseMove) {
SynthesizeMouseMove(false);
}