commit 9c5b5b8d4e7726aa17811dfd3a25319d9dda28f6
parent 8ba9c7901c57cf3b9340fb088c2e0819f4713d18
Author: Jonathan Kew <jkew@mozilla.com>
Date: Tue, 11 Nov 2025 14:15:16 +0000
Bug 1999326 - Fix ancestor-search loop in GetFrameLineNum() to properly handle first-line frames if present. r=layout-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D272142
Diffstat:
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/layout/generic/crashtests/1999326.html b/layout/generic/crashtests/1999326.html
@@ -0,0 +1,11 @@
+<style>
+*::first-line {}
+</style>
+<script>
+document.addEventListener("DOMContentLoaded", () => {
+ a.href = "x"
+ a.text = "A"
+})
+</script>
+<s lang="zh-CN">
+<a id="a" style="float: right">
diff --git a/layout/generic/crashtests/crashtests.list b/layout/generic/crashtests/crashtests.list
@@ -825,3 +825,4 @@ load 1978475-1.html
load 1990258.html
load 1990319.html
load 1998521.html
+load 1999326.html
diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp
@@ -3563,20 +3563,16 @@ static int32_t GetFrameLineNum(nsIFrame* aFrame, nsILineIterator* aLineIter) {
if (!aLineIter) {
return -1;
}
- int32_t n = aLineIter->FindLineContaining(aFrame);
- if (n >= 0) {
- return n;
- }
- // If we didn't find the frame directly, but its parent is an inline,
- // we want the line that the inline ancestor is on.
- nsIFrame* ancestor = aFrame->GetParent();
- while (ancestor && ancestor->IsInlineFrame()) {
- n = aLineIter->FindLineContaining(ancestor);
+ // If we don't find the frame directly, but its parent is an inline or other
+ // "line participant" (e.g. nsFirstLineFrame), we want the line that the
+ // inline ancestor is on.
+ do {
+ int32_t n = aLineIter->FindLineContaining(aFrame);
if (n >= 0) {
return n;
}
- ancestor = ancestor->GetParent();
- }
+ aFrame = aFrame->GetParent();
+ } while (aFrame && aFrame->IsLineParticipant());
return -1;
}