Bug 1270954 - When Win10 Anniversary Update APIs are available, enable automatic scaling of the non-client area when a window is on a secondary display with different DPI. r=emk, a=kwierso
authorJonathan Kew <jkew@mozilla.com>
Thu, 14 Jul 2016 17:46:26 +0100
changeset 330204 b1d95b24cade1b252b61cb2f6718724f343a68eb
parent 330203 2c0a0814add06997075c3326e399466555ee7e3f
child 330205 d1626b1814ae065d49d9504865884064cfcbfaae
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk, kwierso
bugs1270954
milestone50.0a1
Bug 1270954 - When Win10 Anniversary Update APIs are available, enable automatic scaling of the non-client area when a window is on a secondary display with different DPI. r=emk, a=kwierso
widget/windows/WinUtils.cpp
widget/windows/WinUtils.h
widget/windows/nsWindow.cpp
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -483,16 +483,27 @@ WinUtils::Initialize()
         ::GetProcAddress(user32Dll, "EnableNonClientDpiScaling");
       sSetThreadDpiAwarenessContext = (SetThreadDpiAwarenessContextProc)
         ::GetProcAddress(user32Dll, "SetThreadDpiAwarenessContext");
     }
   }
 }
 
 // static
+LRESULT WINAPI
+WinUtils::NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg,
+                                            WPARAM wParam, LPARAM lParam)
+{
+  if (msg == WM_NCCREATE && sEnableNonClientDpiScaling) {
+    sEnableNonClientDpiScaling(hWnd);
+  }
+  return ::DefWindowProcW(hWnd, msg, wParam, lParam);
+}
+
+// static
 void
 WinUtils::LogW(const wchar_t *fmt, ...)
 {
   va_list args = nullptr;
   if(!lstrlenW(fmt)) {
     return;
   }
   va_start(args, fmt);
--- a/widget/windows/WinUtils.h
+++ b/widget/windows/WinUtils.h
@@ -169,16 +169,22 @@ public:
         sSetThreadDpiAwarenessContext(mPrevContext);
       }
     }
 
   private:
     DPI_AWARENESS_CONTEXT mPrevContext;
   };
 
+  // Wrapper for DefWindowProc that will enable non-client dpi scaling on the
+  // window during creation.
+  static LRESULT WINAPI
+  NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg,
+                                    WPARAM wParam, LPARAM lParam);
+
   /**
    * Get the system's default logical-to-physical DPI scaling factor,
    * which is based on the primary display. Note however that unlike
    * LogToPhysFactor(GetPrimaryMonitor()), this will not change during
    * a session even if the displays are reconfigured. This scale factor
    * is used by Windows theme metrics etc, which do not fully support
    * dynamic resolution changes but are only updated on logout.
    */
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -794,17 +794,17 @@ nsWindow::RegisterWindowClass(const wcha
 {
   WNDCLASSW wc;
   if (::GetClassInfoW(nsToolkit::mDllInstance, aClassName, &wc)) {
     // already registered
     return aClassName;
   }
 
   wc.style         = CS_DBLCLKS | aExtraStyle;
-  wc.lpfnWndProc   = ::DefWindowProcW;
+  wc.lpfnWndProc   = WinUtils::NonClientDpiScalingDefWindowProcW;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = nsToolkit::mDllInstance;
   wc.hIcon         = aIconID ? ::LoadIconW(::GetModuleHandleW(nullptr), aIconID) : nullptr;
   wc.hCursor       = nullptr;
   wc.hbrBackground = mBrush;
   wc.lpszMenuName  = nullptr;
   wc.lpszClassName = aClassName;