- From: Yash Malik <ymalik@google.com>
- Date: Wed, 07 Sep 2016 15:36:51 +0000
- To: Marat Tanalin <mtanalin@yandex.ru>, David Bokan <bokan@google.com>, "www-style@w3.org" <www-style@w3.org>
- Message-ID: <CANZmQybpgoYYB4FqdK3XSkBii4e4_U6M1m75vPxt-PB+7D6ikw@mail.gmail.com>
Ah yes, you're right. window.devicePixelRatio does take browser zoom into account. Though I find that the definition of window.devicePixelRatio <https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio> is a bit vague in that the notion of "device independent pixels" can be different. I believe that in Chrome, "device independent pixel" doesn't take browser zoom into account (but window.devicePixelRatio does). I'd like to point out that Firefox has a different viewport architecture, and doesn't have the notion of a "visual" and "layout" viewport (i.e their visual viewport = layout viewport; see this demo <https://dl.dropboxusercontent.com/u/4186806/viewport/index.html>). As far as your purposes, I think what you have should work since the visualViewport.scale is defined as "the ratio of CSS pixels to device pixels derived from the visual viewport". On Wed, Sep 7, 2016 at 11:05 AM Marat Tanalin <mtanalin@yandex.ru> wrote: > 07.09.2016, 17:27, "Yash Malik" <ymalik@google.com>: > >> 2. contains zoom relative to that already reflected in > `window.devicePixelRatio`, so the total physical-pixels-per-logical-pixel > ratio can be calculated as the _product_ of `window.visualViewport.scale` > times `window.devicePixelRatio`? > > > > By physical-pixels-per-logical-pixel, do you mean > physical-pixels-per-css-pixels? If so, then > almost*. `window.visualViewport.scale` times `window.devicePixelRatio` > doesn't take the browser zoom into account. > > Physical-pixels-per-css-pixel ratio is exactly what > `window.devicePixelRatio` is about, and it _does_ account for browser-level > zoom at least in Firefox. > > What I'm interested in is determining _total_ zoom that includes _both_ > `window.devicePixelRatio` and pinch zoom, so that it's possible to > determine exact image (<img>) size in _physical_ pixels. Currently, I'm > using the following formula for this purpose in Firefox for Android: > > (image.width / image.naturalWidth) * window.devicePixelRatio * > (window.outerWidth / window.innerWidth) > > where `window.outerWidth / window.innerWidth` is pinch zoom that, as I > suspect, `window.visualViewport.scale` is supposed to be a legit reliable > equivalent of. So, if I understand correctly, the new reliable formula > would be: > > (image.width / image.naturalWidth) * window.devicePixelRatio * > `window.visualViewport.scale` > > Do I understand `window.visualViewport.scale` purpose correctly? >
Received on Wednesday, 7 September 2016 15:37:30 UTC