implement window.devicePixelRatio

RESOLVED FIXED in mozilla18

Status

()

Core
DOM
--
enhancement
RESOLVED FIXED
7 years ago
4 years ago

People

(Reporter: stechz, Assigned: mbrubeck)

Tracking

({compat, dev-doc-needed})

Trunk
mozilla18
compat, dev-doc-needed
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [parity-chrome][parity-safari][parity-android][parity-opera])

Attachments

(2 attachments)

(Reporter)

Description

7 years ago
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.
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

7 years ago
you can't use things like mm because they're not actually physical units.  We need to add new unit types
We've got mozmm for that.
Component: General → DOM
Product: Fennec → Core
QA Contact: general → general
Summary: Javascript property "devicePixelRatio" → implement window.devicePixelRatio

Comment 4

5 years ago
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.
Duplicate of this bug: 782126
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.
(Assignee)

Comment 7

5 years ago
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.
Assignee: nobody → mbrubeck
Status: NEW → ASSIGNED
Attachment #652534 - Flags: review?(jst)
(Assignee)

Comment 8

5 years ago
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.
Blocks: 674373
Keywords: compat
Whiteboard: [parity-chrome][parity-safari][parity-android][parity-opera]
(Assignee)

Updated

5 years ago
Depends on: 779527
OS: Mac OS X → All
Hardware: x86 → All

Comment 9

5 years ago
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).
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.
Ignore me, that was not an update, but a QuirksBlog entry from June, actually older.
(Assignee)

Comment 12

5 years ago
(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 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.
Attachment #652534 - Flags: review?(jst) → review+
(Assignee)

Updated

5 years ago
Blocks: 507755
(Assignee)

Updated

5 years ago
Attachment #652534 - Flags: superreview?(jonas)
(Assignee)

Comment 14

5 years ago
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
Attachment #656949 - Flags: review?(jst)
Attachment #652534 - Flags: superreview?(jonas) → superreview+
(Assignee)

Comment 15

5 years ago
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.
Attachment #652534 - Flags: checkin+
(Assignee)

Updated

5 years ago
Keywords: dev-doc-needed
Target Milestone: --- → mozilla18
https://hg.mozilla.org/mozilla-central/rev/84b9f209a913
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
(Assignee)

Updated

5 years ago
Depends on: 794056
(Assignee)

Comment 17

5 years ago
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.
Attachment #656949 - Flags: review?(jst) → review?(bzbarsky)
Comment on attachment 656949 [details] [diff] [review]
test

r=me
Attachment #656949 - Flags: review?(bzbarsky) → review+
Depends on: 809788
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.
(Assignee)

Comment 20

5 years ago
(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.
(Assignee)

Comment 21

5 years ago
Comment on attachment 656949 [details] [diff] [review]
test

https://hg.mozilla.org/integration/mozilla-inbound/rev/abfb3201b753
Attachment #656949 - Flags: checkin+
https://hg.mozilla.org/mozilla-central/rev/abfb3201b753
Flags: in-testsuite+

Comment 23

5 years ago
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
krzbor please file a new bug and cc me on it.
(Assignee)

Comment 25

5 years ago
(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.

Updated

5 years ago
Severity: normal → enhancement

Updated

4 years ago
Depends on: 843767

Updated

4 years ago
Depends on: 847077

Updated

4 years ago
Depends on: 904925
You need to log in before you can comment on or make changes to this bug.