Bug 1288696 - Move MenuSeparatorWidget to WidgetCache, r=acomminos
authorMartin Stransky <stransky@redhat.com>
Mon, 25 Jul 2016 05:40:00 +0200
changeset 331758 8f5b78b3d9189cc84a6f22da08a0683a190112f9
parent 331757 cd7544affe40f0ed80059a7b22e2fed6639019d8
child 331759 5db66203614e7591bf7bfb2de3f802f144ae139c
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersacomminos
bugs1288696
milestone50.0a1
Bug 1288696 - Move MenuSeparatorWidget to WidgetCache, r=acomminos
widget/gtk/WidgetStyleCache.cpp
widget/gtk/gtk3drawing.cpp
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -220,16 +220,27 @@ CreateTextViewWidget()
 {
   GtkWidget* widget = gtk_text_view_new();
   gtk_container_add(GTK_CONTAINER(GetWidget(MOZ_GTK_SCROLLED_WINDOW)),
                     widget);
   return widget;
 }
 
 static GtkWidget*
+CreateMenuSeparatorWidget()
+{
+  GtkWidget* widget = gtk_separator_menu_item_new();
+  gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)),
+                        widget);
+  gtk_widget_realize(widget);
+  return widget;
+}
+
+
+static GtkWidget*
 CreateWidget(WidgetNodeType aWidgetType)
 {
   switch (aWidgetType) {
     case MOZ_GTK_WINDOW:
       return CreateWindowWidget();
     case MOZ_GTK_WINDOW_CONTAINER:
       return CreateWindowContainerWidget();
     case MOZ_GTK_CHECKBUTTON_CONTAINER:
@@ -247,16 +258,18 @@ CreateWidget(WidgetNodeType aWidgetType)
     case MOZ_GTK_MENUBAR:
       return CreateMenuBarWidget();
     case MOZ_GTK_MENUPOPUP:
       return CreateMenuPopupWidget();
     case MOZ_GTK_MENUBARITEM:
       return CreateMenuItemWidget(MOZ_GTK_MENUBAR);
     case MOZ_GTK_MENUITEM:
       return CreateMenuItemWidget(MOZ_GTK_MENUPOPUP);
+    case MOZ_GTK_MENUSEPARATOR:
+      return CreateMenuSeparatorWidget();
     case MOZ_GTK_EXPANDER:
       return CreateExpanderWidget();
     case MOZ_GTK_FRAME:
       return CreateFrameWidget();
     case MOZ_GTK_GRIPPER:
       return CreateGripperWidget();
     case MOZ_GTK_TOOLBAR:
       return CreateToolbarWidget();
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -31,17 +31,16 @@ static GtkWidget* gComboBoxEntryButtonWi
 static GtkWidget* gComboBoxEntryArrowWidget;
 static GtkWidget* gTabWidget;
 static GtkWidget* gImageMenuItemWidget;
 static GtkWidget* gCheckMenuItemWidget;
 static GtkWidget* gTreeViewWidget;
 static GtkTreeViewColumn* gMiddleTreeViewColumn;
 static GtkWidget* gTreeHeaderCellWidget;
 static GtkWidget* gTreeHeaderSortArrowWidget;
-static GtkWidget* gMenuSeparatorWidget;
 static GtkWidget* gHPanedWidget;
 static GtkWidget* gVPanedWidget;
 
 static style_prop_t style_prop_func;
 static gboolean have_arrow_scaling;
 static gboolean checkbox_check_state;
 static gboolean notebook_has_tab_gap;
 static gboolean is_initialized;
@@ -339,28 +338,16 @@ ensure_image_menu_item_widget()
         gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)),
                               gImageMenuItemWidget);
         gtk_widget_realize(gImageMenuItemWidget);
     }
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
-ensure_menu_separator_widget()
-{
-    if (!gMenuSeparatorWidget) {
-        gMenuSeparatorWidget = gtk_separator_menu_item_new();
-        gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)),
-                              gMenuSeparatorWidget);
-        gtk_widget_realize(gMenuSeparatorWidget);
-    }
-    return MOZ_GTK_SUCCESS;
-}
-
-static gint
 ensure_check_menu_item_widget()
 {
     if (!gCheckMenuItemWidget) {
         gCheckMenuItemWidget = gtk_check_menu_item_new();
         gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)),
                               gCheckMenuItemWidget);
         gtk_widget_realize(gCheckMenuItemWidget);
     }
