8000 Hairline on selection when bidi text is involved · WebKit/WebKit@df25b49 · GitHub
[go: up one dir, main page]

Skip to content

Commit df25b49

Browse files
committed
Hairline on selection when bidi text is involved
https://bugs.webkit.org/show_bug.cgi?id=220548 <rdar://problem/73362060> Reviewed by Antti Koivisto. Due to webkit.org/b/251318, we may compute a slightly shorter selection rect for non-whitespace runs with soft wrap opportunities between them. Such shrunk selection rects produce hairline gap at inline box boundaries. * Source/WebCore/rendering/TextBoxPainter.cpp: (WebCore::TextBoxPainter<TextBoxPath>::paintBackground): we've got _visual_ values here (at least with ignoring writing-mode), no need for directional pixel snapping. Canonical link: https://commits.webkit.org/259537@main
1 parent 8f8d02d commit df25b49

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ンズpass if no hairline gap after select
2+
(repaint rects
3+
(rect 88 18 694 40)
4+
(rect 8 18 80 40)
5+
)
6+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
2+
<style>
3+
div {
4+
font-family: sans-serif;
5+
font-size: 40px;
6+
}
7+
</style>
8+
<div id=select_this lang="ja"><span>ンズ</span>pass if no hairline gap after select</div>
9+
<script src="../../resources/ui-helper.js"></script>
10+
<script>
11+
if (window.testRunner) {
12+
testRunner.dumpAsText();
13+
testRunner.waitUntilDone();
14+
}
15+
16+
async function repaintTest() {
17+
if (window.internals)
18+
internals.startTrackingRepaints();
19+
20+
let range = document.createRange();
21+
range.selectNodeContents(select_this);
22+
window.getSelection().addRange(range);
23+
24+
await UIHelper.renderingUpdate();
25+
26+
if (window.internals) {
27+
var repaintRects = internals.repaintRectsAsText();
28+
internals.stopTrackingRepaints();
29+
var pre = document.createElement('pre');
30+
document.body.appendChild(pre);
31+
pre.innerHTML = repaintRects;
32+
}
33+
34+
if (window.testRunner)
35+
testRunner.notifyDone();
36+
}
37+
setTimeout(repaintTest, 0);
38+
39+
</script>

Source/WebCore/rendering/TextBoxPainter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,16 @@ void TextBoxPainter<TextBoxPath>::paintBackground(unsigned startOffset, unsigned
358358
auto deltaY = LayoutUnit { m_style.isFlippedLinesWritingMode() ? selectionBottom - m_logicalRect.maxY() : m_logicalRect.y() - selectionTop };
359359
auto selectionHeight = LayoutUnit { std::max(0.f, selectionBottom - selectionTop) };
360360
auto selectionRect = LayoutRect { LayoutUnit(m_paintRect.x()), LayoutUnit(m_paintRect.y() - deltaY), LayoutUnit(m_logicalRect.width()), selectionHeight };
361-
fontCascade().adjustSelectionRectForText(m_paintTextRun, selectionRect, startOffset, endOffset);
361+
auto adjustedSelectionRect = selectionRect;
362+
fontCascade().adjustSelectionRectForText(m_paintTextRun, adjustedSelectionRect, startOffset, endOffset);
363+
if (m_paintTextRun.length() == endOffset - startOffset) {
364+
// FIXME: We should reconsider re-measuring the content when non-whitespace runs are joined together (see webkit.org/b/251318).
365+
auto visualRight = std::max(adjustedSelectionRect.maxX(), selectionRect.maxX());
366+
adjustedSelectionRect.shiftMaxXEdgeTo(visualRight);
367+
}
362368

363369
// FIXME: Support painting combined text. See <https://bugs.webkit.org/show_bug.cgi?id=180993>.
364-
auto backgroundRect = snapRectToDevicePixelsWithWritingDirection(selectionRect, m_document.deviceScaleFactor(), m_paintTextRun.ltr());
370+
auto backgroundRect = snapRectToDevicePixels(adjustedSelectionRect, m_document.deviceScaleFactor());
365371
if (backgroundStyle == BackgroundStyle::Rounded) {
366372
backgroundRect.expand(-1, -1);
367373
backgroundRect.move(0.5, 0.5);

0 commit comments

Comments
 (0)
0