Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 41586fb246c394b32933347f1c3ebdf2fcd58fb5
https://github.com/WebKit/WebKit/commit/41586fb246c394b32933347f1c3ebdf2fcd58fb5
Author: Alan Baradlay <[email protected]>
Date: 2026-04-21 (Tue, 21 Apr 2026)
Changed paths:
A LayoutTests/fast/text/range-bounding-rect-across-lines-expected.txt
A LayoutTests/fast/text/range-bounding-rect-across-lines.html
M Source/WebCore/rendering/RenderText.cpp
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/WKWebViewMacEditingTests.mm
Log Message:
-----------
Range.getBoundingClientRect reports wrong Y for text on second line
https://bugs.webkit.org/show_bug.cgi?id=312671
Reviewed by Antti Koivisto.
Consider "ab" in a zero-width div with arbitrary breaking positions.
Each character is on its own line.
Text boxes: [0,1) "a" on line 1
[1,2) "b" on line 2
Getting the bounding rect for "b":
range.setStart(textNode, 1);
range.setEnd(textNode, 2);
Range: [1-------2)
The range starts at offset 1. Text box [0,1) ends at offset 1 --
the range starts right after it, no overlap. But selectionRectForTextBox
checked rangeStart <= textBox.end() (inclusive), treating offset 1 as
inside box [0,1). This produced a zero-width rect at y=0 (line 1).
getBoundingClientRect unions all rects. The spurious rect at y=0 got
unioned with the correct rect at y=line2, pulling the result to y=0.
The fix changes the boundary check to rangeStart < textBox.end()
(exclusive) so text boxes that end before the range are skipped.
However, there is one case where rangeStart == textBox.end() should
still produce a rect: when there is trimmed whitespace between this
text box and the next (e.g. a collapsed space at a soft wrap). That
whitespace belongs to this line even though it has no text box.
Detected by a gap between textBox.end() and nextTextBox->start().
Test: fast/text/range-bounding-rect-across-lines.html
* LayoutTests/fast/text/range-bounding-rect-across-lines-expected.txt: Added.
* LayoutTests/fast/text/range-bounding-rect-across-lines.html: Added.
* Source/WebCore/rendering/RenderText.cpp:
(WebCore::selectionRectForTextBox):
Canonical link: https://commits.webkit.org/311668@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications