Bug 1273013 - "download progress bar does not show in gtk3 build." r=karlt
authorMartin Stransky <stransky@redhat.com>
Tue, 24 May 2016 13:43:00 +0200
changeset 298911 27e93cb03221d985ee2c389d27be4fa6a5d2307f
parent 298910 6bc253b91d793108f698727957d9e3b2380cc5cd
child 298912 61d37541894f9d87674a6ba790498db0b9278e38
push id77367
push usercbook@mozilla.com
push dateWed, 25 May 2016 11:55:17 +0000
treeherdermozilla-inbound@61d37541894f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1273013
milestone49.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 1273013 - "download progress bar does not show in gtk3 build." r=karlt
widget/gtk/WidgetStyleCache.cpp
widget/gtk/gtk3drawing.cpp
widget/gtk/gtkdrawing.h
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -93,33 +93,43 @@ static GtkWidget*
 CreateMenuItemWidget(WidgetNodeType aShellType)
 {
   GtkWidget* widget = gtk_menu_item_new();
   gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(aShellType)), widget);
   return widget;
 }
 
 static GtkWidget*
+CreateProgressWidget()
+{
+  GtkWidget* widget = gtk_progress_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:
+      return CreateCheckboxWidget();
+    case MOZ_GTK_PROGRESSBAR:
+      return CreateProgressWidget();
+    case MOZ_GTK_RADIOBUTTON_CONTAINER:
+      return CreateRadiobuttonWidget();
     case MOZ_GTK_SCROLLBAR_HORIZONTAL:
       return CreateScrollbarWidget(aWidgetType,
                                    GTK_ORIENTATION_HORIZONTAL);
     case MOZ_GTK_SCROLLBAR_VERTICAL:
       return CreateScrollbarWidget(aWidgetType,
                                    GTK_ORIENTATION_VERTICAL);
-    case MOZ_GTK_CHECKBUTTON_CONTAINER:
-      return CreateCheckboxWidget();
-    case MOZ_GTK_RADIOBUTTON_CONTAINER:
-      return CreateRadiobuttonWidget();
     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);
@@ -236,16 +246,32 @@ GetStyleInternal(WidgetNodeType aNodeTyp
     case MOZ_GTK_CHECKBUTTON_CONTAINER:
       /* Root CSS node / widget for radiobuttons */
       break;
     case MOZ_GTK_CHECKBUTTON:
       return GetChildNodeStyle(aNodeType,
                                MOZ_GTK_CHECKBUTTON_CONTAINER,
                                GTK_STYLE_CLASS_CHECK,
                                MOZ_GTK_CHECKBUTTON_CONTAINER);
+
+    case MOZ_GTK_PROGRESSBAR:
+      /* Root CSS node / widget for progress bars */
+      break;
+    case MOZ_GTK_PROGRESS_TROUGH:
+      /* Progress bar background (trough) */
+      return GetChildNodeStyle(aNodeType,
+                               MOZ_GTK_PROGRESSBAR,
+                               GTK_STYLE_CLASS_TROUGH,
+                               MOZ_GTK_PROGRESSBAR);
+    case MOZ_GTK_PROGRESS_CHUNK:
+      /* Actual progress bar indicator for Gtk3.20+ only. */
+      return GetChildNodeStyle(MOZ_GTK_PROGRESS_CHUNK,
+                               MOZ_GTK_PROGRESSBAR,
+                               "progress",
+                               MOZ_GTK_PROGRESS_TROUGH);
     default:
       break;
   }
 
   GtkWidget* widget = GetWidget(aNodeType);
   if (widget) {
     return gtk_widget_get_style_context(widget);
   }
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -33,17 +33,16 @@ static GtkWidget* gComboBoxArrowWidget;
 static GtkWidget* gComboBoxSeparatorWidget;
 static GtkWidget* gComboBoxEntryWidget;
 static GtkWidget* gComboBoxEntryTextareaWidget;
 static GtkWidget* gComboBoxEntryButtonWidget;
 static GtkWidget* gComboBoxEntryArrowWidget;
 static GtkWidget* gHandleBoxWidget;
 static GtkWidget* gToolbarWidget;
 static GtkWidget* gFrameWidget;
-static GtkWidget* gProgressWidget;
 static GtkWidget* gTabWidget;
 static GtkWidget* gTextViewWidget;
 static GtkWidget* gTooltipWidget;
 static GtkWidget* gImageMenuItemWidget;
 static GtkWidget* gCheckMenuItemWidget;
 static GtkWidget* gTreeViewWidget;
 static GtkTreeViewColumn* gMiddleTreeViewColumn;
 static GtkWidget* gTreeHeaderCellWidget;
@@ -476,26 +475,16 @@ ensure_tab_widget()
     if (!gTabWidget) {
         gTabWidget = gtk_notebook_new();
         setup_widget_prototype(gTabWidget);
     }
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
-ensure_progress_widget()
-{
-    if (!gProgressWidget) {
-        gProgressWidget = gtk_progress_bar_new();
-        setup_widget_prototype(gProgressWidget);
-    }
-    return MOZ_GTK_SUCCESS;
-}
-
-static gint
 ensure_frame_widget()
 {
     if (!gFrameWidget) {
         gFrameWidget = gtk_frame_new(NULL);
         setup_widget_prototype(gFrameWidget);
     }
     return MOZ_GTK_SUCCESS;
 }
