bug 1280951 copy tooltip style context and cache that instead of widget r=stransky+263117
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 22 Jun 2016 16:46:24 +1200
changeset 302300 d56d7039aee08a36f9dc0a9bb4b1ffafd16baa5f
parent 302299 0ca871e39a20d94c5c8948beb41867d679f3709e
child 302301 81a9b4abaf7000b7c23dbca910e8636d453c94c1
push id78687
push userktomlinson@mozilla.com
push dateWed, 22 Jun 2016 07:55:23 +0000
treeherdermozilla-inbound@d56d7039aee0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstransky
bugs1280951, 263117
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 1280951 copy tooltip style context and cache that instead of widget r=stransky+263117 MozReview-Commit-ID: 6thXro9uYHn
widget/gtk/WidgetStyleCache.cpp
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -139,18 +139,16 @@ CreateWidget(WidgetNodeType aWidgetType)
     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);
-    case MOZ_GTK_TOOLTIP:
-      return CreateTooltipWidget();
     default:
       /* Not implemented */
       return nullptr;
   }
 }
 
 GtkWidget*
 GetWidget(WidgetNodeType aWidgetType)
@@ -161,18 +159,19 @@ GetWidget(WidgetNodeType aWidgetType)
     sWidgetStorage[aWidgetType] = widget;
   }
   return widget;
 }
 
 GtkStyleContext*
 CreateStyleForWidget(GtkWidget* aWidget, GtkStyleContext* aParentStyle)
 {
-  GtkWidgetPath* path =
-    gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle));
+  GtkWidgetPath* path = aParentStyle ?
+    gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle)) :
+    gtk_widget_path_new();
 
   // Work around https://bugzilla.gnome.org/show_bug.cgi?id=767312
   // which exists in GTK+ 3.20.
   gtk_widget_get_style_context(aWidget);
 
   gtk_widget_path_append_for_widget(path, aWidget);
   // Release any floating reference on aWidget.
   g_object_ref_sink(aWidget);
@@ -271,23 +270,19 @@ GetCssNodeStyleInternal(WidgetNodeType a
       gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
       break; 
     default:
       // TODO - create style from style path
       GtkWidget* widget = GetWidget(aNodeType);
       return gtk_widget_get_style_context(widget);
   }
 
-  if (style) {
-    sStyleStorage[aNodeType] = style;
-    return style;
-  }
-
-  MOZ_ASSERT_UNREACHABLE("missing style context for node type");
-  return nullptr;
+  MOZ_ASSERT(style, "missing style context for node type");
+  sStyleStorage[aNodeType] = style;
+  return style;
 }
 
 static GtkStyleContext*
 GetWidgetStyleWithClass(WidgetNodeType aWidgetType, const gchar* aStyleClass)
 {
   GtkStyleContext* style = gtk_widget_get_style_context(GetWidget(aWidgetType));
   gtk_style_context_save(style);
   MOZ_ASSERT(!sStyleContextNeedsRestore);
@@ -317,16 +312,30 @@ GetWidgetStyleInternal(WidgetNodeType aN
       return GetWidgetStyleWithClass(MOZ_GTK_RADIOBUTTON_CONTAINER,
                                      GTK_STYLE_CLASS_RADIO);
     case MOZ_GTK_CHECKBUTTON:
       return GetWidgetStyleWithClass(MOZ_GTK_CHECKBUTTON_CONTAINER,
                                      GTK_STYLE_CLASS_CHECK);
     case MOZ_GTK_PROGRESS_TROUGH:
       return GetWidgetStyleWithClass(MOZ_GTK_PROGRESSBAR,
                                      GTK_STYLE_CLASS_TROUGH);
+    case MOZ_GTK_TOOLTIP: {
+      GtkStyleContext* style = sStyleStorage[aNodeType];
+      if (style)
+        return style;
+
+      // The tooltip style class is added first in CreateTooltipWidget() so
+      // that gtk_widget_path_append_for_widget() in CreateStyleForWidget()
+      // will find it.
+      GtkWidget* tooltipWindow = CreateTooltipWidget();
+      style = CreateStyleForWidget(tooltipWindow, nullptr);
+      gtk_widget_destroy(tooltipWindow); // Release GtkWindow self-reference.
+      sStyleStorage[aNodeType] = style;
+      return style;
+    }
     default:
       GtkWidget* widget = GetWidget(aNodeType);
       MOZ_ASSERT(widget);
       return gtk_widget_get_style_context(widget);
   }
 }
 
 void