Bug 1443481 - [Linux/Titlebar] Construct widget tree to get correct titlebar icon style before we render the actual icon, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Tue, 06 Mar 2018 16:45:19 +0100
changeset 407796 8c038bd77897a043f3ccee57b8af2184814fadd2
parent 407795 3429fca91c54e41c032c97bd8ed4449be308d21c
child 407797 4cd3a69dc65b3b4174134eeb397729e3f6b290e6
push id61045
push userstransky@redhat.com
push dateTue, 13 Mar 2018 11:47:51 +0000
treeherderautoland@8c038bd77897 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1443481
milestone61.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 1443481 - [Linux/Titlebar] Construct widget tree to get correct titlebar icon style before we render the actual icon, r=jhorak 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: