Bug 1187203 - Implement GtkInfoBar appearance style on GTK3. r=karlt
authorAndrew Comminos <acomminos@mozilla.com>
Wed, 19 Aug 2015 15:42:17 -0400
changeset 258816 e7591ecf5987
parent 258815 2ca399b0bba8
child 258817 6194cebe2a84
push id64055
push useracomminos@mozilla.com
push date2015-08-21 20:45 +0000
treeherdermozilla-inbound@ea072f95e28e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1187203
milestone43.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 1187203 - Implement GtkInfoBar appearance style on GTK3. r=karlt
gfx/src/nsThemeConstants.h
layout/style/nsCSSKeywordList.h
layout/style/nsCSSProps.cpp
widget/LookAndFeel.h
widget/gtk/gtk3drawing.c
widget/gtk/gtkdrawing.h
widget/gtk/mozgtk/mozgtk.c
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsLookAndFeel.h
widget/gtk/nsNativeThemeGTK.cpp
--- a/gfx/src/nsThemeConstants.h
+++ b/gfx/src/nsThemeConstants.h
@@ -281,8 +281,10 @@
 
 // moz-apperance style used in setting proper glass margins
 #define NS_THEME_WIN_EXCLUDE_GLASS                         242
 
 #define NS_THEME_MAC_VIBRANCY_LIGHT                        243
 #define NS_THEME_MAC_VIBRANCY_DARK                         244
 #define NS_THEME_MAC_DISCLOSURE_BUTTON_OPEN                245
 #define NS_THEME_MAC_DISCLOSURE_BUTTON_CLOSED              246
+
+#define NS_THEME_GTK_INFO_BAR                              247
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -66,16 +66,18 @@ CSS_KEY(-moz-fieldtext, _moz_fieldtext)
 CSS_KEY(-moz-fit-content, _moz_fit_content)
 CSS_KEY(-moz-fixed, _moz_fixed)
 CSS_KEY(-moz-grabbing, _moz_grabbing)
 CSS_KEY(-moz-grab, _moz_grab)
 CSS_KEY(-moz-grid-group, _moz_grid_group)
 CSS_KEY(-moz-grid-line, _moz_grid_line)
 CSS_KEY(-moz-grid, _moz_grid)
 CSS_KEY(-moz-groupbox, _moz_groupbox)
+CSS_KEY(-moz-gtk-info-bar, _moz_gtk_info_bar)
+CSS_KEY(-moz-gtk-info-bar-text, _moz_gtk_info_bar_text)
 CSS_KEY(-moz-hidden-unscrollable, _moz_hidden_unscrollable)
 CSS_KEY(-moz-hyperlinktext, _moz_hyperlinktext)
 CSS_KEY(-moz-html-cellhighlight, _moz_html_cellhighlight)
 CSS_KEY(-moz-html-cellhighlighttext, _moz_html_cellhighlighttext)
 CSS_KEY(-moz-image-rect, _moz_image_rect)
 CSS_KEY(-moz-info, _moz_info)
 CSS_KEY(-moz-inline-box, _moz_inline_box)
 CSS_KEY(-moz-inline-grid, _moz_inline_grid)
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -740,16 +740,17 @@ const KTableValue nsCSSProps::kAppearanc
   eCSSKeyword__moz_window_button_restore,     NS_THEME_WINDOW_BUTTON_RESTORE,
   eCSSKeyword__moz_window_button_box,         NS_THEME_WINDOW_BUTTON_BOX,
   eCSSKeyword__moz_window_button_box_maximized, NS_THEME_WINDOW_BUTTON_BOX_MAXIMIZED,
   eCSSKeyword__moz_win_exclude_glass,         NS_THEME_WIN_EXCLUDE_GLASS,
   eCSSKeyword__moz_mac_vibrancy_light,        NS_THEME_MAC_VIBRANCY_LIGHT,
   eCSSKeyword__moz_mac_vibrancy_dark,         NS_THEME_MAC_VIBRANCY_DARK,
   eCSSKeyword__moz_mac_disclosure_button_open,   NS_THEME_MAC_DISCLOSURE_BUTTON_OPEN,
   eCSSKeyword__moz_mac_disclosure_button_closed, NS_THEME_MAC_DISCLOSURE_BUTTON_CLOSED,
