Last Comment Bug 564815 - implement window.devicePixelRatio
: implement window.devicePixelRatio
Status: RESOLVED FIXED
[parity-chrome][parity-safari][parity...
: compat, dev-doc-needed
Product: Core
Classification: Components
Component: DOM (show other bugs)
: Trunk
: All All
: -- enhancement with 4 votes (vote)
: mozilla18
Assigned To: Matt Brubeck (:mbrubeck)
:
Mentors:
: 782126 (view as bug list)
Depends on: 779527 794056 809788 843767 847077 904925
Blocks: 507755 674373
  Show dependency treegraph
 
Reported: 2010-05-10 09:32 PDT by Benjamin Stover (:stechz)
Modified: 2013-08-14 16:59 PDT (History)
29 users (show)
ryanvm: in‑testsuite+
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
patch (4.10 KB, patch)
2012-08-16 13:14 PDT, Matt Brubeck (:mbrubeck)
jst: review+
jonas: superreview+
mbrubeck: checkin+
Details | Diff | Review
test (1.96 KB, patch)
2012-08-30 11:02 PDT, Matt Brubeck (:mbrubeck)
bzbarsky: review+
mbrubeck: checkin+
Details | Diff | Review

Description Benjamin Stover (:stechz) 2010-05-10 09:32:03 PDT
Android browser commit here: https://android.git.kernel.org/?p=platform/external/webkit.git;a=commit;h=f10585d69aaccf4c1b021df143ee0f08e338cf31

Should Fennec implement this?  I could see this being of use to Javascript widget libraries that want an easy way to guarantee buttons are of a touchable size.
Comment 1 Daniel Brooks [:db48x] 2010-06-20 12:19:49 PDT
This is available to chrome (under a different name), see https://bugzilla.mozilla.org/show_bug.cgi?id=486200. To be honest, I doubt that this is ever needed for content. Content should just use units such as mm. See http://mxr.mozilla.org/mobile-browser/source/themes/wince/platform.css?mark=136-137#135 for an example.
Comment 2 Stuart Parmenter 2010-06-20 14:20:47 PDT
you can't use things like mm because they're not actually physical units.  We need to add new unit types
Comment 3 :Ms2ger 2011-04-03 05:59:02 PDT
We've got mozmm for that.
Comment 4 Brion Vibber 2012-06-25 14:09:15 PDT
http://www.apple.com/ currently has a pretty retina display demo image; it appears to use window.devicePixelRatio to determine whether to load the high-resolution images.
Comment 5 Philipp von Weitershausen [:philikon] 2012-08-12 13:02:55 PDT
*** Bug 782126 has been marked as a duplicate of this bug. ***
Comment 6 Vladimir Vukicevic [:vlad] [:vladv] 2012-08-16 11:19:41 PDT
Mobile needs this as well -- we need to be able to figure out what the actual pixel ratio is on high dpi displays, for being able to appropriately choose backing store size for canvas and similar.
Comment 7 Matt Brubeck (:mbrubeck) 2012-08-16 13:14:44 PDT
Created attachment 652534 [details] [diff] [review]
patch

This patch appears to work, although I it always returns 1 on Android, which I think is because of bug 779527.

This patch basically reverts part of bug 507755, though it keeps the nsIDOMWindowUtils method around too for add-on compatibility.  I still need to add tests, but first I'd like to know if this is basically correct, and if it's a change that we want to ship.
Comment 8 Matt Brubeck (:mbrubeck) 2012-08-16 13:20:42 PDT
http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html has some notes about how this is implemented in other browsers.  Similar to bug 779527, there may be special concerns on mobile where we use a pannable/zoomable "virtual" viewport.
Comment 9 FX 2012-08-18 03:26:38 PDT
The popular retina.js solution for transparently serving high-res images when necessary (http://retinajs.com) uses "root.devicePixelRatio" as a test for HiDPI displays (https://github.com/imulus/retinajs/blob/master/src/retina.js#L107). This works on Safari (Mobile and Desktop), Google Chrome, but fails with the Firefox HiDPI-enable nightly builds (https://bugzilla.mozilla.org/show_bug.cgi?id=674373).
Comment 10 Sergey «Mithgol the Webmaster» Sokoloff 2012-08-21 03:29:25 PDT
The updated QuirksBlog entry is out:

http://www.quirksmode.org/blog/archives/2012/06/devicepixelrati.html

Also, "root.devicePixelRatio" instead of "window.devicePixelRatio" would probably fail in Firefox anyway.
Comment 11 Sergey «Mithgol the Webmaster» Sokoloff 2012-08-21 03:30:43 PDT
Ignore me, that was not an update, but a QuirksBlog entry from June, actually older.
Comment 12 Matt Brubeck (:mbrubeck) 2012-08-21 06:56:19 PDT
(In reply to Sergey «Mithgol the Webmaster» Sokoloff from comment #10)
> Also, "root.devicePixelRatio" instead of "window.devicePixelRatio" would
> probably fail in Firefox anyway.

"root" is just an alias for "window" in the code referenced above:
https://github.com/imulus/retinajs/blob/master/src/retina.js#L3
Comment 13 Johnny Stenback (:jst, jst@mozilla.com) 2012-08-30 10:21:31 PDT
Comment on attachment 652534 [details] [diff] [review]
patch

I think we should take this, it's basically a defacto standard at this point... Is someone raising this is the standards world already? If not, that needs to happen as well.
Comment 14 Matt Brubeck (:mbrubeck) 2012-08-30 11:02:27 PDT
Created attachment 656949 [details] [diff] [review]
test

Adds some simple assertions to match the ones for screenPixelsPerCSSPixel.  Pushed to Try: https://tbpl.mozilla.org/?tree=Try&rev=420ebbefd766
Comment 15 Matt Brubeck (:mbrubeck) 2012-09-07 12:54:04 PDT
Comment on attachment 652534 [details] [diff] [review]
patch

Pushed the reviewed patch to inbound so that we can start getting coverage of this in nightlies:
https://hg.mozilla.org/integration/mozilla-inbound/rev/84b9f209a913

The other patch is a trivial test-only change; I'll push that whenever it's reviewed.
Comment 16 Ryan VanderMeulen [:RyanVM] 2012-09-07 21:16:37 PDT
https://hg.mozilla.org/mozilla-central/rev/84b9f209a913
Comment 17 Matt Brubeck (:mbrubeck) 2012-10-25 09:40:57 PDT
Comment on attachment 656949 [details] [diff] [review]
test

This test-only patch adds two assertions to check the value of window.devicePixelRatio.  Since this new property is an alias for nsIDOMWindowUtils.screenPixelsPerCSSPixel, we expect it to have the same value.
Comment 18 Boris Zbarsky [:bz] (Out June 25-July 6) 2012-10-25 09:47:37 PDT
Comment on attachment 656949 [details] [diff] [review]
test

r=me
Comment 19 Jonathan Kew (:jfkthame) 2012-11-08 07:41:26 PST
I notice that the test patch here hasn't landed yet... be aware that bug 809788 is proposing to change window.devicePixelRatio (to make it independent of page zoom), so it has a modified version of the test that will supersede this one, assuming we accept that behavior change.
Comment 20 Matt Brubeck (:mbrubeck) 2012-11-08 10:48:36 PST
(In reply to Jonathan Kew (:jfkthame) from comment #19)
> I notice that the test patch here hasn't landed yet...

Oops! I guess that slipped through the cracks here.

> be aware that bug
> 809788 is proposing to change window.devicePixelRatio (to make it
> independent of page zoom), so it has a modified version of the test that
> will supersede this one, assuming we accept that behavior change.

Thanks for the heads-up.  If bug 809788 is not already landed soon, then I'll push my test patch so we have basic testing in the meantime.
Comment 22 Ryan VanderMeulen [:RyanVM] 2012-11-26 17:57:00 PST
https://hg.mozilla.org/mozilla-central/rev/abfb3201b753
Comment 23 krzbor 2013-01-06 13:44:10 PST
Unfortunately, in version 18 window.devicePixelRatio not working properly. For Samsung Galaxy S II is 1.0, should be 1.5. For Google Nexus 7 is 1.0, should be 1.3. It should see the page: http://en.wikipedia.org/wiki/List_of_displays_by_pixel_density
Comment 24 Kevin Brosnan [:kbrosnan] 2013-01-06 17:52:17 PST
krzbor please file a new bug and cc me on it.
Comment 25 Matt Brubeck (:mbrubeck) 2013-01-07 09:27:23 PST
(In reply to krzbor from comment #23)
> Unfortunately, in version 18 window.devicePixelRatio not working properly.
> For Samsung Galaxy S II is 1.0, should be 1.5. For Google Nexus 7 is 1.0,
> should be 1.3. It should see the page:
> http://en.wikipedia.org/wiki/List_of_displays_by_pixel_density

Yes, window.devicePixelRatio and related properties are broken on Android; see bug 794056 and bug 803207.

Note You need to log in before you can comment on or make changes to this bug.