Bug 1753995 - Remove nsDOMWindowUtils.screenPixelsPerCSSPixel. r=smaug,dholbert

For all purposes, this is the same as devicePixelRatio. It was meant to
skip the resistFingerprinting check the devicePixelRatio getter does,
but we do that now using CallerType in WebIDL, so if we cared about that
for these tests (which we don't) we could just do
SpecialPowers.wrap(window).devicePixelRatio.

As a follow-up we could move the NoOverride to window for symmetry. But
it's only used by devtools touch simulation so not sure if worth it.

Differential Revision: https://phabricator.services.mozilla.com/D138021
This commit is contained in:
Emilio Cobos Álvarez 2022-02-07 18:23:36 +00:00
parent 00cc720134
commit b699e8cdc8
20 changed files with 25 additions and 69 deletions

View File

@ -121,8 +121,7 @@ const Layout = {
},
CSSToDevicePixels(win, x, y, width, height) {
const winUtil = win.windowUtils;
const ratio = winUtil.screenPixelsPerCSSPixel;
const ratio = win.devicePixelRatio;
// CSS pixels and ratio can be not integer. Device pixels are always integer.
// Do our best and hope it works.

View File

@ -371,9 +371,7 @@ function getBoundsForDOMElm(aID) {
}
function CSSToDevicePixels(aWindow, aX, aY, aWidth, aHeight) {
var winUtil = aWindow.windowUtils;
var ratio = winUtil.screenPixelsPerCSSPixel;
var ratio = aWindow.devicePixelRatio;
// CSS pixels and ratio can be not integer. Device pixels are always integer.
// Do our best and hope it works.

View File

@ -2189,19 +2189,6 @@ nsDOMWindowUtils::GetViewId(Element* aElement, nsViewID* aResult) {
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetScreenPixelsPerCSSPixel(float* aScreenPixels) {
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
nsCOMPtr<nsPIDOMWindowInner> innerWindow = window->GetCurrentInnerWindow();
NS_ENSURE_STATE(innerWindow);
// XXX Why does this API exist? Callers should just use devicePixelRatio!
*aScreenPixels =
nsGlobalWindowInner::Cast(innerWindow)
->GetDevicePixelRatio(CallerType::System, IgnoreErrors());
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetScreenPixelsPerCSSPixelNoOverride(float* aScreenPixels) {
nsPresContext* presContext = GetPresContext();

View File

@ -31,8 +31,7 @@ add_task(async () => {
SpecialPowers.setFullZoom(window, 2.0);
const rect = target.getBoundingClientRect();
const screenPixelsPerCSSPixel =
SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixel;
const screenPixelsPerCSSPixel = window.devicePixelRatio;
const screenPixelsPerCSSPixelNoOverride =
SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixelNoOverride;

View File

@ -9,13 +9,11 @@
<iframe width=100></iframe>
<iframe width=100></iframe>
<script>
const utils = SpecialPowers.DOMWindowUtils;
function getScreenPosition(aElement, aOffsetX, aOffsetY) {
const rect = aElement.getBoundingClientRect();
const x = aOffsetX + window.mozInnerScreenX + rect.left;
const y = aOffsetY + window.mozInnerScreenY + rect.top;
const scale = utils.screenPixelsPerCSSPixel;
const scale = window.devicePixelRatio;
return [Math.round(x * scale), Math.round(y * scale)];
}

View File

@ -12,13 +12,11 @@ SimpleTest.requestLongerTimeout(2);
let state = "start";
const utils = SpecialPowers.DOMWindowUtils;
function getScreenPosition(aElement, aOffsetX, aOffsetY) {
const rect = aElement.getBoundingClientRect();
const x = aOffsetX + window.mozInnerScreenX + rect.left;
const y = aOffsetY + window.mozInnerScreenY + rect.top;
const scale = utils.screenPixelsPerCSSPixel;
const scale = window.devicePixelRatio;
return [Math.round(x * scale), Math.round(y * scale)];
}

View File

@ -10,8 +10,7 @@
<script>
let state = "start";
const utils = SpecialPowers.DOMWindowUtils;
const scale = utils.screenPixelsPerCSSPixel;
const scale = window.devicePixelRatio;
function getScreenPosition(aElement, aOffsetX, aOffsetY) {
const rect = aElement.getBoundingClientRect();

View File

@ -1154,15 +1154,6 @@ interface nsIDOMWindowUtils : nsISupports {
*/
readonly attribute Node nodeObservedByIMEContentObserver;
/**
* Get the number of screen pixels per CSS pixel.
*
* This is the same as window.devicePixelRatio, except it bypasses
* the fingerprinting resistance efforts that window.devicePixelRatio
* does (which is fine as this is only exposed to browser internals).
*/
readonly attribute float screenPixelsPerCSSPixel;
/**
* Get the number of screen pixels per CSS pixel,
* not taking into account any override of the device pixel scale

View File

@ -35,8 +35,7 @@ function doTests()
catch(ex) { }
ok(!readable, "window pixels per css pixel shouldn't be readable to content");
var domWindowUtils = window.windowUtils;
var devPxPerCSSPx = domWindowUtils.screenPixelsPerCSSPixel;
var devPxPerCSSPx = window.devicePixelRatio;
is(window.devicePixelRatio, devPxPerCSSPx, "window.devicePixelRatio");
@ -59,8 +58,7 @@ function doTests()
"frame screen Y");
fbc.fullZoom *= 2;
var frameDomWindowUtils = f.contentWindow.windowUtils;
is(frameDomWindowUtils.screenPixelsPerCSSPixel, 2*devPxPerCSSPx,
is(f.contentWindow.devicePixelRatio, 2*devPxPerCSSPx,
"frame screen pixels per CSS pixel");
is(f.contentWindow.devicePixelRatio, 2*devPxPerCSSPx, "frame devicePixelRatio");

View File

@ -323,7 +323,7 @@ async function coordinatesRelativeToScreen(aParams) {
// document, not to mozInnerScreen{X,Y}.
const utils = SpecialPowers.getDOMWindowUtils(window);
const resolution = await getResolution();
const deviceScale = utils.screenPixelsPerCSSPixel;
const deviceScale = window.devicePixelRatio;
const deviceScaleNoOverride = utils.screenPixelsPerCSSPixelNoOverride;
return {
x:

View File

@ -12,8 +12,7 @@
async function test() {
let useTouchpad = (location.search == "?touchpad");
const utils = SpecialPowers.getDOMWindowUtils(window);
const deviceScale = utils.screenPixelsPerCSSPixel;
const deviceScale = window.devicePixelRatio;
let target2 = document.getElementById("target2")
info("deviceScale " + deviceScale);

View File

@ -99,7 +99,7 @@ async function test() {
// on both the browser chrome window and the content window.
// This makes sure we catch the case where the overscroll transform causes
// the event to incorrectly target the browser chrome.
let deviceScale = utils.screenPixelsPerCSSPixel;
let deviceScale = window.devicePixelRatio;
let midGutter = 4 / deviceScale; // gutter is 8 *screen* pixels
startListeningForContextmenuEventsInChrome();
let contentReceivedContextmenu = false;

View File

@ -21,12 +21,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=513439
SimpleTest.waitForExplicitFinish();
var domWindowUtils = SpecialPowers.DOMWindowUtils;
SpecialPowers.pushPrefEnv({set: [["layout.css.devPixelsPerPx", "2"]]}, () => {
is(domWindowUtils.screenPixelsPerCSSPixel, 2, "devPixelsPerPx wasn't set correctly");
is(window.devicePixelRatio, 2, "devPixelsPerPx wasn't set correctly");
SpecialPowers.pushPrefEnv({set: [["layout.css.devPixelsPerPx", "1.5"]]}, () => {
is(domWindowUtils.screenPixelsPerCSSPixel, 1.5, "devPixelsPerPx wasn't set correctly");
is(window.devicePixelRatio, 1.5, "devPixelsPerPx wasn't set correctly");
SimpleTest.finish();
});
});

View File

@ -129,7 +129,7 @@ add_task(async function() {
isfuzzy(
popupRect.y,
expectedYPosition,
window.windowUtils.screenPixelsPerCSSPixel,
window.devicePixelRatio,
"y position of the popup"
);

View File

@ -28,7 +28,7 @@ SimpleTest.requestLongerTimeout(2);
var iframe;
function getScreenPixelsPerCSSPixel() {
return SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixel;
return window.devicePixelRatio;
}
function run() {

View File

@ -38,16 +38,12 @@ function run() {
return window.getComputedStyle(document.getElementById(divName)).visibility == "visible";
}
function getScreenPixelsPerCSSPixel() {
return SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixel;
}
var screenPixelsPerCSSPixel = getScreenPixelsPerCSSPixel();
var screenPixelsPerCSSPixel = window.devicePixelRatio;
var baseRatio = 1.0 * screenPixelsPerCSSPixel;
var doubleRatio = 2.0 * screenPixelsPerCSSPixel;
var halfRatio = 0.5 * screenPixelsPerCSSPixel;
var styleElem = document.getElementsByTagName("style")[1];
styleElem.textContent =
styleElem.textContent =
["@media all and (-moz-device-pixel-ratio: " + baseRatio + ") {",
"#zoom1 { visibility: visible; }",
"}",

View File

@ -38,16 +38,12 @@ function run() {
return window.getComputedStyle(document.getElementById(divName)).visibility == "visible";
}
function getScreenPixelsPerCSSPixel() {
return SpecialPowers.DOMWindowUtils.screenPixelsPerCSSPixel;
}
var screenPixelsPerCSSPixel = getScreenPixelsPerCSSPixel();
var screenPixelsPerCSSPixel = window.devicePixelRatio;
var baseRatio = 1.0 * screenPixelsPerCSSPixel;
var doubleRatio = 2.0 * screenPixelsPerCSSPixel;
var halfRatio = 0.5 * screenPixelsPerCSSPixel;
var styleElem = document.getElementsByTagName("style")[1];
styleElem.textContent =
styleElem.textContent =
["@media all and (-webkit-device-pixel-ratio: " + baseRatio + ") {",
"#zoom1 { visibility: visible; }",
"}",

View File

@ -61,8 +61,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=987230
} else {
//XXXgijs set mouse position back outside the iframe:
let frameRect = window.frameElement.getBoundingClientRect();
let utils = window.windowUtils;
let scale = utils.screenPixelsPerCSSPixel;
let scale = window.devicePixelRatio;
let outsideOfFrameX = (window.mozInnerScreenX + frameRect.width + 100) * scale;
let outsideOfFrameY = Math.max(0, window.mozInnerScreenY - 100) * scale;

View File

@ -1032,7 +1032,7 @@ function synthesizeNativeTap(
return;
}
let scale = utils.screenPixelsPerCSSPixel;
let scale = aWindow.devicePixelRatio;
let rect = aTarget.getBoundingClientRect();
let x = (aWindow.mozInnerScreenX + rect.left + aOffsetX) * scale;
let y = (aWindow.mozInnerScreenY + rect.top + aOffsetY) * scale;
@ -1056,7 +1056,7 @@ function synthesizeNativeMouseEvent(aParams, aCallback = null) {
atCenter, // Instead of offsetX/Y, synthesize the event at center of `target`
screenX, // X offset in screen (in CSS pixels if `scale` is "screenPixelsPerCSSPixel*"), offsetX/Y nor atCenter must not be set if this is set
screenY, // Y offset in screen (in CSS pixels if `scale` is "screenPixelsPerCSSPixel*"), offsetX/Y nor atCenter must not be set if this is set
// If scale is "screenPixelsPerCSSPixel", it'll be used.
// If scale is "screenPixelsPerCSSPixel", devicePixelRatio will be used.
// If scale is "screenPixelsPerCSSPixelNoOverride", it'll be used.
// If scale is "inScreenPixels", clientX/Y nor scaleX/Y are not adjusted with screenPixelsPerCSSPixel*.
scale = "screenPixelsPerCSSPixel",
@ -1117,7 +1117,7 @@ function synthesizeNativeMouseEvent(aParams, aCallback = null) {
return 1.0;
}
if (scale === "screenPixelsPerCSSPixel") {
return utils.screenPixelsPerCSSPixel;
return win.devicePixelRatio;
}
if (scale === "screenPixelsPerCSSPixelNoOverride") {
return utils.screenPixelsPerCSSPixelNoOverride;

View File

@ -59,8 +59,8 @@ function sendMouseEvent() {
}
function checkCoords(event) {
isfuzzy(event.clientX, rect.left + 1, window.windowUtils.screenPixelsPerCSSPixel, "Motion x coordinate");
isfuzzy(event.clientY, rect.top + 2, window.windowUtils.screenPixelsPerCSSPixel, "Motion y coordinate");
isfuzzy(event.clientX, rect.left + 1, window.devicePixelRatio, "Motion x coordinate");
isfuzzy(event.clientY, rect.top + 2, window.devicePixelRatio, "Motion y coordinate");
done();
}