Bug 263658

Summary: Selection gaps are not painted with the expected Selection pseudoelement color
Product: WebKit Reporter: Daniel Jalkut <jalkut>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: jalkut, megan_gardner, rniwa, webkit-bug-importer, wenson_hsieh, zalan
Priority: P2 Keywords: InRadar
Version: Safari 17   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Test case reduction
none
Proposed patch to address the bug
none
Proposed test case for the bug
none
Proposed test case expected png result none

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.