Bug 1590769 - Scale PiP player window correctly on OS X retina r=mconley
authorMark Striemer <mstriemer@mozilla.com>
Fri, 15 Nov 2019 18:53:13 +0000
changeset 502282 ae8d3569d4b4f2a2877c640bb61d62b14113d43f
parent 502281 c1c84c2869be73727aa38e6220792aa83cb25e6a
child 502283 bd42216f7b6309c683bcc8d9d63c26a834d08d04
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1590769
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1590769 - Scale PiP player window correctly on OS X retina r=mconley Differential Revision: https://phabricator.services.mozilla.com/D53098
toolkit/components/pictureinpicture/PictureInPicture.jsm
--- a/toolkit/components/pictureinpicture/PictureInPicture.jsm
+++ b/toolkit/components/pictureinpicture/PictureInPicture.jsm
@@ -292,22 +292,32 @@ var PictureInPicture = {
       screenWidth = {},
       screenHeight = {};
     screen.GetAvailRectDisplayPix(
       screenLeft,
       screenTop,
       screenWidth,
       screenHeight
     );
+    let fullLeft = {},
+      fullTop = {},
+      fullWidth = {},
+      fullHeight = {};
+    screen.GetRectDisplayPix(fullLeft, fullTop, fullWidth, fullHeight);
 
     // We have to divide these dimensions by the CSS scale factor for the
     // display in order for the video to be positioned correctly on displays
     // that are not at a 1.0 scaling.
-    screenWidth.value = screenWidth.value / screen.defaultCSSScaleFactor;
-    screenHeight.value = screenHeight.value / screen.defaultCSSScaleFactor;
+    let scaleFactor = screen.contentsScaleFactor / screen.defaultCSSScaleFactor;
+    screenWidth.value *= scaleFactor;
+    screenHeight.value *= scaleFactor;
+    screenLeft.value =
+      (screenLeft.value - fullLeft.value) * scaleFactor + fullLeft.value;
+    screenTop.value =
+      (screenTop.value - fullTop.value) * scaleFactor + fullTop.value;
 
     // For now, the Picture in Picture window will be a maximum of a quarter
     // of the screen height, and a third of the screen width.
     const MAX_HEIGHT = screenHeight.value / 4;
     const MAX_WIDTH = screenWidth.value / 3;
 
     let resultWidth = videoWidth;
     let resultHeight = videoHeight;