Bug 1367576 - Refactor to allow for caching of some gtk widget padding/border results. r=karlt
authorL. David Baron <dbaron@dbaron.org>
Tue, 06 Jun 2017 22:27:17 -0700
changeset 362645 db68e1963b3974821cc065440f1b693a82721619
parent 362644 05cb421de1c392e23da293e03dd2d28a3d65457d
child 362646 b8e44a1cb4505c51d398db387c4c1d5c8afc462c
push id31987
push userryanvm@gmail.com
push dateThu, 08 Jun 2017 02:55:14 +0000
treeherdermozilla-central@7efda263a842 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1367576
milestone55.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 1367576 - Refactor to allow for caching of some gtk widget padding/border results. r=karlt This refactors the two nearly-identical callsites into a method so that I can do caching in that method in the next patch. Note that there was a slight difference between them in that the aWidgetFlags parameter to GetGtkWidgetAndState was only passed from one callsite. However, given that the aState parameter is null, this doesn't cause any behavior differences. (Some controls in GetGtkWidgetAndState null-check aWidgetFlags and some don't!) Note also that this makes it always assign a result (often zero). This is fine for both callsites; GetWidgetPadding previously assigned zero right before the call, and GetWidgetBorder did so at the start of the function (and wasn't modified in between, since it was immediately before the switch that the modified code is a case in). MozReview-Commit-ID: IKurwry3UTi
widget/gtk/nsNativeThemeGTK.cpp
widget/gtk/nsNativeThemeGTK.h
--- a/widget/gtk/nsNativeThemeGTK.cpp
+++ b/widget/gtk/nsNativeThemeGTK.cpp
@@ -1253,16 +1253,32 @@ nsNativeThemeGTK::NativeThemeToGtkTheme(
                             &unusedFlags))
   {
     MOZ_ASSERT_UNREACHABLE("Unknown native widget to gtk widget mapping");
     return MOZ_GTK_WINDOW;
   }
   return gtkWidgetType;
 }
 
+void
+nsNativeThemeGTK::GetCachedWidgetBorder(nsIFrame* aFrame, uint8_t aWidgetType,
+                                        GtkTextDirection aDirection,
+                                        nsIntMargin* aResult)
+{
+  aResult->SizeTo(0, 0, 0, 0);
+
+  WidgetNodeType gtkWidgetType;
+  gint unusedFlags;
+  if (GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, nullptr,
+                           &unusedFlags)) {
+    moz_gtk_get_widget_border(gtkWidgetType, &aResult->left, &aResult->top,
+                              &aResult->right, &aResult->bottom, aDirection);
+  }
+}
+
 NS_IMETHODIMP
 nsNativeThemeGTK::GetWidgetBorder(nsDeviceContext* aContext, nsIFrame* aFrame,
                                   uint8_t aWidgetType, nsIntMargin* aResult)
 {
   GtkTextDirection direction = GetTextDirection(aFrame);
   aResult->top = aResult->left = aResult->right = aResult->bottom = 0;
   switch (aWidgetType) {
   case NS_THEME_SCROLLBAR_HORIZONTAL:
@@ -1328,23 +1344,17 @@ nsNativeThemeGTK::GetWidgetBorder(nsDevi
     // For regular menuitems, we will be using GetWidgetPadding instead of
     // GetWidgetBorder to pad up the widget's internals; other menuitems
     // will need to fall through and use the default case as before.
     if (IsRegularMenuItem(aFrame))
       break;
     MOZ_FALLTHROUGH;
   default:
     {
-      WidgetNodeType gtkWidgetType;
-      gint unusedFlags;
-      if (GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, nullptr,
-                               &unusedFlags)) {
-        moz_gtk_get_widget_border(gtkWidgetType, &aResult->left, &aResult->top,
-                                  &aResult->right, &aResult->bottom, direction);
-      }
+      GetCachedWidgetBorder(aFrame, aWidgetType, direction, aResult);
     }
   }
 
   gint scale = ScreenHelperGTK::GetGTKMonitorScaleFactor();
   aResult->top *= scale;
   aResult->right *= scale;
   aResult->bottom *= scale;
   aResult->left *= scale;
@@ -1379,24 +1389,18 @@ nsNativeThemeGTK::GetWidgetPadding(nsDev
     case NS_THEME_MENUITEM:
     case NS_THEME_CHECKMENUITEM:
     case NS_THEME_RADIOMENUITEM:
       {
         // Menubar and menulist have their padding specified in CSS.
         if (!IsRegularMenuItem(aFrame))
           return false;
 
-        aResult->SizeTo(0, 0, 0, 0);
-        WidgetNodeType gtkWidgetType;
-        if (GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, nullptr,
-                                 nullptr)) {
-          moz_gtk_get_widget_border(gtkWidgetType, &aResult->left, &aResult->top,
-                                    &aResult->right, &aResult->bottom,
-                                    GetTextDirection(aFrame));
-        }
+        GetCachedWidgetBorder(aFrame, aWidgetType, GetTextDirection(aFrame),
+                              aResult);
 
         gint horizontal_padding;
 
         if (aWidgetType == NS_THEME_MENUITEM)
           moz_gtk_menuitem_get_horizontal_padding(&horizontal_padding);
         else
           moz_gtk_checkmenuitem_get_horizontal_padding(&horizontal_padding);
 
--- a/widget/gtk/nsNativeThemeGTK.h
+++ b/widget/gtk/nsNativeThemeGTK.h
@@ -83,11 +83,14 @@ private:
                                nsIntMargin* aExtra);
 
   void RefreshWidgetWindow(nsIFrame* aFrame);
   WidgetNodeType NativeThemeToGtkTheme(uint8_t aWidgetType, nsIFrame* aFrame);
 
   uint8_t mDisabledWidgetTypes[32];
   uint8_t mSafeWidgetStates[1024];    // 256 widgets * 32 bits per widget
   static const char* sDisabledEngines[];
+
+  void GetCachedWidgetBorder(nsIFrame* aFrame, uint8_t aWidgetType,
+                             GtkTextDirection aDirection, nsIntMargin* aResult);
 };
 
 #endif