Closed Bug 1617317 Opened 4 years ago Closed 4 years ago

Add an nsIDOMWindowUtils API for getting the device pixel ratio without taking into account RDM's override

Categories

(DevTools :: Responsive Design Mode, task)

task
Not set
normal

Tracking

(firefox75 fixed)

RESOLVED FIXED
Firefox 75
Tracking Status
firefox75 --- fixed

People

(Reporter: botond, Assigned: botond)

References

Details

Attachments

(3 files)

In Responsive Design Mode, the device being emulated can have a device pixel ratio (DPR) that's different from the DPR of the surrounding content (browser chrome and RDM controls).

RDM achieves this by setting an "override DPR", which is reflected in window.devicePixelRatio, but not in PresContext::AppUnitsPerDevPixel().

Sometimes, however, browser internals need to know the DPR of the surrounding content, ignoring the "override DPR".

For example, to transform a point from CSS coordinates of the document inside the RDM to device pixels relative to the screen (the latter being what native event synthesization functions like nsIDOMWindowUtils.sendNativeTouchTap() expect), one of the things we need to do is translate the point from window coordinates to screen coordinates. This translation is obtained via window.mozInnerScreenX/Y, which returns CSS coordinates. However, these CSS coordinates are computed using PresContext::AppUnitsPerDevPixel(), and do not take into account RDM's override DPR, even when called on the window of the document inside the RDM pane.

To transform window.mozInnerScreenX/Y into device pixels, then, we need to correspondingly use the non-override DPR. I am proposing that we add a new nsIDOMWindowUtils API to access it from browser-internal code.

(An alternative solution might be to have PresContext::AppUnitsPerDevPixel() take into account the "override DPR". However, I feel like there's probably a good reason why it doesn't do that, as there are many callers of AppUnitsPerDevPixel(), while the "override DPR" is only taken into account in a few places like window.devicePixelRatio.)

This is like screenPixelsPerCSSPixel, but does not take into account the
RDM override of the device pixel ratio. It is needed to be able to correctly
compute the translation from window coordinates to screen coordinates
from inside the RDM pane.

Depends on D63750

This makes its calculation correct even for content inside RDM.

I don't think coordinatesRelativeToScreen() is currently used inside RDM,
but it might be in the future, and in any case it's good for it to be
conceptually correct.

Depends on D63751

Pushed by bballo@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8b1de8fafb5b
Clarify the relationship between nsIDOMWindowUtils.screenPixelsPerCSSPixel and window.devicePixelRatio. r=kats
https://hg.mozilla.org/integration/autoland/rev/5d5afd1abb80
Add nsIDOMWindowUtils.screenPixelsPerCSSPixelNoOverride. r=kats,bradwerth
https://hg.mozilla.org/integration/autoland/rev/9516d599e929
Use nsIDOMWindowUtils.screenPixelsPerCSSPixelNoOverride in coordinatesRelativeToScreen(). r=kats
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: