commit aa50a239e23842c526b42721560a33a1fd0b6c7f
parent 20427cb8aacdd00c41479e6ca91ae89acdf262a1
Author: Timothy Nikkel <tnikkel@gmail.com>
Date: Sat, 22 Nov 2025 14:48:50 +0000
Bug 2001616. Create nsLayoutUtils::IsProperAncestorFrameConsideringContinuations function. r=layout-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D273573
Diffstat:
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp
@@ -1103,6 +1103,28 @@ bool nsLayoutUtils::IsProperAncestorFrame(const nsIFrame* aAncestorFrame,
}
// static
+bool nsLayoutUtils::IsProperAncestorFrameConsideringContinuations(
+ const nsIFrame* aAncestorFrame, const nsIFrame* aFrame,
+ const nsIFrame* aCommonAncestor) {
+ MOZ_ASSERT(aAncestorFrame);
+ const nsIFrame* ancestorFirstContinuation =
+ aAncestorFrame->FirstContinuation();
+ if (!aFrame || aFrame->FirstContinuation() == ancestorFirstContinuation) {
+ return false;
+ }
+ const nsIFrame* commonFirstContinuation =
+ aCommonAncestor ? aCommonAncestor->FirstContinuation() : nullptr;
+ const nsIFrame* f = aFrame;
+ for (; f && f->FirstContinuation() != commonFirstContinuation;
+ f = f->GetParent()) {
+ if (f->FirstContinuation() == ancestorFirstContinuation) {
+ return true;
+ }
+ }
+ return f && commonFirstContinuation == ancestorFirstContinuation;
+}
+
+// static
const nsIFrame* nsLayoutUtils::FillAncestors(
const nsIFrame* aFrame, const nsIFrame* aStopAtAncestor,
nsTArray<const nsIFrame*>* aAncestors) {
diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h
@@ -474,6 +474,17 @@ class nsLayoutUtils {
const nsIFrame* aCommonAncestor = nullptr);
/**
+ * IsProperAncestorFrameConsideringContinuations checks whether aAncestorFrame
+ * or a continuation of it is an ancestor of aFrame and not equal to aFrame.
+ * @param aCommonAncestor nullptr, or a common ancestor of aFrame and
+ * aAncestorFrame. If non-null, this can bound the search and speed up
+ * the function
+ */
+ static bool IsProperAncestorFrameConsideringContinuations(
+ const nsIFrame* aAncestorFrame, const nsIFrame* aFrame,
+ const nsIFrame* aCommonAncestor = nullptr);
+
+ /**
* Like IsProperAncestorFrame, but looks across document boundaries.
*
* Just like IsAncestorFrameCrossDoc, except that it returns false when