[css3-mediaqueries] "not", "only" and "and" as media_type

My reading of the current grammar

  # media_query
  #  : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
  #  | expression [ AND S* expression ]*
  #  ;
  # media_type
  #  : IDENT
  #  ;

suggests that "not", "only" and "and" can be used as media_type and
therefore the following are all valid: "not and (width)", "not not",
"not and and (width)". However, no browser implements this. Here are
some options:

A. Change the spec: "not" and "only" as media_type cannot be valid
unless it's preceded by "not" or "only".

== valid ==
and [ and (expr) ]*
[ not | only ] [ not | only | and ] [ and (expr) ]*

== invalid ==
[ not | only ] [ and (expr) ]*

Firefox12 and IE9 implement this. I probably support this. If we had
started writing this section using a state machine-based instead of a
rule-based approach, we would have been closer to this, I think.

I think I support this. The concrete proposal is to change

  # media_query
  #  : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
  #  | expression [ AND S* expression ]*
  #  ;
  # media_type
  #  : IDENT
  #  ;

to

  | media_query
  |  : [ONLY | NOT] S* media_type S* [ AND S* expression ]*
  |  | media_type_no_keywords S* [ AND S* expression ]*
  |  | expression [ AND S* expression ]*
  |  ;
  | media_type
  |  : IDENT
  |  ;
  | /*
  |  * There is a constraint on it that it must not be {O}{N}{L}{Y} or
  |  * {N}{O}{T}
  |  */
  | media_type_no_keywords
  |  : IDENT
  |  ;

B. Don't change the spec (besides perhaps add some test cases to the
test suite)

== valid ==
and [ and (expr) ]*
[ not | only ] [ not | only | and ] [ and (expr) ]*
[ not | only ] [ and (expr) ]*

== invalid ==

This is actually implementable (I have a patch for Gecko[1], though the
code is admittedly quite crappy.).


C. Change the spec: "not", "only" and "and" cannot be media_type.

== valid ==

== invalid ==
and [ and (expr) ]*
[ not | only ] [ not | only | and ] [ and (expr) ]*
[ not | only ] [ and (expr) ]*

Chromium nightly and Opera12alpha implement this. I am slightly opposed
to this because, for the majority of normal cases, an extra check to see
if it's "and" is required.


I should note that while some of these are only observable via CSSOM,
the ones starting with "not" can be observed without scripts, say:

data:text/html,<style>@media not not {:root{background: green;}}</style>

data:text/html,<style>@media not and and (width) {:root{background:
green;}}</style>

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=757554#c3


Cheers,
Kenny

Received on Tuesday, 22 May 2012 20:48:15 UTC