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

Re: Behavior of device-pixel-ratio under zoom

From: John Mellor <johnme@chromium.org>
Date: Wed, 14 Nov 2012 17:33:01 +0000
Message-ID: <CAG_kaUanEKpZes-G94x_9_mXBCm3JcOUD_Pab+mBONXr5DVokA@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: Boris Zbarsky <bzbarsky@mit.edu>, James Robinson <jamesr@google.com>, Rune Lillesveen <rune@opera.com>, www-style list <www-style@w3.org>, Adam Barth <w3c@adambarth.com>
On Wed, Nov 14, 2012 at 4:55 PM, Tab Atkins Jr. <jackalmage@gmail.com>wrote:

> On Wed, Nov 14, 2012 at 7:42 AM, John Mellor <johnme@chromium.org> wrote:
> > On Wed, Nov 14, 2012 at 9:14 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> >> On 11/13/12 6:02 PM, James Robinson wrote:
> >>> Neither change
> >>> window.devicePixelRatio - that's an artifact of the display and cannot
> >>> be changed by user interaction.
> >>
> >> How is it an artifact of the display?  It's a ratio of CSS pixels to
> >> device pixels; the display knows nothing about CSS pixels, and in fact
> "page
> >> zoom" in your terminology changes this ratio!
> >
> > Minor nitpick: it's the ratio of density-independent pixels (aka
> > device-independent/logical/UI pixels) to device pixels (aka physical
> screen
> > pixels). On mobile, if you have a width=device-width viewport, then DIPs
> are
> > initially equivalent to CSS pixels, but when the user pinch-zooms, the
> size
> > of CSS pixels changes, whereas the size of DIPs does not change, hence
> the
> > devicePixelRatio does not change either when you pinch zoom.
>
> That's one way of thinking of it.  I prefer to keep it as "CSS pixels"
> in my head, and take its ratio with "the width that the virtual
> viewport would have, in device pixels".  The two are probably
> equivalent.
>

If you want you can define devicePixelRatio as the ratio between a) the
screen width in device pixels, and b) the width in CSS pixels that the
layout viewport would have if the viewport were to be width=device-width
(note that devicePixelRatio doesn't depend on the site's chosen viewport
width). But that's a slightly more awkward way of thinking about things
when the viewport is not width=device-width (e.g. when viewing a desktop
site on mobile), so it's nice to have a name (DIP) for "the size that a CSS
pixel would have if the viewport was width=device-width and the user hadn't
pinch zoomed".

Incidentally, some specs (notably CSSOM View Module) are ambiguous
(and implemented
inconsistently<http://www.quirksmode.org/blog/archives/2012/03/windowouterwidt.html>between
mobile browsers) as a result of trying to describe window sizes in
CSS pixels. In most cases the spec really means DIPs not CSS pixels...

-- John
Received on Wednesday, 14 November 2012 17:33:47 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:21:02 GMT