Open delan opened 2 years ago
I agree, but we should also allow mix-blend-mode
(especially with multiply
against a light underlying element, and screen
against dark), and probably backdrop-filter
too. These would produce much better typically Mac-like selections, IMO, than just translucency.
mix-blend-mode
and backdrop-filter
both have stacking context side-effects. They are not simple painting effects, so we can't make them work for selection.
If Safari makes opaque colors specified by the author translucent, then it's going to have different highlight colors than e.g. Blink and Gecko. This can, in fact, result in color/background pairs that while readable in one browser are unreadable in another--and this has occurred on real websites in the past.
So either everyone has to apply magic alpha the same way, or there is no magic alpha. We can't have every UA choosing independently on whether to apply alpha magic to author-specified ::selection colors, if we want authors to be able to reliably specify sufficiently-contrasting colors.
The CSS Working Group just discussed [css-pseudo] Safari’s ::selection “wash” and UA tweaks to highlight colors
, and agreed to the following:
RESOLVED: If there is color in the author origin the UA must respect that color
RESOLVED: If there isn't a color from the author origin the UA may apply magic
Edited. @delan Let me know if the new prose is clear or if it could be written better.
Thanks @fantasai!
However if there are no colors in the [=author origin=], the UA may apply additional color processing.
Does this mean setting any <color>-taking property suppresses UA magic in all such properties? For example, if the author sets ‘text-shadow’ on ::selection, does that suppress UA magic in ‘color’ or ‘background-color’?
@delan That was my interpretation of the resolution; though it does seem a bit odd so maybe we need to tweak it. CC @megangardner
My recollection of the discussion, after reading the transcript, is that if there are any colors then magic doesn't apply. I kinda thought it was odd at the time but I can see why: As soon as there is one color that is author changed the UA can't know what might happen with the other colors and should take what the author said.
On the other hand, what if you give a foreground color but not a background color, and the browser only has a unified magic way of setting all default highlight colors? What should the browser do for the background? I suspect that is not a real issue in which case this spec text is fine by me.
Otherwise it's probably back to the WG for a resolution saying something about "you must give all colors if you give one", and that seems a stretch.
Safari has a special approach to painting text ::selection, where it only paints a “wash” on top of the text being selected (see #6022 irc log, “blue wash”, “magic transluscent”). The way this is achieved is interesting: iff the author sets the ::selection background to a fully-opaque color, Safari overrides the alpha value to make the color translucent (demo).
But @fantasai says:
I don’t think we can allow Safari to paint ::selection as a translucent “wash” and forbid Safari from making opaque ::selection backgrounds translucent, because any author unaware of Safari’s different approach might set the ::selection background to an opaque color (such as a named color or other color without alpha) while expecting the selected text to stay legible.
I want to agree with @fantasai here and forbid all UA tweaks to author highlight colors (see also #6150). But I think I’m biased here, because I also feel like we should forbid the “text wash”, because both of these would make it easier to specify and test highlight painting precisely.
(@smfr, @mrego)