+  eCSSKeyword__moz_gtk_info_bar,              NS_THEME_GTK_INFO_BAR,
   eCSSKeyword_UNKNOWN,-1
 };
 
 const KTableValue nsCSSProps::kBackfaceVisibilityKTable[] = {
   eCSSKeyword_visible, NS_STYLE_BACKFACE_VISIBILITY_VISIBLE,
   eCSSKeyword_hidden, NS_STYLE_BACKFACE_VISIBILITY_HIDDEN,
   eCSSKeyword_UNKNOWN,-1
 };
@@ -955,16 +956,17 @@ const KTableValue nsCSSProps::kColorKTab
   eCSSKeyword__moz_eventreerow, LookAndFeel::eColorID__moz_eventreerow,
   eCSSKeyword__moz_field, LookAndFeel::eColorID__moz_field,
   eCSSKeyword__moz_fieldtext, LookAndFeel::eColorID__moz_fieldtext,
   eCSSKeyword__moz_default_background_color, NS_COLOR_MOZ_DEFAULT_BACKGROUND_COLOR,
   eCSSKeyword__moz_default_color, NS_COLOR_MOZ_DEFAULT_COLOR,
   eCSSKeyword__moz_dialog, LookAndFeel::eColorID__moz_dialog,
   eCSSKeyword__moz_dialogtext, LookAndFeel::eColorID__moz_dialogtext,
   eCSSKeyword__moz_dragtargetzone, LookAndFeel::eColorID__moz_dragtargetzone,
+  eCSSKeyword__moz_gtk_info_bar_text, LookAndFeel::eColorID__moz_gtk_info_bar_text,
   eCSSKeyword__moz_hyperlinktext, NS_COLOR_MOZ_HYPERLINKTEXT,
   eCSSKeyword__moz_html_cellhighlight, LookAndFeel::eColorID__moz_html_cellhighlight,
   eCSSKeyword__moz_html_cellhighlighttext, LookAndFeel::eColorID__moz_html_cellhighlighttext,
   eCSSKeyword__moz_mac_buttonactivetext, LookAndFeel::eColorID__moz_mac_buttonactivetext,
   eCSSKeyword__moz_mac_chrome_active, LookAndFeel::eColorID__moz_mac_chrome_active,
   eCSSKeyword__moz_mac_chrome_inactive, LookAndFeel::eColorID__moz_mac_chrome_inactive,
   eCSSKeyword__moz_mac_defaultbuttontext, LookAndFeel::eColorID__moz_mac_defaultbuttontext,
   eCSSKeyword__moz_mac_focusring, LookAndFeel::eColorID__moz_mac_focusring,
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -169,16 +169,19 @@ public:
     // but it is used regularly within Windows and the Gnome DE on Dialog and
     // Window colors.
     eColorID__moz_nativehyperlinktext,
 
     // Combo box widgets
     eColorID__moz_comboboxtext,
     eColorID__moz_combobox,
 
+    // GtkInfoBar
+    eColorID__moz_gtk_info_bar_text,
+
     // keep this one last, please
     eColorID_LAST_COLOR
   };
 
   // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
   // in widget/xpwidgts/nsXPLookAndFeel.cpp.
   enum IntID {
     // default, may be overriden by OS
--- a/widget/gtk/gtk3drawing.c
+++ b/widget/gtk/gtk3drawing.c
@@ -56,16 +56,17 @@ static GtkTreeViewColumn* gMiddleTreeVie
 static GtkWidget* gTreeHeaderCellWidget;
 static GtkWidget* gTreeHeaderSortArrowWidget;
 static GtkWidget* gExpanderWidget;
 static GtkWidget* gToolbarSeparatorWidget;
 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
@@ -353,16 +354,25 @@ 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
@@ -2598,16 +2608,39 @@ moz_gtk_check_menu_item_paint(cairo_t *c
     } else {
       gtk_render_check(style, cr, x, y, indicator_size, indicator_size);
     }
     gtk_style_context_restore(style);
 
     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);
