Bug 574454 - Cleanup nsNativeThemeWin's GetMinimumWidgetSize a bit. r=roc.
authorJim Mathies <jmathies@mozilla.com>
Mon, 09 Aug 2010 20:49:34 -0500
changeset 49248 c051f7df730ef5c21b082f28c1479b016afcf99f
parent 49247 4a345ea809f6f6a859e908bc8bb3e126c169c08e
child 49249 ff19c2e8669545c99eefd70d4315c2f36928cd7e
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs574454
milestone2.0b4pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 574454 - Cleanup nsNativeThemeWin's GetMinimumWidgetSize a bit. r=roc.
widget/src/windows/nsNativeThemeWin.cpp
--- a/widget/src/windows/nsNativeThemeWin.cpp
+++ b/widget/src/windows/nsNativeThemeWin.cpp
@@ -1550,122 +1550,137 @@ nsNativeThemeWin::GetMinimumWidgetSize(n
       return NS_OK; // Don't worry about it for top level menus
 
   if (!nsUXThemeData::getThemePartSize)
     return NS_ERROR_FAILURE;
   
   // Call GetSystemMetrics to determine size for WinXP scrollbars
   // (GetThemeSysSize API returns the optimal size for the theme, but 
   //  Windows appears to always use metrics when drawing standard scrollbars)
+  PRInt32 sizeReq = TS_TRUE; // Best-fit size
   switch (aWidgetType) {
     case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
     case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
     case NS_THEME_SCROLLBAR_BUTTON_UP:
     case NS_THEME_SCROLLBAR_BUTTON_DOWN:
     case NS_THEME_SCROLLBAR_BUTTON_LEFT:
     case NS_THEME_SCROLLBAR_BUTTON_RIGHT:
     case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
     case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
     case NS_THEME_DROPDOWN_BUTTON:
       return ClassicGetMinimumWidgetSize(aContext, aFrame, aWidgetType, aResult, aIsOverridable);
+
     case NS_THEME_MENUITEM:
     case NS_THEME_CHECKMENUITEM:
     case NS_THEME_RADIOMENUITEM:
       if(!IsTopLevelMenu(aFrame))
       {
         SIZE gutterSize(GetGutterSize(theme, NULL));
         aResult->width = gutterSize.cx;
         aResult->height = gutterSize.cy;
         return NS_OK;
       }
       break;
+
     case NS_THEME_MENUIMAGE:
     case NS_THEME_MENUCHECKBOX:
     case NS_THEME_MENURADIO:
       {
         SIZE boxSize(GetGutterSize(theme, NULL));
         aResult->width = boxSize.cx+2;
         aResult->height = boxSize.cy;
         *aIsOverridable = PR_FALSE;
       }
+
     case NS_THEME_MENUITEMTEXT:
       return NS_OK;
+
     case NS_THEME_MENUARROW:
       aResult->width = 26;
       aResult->height = 16;
       return NS_OK;
-  }
+
+    case NS_THEME_PROGRESSBAR:
+    case NS_THEME_PROGRESSBAR_VERTICAL:
+      // Best-fit size for progress meters is too large for most 
+      // themes. We want these widgets to be able to really shrink
+      // down, so use the min-size request value (of 0).
+      sizeReq = TS_MIN; 
+      break;
+
+    case NS_THEME_RESIZER:
+      *aIsOverridable = PR_FALSE;
+      break;
 
-  if (aWidgetType == NS_THEME_RESIZER) {
-    *aIsOverridable = PR_FALSE;
-  }
-  else if (aWidgetType == NS_THEME_SCALE_THUMB_HORIZONTAL ||
-           aWidgetType == NS_THEME_SCALE_THUMB_VERTICAL) {
-    *aIsOverridable = PR_FALSE;
-    // on Vista, GetThemePartAndState returns odd values for
-    // scale thumbs, so use a hardcoded size instead.
-    if (nsUXThemeData::sIsVistaOrLater) {
-      if (aWidgetType == NS_THEME_SCALE_THUMB_HORIZONTAL) {
-        aResult->width = 12;
-        aResult->height = 20;
+    case NS_THEME_SCALE_THUMB_HORIZONTAL:
+    case NS_THEME_SCALE_THUMB_VERTICAL:
+    {
+      *aIsOverridable = PR_FALSE;
+      // on Vista, GetThemePartAndState returns odd values for
+      // scale thumbs, so use a hardcoded size instead.
+      if (nsUXThemeData::sIsVistaOrLater) {
+        if (aWidgetType == NS_THEME_SCALE_THUMB_HORIZONTAL) {
+          aResult->width = 12;
+          aResult->height = 20;
+        }
+        else {
+          aResult->width = 20;
+          aResult->height = 12;
+        }
+        return NS_OK;
       }
-      else {
-        aResult->width = 20;
-        aResult->height = 12;
-      }
-      return NS_OK;
+      break;
     }
-  }
-  else if (aWidgetType == NS_THEME_TOOLBAR_SEPARATOR) {
-    // that's 2px left margin, 2px right margin and 2px separator
-    // (the margin is drawn as part of the separator, though)
-    aResult->width = 6;
-    return NS_OK;
+
+    case NS_THEME_TOOLBAR_SEPARATOR:
+      // that's 2px left margin, 2px right margin and 2px separator
+      // (the margin is drawn as part of the separator, though)
+      aResult->width = 6;
+      return NS_OK;
+
+    case NS_THEME_BUTTON:
+      // We should let HTML buttons shrink to their min size.
+      // FIXME bug 403934: We should probably really separate
+      // GetPreferredWidgetSize from GetMinimumWidgetSize, so callers can
+      // use the one they want.
+      if (aFrame->GetContent()->IsHTML()) {
+        sizeReq = TS_MIN;
+      }
+      break;
   }
 
   PRInt32 part, state;
   nsresult rv = GetThemePartAndState(aFrame, aWidgetType, part, state);
   if (NS_FAILED(rv))
     return rv;
 
   HDC hdc = (HDC)aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_WINDOWS_DC);
   if (!hdc)
     return NS_ERROR_FAILURE;
 
-  PRInt32 sizeReq = 1; // Best-fit size. (TS_TRUE)
-  if (aWidgetType == NS_THEME_PROGRESSBAR ||
-      aWidgetType == NS_THEME_PROGRESSBAR_VERTICAL)
-    sizeReq = 0; // Best-fit size for progress meters is too large for most 
-                 // themes.
-                 // In our app, we want these widgets to be able to really shrink down,
-                 // so use the min-size request value (of 0).
-
-  // We should let HTML buttons shrink to their min size.
-  // FIXME bug 403934: We should probably really separate
-  // GetPreferredWidgetSize from GetMinimumWidgetSize, so callers can
-  // use the one they want.
-  if (aWidgetType == NS_THEME_BUTTON &&
-      aFrame->GetContent()->IsHTML())
-    sizeReq = 0; /* TS_MIN */
-
   SIZE sz;
   nsUXThemeData::getThemePartSize(theme, hdc, part, state, NULL, sizeReq, &sz);
   aResult->width = sz.cx;
   aResult->height = sz.cy;
 
-  if (aWidgetType == NS_THEME_SPINNER_UP_BUTTON ||
-      aWidgetType == NS_THEME_SPINNER_DOWN_BUTTON) {
-    aResult->width++;
-    aResult->height = aResult->height / 2 + 1;
+  switch(aWidgetType) {
+    case NS_THEME_SPINNER_UP_BUTTON:
+    case NS_THEME_SPINNER_DOWN_BUTTON:
+      aResult->width++;
+      aResult->height = aResult->height / 2 + 1;
+      break;
+
+    case NS_THEME_MENUSEPARATOR:
+    {
+      SIZE gutterSize(GetGutterSize(theme,hdc));
+      aResult->width += gutterSize.cx;
+      break;
+    }
   }
-  else if (aWidgetType == NS_THEME_MENUSEPARATOR)
-  {
-    SIZE gutterSize(GetGutterSize(theme,hdc));
-    aResult->width += gutterSize.cx;
-  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNativeThemeWin::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType, 
                                      nsIAtom* aAttribute, PRBool* aShouldRepaint)
 {
   // Some widget types just never change state.