From 78b6f639b2677253d0dfd54724070fa2e13f3c27 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 15 May 2019 12:45:10 +0200 Subject: [PATCH] Map IntersectionObserver rect to the correct viewport. targetFrame is modified during the intersection computation loop, so it's not the viewport you want if there are scrollframes around. This bug triggers when IntersectionObservers are used on frames that wrap. Follow-up for #249. --- dom/base/DOMIntersectionObserver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp index 389b93071f..70b5534ba4 100644 --- a/dom/base/DOMIntersectionObserver.cpp +++ b/dom/base/DOMIntersectionObserver.cpp @@ -339,6 +339,7 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time for (size_t i = 0; i < mObservationTargets.Length(); ++i) { Element* target = mObservationTargets.ElementAt(i); nsIFrame* targetFrame = target->GetPrimaryFrame(); + nsIFrame* originalTargetFrame = targetFrame; nsRect targetRect; Maybe intersectionRect; bool isSameDoc = root && root->GetComposedDoc() == target->GetComposedDoc(); @@ -424,7 +425,7 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time ); if (intersectionRect.isSome() && !isSameDoc) { nsRect rect = intersectionRect.value(); - nsPresContext* presContext = targetFrame->PresContext(); + nsPresContext* presContext = originalTargetFrame->PresContext(); nsLayoutUtils::TransformRect(rootFrame, presContext->PresShell()->GetRootScrollFrame(), rect); intersectionRect = Some(rect);