W3C home > Mailing lists > Public > www-style@w3.org > July 2012

Re: Proposal on handling invalid media queries

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 2 Jul 2012 10:59:53 -0700
Message-ID: <CAAWBYDB0b5u6v7pJf=a1Q0DkoJgJFZ1eZemhi8m9OqEpwKhXkQ@mail.gmail.com>
To: Boris Smus <smus@google.com>
Cc: www-style@w3.org
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.  I'm not against your proposal to
add an explicit validity boolean to the returned value of matchMedia.

Received on Monday, 2 July 2012 18:00:41 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:18 UTC