@@ -1895,46 +1884,41 @@ moz_gtk_frame_paint(cairo_t *cr, GdkRect
     gtk_style_context_restore(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_progressbar_paint(cairo_t *cr, GdkRectangle* rect,
                           GtkTextDirection direction)
 {
-    GtkStyleContext* style;
-
-    ensure_progress_widget();
-    gtk_widget_set_direction(gProgressWidget, direction);
-
-    style = gtk_widget_get_style_context(gProgressWidget);
-    gtk_style_context_save(style);
-    gtk_style_context_add_class(style, GTK_STYLE_CLASS_TROUGH);
-    
+    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_PROGRESS_TROUGH,
+                                               direction);
     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 gint
 moz_gtk_progress_chunk_paint(cairo_t *cr, GdkRectangle* rect,
                              GtkTextDirection direction,
                              WidgetNodeType widget)
 {
     GtkStyleContext* style;
 
-    ensure_progress_widget();
-    gtk_widget_set_direction(gProgressWidget, direction);
-
-    style = gtk_widget_get_style_context(gProgressWidget);
-    gtk_style_context_save(style);
-    gtk_style_context_remove_class(style, GTK_STYLE_CLASS_TROUGH);
-    gtk_style_context_add_class(style, GTK_STYLE_CLASS_PROGRESSBAR);
+    if (gtk_check_version(3, 20, 0) != nullptr) {
+      /* Ask for MOZ_GTK_PROGRESS_TROUGH instead of MOZ_GTK_PROGRESSBAR
+       * because ClaimStyleContext() saves/restores that style */
+      style = ClaimStyleContext(MOZ_GTK_PROGRESS_TROUGH, direction);
+      gtk_style_context_remove_class(style, GTK_STYLE_CLASS_TROUGH);
+      gtk_style_context_add_class(style, GTK_STYLE_CLASS_PROGRESSBAR);
+    } else {
+      style = ClaimStyleContext(MOZ_GTK_PROGRESS_CHUNK, direction);
+    }
 
     if (widget == MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE ||
         widget == MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE) {
       /**
        * The bar's size and the bar speed are set depending of the progress'
        * size. These could also be constant for all progress bars easily.
        */
       gboolean vertical = (widget == MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE);
@@ -1968,17 +1952,17 @@ moz_gtk_progress_chunk_paint(cairo_t *cr
     // gtk_render_activity was used to render progress chunks on GTK versions
     // before 3.13.7, see bug 1173907.
     if (!gtk_check_version(3, 13, 7)) {
       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);
     } else {
       gtk_render_activity(style, cr, rect->x, rect->y, rect->width, rect->height);
     }
-    gtk_style_context_restore(style);
+    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_tab_thickness(void)
 {
     GtkBorder border;
@@ -2702,18 +2686,17 @@ moz_gtk_get_widget_border(WidgetNodeType
 
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_TABPANELS:
         ensure_tab_widget();
         w = gTabWidget;
         break;
     case MOZ_GTK_PROGRESSBAR:
-        ensure_progress_widget();
-        w = gProgressWidget;
+        w = GetWidget(MOZ_GTK_PROGRESSBAR);
         break;
     case MOZ_GTK_SPINBUTTON_ENTRY:
     case MOZ_GTK_SPINBUTTON_UP:
     case MOZ_GTK_SPINBUTTON_DOWN:
         ensure_spin_widget();
         w = gSpinWidget;
         break;
     case MOZ_GTK_SCALE_HORIZONTAL:
@@ -3340,17 +3323,16 @@ moz_gtk_shutdown()
     gComboBoxArrowWidget = NULL;
     gComboBoxEntryWidget = NULL;
     gComboBoxEntryButtonWidget = NULL;
     gComboBoxEntryArrowWidget = NULL;
     gComboBoxEntryTextareaWidget = NULL;
     gHandleBoxWidget = NULL;
     gToolbarWidget = NULL;
     gFrameWidget = NULL;
-    gProgressWidget = NULL;
     gTabWidget = NULL;
     gTextViewWidget = nullptr;
     gTooltipWidget = NULL;
     gImageMenuItemWidget = NULL;
     gCheckMenuItemWidget = NULL;
     gTreeViewWidget = NULL;
     gMiddleTreeViewColumn = NULL;
     gTreeHeaderCellWidget = NULL;
--- a/widget/gtk/gtkdrawing.h
+++ b/widget/gtk/gtkdrawing.h
@@ -150,16 +150,18 @@ typedef enum {
   /* Paints a GtkToolTip */
   MOZ_GTK_TOOLTIP,
   /* Paints a GtkFrame (e.g. a status bar panel). */
   MOZ_GTK_FRAME,
   /* Paints a resize grip for a GtkWindow */
   MOZ_GTK_RESIZER,
   /* Paints a GtkProgressBar. */
   MOZ_GTK_PROGRESSBAR,
+  /* Paints a trough (track) of a GtkProgressBar */
+  MOZ_GTK_PROGRESS_TROUGH,
   /* Paints a progress chunk of a GtkProgressBar. */
   MOZ_GTK_PROGRESS_CHUNK,
   /* Paints a progress chunk of an indeterminated GtkProgressBar. */
   MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE,
   /* Paints a progress chunk of a vertical indeterminated GtkProgressBar. */
   MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE,
   /* Paints a tab of a GtkNotebook. flags is a GtkTabFlags, defined above. */
   MOZ_GTK_TAB,