From 67ba68c83eee3a987ff127f9a8d0fa48a0173042 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Mon, 1 Apr 2013 10:09:51 +0100 Subject: [PATCH] bug 832524 pt 1 - account for resolution-dependent size of menuitem icons in GetGutterSize. r=jimm --- widget/windows/nsNativeThemeWin.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/widget/windows/nsNativeThemeWin.cpp b/widget/windows/nsNativeThemeWin.cpp index 2a5f3b125de..25f1c757552 100644 --- a/widget/windows/nsNativeThemeWin.cpp +++ b/widget/windows/nsNativeThemeWin.cpp @@ -201,8 +201,22 @@ GetGutterSize(HANDLE theme, HDC hdc) SIZE itemSize; GetThemePartSize(theme, hdc, MENU_POPUPITEM, MPI_NORMAL, NULL, TS_TRUE, &itemSize); - int width = std::max(itemSize.cx, checkboxBGSize.cx + gutterSize.cx); - int height = std::max(itemSize.cy, checkboxBGSize.cy); + // Figure out how big the menuitem's icon will be (if present) at current DPI + FLOAT scaleFactor = GetDeviceCaps(gfxWindowsPlatform::GetPlatform()->GetScreenDC(), LOGPIXELSY) / 96.0; + int iconDevicePixels = NSToIntRound(16 * scaleFactor); + SIZE iconSize = { + iconDevicePixels, iconDevicePixels + }; + // Not really sure what margins should be used here, but this seems to work in practice... + MARGINS margins = {0}; + GetThemeMargins(theme, hdc, MENU_POPUPCHECKBACKGROUND, MCB_NORMAL, + TMT_CONTENTMARGINS, NULL, &margins); + iconSize.cx += margins.cxLeftWidth + margins.cxRightWidth; + iconSize.cy += margins.cyTopHeight + margins.cyBottomHeight; + + int width = std::max(itemSize.cx, std::max(iconSize.cx, checkboxBGSize.cx) + gutterSize.cx); + int height = std::max(itemSize.cy, std::max(iconSize.cy, checkboxBGSize.cy)); + SIZE ret; ret.cx = width; ret.cy = height;