W3C home > Mailing lists > Public > www-style@w3.org > April 2010

Re: [css3-mediaqueries][cssom] Empty media queries in stylesheets and the DOM

From: L. David Baron <dbaron@dbaron.org>
Date: Wed, 28 Apr 2010 10:50:53 -0700
To: Sylvain Galineau <sylvaing@microsoft.com>
Cc: www-style list <www-style@w3.org>
Message-ID: <20100428175053.GA1748@pickering.dbaron.org>
On Thursday 2010-04-15 00:49 +0000, Sylvain Galineau wrote:
> It is unclear whether the second statement means a) that this:
>    @media { ... }
> ...is equivalent to:
>    @media all { ... } 
> ...or b) whether it only means that:
>    @media (orientation:portrait) { ... }
> ...is equivalent to:
>    @media all and (orientation:portrait) { ... }
> ...but that @media { ... } is otherwise invalid.

As I mentioned in
http://lists.w3.org/Archives/Public/www-style/2010Apr/0512.html , we
resolved in
http://lists.w3.org/Archives/Public/www-style/2009Aug/0128.html that
an empty media query list is equivalent to 'all', but that some
users of media queries can forbid empty lists, and @media is one of
those users.

(The minutes weren't all that clear, but I implemented the change
that day based on what we discussed, perhaps even during the
telecon, and then forgot to get the change landed... it's now
https://bugzilla.mozilla.org/show_bug.cgi?id=561580 .)

As Daniel pointed out in today's telecon, we also need to specify
whether that restriction for @media is syntactic (something enforced
only at parse time) or dynamic (something that's also enforced after
mutation of the media list is mutated via the object model).  I
believe Daniel said that it should be syntactic (a parse time check
only), which happens to be what I implemented.  I also agree that
this is the right thing (presuming we want this restriction on
@media at all); I would not want to have to implement dynamic
enforcement of this restriction, while enforcing it syntactically is
a one line code change (see the patch in the above bug).  However,
it would mean that an @media rule all of whose media had been
removed dynamically would have to be serialized as @media all, a
slight quirk.

I'd also be happy just allowing @media {} (and throwing away the
patch in that bug).

> On my Win7 laptop, Firefox 3.6.3 and Opera 10.51 treat @media {...}  like 
> @media all { ... }. Safari 4.0.3 and Chrome 4.1 ignore the @media rule.
> As it is currently specified, however, Safari and Chrome comply
> with the media query syntax defined in CSS2.1[2] and CSS3 Media
> Queries[3], where both the media_list (2.1) and media_query_list
> (CSS3) productions require at least one media type/medium IDENT.
> Things get more confusing at the DOM level. 
> If one specifies an @media all {...} rule and then removes the
> 'all' medium using MediaList.deleteMedium()[4], Firefox then
> returns 'not all' for MediaList.mediaText. 
> Consistent with this media query value, the content of the @media
> rule no longer applies and the relevant elements' style is updated
> accordingly. 

This is related to our handling of the combination of these two
statements in section 3.1 of media queries
http://www.w3.org/TR/2009/CR-css3-mediaqueries-20090915/#error-handling :

Statement 1:
  # * Unknown media features. User agents are to ignore a media
  #   query when one of the specified media features is unknown.
  # [...]
  # * Unknown media feature values. As with unknown media features,
  #   user agents are to ignore a media query when one of the
  #   specified media feature values is unknown.

Statement 2:
  # When all media queries in a media query list are ignored it is
  # the same as if "not all" was specified.

I implemented this by recording in a media query list whether it had
any queries in it (ignored or not), which leads to the bad side
effect that you mention: once a media query is non-empty, it becomes
impossible to empty it back to being equivalent to 'all'.

I think the object model handling here would be much more sensible
if statement 2 were changed to say that *each* media query in a
media query list that is ignored is treated as 'not all', and
replaced in the object model by 'not all'.

Then the emptiness check for media query lists can be made using
only information that is represented in the object model rather than
requiring hidden information (whether any media queries were
ignored) that is not in the object model.

> In this same case, Opera returns an empty string for the mediaText
> property, and, consistent with its handling of @media {...}, still
> applies the styles defined in the rule.
> Safari and Chrome return the empty string but do not refresh the
> styles originally applied by the @media all {...} rule (although I
> haven't verified whether that is true for all properties).

What do you mean by "do not refresh"?  How is this different from
what Opera does?


L. David Baron                                 http://dbaron.org/
Mozilla Corporation                       http://www.mozilla.com/
Received on Wednesday, 28 April 2010 17:51:23 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:07:45 UTC