Bug 1387340 - Ensure popup windows spawned on non-primary windows get a correct scale. r?jfkthame,emk draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 09 Jan 2018 11:19:36 -0500
changeset 717796 b3ae546b473004053d4589899850cf77fc2825a5
parent 717738 6f5fac320fcb6625603fa8a744ffa8523f8b3d71
child 745345 56ca894eea5df2df1c6e0bad41357ace99f6ef2d
push id94778
push userkgupta@mozilla.com
push dateTue, 09 Jan 2018 16:19:57 +0000
reviewersjfkthame, emk
bugs1387340
milestone59.0a1
Bug 1387340 - Ensure popup windows spawned on non-primary windows get a correct scale. r?jfkthame,emk MozReview-Commit-ID: CPKuH0W3KRL
widget/windows/nsWindow.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -842,16 +842,24 @@ nsWindow::Create(nsIWidget* aParent,
                            nullptr,
                            nsToolkit::mDllInstance,
                            nullptr);
 
   if (!mWnd) {
     NS_WARNING("nsWindow CreateWindowEx failed.");
     return NS_ERROR_FAILURE;
   }
+  // If mDefaultScale is set before mWnd has been set, it will have the scale of the
+  // primary monitor, rather than the monitor that the window is actually on. For
+  // non-popup windows this gets corrected by the WM_DPICHANGED message which resets
+  // mDefaultScale, but for popup windows we don't reset mDefaultScale on that message.
+  // In order to ensure that popup windows spawned on a non-primary monitor end up
+  // with the correct scale, we reset mDefaultScale here so that it gets recomputed
+  // using the correct monitor now that we have a mWnd.
+  mDefaultScale = -1.0;
 
   if (mIsRTL) {
     DWORD dwAttribute = TRUE;    
     DwmSetWindowAttribute(mWnd, DWMWA_NONCLIENT_RTL_LAYOUT, &dwAttribute, sizeof dwAttribute);
   }
 
   if (mOpeningAnimationSuppressed) {
     SuppressAnimation(true);