bug 1234158 share code to check and set sWidgetStorage r?stransky draft
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 05 May 2016 15:26:44 +1200
changeset 363585 6d0d926d89504a95dd38505d6d346e47458e08fd
parent 363517 a0b1359dba81dab40e76a51f0bc7f136ac05b29d
child 520082 39923818cbd9941e97971f7065cea5c2f6e6ee0c
push id17250
push userktomlinson@mozilla.com
push dateThu, 05 May 2016 03:33:23 +0000
reviewersstransky
bugs1234158
milestone48.0a1
bug 1234158 share code to check and set sWidgetStorage r?stransky With array-based storage, it is easier to share this code and simply widget creation functions. MozReview-Commit-ID: ICWFN57AF8g
widget/gtk/WidgetStyleCache.cpp
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -19,77 +19,76 @@ static GtkStyleContext* sStyleStorage[MO
 
 static bool sStyleContextNeedsRestore;
 static GtkStyleContext* sCurrentStyleContext;
 
 static GtkStyleContext*
 GetStyleInternal(WidgetNodeType aNodeType);
 
 static GtkWidget*
-GetWindowWidget()
+CreateWindowWidget()
 {
-  static GtkWidget *widget = sWidgetStorage[MOZ_GTK_WINDOW];
-  if (!widget) {
-    widget = gtk_window_new(GTK_WINDOW_POPUP);
-    gtk_widget_realize(widget);
-    gtk_widget_set_name(widget, "MozillaGtkWidget");
-    sWidgetStorage[MOZ_GTK_WINDOW] = widget;
-  }
+  GtkWidget *widget = gtk_window_new(GTK_WINDOW_POPUP);
+  gtk_widget_realize(widget);
+  gtk_widget_set_name(widget, "MozillaGtkWidget");
   return widget;
 }
 
 static GtkWidget*
-GetWindowContainerWidget()
+CreateWindowContainerWidget()
 {
-  static GtkWidget *widget = sWidgetStorage[MOZ_GTK_WINDOW_CONTAINER];
-  if (!widget) {
-    widget = gtk_fixed_new();
-    gtk_container_add(GTK_CONTAINER(GetWindowWidget()), widget);
-    sWidgetStorage[MOZ_GTK_WINDOW_CONTAINER] = widget;
-  }
+  GtkWidget *widget = gtk_fixed_new();
+  gtk_container_add(GTK_CONTAINER(GetWidget(MOZ_GTK_WINDOW)), widget);
   return widget;
 }
 
 static void
 AddToWindowContainer(GtkWidget* widget)
 {
-  gtk_container_add(GTK_CONTAINER(GetWindowContainerWidget()), widget);
+  gtk_container_add(GTK_CONTAINER(GetWidget(MOZ_GTK_WINDOW_CONTAINER)), widget);
   gtk_widget_realize(widget);
 }
 
 static GtkWidget*
-GetScrollbarWidget(WidgetNodeType aWidgetType, GtkOrientation aOrientation)
+CreateScrollbarWidget(WidgetNodeType aWidgetType, GtkOrientation aOrientation)
+{
+  GtkWidget* widget = gtk_scrollbar_new(aOrientation, nullptr);
+  AddToWindowContainer(widget);
+  return widget;
+}
+
+static GtkWidget*
+CreateWidget(WidgetNodeType aWidgetType)
 {
-  GtkWidget* widget = sWidgetStorage[aWidgetType];
-  if (!widget) {
-    widget = gtk_scrollbar_new(aOrientation, nullptr);
-    AddToWindowContainer(widget);
-    sWidgetStorage[aWidgetType] = widget;
+  switch (aWidgetType) {
+    case MOZ_GTK_WINDOW:
+      return CreateWindowWidget();
+    case MOZ_GTK_WINDOW_CONTAINER:
+      return CreateWindowContainerWidget();
+    case MOZ_GTK_SCROLLBAR_HORIZONTAL:
+      return CreateScrollbarWidget(aWidgetType,
+                                   GTK_ORIENTATION_HORIZONTAL);
+    case MOZ_GTK_SCROLLBAR_VERTICAL:
+      return CreateScrollbarWidget(aWidgetType,
+                                   GTK_ORIENTATION_VERTICAL);
+    default:
+      /* Not implemented */
+      return nullptr;
   }
-  return widget;
 }
 
 GtkWidget*
 GetWidget(WidgetNodeType aWidgetType)
 {
-  switch (aWidgetType) {
-    case MOZ_GTK_WINDOW:
-      return GetWindowWidget();
-    case MOZ_GTK_WINDOW_CONTAINER:
-      return GetWindowContainerWidget();
-    case MOZ_GTK_SCROLLBAR_HORIZONTAL:
-      return GetScrollbarWidget(aWidgetType,
-                                GTK_ORIENTATION_HORIZONTAL);
-    case MOZ_GTK_SCROLLBAR_VERTICAL:
-      return GetScrollbarWidget(aWidgetType,
-                                GTK_ORIENTATION_VERTICAL);
-    default:
-      /* Not implemented */
-      return nullptr;
+  GtkWidget* widget = sWidgetStorage[aWidgetType];
+  if (!widget) {
+    widget = CreateWidget(aWidgetType);
+    sWidgetStorage[aWidgetType] = widget;
   }
+  return widget;
 }
 
 static GtkStyleContext*
 CreateCSSNode(const char* aName, GtkStyleContext *aParentStyle)
 {
   static auto sGtkWidgetPathIterSetObjectName =
     reinterpret_cast<void (*)(GtkWidgetPath *, gint, const char *)>
     (dlsym(RTLD_DEFAULT, "gtk_widget_path_iter_set_object_name"));