Bug 1287734 - Make nsWindowWatcher::SizeOpenedDocShellItem use global desktop coordinates to position the window, for reliable placement on mixed-resolution Mac systems. r=emk
authorJonathan Kew <jkew@mozilla.com>
Tue, 19 Jul 2016 14:17:25 +0100
changeset 305515 6f91113b1bc9e3b3c0a2c4d0e91ec4d7159d84d8
parent 305514 3996c602754f1653b9affb07485ad641189cc771
child 305516 7bfa8f091fcc2b1755b5a8eaae50f4cf59870a55
push id79608
push userjkew@mozilla.com
push dateTue, 19 Jul 2016 13:17:49 +0000
treeherdermozilla-inbound@6f91113b1bc9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1287734
milestone50.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 1287734 - Make nsWindowWatcher::SizeOpenedDocShellItem use global desktop coordinates to position the window, for reliable placement on mixed-resolution Mac systems. r=emk
embedding/components/windowwatcher/nsWindowWatcher.cpp
--- a/embedding/components/windowwatcher/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/nsWindowWatcher.cpp
@@ -2249,23 +2249,27 @@ nsWindowWatcher::SizeOpenedDocShellItem(
     // positioning on.
     nsCOMPtr<nsIScreen> screen;
     nsCOMPtr<nsIScreenManager> screenMgr(
       do_GetService("@mozilla.org/gfx/screenmanager;1"));
     if (screenMgr) {
       screenMgr->ScreenForRect(left, top, 1, 1, getter_AddRefs(screen));
     }
     if (screen) {
-      screen->GetDefaultCSSScaleFactor(&scale);
+      double cssToDevPixScale, desktopToDevPixScale;
+      screen->GetDefaultCSSScaleFactor(&cssToDevPixScale);
+      screen->GetContentsScaleFactor(&desktopToDevPixScale);
+      double cssToDesktopScale = cssToDevPixScale / desktopToDevPixScale;
       int32_t screenLeft, screenTop, screenWd, screenHt;
       screen->GetRectDisplayPix(&screenLeft, &screenTop, &screenWd, &screenHt);
-      // Adjust by desktop-pixel origin of the target screen to convert from
-      // per-screen CSS-px coordinates.
-      treeOwnerAsWin->SetPosition((left - screenLeft) * scale + screenLeft,
-                                  (top - screenTop) * scale + screenTop);
+      // Adjust by desktop-pixel origin of the target screen when scaling
+      // to convert from per-screen CSS-px coords to global desktop coords.
+      treeOwnerAsWin->SetPositionDesktopPix(
+        (left - screenLeft) * cssToDesktopScale + screenLeft,
+        (top - screenTop) * cssToDesktopScale + screenTop);
     } else {
       // Couldn't find screen? This shouldn't happen.
       treeOwnerAsWin->SetPosition(left * scale, top * scale);
     }
     // This shouldn't be necessary, given the screen check above, but in case
     // moving the window didn't put it where we expected (e.g. due to issues
     // at the widget level, or whatever), let's re-fetch the scale factor for
     // wherever it really ended up