Re: Behavior of device-pixel-ratio under zoom

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 UTC