Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear how specificity of ::cue() and ::cue-region() should be calculated #499

Open
dd8 opened this issue Oct 16, 2021 · 5 comments
Open

Comments

@dd8
Copy link

dd8 commented Oct 16, 2021

Should the selectors passed as an argument be taken into consideration or ignored when calculating specificity?

::cue /* a=0 b=0 c=1 */
::cue(div) /* is this a=0 b=0 c=1  or a=0 b=0 c=2 */
::cue-region /* a=0 b=0 c=1 */
::cue-region(#first) /* is this a=0 b=0 c=1  or a=1 b=0 c=1 */

Looking at 'Calculating a selector’s specificity' in selectors-4 doesn't make things clear since pseudo classes that take selectors as parameters are special-cased:
https://drafts.csswg.org/selectors/#specificity-rules

@silviapfeiffer
Copy link
Member

You'll want to check the WebVTT spec: it talks about applying the selectors: https://www.w3.org/TR/webvtt1/#the-cue-pseudo-element and https://www.w3.org/TR/webvtt1/#the-cue-region-pseudo-element

@dd8
Copy link
Author

dd8 commented Oct 19, 2021

I can't see any definition for the specificity for ::cue(selector) and ::cue-region(selector) anywhere. The specificity is used when there are multiple rules that match and declare the same property value:
https://drafts.csswg.org/css-cascade/#cascade-sort

There are specificity rules for :is() :where() and other selectors that take a selector list as a parameter:
https://www.w3.org/TR/selectors/#specificity-rules

In example 2 the the specificity decides whether color:papayawhip or color:peachpuff is used for items matching video::cue(b):
https://www.w3.org/TR/webvtt1/#styling

  • if the specificity of ::cue(<selector>) is zero like the :where(<selector>) (so A=0, B=0, C=0) then the color of items matching video::cue(b) is papayawhip (because :cue with no selector has higher specificity and wins the cascade)
  • if the specificity of ::cue(<selector>) is the same as ::cue without a selector (so A=0,B=0, C=1) then the color of items matching video::cue(b) is peachpuff (because both selectors have the same specificity, so last in order of declaration wins)
  • if the specificity of ::cue(<selector>) is calculated like :is(<selector>) (so A=0,B=0, C=1 in this example) then the color of items matching video::cue(b) is peachpuff (because both selectors have the same specificity, so last in order of declaration wins)

The difference between the last two becomes clearer if the universal selector is used:

   video::cue {
     background-image: linear-gradient(to bottom, dimgray, lightgray);
     color: papayawhip;
   }
   video::cue(*) {
     color: peachpuff;
   }
  • if the specificity of ::cue(*) is the same as ::cue without a selector (so A=0,B=0, C=1) then the color of items matching video::cue(*) is peachpuff (because both selectors have the same specificity, so last in order of declaration wins)
  • if the specificity of ::cue(*) is calculated like :is(*) (so A=0,B=0, C=0) then the color of items matching video::cue(*) is papayawhip (because :cue with no selector has higher specificity and wins the cascade)

Background: I'm adding support for ::cue() and ::cue-region() to an existing CSS engine. I need to know the specificity of these selectors to do this interoperably.

@dd8
Copy link
Author

dd8 commented Oct 20, 2021

The specificity wording for :host() and :host-context() may be a good starting point:
https://drafts.csswg.org/css-scoping/#host-selector

@gkatsev
Copy link
Collaborator

gkatsev commented Oct 28, 2021

I would need to spend more time on this, including investigating current implementations, but my current reading and knowledge of the spec seems like the intent was to have ::cue and ::cue() behave in a similar way to :host(). So, ::cue would have the specificity of a pseudo-element and ::cue() would have a specificity of a pseudo-element plus the specificity of the argument given.

You are correct that the spec doesn't currently make this explicit, and it would be something that should be updated in the spec.

@silviapfeiffer
Copy link
Member

silviapfeiffer commented Oct 31, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants