Bug 1287085 - Move GtkInfoBar from gtk3drawing to WidgetCache. r=acomminos
authorMartin Stransky <stransky@redhat.com>
Tue, 19 Jul 2016 00:03:00 -0400
changeset 305915 efb4af0a5b7550d9d2efbb126df62c75a3082be2
parent 305914 8ad0c8d5de33527f66ff9d42aab4ed6ab55feecc
child 305916 f90a9f8af37c202842f5d9c5b2928004124ab5e1
push id30474
push usercbook@mozilla.com
push dateThu, 21 Jul 2016 14:25:10 +0000
treeherdermozilla-central@6b180266ac16 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersacomminos
bugs1287085
milestone50.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 1287085 - Move GtkInfoBar from gtk3drawing to WidgetCache. r=acomminos
widget/gtk/WidgetStyleCache.cpp
widget/gtk/gtk3drawing.cpp
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -153,16 +153,24 @@ static GtkWidget*
 CreateToolbarSeparatorWidget()
 {
   GtkWidget* widget = GTK_WIDGET(gtk_separator_tool_item_new());
   AddToWindowContainer(widget);
   return widget;
 }
 
 static GtkWidget*
+CreateInfoBarWidget()
+{
+  GtkWidget* widget = gtk_info_bar_new();
+  AddToWindowContainer(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:
@@ -190,16 +198,18 @@ CreateWidget(WidgetNodeType aWidgetType)
     case MOZ_GTK_FRAME:
       return CreateFrameWidget();
     case MOZ_GTK_GRIPPER:
       return CreateGripperWidget();
     case MOZ_GTK_TOOLBAR:
       return CreateToolbarWidget();
     case MOZ_GTK_TOOLBAR_SEPARATOR:
       return CreateToolbarSeparatorWidget();
+    case MOZ_GTK_INFO_BAR:
+      return CreateInfoBarWidget();
     default:
       /* Not implemented */
       return nullptr;
   }
 }
 
 GtkWidget*
 GetWidget(WidgetNodeType aWidgetType)
@@ -330,16 +340,20 @@ GetCssNodeStyleInternal(WidgetNodeType a
       // We create this from the path because GtkTooltipWindow is not public.
       style = CreateCSSNode("tooltip", nullptr, GTK_TYPE_TOOLTIP);
       gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
       break; 
     case MOZ_GTK_GRIPPER:
       // TODO - create from CSS node
       return GetWidgetStyleWithClass(MOZ_GTK_GRIPPER,
                                      GTK_STYLE_CLASS_GRIP);
+    case MOZ_GTK_INFO_BAR:
+      // TODO - create from CSS node
+      return GetWidgetStyleWithClass(MOZ_GTK_INFO_BAR,
+                                     GTK_STYLE_CLASS_INFO);
     default:
       // TODO - create style from style path
       GtkWidget* widget = GetWidget(aNodeType);
       return gtk_widget_get_style_context(widget);
   }
 
   MOZ_ASSERT(style, "missing style context for node type");
   sStyleStorage[aNodeType] = style;
@@ -384,16 +398,19 @@ GetWidgetStyleInternal(WidgetNodeType aN
       style = CreateStyleForWidget(tooltipWindow, nullptr);
       gtk_widget_destroy(tooltipWindow); // Release GtkWindow self-reference.
       sStyleStorage[aNodeType] = style;
       return style;
     }
     case MOZ_GTK_GRIPPER:
       return GetWidgetStyleWithClass(MOZ_GTK_GRIPPER,
                                      GTK_STYLE_CLASS_GRIP);
+    case MOZ_GTK_INFO_BAR:
+      return GetWidgetStyleWithClass(MOZ_GTK_INFO_BAR,
+                                     GTK_STYLE_CLASS_INFO);
     default:
       GtkWidget* widget = GetWidget(aNodeType);
       MOZ_ASSERT(widget);
       return gtk_widget_get_style_context(widget);
   }
 }
 
 void
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -41,17 +41,16 @@ 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 GtkWidget* gScrolledWindowWidget;
-static GtkWidget* gInfoBar;
 
 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;
 
 #define ARROW_UP      0
@@ -281,25 +280,16 @@ ensure_combo_box_widgets()
 
     /* We don't test the validity of gComboBoxSeparatorWidget since there
      * is none when "appears-as-list" = TRUE or "cell-view" = FALSE; if it
      * is invalid we just won't paint it. */
 
     return MOZ_GTK_SUCCESS;
 }
 
-static void
-ensure_info_bar()
-{
-  if (!gInfoBar) {
-      gInfoBar = gtk_info_bar_new();
-      setup_widget_prototype(gInfoBar);
-  }
-}
-
 /* We need to have pointers to the inner widgets (entry, button, arrow) of
  * the ComboBoxEntry to get the correct rendering from theme engines which
  * special cases their look. Since the inner layout can change, we ask GTK
  * to NULL our pointers when they are about to become invalid because the
  * corresponding widgets don't exist anymore. It's the role of
  * g_object_add_weak_pointer().
  * Note that if we don't find the inner widgets (which shouldn't happen), we
  * fallback to use generic "non-inner" widgets, and they don't need that kind
@@ -2411,31 +2401,23 @@ moz_gtk_check_menu_item_paint(cairo_t *c
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_info_bar_paint(cairo_t *cr, GdkRectangle* rect,
                        GtkWidgetState* state)
 {
-    GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
-    GtkStyleContext *style;
-    ensure_info_bar();
-
-    style = gtk_widget_get_style_context(gInfoBar);
-    gtk_style_context_save(style);
-
-    gtk_style_context_set_state(style, state_flags);
-    gtk_style_context_add_class(style, GTK_STYLE_CLASS_INFO);
-
+    GtkStyleContext *style =
+        ClaimStyleContext(MOZ_GTK_INFO_BAR, GTK_TEXT_DIR_LTR,
+                          GetStateFlagsFromGtkWidgetState(state));
     gtk_render_background(style, cr, rect->x, rect->y, rect->width,
                           rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
-
-    gtk_style_context_restore(style);
+    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static void
 moz_gtk_add_style_border(GtkStyleContext* style,
                          gint* left, gint* top, gint* right, gint* bottom)
 {
@@ -2647,18 +2629,17 @@ moz_gtk_get_widget_border(WidgetNodeType
             }
 
             *left = *top = *right = *bottom = gtk_container_get_border_width(GTK_CONTAINER(w));
             moz_gtk_add_style_padding(gtk_widget_get_style_context(w),
                                       left, top, right, bottom);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_INFO_BAR:
-        ensure_info_bar();
-        w = gInfoBar;
+        w = GetWidget(MOZ_GTK_INFO_BAR);
         break;
     case MOZ_GTK_TOOLTIP:
         {
             style = ClaimStyleContext(MOZ_GTK_TOOLTIP);
             moz_gtk_add_style_border(style, left, top, right, bottom);
             moz_gtk_add_style_padding(style, left, top, right, bottom);
             ReleaseStyleContext(style);
             return MOZ_GTK_SUCCESS;
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1352,16 +1352,17 @@ nsLookAndFeel::Init()
     GtkWidget *frame = gtk_frame_new(nullptr);
     gtk_container_add(GTK_CONTAINER(parent), frame);
     style = gtk_widget_get_style_context(frame);
     GetBorderColors(style, &sFrameOuterLightBorder, &sFrameInnerDarkBorder);
 
     gtk_widget_path_free(path);
 
     // GtkInfoBar
+    // TODO - Use WidgetCache for it?
     GtkWidget* infoBar = gtk_info_bar_new();
     GtkWidget* infoBarContent = gtk_info_bar_get_content_area(GTK_INFO_BAR(infoBar));
     GtkWidget* infoBarLabel = gtk_label_new(nullptr);
     gtk_container_add(GTK_CONTAINER(parent), infoBar);
     gtk_container_add(GTK_CONTAINER(infoBarContent), infoBarLabel);
     style = gtk_widget_get_style_context(infoBarLabel);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_INFO);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);