commit 2490e6d383b35ddf61643075de728d87030d1d04
parent dfa52bf95cd9a851946ac1a89b47d0a4aba5e439
Author: Emily McDonough <emcdonough@mozilla.com>
Date: Thu, 16 Oct 2025 17:43:13 +0000
Bug 1994516 - Make nsILineIterator::FindLineContaining take a const nsIFrame*. r=layout-reviewers,TYLin
This requires making nsTHashtable::Contains and nsFrameList::IndexOf accept
const pointers.
Differential Revision: https://phabricator.services.mozilla.com/D268778
Diffstat:
12 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp
@@ -6680,7 +6680,7 @@ Result<nsILineIterator::LineInfo, nsresult> nsFlexContainerFrame::GetLine(
return lineInfo;
}
-int32_t nsFlexContainerFrame::FindLineContaining(nsIFrame* aFrame,
+int32_t nsFlexContainerFrame::FindLineContaining(const nsIFrame* aFrame,
int32_t aStartLine) {
const int32_t index = mFrames.IndexOf(aFrame);
if (index < 0) {
diff --git a/layout/generic/nsFlexContainerFrame.h b/layout/generic/nsFlexContainerFrame.h
@@ -269,7 +269,8 @@ class nsFlexContainerFrame final : public nsContainerFrame,
int32_t GetNumLines() const final;
bool IsLineIteratorFlowRTL() final;
mozilla::Result<LineInfo, nsresult> GetLine(int32_t aLineNumber) final;
- int32_t FindLineContaining(nsIFrame* aFrame, int32_t aStartLine = 0) final;
+ int32_t FindLineContaining(const nsIFrame* aFrame,
+ int32_t aStartLine = 0) final;
NS_IMETHOD FindFrameAt(int32_t aLineNumber, nsPoint aPos,
nsIFrame** aFrameFound, bool* aPosIsBeforeFirstFrame,
bool* aPosIsAfterLastFrame) final;
diff --git a/layout/generic/nsFrameList.cpp b/layout/generic/nsFrameList.cpp
@@ -186,7 +186,7 @@ nsIFrame* nsFrameList::FrameAt(int32_t aIndex) const {
return frame;
}
-int32_t nsFrameList::IndexOf(nsIFrame* aFrame) const {
+int32_t nsFrameList::IndexOf(const nsIFrame* aFrame) const {
int32_t count = 0;
for (nsIFrame* f = mFirstChild; f; f = f->GetNextSibling()) {
if (f == aFrame) {
diff --git a/layout/generic/nsFrameList.h b/layout/generic/nsFrameList.h
@@ -271,7 +271,7 @@ class nsFrameList {
nsIFrame* LastChild() const { return mLastChild; }
nsIFrame* FrameAt(int32_t aIndex) const;
- int32_t IndexOf(nsIFrame* aFrame) const;
+ int32_t IndexOf(const nsIFrame* aFrame) const;
bool IsEmpty() const { return nullptr == mFirstChild; }
diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp
@@ -10807,7 +10807,7 @@ Result<nsILineIterator::LineInfo, nsresult> nsGridContainerFrame::GetLine(
return rv;
}
-int32_t nsGridContainerFrame::FindLineContaining(nsIFrame* aFrame,
+int32_t nsGridContainerFrame::FindLineContaining(const nsIFrame* aFrame,
int32_t aStartLine) {
const int32_t index = mFrames.IndexOf(aFrame);
if (index < 0) {
diff --git a/layout/generic/nsGridContainerFrame.h b/layout/generic/nsGridContainerFrame.h
@@ -161,7 +161,8 @@ class nsGridContainerFrame final : public nsContainerFrame,
int32_t GetNumLines() const final;
bool IsLineIteratorFlowRTL() final;
mozilla::Result<LineInfo, nsresult> GetLine(int32_t aLineNumber) final;
- int32_t FindLineContaining(nsIFrame* aFrame, int32_t aStartLine = 0) final;
+ int32_t FindLineContaining(const nsIFrame* aFrame,
+ int32_t aStartLine = 0) final;
NS_IMETHOD FindFrameAt(int32_t aLineNumber, nsPoint aPos,
nsIFrame** aFrameFound, bool* aPosIsBeforeFirstFrame,
bool* aPosIsAfterLastFrame) final;
diff --git a/layout/generic/nsILineIterator.h b/layout/generic/nsILineIterator.h
@@ -73,7 +73,7 @@ class nsILineIterator {
* aStartLine. Returns -1 if the frame cannot be found on lines
* starting with aStartLine.
*/
- virtual int32_t FindLineContaining(nsIFrame* aFrame,
+ virtual int32_t FindLineContaining(const nsIFrame* aFrame,
int32_t aStartLine = 0) = 0;
// Given a line number and a coordinate, find the frame on the line
diff --git a/layout/generic/nsLineBox.cpp b/layout/generic/nsLineBox.cpp
@@ -600,7 +600,7 @@ Result<nsILineIterator::LineInfo, nsresult> nsLineIterator::GetLine(
return structure;
}
-int32_t nsLineIterator::FindLineContaining(nsIFrame* aFrame,
+int32_t nsLineIterator::FindLineContaining(const nsIFrame* aFrame,
int32_t aStartLine) {
const nsLineBox* line = GetLineAt(aStartLine);
MOZ_ASSERT(line, "aStartLine out of range");
diff --git a/layout/generic/nsLineBox.h b/layout/generic/nsLineBox.h
@@ -430,7 +430,7 @@ class nsLineBox final : public nsLineLink {
int32_t RLIndexOf(const nsIFrame* aFrame,
const nsIFrame* aLastFrameInLine) const;
- bool Contains(nsIFrame* aFrame) const {
+ bool Contains(const nsIFrame* aFrame) const {
return MOZ_UNLIKELY(mFlags.mHasHashedFrames) ? mFrames->Contains(aFrame)
: IndexOf(aFrame) >= 0;
}
@@ -1047,7 +1047,8 @@ class nsLineIterator final : public nsILineIterator {
// Note that this updates the iterator's current position!
mozilla::Result<LineInfo, nsresult> GetLine(int32_t aLineNumber) final;
- int32_t FindLineContaining(nsIFrame* aFrame, int32_t aStartLine = 0) final;
+ int32_t FindLineContaining(const nsIFrame* aFrame,
+ int32_t aStartLine = 0) final;
NS_IMETHOD FindFrameAt(int32_t aLineNumber, nsPoint aPos,
nsIFrame** aFrameFound, bool* aPosIsBeforeFirstFrame,
diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp
@@ -1671,11 +1671,11 @@ Result<nsILineIterator::LineInfo, nsresult> nsTableRowGroupFrame::GetLine(
return Err(NS_ERROR_FAILURE);
}
-int32_t nsTableRowGroupFrame::FindLineContaining(nsIFrame* aFrame,
+int32_t nsTableRowGroupFrame::FindLineContaining(const nsIFrame* aFrame,
int32_t aStartLine) {
NS_ENSURE_TRUE(aFrame, -1);
- nsTableRowFrame* rowFrame = do_QueryFrame(aFrame);
+ const nsTableRowFrame* rowFrame = do_QueryFrame(aFrame);
if (MOZ_UNLIKELY(!rowFrame)) {
// When we do not have valid table structure in the DOM tree, somebody wants
// to check the line number with an out-of-flow child of this frame because
diff --git a/layout/tables/nsTableRowGroupFrame.h b/layout/tables/nsTableRowGroupFrame.h
@@ -189,7 +189,8 @@ class nsTableRowGroupFrame final : public nsContainerFrame,
* frame and the index is at least aStartLine.
* -1 if the frame cannot be found.
*/
- int32_t FindLineContaining(nsIFrame* aFrame, int32_t aStartLine = 0) final;
+ int32_t FindLineContaining(const nsIFrame* aFrame,
+ int32_t aStartLine = 0) final;
/** Find the orginating cell frame on a row that is the nearest to the
* inline-dir coordinate of aPos.
diff --git a/xpcom/ds/nsTHashtable.h b/xpcom/ds/nsTHashtable.h
@@ -810,7 +810,7 @@ class nsTHashtable<nsPtrHashKey<T>>
return reinterpret_cast<EntryType*>(Base::GetEntry(aKey));
}
- bool Contains(T* aKey) const { return Base::Contains(aKey); }
+ bool Contains(const T* aKey) const { return Base::Contains(aKey); }
EntryType* PutEntry(T* aKey) {
return reinterpret_cast<EntryType*>(Base::PutEntry(aKey));