Bug 1443481 - [Linux/Titlebar] Construct widget tree to get correct titlebar icon style before we render the actual icon. r=jhorak, a=jcristau
authorMartin Stransky <stransky@redhat.com>
Tue, 06 Mar 2018 16:45:19 +0100
changeset 460276 52dbbfde4866dcae4aa31ab7e0917cbed8ddd2fc
parent 460273 23a13199eb6e47552be72347e96d5fab45378209
child 460277 51a32e744f22867fcca329ee58244044ec038b6b
push id8895
push userryanvm@gmail.com
push dateWed, 21 Mar 2018 17:57:42 +0000
treeherdermozilla-beta@f304fa7bc72e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak, jcristau
bugs1443481
milestone60.0
Bug 1443481 - [Linux/Titlebar] Construct widget tree to get correct titlebar icon style before we render the actual icon. r=jhorak, a=jcristau MozReview-Commit-ID: DEb2pU31os9
widget/gtk/WidgetStyleCache.cpp
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -628,21 +628,30 @@ GetWidgetIconSurface(GtkWidget* aWidgetI
     aScale = ICON_SCALE_VARIANTS;
 
   nsAutoCString surfaceName;
   surfaceName = nsPrintfCString("MozillaIconSurface%d", aScale);
   return (cairo_surface_t*)
     g_object_get_data(G_OBJECT(aWidgetIcon), surfaceName.get());
 }
 
-static GtkWidget*
-CreateHeaderBarButton(WidgetNodeType aWidgetType)
+static void
+CreateHeaderBarButton(GtkWidget* aParentWidget,
+                      WidgetNodeType aWidgetType)
 {
   GtkWidget* widget = gtk_button_new();
 
+  // We have to add button to widget hierarchy now to pick
+  // right icon style at LoadWidgetIconPixbuf().
+  if (GTK_IS_BOX(aParentWidget)) {
+      gtk_box_pack_start(GTK_BOX(aParentWidget), widget, FALSE, FALSE, 0);
+  } else {
+      gtk_container_add(GTK_CONTAINER(aParentWidget), widget);
+  }
+
   // We bypass GetWidget() here because we create all titlebar
   // buttons at once when a first one is requested.
   NS_ASSERTION(sWidgetStorage[aWidgetType] == nullptr,
                "Titlebar button is already created!");
   sWidgetStorage[aWidgetType] = widget;
 
   // We need to show the button widget now as GtkBox does not
   // place invisible widgets and we'll miss first-child/last-child
@@ -685,18 +694,16 @@ CreateHeaderBarButton(WidgetNodeType aWi
    gtk_container_add(GTK_CONTAINER (widget), image);
 
    // We bypass GetWidget() here by explicit sWidgetStorage[] update so
    // invalidate the style as well as GetWidget() does.
    style = gtk_widget_get_style_context(image);
    gtk_style_context_invalidate(style);
 
    LoadWidgetIconPixbuf(image);
-
-   return widget;
 }
 
 static bool
 IsToolbarButtonEnabled(WidgetNodeType* aButtonLayout, int aButtonNums,
                        WidgetNodeType aWidgetType)
 {
     for (int i = 0; i < aButtonNums; i++) {
       if (aButtonLayout[i] == aWidgetType) {
@@ -721,31 +728,29 @@ CreateHeaderBarButtons()
   gtk_container_add(GTK_CONTAINER(GetWidget(MOZ_GTK_HEADER_BAR)), buttonBox);
 
   WidgetNodeType buttonLayout[TOOLBAR_BUTTONS];
   int activeButtons =
       GetGtkHeaderBarButtonLayout(buttonLayout, TOOLBAR_BUTTONS);
 
   if (IsToolbarButtonEnabled(buttonLayout, activeButtons,
                              MOZ_GTK_HEADER_BAR_BUTTON_MINIMIZE)) {
-    GtkWidget* button = CreateHeaderBarButton(MOZ_GTK_HEADER_BAR_BUTTON_MINIMIZE);
-    gtk_box_pack_start(GTK_BOX(buttonBox), button, FALSE, FALSE, 0);
+    CreateHeaderBarButton(buttonBox, MOZ_GTK_HEADER_BAR_BUTTON_MINIMIZE);
   }
   if (IsToolbarButtonEnabled(buttonLayout, activeButtons,
                              MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE)) {
-    GtkWidget* button = CreateHeaderBarButton(MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE);
-    gtk_box_pack_start(GTK_BOX(buttonBox), button, FALSE, FALSE, 0);
-    // We don't pack "restore" headerbar button as it's an icon
-    // placeholder only.
-    CreateHeaderBarButton(MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE_RESTORE);
+    CreateHeaderBarButton(buttonBox, MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE);
+    // We don't pack "restore" headerbar button to box as it's an icon
+    // placeholder. Pack it only to header bar to get correct style.
+    CreateHeaderBarButton(GetWidget(MOZ_GTK_HEADER_BAR),
+                          MOZ_GTK_HEADER_BAR_BUTTON_MAXIMIZE_RESTORE);
   }
   if (IsToolbarButtonEnabled(buttonLayout, activeButtons,
                              MOZ_GTK_HEADER_BAR_BUTTON_CLOSE)) {
-    GtkWidget* button = CreateHeaderBarButton(MOZ_GTK_HEADER_BAR_BUTTON_CLOSE);
-    gtk_box_pack_start(GTK_BOX(buttonBox), button, FALSE, FALSE, 0);
+    CreateHeaderBarButton(buttonBox, MOZ_GTK_HEADER_BAR_BUTTON_CLOSE);
   }
 }
 
 static GtkWidget*
 CreateWidget(WidgetNodeType aWidgetType)
 {
   switch (aWidgetType) {
     case MOZ_GTK_WINDOW: