Re: Proposal on handling invalid media queries

On Mon, Jul 2, 2012 at 10:59 AM, Tab Atkins Jr. <jackalmage@gmail.com>wrote:

> On Sat, Jun 30, 2012 at 9:35 PM, Boris Smus <smus@google.com> wrote:
> > Hi Folks,
> >
> > Section 3.1 of the Media Query specification
> > (http://www.w3.org/TR/css3-mediaqueries/) says "Unknown media types
> evaluate
> > to false". While this might be acceptable for declarative CSS (sorta), it
> > poses problems in JavaScript using the window.matchMedia function
> > (http://dev.w3.org/csswg/cssom-view/#mediaquerylist).
> >
> > # Problem
> >
> > Here's the problem: there is no way to tell if a media query is
> implemented
> > in a given user agent, because unknown media features still evaluate to
> > false. Really, there are three possibilities: 1) MQ matches 2) MQ doesn't
> > match 3) MQ Is invalid. For example, in Chrome, the following returns
> false:
> >
> > matchMedia('(min--moz-device-pixel-ratio: 2)').matches
> >
> > which can imply either than the query didn't match, or was invalid. This
> > particular case is obviously invalid since moz-prefixing, but the general
> > case is very confusing because there's no distinction between "no match"
> and
> > "invalid".
>
> In a conforming browser (FF and Opera do it right I think, WebKit
> doesn't, don't know about IE), you can test this by putting the MQ in
> a stylesheet and then reading it back out.  If it comes out with the
> query transformed into "not all", it's an unsupported query.
>
> That said, this is slightly clumsy.


Agree. Seems unintuitive and requires special knowledge on the web
developer's part.


> I'm not against your proposal to
> add an explicit validity boolean to the returned value of matchMedia.
>

If there is consensus, what can I do to help change the spec?


>
> ~TJ
>

Received on Monday, 9 July 2012 22:22:24 UTC