[csswg-drafts] [mediaqueries] Define more precisely the evaluation of media queries (#8056)

cdoublev has just created a new issue for https://github.com/w3c/csswg-drafts:

== [mediaqueries] Define more precisely the evaluation of media queries ==
[Section 3.1](https://drafts.csswg.org/mediaqueries-5/#evaluating) is *Evaluating Media Queries* but it does not even define how to evaluate `<media-query-list>`, `<media-query>`, `<media-type>`, but only non top-level subproductions. How to evaluate them is actually defined:

  - for `<media-query-list>`: in [2.1 Combining Media Queries](https://drafts.csswg.org/mediaqueries-5/#media-conditions) with *A media query list is true if any of its component media queries are true, and false only if all of its component media queries are false*
  - for `<media-query>`: in [2. Media Queries](https://drafts.csswg.org/mediaqueries-5/#media) with *a media query is true if: the media type, if specified, matches the media type of the device where the user agent is running, and the media condition is true.*
  - for `<media-type>`: in [2.3 Media Types](https://drafts.csswg.org/mediaqueries-5/#media-types) with *User agents must recognize the following media types as valid, but must make them match nothing*

In my opinion, it would help to have some consistency by using *"evaluates to true"* instead of *"is true"*, or *"must evaluate"* instead of *"must recognize"* or *"must match"*, to make a clear distinction between parsing and evaluating, even if both could apply at the same time.

---

> Each of the major subexpression of `<media-condition>` or `<media-condition-without-or>` is associated with a boolean result

It may be obvious to experienced implementers but I am not one of them and **how** and **when** *the major subexpression of `<media-condition>` or `<media-condition-without-or>` is associated with a boolean result* is not really clear to me, and some general guidance would have been helpfull, like in the introduction of [5. Parsing](https://drafts.csswg.org/css-syntax-3/#parsing) in CSS Syntax.

I know that evaluating media queries is required at parse time to decide whether the style sheet referenced by `@import` must be fetched, and at computed value time to filter the declared values (but also as part of the event loop and when running `window.matchMedia()`). This answers the "when".

I do not think that the result from their evaluation should be assigned as a property of the result from parsing these productions. It would be useless since it would have to be updated each time the definition of the user environment has changed.

`MediaQueryList` seems like a good fit to make this association: it holds the result from parsing `<media-query-list>` and returns its evaluation. It could hold an internal state that optimize running an evaluation depending on which media feature of the user environment has changed. But there is no mention of `MediaQueryList` in the Media Queries spec, except in a note about custom media queries that is obscure to me, so I am not sure about this idea.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8056 using your GitHub account


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

Received on Thursday, 10 November 2022 14:36:49 UTC