+
+    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);
+
+    return MOZ_GTK_SUCCESS;
+}
+
 static void
 moz_gtk_add_style_border(GtkStyleContext* style,
                          gint* left, gint* top, gint* right, gint* bottom)
 {
     GtkBorder border;
 
     gtk_style_context_get_border(style, 0, &border);
 
@@ -2824,16 +2857,20 @@ moz_gtk_get_widget_border(GtkThemeWidget
                 w = gCheckMenuItemWidget;
             }
 
             *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;
+        break;
     /* These widgets have no borders, since they are not containers. */
     case MOZ_GTK_CHECKBUTTON_LABEL:
     case MOZ_GTK_RADIOBUTTON_LABEL:
     case MOZ_GTK_SPLITTER_HORIZONTAL:
     case MOZ_GTK_SPLITTER_VERTICAL:
     case MOZ_GTK_CHECKBUTTON:
     case MOZ_GTK_RADIOBUTTON:
     case MOZ_GTK_SCROLLBAR_BUTTON:
@@ -3305,16 +3342,19 @@ moz_gtk_widget_paint(GtkThemeWidgetType 
         return moz_gtk_vpaned_paint(cr, rect, state);
         break;
     case MOZ_GTK_SPLITTER_VERTICAL:
         return moz_gtk_hpaned_paint(cr, rect, state);
         break;
     case MOZ_GTK_WINDOW:
         return moz_gtk_window_paint(cr, rect, direction);
         break;
+    case MOZ_GTK_INFO_BAR:
+        return moz_gtk_info_bar_paint(cr, rect, state);
+        break;
     default:
         g_warning("Unknown widget type: %d", widget);
     }
 
     return MOZ_GTK_UNKNOWN_WIDGET;
 }
 
 GtkWidget* moz_gtk_get_scrollbar_widget(void)
--- a/widget/gtk/gtkdrawing.h
+++ b/widget/gtk/gtkdrawing.h
@@ -180,17 +180,19 @@ typedef enum {
   MOZ_GTK_CHECKMENUITEM,
   MOZ_GTK_RADIOMENUITEM,
   MOZ_GTK_MENUSEPARATOR,
   /* Paints a GtkVPaned separator */
   MOZ_GTK_SPLITTER_HORIZONTAL,
   /* Paints a GtkHPaned separator */
   MOZ_GTK_SPLITTER_VERTICAL,
   /* Paints the background of a window, dialog or page. */
-  MOZ_GTK_WINDOW
+  MOZ_GTK_WINDOW,
+  /* Paints a GtkInfoBar, for notifications. */
+  MOZ_GTK_INFO_BAR
 } GtkThemeWidgetType;
 
 /*** General library functions ***/
 /**
  * Initializes the drawing library.  You must call this function
  * prior to using any other functionality.
  * returns: MOZ_GTK_SUCCESS if there were no errors
  *          MOZ_GTK_UNSAFE_THEME if the current theme engine is known
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -249,16 +249,18 @@ STUB(gtk_im_context_focus_out)
 STUB(gtk_im_context_get_preedit_string)
 STUB(gtk_im_context_reset)
 STUB(gtk_im_context_set_client_window)
 STUB(gtk_im_context_set_cursor_location)
 STUB(gtk_im_context_set_surrounding)
 STUB(gtk_im_context_simple_new)
 STUB(gtk_im_multicontext_get_type)
 STUB(gtk_im_multicontext_new)
+STUB(gtk_info_bar_get_type)
+STUB(gtk_info_bar_new)
 STUB(gtk_init)
 STUB(gtk_invisible_new)
 STUB(gtk_key_snooper_install)
 STUB(gtk_key_snooper_remove)
 STUB(gtk_label_get_type)
 STUB(gtk_label_new)
 STUB(gtk_label_set_markup)
 STUB(gtk_link_button_new)
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -409,16 +409,23 @@ nsLookAndFeel::NativeGetColor(ColorID aI
         break;
 #endif
     case eColorID__moz_menubartext:
         aColor = sMenuBarText;
         break;
     case eColorID__moz_menubarhovertext:
         aColor = sMenuBarHoverText;
         break;
+    case eColorID__moz_gtk_info_bar_text:
+#if (MOZ_WIDGET_GTK == 3)
+        aColor = sInfoBarText;
+#else
+        aColor = sInfoText;
+#endif
+        break;
     default:
         /* default color is BLACK */
         aColor = 0;
         res    = NS_ERROR_FAILURE;
         break;
     }
 
     return res;
