Bug 1173617. Don't cache titlebar caption sizes unless the widget has a titlebar. r=jimm
authorMason Chang <mchang@mozilla.com>
Mon, 15 Jun 2015 08:53:20 -0700
changeset 279660 8f567d41d84914ced019ff57d03f3f87dba4517b
parent 279659 bd11384b3241596c4ab1b4bb95a0fecbbaaf811d
child 279661 758269f1463cf81ac344cca34ca942f13c204d50
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1173617
milestone41.0a1
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 1173617. Don't cache titlebar caption sizes unless the widget has a titlebar. r=jimm
widget/windows/nsUXThemeData.cpp
widget/windows/nsWindow.cpp
--- a/widget/windows/nsUXThemeData.cpp
+++ b/widget/windows/nsUXThemeData.cpp
@@ -25,17 +25,18 @@ nsUXThemeData::sThemes[eUXNumClasses];
 HMODULE
 nsUXThemeData::sThemeDLL = nullptr;
 
 bool
 nsUXThemeData::sFlatMenus = false;
 
 bool nsUXThemeData::sTitlebarInfoPopulatedAero = false;
 bool nsUXThemeData::sTitlebarInfoPopulatedThemed = false;
-SIZE nsUXThemeData::sCommandButtons[4];
+const int NUM_COMMAND_BUTTONS = 4;
+SIZE nsUXThemeData::sCommandButtons[NUM_COMMAND_BUTTONS];
 
 void
 nsUXThemeData::Teardown() {
   Invalidate();
   if(sThemeDLL)
     FreeLibrary(sThemeDLL);
 }
 
@@ -216,16 +217,25 @@ nsUXThemeData::UpdateTitlebarInfo(HWND a
   sCommandButtons[0].cy = info.rgrect[2].bottom - info.rgrect[2].top;
   // maximize/restore
   sCommandButtons[1].cx = info.rgrect[3].right - info.rgrect[3].left;
   sCommandButtons[1].cy = info.rgrect[3].bottom - info.rgrect[3].top;
   // close
   sCommandButtons[2].cx = info.rgrect[5].right - info.rgrect[5].left;
   sCommandButtons[2].cy = info.rgrect[5].bottom - info.rgrect[5].top;
 
+#ifdef DEBUG
+  // Verify that all values for the command buttons are positive values
+  // otherwise we have cached bad values for the caption buttons
+  for (int i = 0; i < NUM_COMMAND_BUTTONS; i++) {
+    MOZ_ASSERT(sCommandButtons[i].cx > 0);
+    MOZ_ASSERT(sCommandButtons[i].cy > 0);
+  }
+#endif
+
   sTitlebarInfoPopulatedThemed = true;
 }
 
 // visual style (aero glass, aero basic)
 //    theme (aero, luna, zune)
 //      theme color (silver, olive, blue)
 //        system colors
 
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -453,16 +453,26 @@ NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, n
 
 // Allow Derived classes to modify the height that is passed
 // when the window is created or resized.
 int32_t nsWindow::GetHeight(int32_t aProposedHeight)
 {
   return aProposedHeight;
 }
 
+static bool
+ShouldCacheTitleBarInfo(nsWindowType aWindowType, nsBorderStyle aBorderStyle)
+{
+  return (aWindowType == eWindowType_toplevel)  &&
+         (aBorderStyle == eBorderStyle_default  ||
+            aBorderStyle == eBorderStyle_all)   &&
+      (!nsUXThemeData::sTitlebarInfoPopulatedThemed ||
+       !nsUXThemeData::sTitlebarInfoPopulatedAero);
+}
+
 // Create the proper widget
 nsresult
 nsWindow::Create(nsIWidget *aParent,
                  nsNativeWidget aNativeParent,
                  const nsIntRect &aRect,
                  nsWidgetInitData *aInitData)
 {
   nsWidgetInitData defaultInitData;
@@ -640,20 +650,18 @@ nsWindow::Create(nsIWidget *aParent,
     sTrimOnMinimize =
       Preferences::GetBool("config.trim_on_minimize",
         IsVistaOrLater() ? 1 : 0);
     sSwitchKeyboardLayout =
       Preferences::GetBool("intl.keyboard.per_window_layout", false);
   }
 
   // Query for command button metric data for rendering the titlebar. We
-  // only do this once on the first window.
-  if (mWindowType == eWindowType_toplevel &&
-      (!nsUXThemeData::sTitlebarInfoPopulatedThemed ||
-       !nsUXThemeData::sTitlebarInfoPopulatedAero)) {
+  // only do this once on the first window that has an actual titlebar
+  if (ShouldCacheTitleBarInfo(mWindowType, mBorderStyle)) {
     nsUXThemeData::UpdateTitlebarInfo(mWnd);
   }
 
   return NS_OK;
 }
 
 // Close this nsWindow
 NS_METHOD nsWindow::Destroy()