Bug 1302168: Fix maximized caption height with per-monitor DPI r=jmathies

Differential Revision: https://phabricator.services.mozilla.com/D4957

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Adam Gashlin 2018-09-26 15:40:48 +00:00
Родитель 177b10d96f
Коммит c4b29e1ba9
3 изменённых файлов: 44 добавлений и 3 удалений

Просмотреть файл

@ -433,6 +433,7 @@ struct CoTaskMemFreePolicy
SetThreadDpiAwarenessContextProc WinUtils::sSetThreadDpiAwarenessContext = NULL;
EnableNonClientDpiScalingProc WinUtils::sEnableNonClientDpiScaling = NULL;
GetSystemMetricsForDpiProc WinUtils::sGetSystemMetricsForDpi = NULL;
/* static */
void
@ -454,6 +455,9 @@ WinUtils::Initialize()
sSetThreadDpiAwarenessContext = (SetThreadDpiAwarenessContextProc)
::GetProcAddress(user32Dll, "SetThreadDpiAwarenessContext");
}
sGetSystemMetricsForDpi = (GetSystemMetricsForDpiProc)
::GetProcAddress(user32Dll, "GetSystemMetricsForDpi");
}
}
}
@ -671,6 +675,27 @@ WinUtils::MonitorFromRect(const gfx::Rect& rect)
return ::MonitorFromRect(&globalWindowBounds, MONITOR_DEFAULTTONEAREST);
}
/* static */
bool
WinUtils::HasSystemMetricsForDpi()
{
return (sGetSystemMetricsForDpi != NULL);
}
/* static */
int
WinUtils::GetSystemMetricsForDpi(int nIndex, UINT dpi)
{
if (HasSystemMetricsForDpi()) {
return sGetSystemMetricsForDpi(nIndex, dpi);
} else {
double scale = IsPerMonitorDPIAware()
? dpi / SystemDPI()
: 1.0;
return NSToIntRound(::GetSystemMetrics(nIndex) * scale);
}
}
#ifdef ACCESSIBILITY
/* static */
a11y::Accessible*

Просмотреть файл

@ -103,6 +103,7 @@ AreDpiAwarenessContextsEqual(DPI_AWARENESS_CONTEXT, DPI_AWARENESS_CONTEXT);
#endif /* WINVER < 0x0605 */
typedef DPI_AWARENESS_CONTEXT(WINAPI * SetThreadDpiAwarenessContextProc)(DPI_AWARENESS_CONTEXT);
typedef BOOL(WINAPI * EnableNonClientDpiScalingProc)(HWND);
typedef int (WINAPI * GetSystemMetricsForDpiProc)(int, UINT);
namespace mozilla {
enum class PointerCapabilities : uint8_t;
@ -163,6 +164,7 @@ class WinUtils
// the Win10 update version -- will be set up in Initialize().
static SetThreadDpiAwarenessContextProc sSetThreadDpiAwarenessContext;
static EnableNonClientDpiScalingProc sEnableNonClientDpiScaling;
static GetSystemMetricsForDpiProc sGetSystemMetricsForDpi;
public:
class AutoSystemDpiAware
@ -227,6 +229,9 @@ public:
static HMONITOR GetPrimaryMonitor();
static HMONITOR MonitorFromRect(const gfx::Rect& rect);
static bool HasSystemMetricsForDpi();
static int GetSystemMetricsForDpi(int nIndex, UINT dpi);
/**
* Logging helpers that dump output to prlog module 'Widget', console, and
* OutputDebugString. Note these output in both debug and release builds.

Просмотреть файл

@ -2168,9 +2168,20 @@ nsNativeThemeWin::GetWidgetPadding(nsDeviceContext* aContext,
// XXX Maximized windows have an offscreen offset equal to
// the border padding. This should be addressed in nsWindow,
// but currently can't be, see UpdateNonClientMargins.
if (aWidgetType == StyleAppearance::MozWindowTitlebarMaximized)
aResult->top = GetSystemMetrics(SM_CXFRAME)
+ GetSystemMetrics(SM_CXPADDEDBORDER);
if (aWidgetType == StyleAppearance::MozWindowTitlebarMaximized) {
nsIWidget* rootWidget = nullptr;
if (WinUtils::HasSystemMetricsForDpi()) {
rootWidget = aFrame->PresContext()->GetRootWidget();
}
if (rootWidget) {
double dpi = rootWidget->GetDPI();
aResult->top = WinUtils::GetSystemMetricsForDpi(SM_CXFRAME, dpi)
+ WinUtils::GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi);
} else {
aResult->top = GetSystemMetrics(SM_CXFRAME)
+ GetSystemMetrics(SM_CXPADDEDBORDER);
}
}
return ok;
}