diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 1c9adc36ca51b..b849e37d7ec28 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -3197,6 +3197,12 @@ nsRect nsLayoutUtils::TransformFrameRectToAncestor( Maybe* aMatrixCache /* = nullptr */, bool aStopAtStackingContextAndDisplayPortAndOOFFrame /* = false */, nsIFrame** aOutAncestor /* = nullptr */) { +#if 0 + // FIXME(bug 1668156): This should hold. + MOZ_ASSERT(IsAncestorFrameCrossDoc(aAncestor.mFrame, aFrame), + "Fix the caller"); +#endif + SVGTextFrame* text = GetContainingSVGTextFrame(aFrame); float srcAppUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel(); @@ -4565,10 +4571,12 @@ struct BoxToRect : public nsLayoutUtils::BoxCallback { const nsIFrame* mRelativeTo; nsLayoutUtils::RectCallback* mCallback; uint32_t mFlags; + bool mRelativeToIsRoot; BoxToRect(const nsIFrame* aRelativeTo, nsLayoutUtils::RectCallback* aCallback, uint32_t aFlags) - : mRelativeTo(aRelativeTo), mCallback(aCallback), mFlags(aFlags) {} + : mRelativeTo(aRelativeTo), mCallback(aCallback), mFlags(aFlags), + mRelativeToIsRoot(!aRelativeTo->GetParent()) {} virtual void AddBox(nsIFrame* aFrame) override { nsRect r; @@ -4590,7 +4598,11 @@ struct BoxToRect : public nsLayoutUtils::BoxCallback { } } if (mFlags & nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS) { - r = nsLayoutUtils::TransformFrameRectToAncestor(outer, r, mRelativeTo); + if (mRelativeToIsRoot) { + r = nsLayoutUtils::TransformFrameRectToAncestor(outer, r, mRelativeTo); + } else { + nsLayoutUtils::TransformRect(outer, mRelativeTo, r); + } } else { r += outer->GetOffsetTo(mRelativeTo); } diff --git a/testing/web-platform/tests/intersection-observer/intersection-ratio-ib-split.html b/testing/web-platform/tests/intersection-observer/intersection-ratio-ib-split.html index 905ea436fd6a8..1cba6daf6e8eb 100644 --- a/testing/web-platform/tests/intersection-observer/intersection-ratio-ib-split.html +++ b/testing/web-platform/tests/intersection-observer/intersection-ratio-ib-split.html @@ -26,6 +26,16 @@ assert_equals(entries.length, 1, element.nodeName + ": Should get an entry"); assert_true(entries[0].isIntersecting, element.nodeName + ": Should be intersecting"); assert_equals(entries[0].intersectionRatio, 1, element.nodeName + ": Should be fully intersecting"); + + function assert_rects_equal(r1, r2, label) { + assert_equals(r1.top, r2.top, label + ": top should be equal"); + assert_equals(r1.right, r2.right, label + ": right should be equal"); + assert_equals(r1.bottom, r2.bottom, label + ": bottom should be equal"); + assert_equals(r1.left, r2.left, label + ": left should be equal"); + } + + assert_rects_equal(entries[0].boundingClientRect, element.getBoundingClientRect(), element.nodeName + ": boundingClientRect should match"); + assert_rects_equal(entries[0].intersectionRect, entries[0].boundingClientRect, element.nodeName + ": intersectionRect should match entry.boundingClientRect"); } }, "IntersectionObserver on an IB split gets the right intersection ratio");