summaryrefslogtreecommitdiffstats
path: root/dom/base/DOMIntersectionObserver.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-06-27 16:00:53 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-06-27 16:00:53 +0200
commit8b71cda1956ab640ad76bea36e7971476aa78bcf (patch)
treec369019586632332b2627225eb7f6adab1e285d8 /dom/base/DOMIntersectionObserver.cpp
parent9168a0fc95f523c7c852ca95969edb39069f4a03 (diff)
downloadUXP-8b71cda1956ab640ad76bea36e7971476aa78bcf.tar
UXP-8b71cda1956ab640ad76bea36e7971476aa78bcf.tar.gz
UXP-8b71cda1956ab640ad76bea36e7971476aa78bcf.tar.lz
UXP-8b71cda1956ab640ad76bea36e7971476aa78bcf.tar.xz
UXP-8b71cda1956ab640ad76bea36e7971476aa78bcf.zip
Stabilize and align Intersection Observers
- Fixes several crashes - Aligns the feature with the W3C WD spec Tag #249
Diffstat (limited to 'dom/base/DOMIntersectionObserver.cpp')
-rw-r--r--dom/base/DOMIntersectionObserver.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp
index 169c3fe7a..e39abf1a6 100644
--- a/dom/base/DOMIntersectionObserver.cpp
+++ b/dom/base/DOMIntersectionObserver.cpp
@@ -47,6 +47,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMIntersectionObserver)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallback)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRoot)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mQueuedEntries)
+ tmp->Disconnect();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMIntersectionObserver)
@@ -184,9 +185,10 @@ DOMIntersectionObserver::Connect()
if (mConnected) {
return;
}
+ mConnected = true;
+
nsIDocument* document = mOwner->GetExtantDoc();
document->AddIntersectionObserver(this);
- mConnected = true;
}
void
@@ -202,7 +204,9 @@ DOMIntersectionObserver::Disconnect()
mObservationTargets.Clear();
if (mOwner) {
nsIDocument* document = mOwner->GetExtantDoc();
- document->RemoveIntersectionObserver(this);
+ if (document) {
+ document->RemoveIntersectionObserver(this);
+ }
}
mConnected = false;
}
@@ -248,6 +252,12 @@ EdgeInclusiveIntersection(const nsRect& aRect, const nsRect& aOtherRect)
return Some(nsRect(left, top, right - left, bottom - top));
}
+enum class BrowsingContextInfo {
+ SimilarOriginBrowsingContext,
+ DifferentOriginBrowsingContext,
+ UnknownBrowsingContext
+};
+
void
DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time)
{
@@ -359,11 +369,22 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time
}
}
- nsRect rootIntersectionRect = rootRect;
- bool isInSimilarOriginBrowsingContext = rootFrame && targetFrame &&
- CheckSimilarOrigin(root, target);
+ nsRect rootIntersectionRect;
+ BrowsingContextInfo isInSimilarOriginBrowsingContext =
+ BrowsingContextInfo::UnknownBrowsingContext;
+
+ if (rootFrame && targetFrame) {
+ rootIntersectionRect = rootRect;
+ }
+
+ if (root && target) {
+ isInSimilarOriginBrowsingContext = CheckSimilarOrigin(root, target) ?
+ BrowsingContextInfo::SimilarOriginBrowsingContext :
+ BrowsingContextInfo::DifferentOriginBrowsingContext;
+ }
- if (isInSimilarOriginBrowsingContext) {
+ if (isInSimilarOriginBrowsingContext ==
+ BrowsingContextInfo::SimilarOriginBrowsingContext) {
rootIntersectionRect.Inflate(rootMargin);
}
@@ -413,7 +434,9 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time
if (target->UpdateIntersectionObservation(this, threshold)) {
QueueIntersectionObserverEntry(
target, time,
- isInSimilarOriginBrowsingContext ? Some(rootIntersectionRect) : Nothing(),
+ isInSimilarOriginBrowsingContext ==
+ BrowsingContextInfo::DifferentOriginBrowsingContext ?
+ Nothing() : Some(rootIntersectionRect),
targetRect, intersectionRect, intersectionRatio
);
}