Bug 263658 - Selection gaps are not painted with the expected Selection pseudoelement color
Summary: Selection gaps are not painted with the expected Selection pseudoelement color
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Safari 17
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-10-25 08:05 PDT by Daniel Jalkut
Modified: 2023-11-26 23:15 PST (History)
6 users (show)

See Also:


Attachments
Test case reduction (134 bytes, text/html)
2023-10-25 08:05 PDT, Daniel Jalkut
no flags Details
Proposed patch to address the bug (1.13 KB, patch)
2023-10-25 08:08 PDT, Daniel Jalkut
no flags Details | Formatted Diff | Diff
Proposed test case for the bug (334 bytes, text/html)
2023-10-25 08:55 PDT, Daniel Jalkut
no flags Details
Proposed test case expected png result (25.98 KB, image/png)
2023-10-25 08:55 PDT, Daniel Jalkut
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Jalkut 2023-10-25 08:05:21 PDT
Created attachment 468331 [details]
Test case reduction

When a custom selection background color is specified in a ::selection pseudo-element CSS rule, there are scenarios in which child nodes of the affected node are not painted with the expected custom color.

One such scenario occurs when top-level "anonymous" text abuts a top-level paragraph block. The attached reduction.html exhibits the bug using this scenario.

To reproduce: 

1. Open attached reduction.html in Safari on Mac.
2. Select all.

Expected: The entirety of the top line of rendered text should be painted with the custom selection color.

Actual: Only the text portion of the line is painted with the custom color, and the right gap is painted with the default selection background color.
Comment 1 Daniel Jalkut 2023-10-25 08:08:27 PDT
Created attachment 468332 [details]
Proposed patch to address the bug
Comment 2 Daniel Jalkut 2023-10-25 08:08:46 PDT
The root of the problem is that anonymous nodes do not consult their ancestors when determining the appropriate background color. The attached patch offers one solution to the bug, in which the RenderElement::selectionBackgroundColor method is amended such that if the element is anonymous, it consults the first non-anonymous ancestor in order instead.

I will work on a test case for this but I wanted to get the core bug logged as a baseline.
Comment 3 Daniel Jalkut 2023-10-25 08:55:17 PDT
Created attachment 468333 [details]
Proposed test case for the bug
Comment 4 Daniel Jalkut 2023-10-25 08:55:53 PDT
Created attachment 468334 [details]
Proposed test case expected png result
Comment 5 Daniel Jalkut 2023-10-25 09:03:18 PDT
Pull request: https://github.com/WebKit/WebKit/pull/19541
Comment 6 Radar WebKit Bug Importer 2023-11-01 08:06:14 PDT
<rdar://problem/117796745>
Comment 7 EWS 2023-11-26 23:15:44 PST
Committed 271129@main (76bb9606ee1b): <https://commits.webkit.org/271129@main>

Reviewed commits have been landed. Closing PR #19541 and removing active labels.