@@ -2111,22 +2098,20 @@ moz_gtk_menu_separator_paint(cairo_t *cr
 {
     GtkStyleContext* style;
     gboolean wide_separators;
     gint separator_height;
     guint border_width;
     gint x, y, w;
     GtkBorder padding;
 
-    ensure_menu_separator_widget();
-    gtk_widget_set_direction(gMenuSeparatorWidget, direction);
-
-    border_width = gtk_container_get_border_width(GTK_CONTAINER(gMenuSeparatorWidget));
-
-    style = gtk_widget_get_style_context(gMenuSeparatorWidget);
+    border_width =
+        gtk_container_get_border_width(GTK_CONTAINER(
+                                       GetWidget(MOZ_GTK_MENUSEPARATOR)));
+    style = ClaimStyleContext(MOZ_GTK_MENUSEPARATOR, direction);
     gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
 
     x = rect->x + border_width;
     y = rect->y + border_width;
     w = rect->width - border_width * 2;
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_SEPARATOR);
@@ -2146,16 +2131,17 @@ moz_gtk_menu_separator_paint(cairo_t *cr
       gtk_render_line(style, cr,
                       x + padding.left,
                       y + padding.top,
                       x + w - padding.right - 1,
                       y + padding.top);
     }
 
     gtk_style_context_restore(style);
+    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 // See gtk_menu_item_draw() for reference.
 static gint
 moz_gtk_menu_item_paint(WidgetNodeType widget, cairo_t *cr, GdkRectangle* rect,
                         GtkWidgetState* state, GtkTextDirection direction)
@@ -2690,32 +2676,33 @@ gint
 moz_gtk_get_menu_separator_height(gint *size)
 {
     gboolean  wide_separators;
     gint      separator_height;
     GtkBorder padding;
     GtkStyleContext* style;
     guint border_width;
 
-    ensure_menu_separator_widget();
-
-    border_width = gtk_container_get_border_width(GTK_CONTAINER(gMenuSeparatorWidget));
-
-    style = gtk_widget_get_style_context(gMenuSeparatorWidget);
+    border_width =
+        gtk_container_get_border_width(GTK_CONTAINER(
+                                       GetWidget(MOZ_GTK_MENUSEPARATOR)));
+
+    style = ClaimStyleContext(MOZ_GTK_MENUSEPARATOR);
     gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_SEPARATOR);
 
     gtk_style_context_get_style(style,
                                 "wide-separators",  &wide_separators,
                                 "separator-height", &separator_height,
                                 NULL);
 
     gtk_style_context_restore(style);
+    ReleaseStyleContext(style);
 
     *size = padding.top + padding.bottom + border_width*2;
     *size += (wide_separators) ? separator_height : 1;
 
     return MOZ_GTK_SUCCESS;
 }
 
 void
@@ -3077,16 +3064,15 @@ moz_gtk_shutdown()
     gComboBoxEntryTextareaWidget = NULL;
     gTabWidget = NULL;
     gImageMenuItemWidget = NULL;
     gCheckMenuItemWidget = NULL;
     gTreeViewWidget = NULL;
     gMiddleTreeViewColumn = NULL;
     gTreeHeaderCellWidget = NULL;
     gTreeHeaderSortArrowWidget = NULL;
-    gMenuSeparatorWidget = NULL;
     gHPanedWidget = NULL;
     gVPanedWidget = NULL;
 
     is_initialized = FALSE;
 
     return MOZ_GTK_SUCCESS;
 }