Bug 1967453: Change tree comparing helpers to act on const arguments. r=layout-reviewers,emilio

Differential Revision: https://phabricator.services.mozilla.com/D250245
This commit is contained in:
Jari Jalkanen
2025-05-21 04:13:58 +00:00
committed by jjalkanen@mozilla.com
parent 63c83deb26
commit 3fae0beeca
3 changed files with 40 additions and 33 deletions

View File

@@ -1229,8 +1229,8 @@ MOZ_NEVER_INLINE void nsFrameConstructorState::ProcessFrameInsertions(
nsIFrame* firstNewFrame = aFrameList.FirstChild();
// Cache the ancestor chain so that we can reuse it if needed.
AutoTArray<nsIFrame*, 20> firstNewFrameAncestors;
nsIFrame* notCommonAncestor = nullptr;
AutoTArray<const nsIFrame*, 20> firstNewFrameAncestors;
const nsIFrame* notCommonAncestor = nullptr;
if (lastChild) {
notCommonAncestor = nsLayoutUtils::FillAncestors(
firstNewFrame, containingBlock, &firstNewFrameAncestors);

View File

@@ -1111,19 +1111,20 @@ bool nsLayoutUtils::IsProperAncestorFrame(const nsIFrame* aAncestorFrame,
}
// static
nsIFrame* nsLayoutUtils::FillAncestors(nsIFrame* aFrame,
nsIFrame* aStopAtAncestor,
nsTArray<nsIFrame*>* aAncestors) {
while (aFrame && aFrame != aStopAtAncestor) {
aAncestors->AppendElement(aFrame);
aFrame = nsLayoutUtils::GetParentOrPlaceholderFor(aFrame);
const nsIFrame* nsLayoutUtils::FillAncestors(
const nsIFrame* aFrame, const nsIFrame* aStopAtAncestor,
nsTArray<const nsIFrame*>* aAncestors) {
const nsIFrame* it = aFrame;
while (it && it != aStopAtAncestor) {
aAncestors->AppendElement(it);
it = nsLayoutUtils::GetParentOrPlaceholderFor(it);
}
return aFrame;
return it;
}
// Return true if aFrame1 is after aFrame2
static bool IsFrameAfter(nsIFrame* aFrame1, nsIFrame* aFrame2) {
nsIFrame* f = aFrame2;
static bool IsFrameAfter(const nsIFrame* aFrame1, const nsIFrame* aFrame2) {
const nsIFrame* f = aFrame2;
do {
f = f->GetNextSibling();
if (f == aFrame1) {
@@ -1134,14 +1135,14 @@ static bool IsFrameAfter(nsIFrame* aFrame1, nsIFrame* aFrame2) {
}
// static
int32_t nsLayoutUtils::DoCompareTreePosition(nsIFrame* aFrame1,
nsIFrame* aFrame2,
nsIFrame* aCommonAncestor) {
int32_t nsLayoutUtils::DoCompareTreePosition(const nsIFrame* aFrame1,
const nsIFrame* aFrame2,
const nsIFrame* aCommonAncestor) {
MOZ_ASSERT(aFrame1, "aFrame1 must not be null");
MOZ_ASSERT(aFrame2, "aFrame2 must not be null");
AutoTArray<nsIFrame*, 20> frame2Ancestors;
nsIFrame* nonCommonAncestor =
AutoTArray<const nsIFrame*, 20> frame2Ancestors;
const nsIFrame* nonCommonAncestor =
FillAncestors(aFrame2, aCommonAncestor, &frame2Ancestors);
return DoCompareTreePosition(aFrame1, aFrame2, frame2Ancestors,
nonCommonAncestor ? aCommonAncestor : nullptr);
@@ -1149,8 +1150,9 @@ int32_t nsLayoutUtils::DoCompareTreePosition(nsIFrame* aFrame1,
// static
int32_t nsLayoutUtils::DoCompareTreePosition(
nsIFrame* aFrame1, nsIFrame* aFrame2, nsTArray<nsIFrame*>& aFrame2Ancestors,
nsIFrame* aCommonAncestor) {
const nsIFrame* aFrame1, const nsIFrame* aFrame2,
nsTArray<const nsIFrame*>& aFrame2Ancestors,
const nsIFrame* aCommonAncestor) {
MOZ_ASSERT(aFrame1, "aFrame1 must not be null");
MOZ_ASSERT(aFrame2, "aFrame2 must not be null");
@@ -1160,7 +1162,7 @@ int32_t nsLayoutUtils::DoCompareTreePosition(
return 0;
}
AutoTArray<nsIFrame*, 20> frame1Ancestors;
AutoTArray<const nsIFrame*, 20> frame1Ancestors;
if (aCommonAncestor &&
!FillAncestors(aFrame1, aCommonAncestor, &frame1Ancestors)) {
// We reached the root of the frame tree ... if aCommonAncestor was set,
@@ -1190,8 +1192,8 @@ int32_t nsLayoutUtils::DoCompareTreePosition(
return 1;
}
nsIFrame* ancestor1 = frame1Ancestors[last1];
nsIFrame* ancestor2 = aFrame2Ancestors[last2];
const nsIFrame* ancestor1 = frame1Ancestors[last1];
const nsIFrame* ancestor2 = aFrame2Ancestors[last2];
// Now we should be able to walk sibling chains to find which one is first
if (IsFrameAfter(ancestor2, ancestor1)) {
return -1;

View File

@@ -380,26 +380,31 @@ class nsLayoutUtils {
* 0 otherwise (meaning they're the same, or they're in
* different frame trees)
*/
static int32_t CompareTreePosition(nsIFrame* aFrame1, nsIFrame* aFrame2,
nsIFrame* aCommonAncestor = nullptr) {
static int32_t CompareTreePosition(
const nsIFrame* aFrame1, const nsIFrame* aFrame2,
const nsIFrame* aCommonAncestor = nullptr) {
return DoCompareTreePosition(aFrame1, aFrame2, aCommonAncestor);
}
static int32_t CompareTreePosition(nsIFrame* aFrame1, nsIFrame* aFrame2,
nsTArray<nsIFrame*>& aFrame2Ancestors,
nsIFrame* aCommonAncestor = nullptr) {
static int32_t CompareTreePosition(
const nsIFrame* aFrame1, const nsIFrame* aFrame2,
nsTArray<const nsIFrame*>& aFrame2Ancestors,
const nsIFrame* aCommonAncestor = nullptr) {
return DoCompareTreePosition(aFrame1, aFrame2, aFrame2Ancestors,
aCommonAncestor);
}
static nsIFrame* FillAncestors(nsIFrame* aFrame, nsIFrame* aStopAtAncestor,
nsTArray<nsIFrame*>* aAncestors);
static const nsIFrame* FillAncestors(const nsIFrame* aFrame,
const nsIFrame* aStopAtAncestor,
nsTArray<const nsIFrame*>* aAncestors);
static int32_t DoCompareTreePosition(nsIFrame* aFrame1, nsIFrame* aFrame2,
nsIFrame* aCommonAncestor);
static int32_t DoCompareTreePosition(nsIFrame* aFrame1, nsIFrame* aFrame2,
nsTArray<nsIFrame*>& aFrame2Ancestors,
nsIFrame* aCommonAncestor);
static int32_t DoCompareTreePosition(const nsIFrame* aFrame1,
const nsIFrame* aFrame2,
const nsIFrame* aCommonAncestor);
static int32_t DoCompareTreePosition(
const nsIFrame* aFrame1, const nsIFrame* aFrame2,
nsTArray<const nsIFrame*>& aFrame2Ancestors,
const nsIFrame* aCommonAncestor);
/**
* LastContinuationWithChild gets the last continuation in aFrame's chain