bug 832524 pt 1 - account for resolution-dependent size of menuitem icons in GetGutterSize. r=jimm
authorJonathan Kew <jkew@mozilla.com>
Mon, 01 Apr 2013 10:09:51 +0100
changeset 127240 40cde6c631d3b93c5863b8deae4011d0c61e5a44
parent 127239 eca6757e918af9e8f665e915dcbce400ca823c7d
child 127241 0517b64b90d24b1c654683c2ebc51177f5d377e6
push id1651
push userjandemooij@gmail.com
push dateMon, 01 Apr 2013 19:51:43 +0000
reviewersjimm
bugs832524
milestone22.0a1
bug 832524 pt 1 - account for resolution-dependent size of menuitem icons in GetGutterSize. r=jimm
widget/windows/nsNativeThemeWin.cpp
--- a/widget/windows/nsNativeThemeWin.cpp
+++ b/widget/windows/nsNativeThemeWin.cpp
@@ -196,18 +196,32 @@ GetGutterSize(HANDLE theme, HDC hdc)
     SIZE gutterSize;
     GetThemePartSize(theme, hdc, MENU_POPUPGUTTER, 0, NULL, TS_TRUE, &gutterSize);
 
     SIZE checkboxBGSize(GetCheckboxBGBounds(theme, 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;
     return ret;
 }
 
 /* DrawThemeBGRTLAware - render a theme part based on rtl state.
  * Some widgets are not direction-neutral and need to be drawn reversed for