Re: [csswg-drafts] [css-pseudo] Allow custom Properties in ::selection pseudos (revisited) (#11317)

If we do want to support the back-compat behavior and the new highlight inheritance model at the same time, I think we would need a zig-zag or zipper inheritance model. Say we have
```
 root { .. }
   root::selection { ... }
parent { ... }
  parent::selection { ... }
child { ... }
  child::selection { ... }
```
then `child::selection`, in order, looks for variables on
```
child::selection (itself)
child (the originating element)
parent::selection (it's highlight parent)
parent (it's originating element's parent)
root::selection (one more level)
root (final option)
```
This sort-of supports both authors trying to use the new model and authors trying to use the old model for selection property inheritance. In particular, it will be back-compatible with custom properties inheriting from the originating element, because that's the first place to look for a property (second if you count the pseudo itself). And anything that works with previous browsers must have any properties used for selection inheriting up through the element tree.

It is possible to support both old and new behavior at the same time in one page if you (a) use property names specific to the highlights e.g. `-selection-background-color` and (b) mirror all highlight related properties between `foo` and `foo::selection` (for example). This is probably a big win, if authors get it right.

I believe then we can choose between two options, each of which would enable Highlight Inheritance to launch:
 1. Define custom properties to inherit from the originating element (and implicitly on through the element tree). The up side is that it is very easy to state and likely reasonable to implement in all browsers. The downside is that it makes custom properties inherit differently to every other property on highlight pseudos, which authors in the future will no doubt find very confusing.
 2. Define custom properties to inherit alternating between highlight pseudos and originating elements up the tree. The up side is that old content will still work while new content can use a consistent model for highlight inheritance of all properties. The down side is that it is tricky to explain and if you break the rules the behavior may be odd. And maybe it's not very efficient to implement in all browsers.

I am leaning toward option 2 because it supports back-compat while giving a viable transition to the new highlight inheritance model.


-- 
GitHub Notification of comment by schenney-chromium
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11317#issuecomment-2617756405 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 28 January 2025 03:14:50 UTC