Summary: | Cannot style ::selection for a flex container | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | adam | ||||||||||
Component: | CSS | Assignee: | Nobody <webkit-unassigned> | ||||||||||
Status: | RESOLVED FIXED | ||||||||||||
Severity: | Normal | CC: | changseok, esprehn+autocc, ews-watchlist, glenn, koivisto, kondapallykalyan, megan_gardner, mmaxfield, pdr, simon.fraser, twilco.o, webkit-bug-importer, zalan | ||||||||||
Priority: | P2 | Keywords: | InRadar | ||||||||||
Version: | Safari 13 | ||||||||||||
Hardware: | Mac | ||||||||||||
OS: | macOS 10.15 | ||||||||||||
Attachments: |
|
Description
adam
2020-03-31 10:52:07 PDT
<style> .example { display: flex; } .example::selection { background: red !important; } </style> <div class="example"> some text </div> Did a little digging into this one. From what I can tell, this is happening because the TextRender's parent is sometimes set as anonymous when it maybe shouldn't be. https://github.com/WebKit/webkit/blob/master/Source/WebCore/rendering/TextPaintStyle.cpp#L161 calls here: https://github.com/WebKit/webkit/blob/master/Source/WebCore/rendering/RenderText.h#L303#L306 eventually calling here, and shortcircuiting `nullptr` in the `isAnonymous()` check: https://github.com/WebKit/webkit/blob/master/Source/WebCore/rendering/RenderElement.cpp#L1407#L1410 Also of note, this behavior is not specific to `display: flex`. See this repro with `display: block` and the introduction of a sibling div. Again, "some text" should be highlighted red, assuming Chrome and Firefox are correct and our behavior is not. Removing the sibling div results in the correct behavior. https://jsfiddle.net/dwuzsmft/ Going to do some more investigation. ^^^ RenderText, not TextRender. Also, I thought those were permalinks, but they aren't. Here are those three Github URLs as permalinks (the old ones are already broken): https://github.com/WebKit/webkit/blob/067ffd731ff6bf0b868e4cb284e2bfa90ee6de2d/Source/WebCore/rendering/TextPaintStyle.cpp#L161 https://github.com/WebKit/webkit/blob/02a0c958678dbba8abb8c83ee888cdbbf66f2a25/Source/WebCore/rendering/RenderText.h#L306 https://github.com/WebKit/webkit/blob/c8e58f74b5c21bfd9e4dd55f31e04cb1d58b5143/Source/WebCore/rendering/RenderElement.cpp#L1425#L1428 Created attachment 396256 [details]
Patch
Created attachment 396257 [details]
Patch
I think this should do it. The TLDR is that RenderText unconditionally checks its direct parent for pseudostyles, but the direct parent of text nodes/runs is often anonymous, and pseudostyles are associated with elements of the DOM (i.e., non-anonymous). My proposed patch changes RenderText look for pseudostyles by ascending the tree until a non-anonymous renderer is found. Should be ready for review. I added two test cases. I'm running the GTK port of WebKit, so test expectations were added for LayoutTests/platform/gtk. According to this (https://trac.webkit.org/wiki/CreatingLayoutTests) wiki article, I also need to add test expectations for other platforms. What is the best way to do this? I'm not seeing anything on the Builders page that shows newly generated test expectations as the previous article suggests, but perhaps I'm missing it. Created attachment 399934 [details]
Patch
Rebased onto latest master -- tests are still passing. Comment on attachment 399934 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=399934&action=review > Source/WebCore/rendering/RenderObject.cpp:170 > + RenderElement* ancestor = parent(); Could use auto* > Source/WebCore/rendering/RenderText.h:287 > + if (RenderElement* ancestor = firstNonAnonymousAncestor()) Here too > Source/WebCore/rendering/RenderText.h:294 > + if (RenderElement* ancestor = firstNonAnonymousAncestor()) etc Created attachment 399968 [details]
Patch
Thanks for the review, Antti. I applied your suggestions in this latest patch and tests are again green. I think my addition of a new patch nullified your r+ -- could you take another look, please? Committed r262049: <https://trac.webkit.org/changeset/262049> All reviewed patches have been landed. Closing bug and clearing flags on attachment 399968 [details]. Added test baselines for macOS and iOS in r262059 |