@@ -1188,16 +1195,27 @@ nsLookAndFeel::Init()
 
     // TODO GTK3 - update sFrameOuterLightBorder 
     // for GTK_BORDER_STYLE_INSET/OUTSET/GROVE/RIDGE border styles (Bug 978172).
     style = gtk_widget_get_style_context(frame);
     gtk_style_context_get_border_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sFrameInnerDarkBorder = sFrameOuterLightBorder = GDK_RGBA_TO_NS_RGBA(color);
 
     gtk_widget_path_free(path);
+
+    // GtkInfoBar
+    path = gtk_widget_path_new();
+    gtk_widget_path_append_type(path, GTK_TYPE_WINDOW);
+    gtk_widget_path_append_type(path, GTK_TYPE_INFO_BAR);
+    style = create_context(path);
+    gtk_style_context_add_class(style, GTK_STYLE_CLASS_INFO);
+    gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
+    sInfoBarText = GDK_RGBA_TO_NS_RGBA(color);
+    g_object_unref(style);
+    gtk_widget_path_free(path);
 #endif
     // Some themes have a unified menu bar, and support window dragging on it
     gboolean supports_menubar_drag = FALSE;
     GParamSpec *param_spec =
         gtk_widget_class_find_style_property(GTK_WIDGET_GET_CLASS(menuBar),
                                              "window-dragging");
     if (param_spec) {
         if (g_type_is_a(G_PARAM_SPEC_VALUE_TYPE(param_spec), G_TYPE_BOOLEAN)) {
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -73,16 +73,19 @@ protected:
     nscolor sComboBoxBackground;
     nscolor sMozFieldText;
     nscolor sMozFieldBackground;
     nscolor sMozWindowText;
     nscolor sMozWindowBackground;
     nscolor sTextSelectedText;
     nscolor sTextSelectedBackground;
     nscolor sMozScrollbar;
+#if (MOZ_WIDGET_GTK == 3)
+    nscolor sInfoBarText;
+#endif
     char16_t sInvisibleCharacter;
     float   sCaretRatio;
     bool    sMenuSupportsDrag;
 
     void Init();
 };
 
 #endif
--- a/widget/gtk/nsNativeThemeGTK.cpp
+++ b/widget/gtk/nsNativeThemeGTK.cpp
@@ -679,16 +679,19 @@ nsNativeThemeGTK::GetGtkWidgetAndState(u
     break;
   case NS_THEME_RADIOMENUITEM:
     aGtkWidgetType = MOZ_GTK_RADIOMENUITEM;
     break;
   case NS_THEME_WINDOW:
   case NS_THEME_DIALOG:
     aGtkWidgetType = MOZ_GTK_WINDOW;
     break;
+  case NS_THEME_GTK_INFO_BAR:
+    aGtkWidgetType = MOZ_GTK_INFO_BAR;
+    break;
   default:
     return false;
   }
 
   return true;
 }
 
 #if (MOZ_WIDGET_GTK == 2)
@@ -1768,16 +1771,19 @@ nsNativeThemeGTK::ThemeSupportsWidget(ns
   case NS_THEME_MENUITEM:
   case NS_THEME_MENUARROW:
   case NS_THEME_MENUSEPARATOR:
   case NS_THEME_CHECKMENUITEM:
   case NS_THEME_RADIOMENUITEM:
   case NS_THEME_SPLITTER:
   case NS_THEME_WINDOW:
   case NS_THEME_DIALOG:
+#if (MOZ_WIDGET_GTK == 3)
+  case NS_THEME_GTK_INFO_BAR:
+#endif
     return !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
 
   case NS_THEME_DROPDOWN_BUTTON:
     if (aFrame && aFrame->GetWritingMode().IsVertical()) {
       return false;
     }
     // "Native" dropdown buttons cause padding and margin problems, but only
     // in HTML so allow them in XUL.