bug 1319353 CreateCSSNode: Copy classes from the parent style context to its corresponding node in the path r?stransky draft
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 16 Nov 2016 16:55:13 +1300
changeset 442299 ebba2723cb003cdac35793393c8c97f9f3e09f7d
parent 442295 9344ad8ae0a42192d93bbb69c92840138b9db4b6
child 537768 eb0a2a6a49e4cb7c817a503fefe5aa041327ea3f
push id36668
push userktomlinson@mozilla.com
push dateTue, 22 Nov 2016 08:27:37 +0000
reviewersstransky
bugs1319353
milestone53.0a1
bug 1319353 CreateCSSNode: Copy classes from the parent style context to its corresponding node in the path r?stransky This is necessary for GTK to match CSS rules against classes on ancestor nodes of style contexts constructed from paths. It can be tested with the following in ~/.config/gtk-3.0/gtk.css tooltip.background label {padding: 100px;} MozReview-Commit-ID: EUQ9ndeSl1Z
widget/gtk/WidgetStyleCache.cpp
widget/gtk/mozgtk/mozgtk.c
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -703,19 +703,30 @@ CreateStyleForWidget(GtkWidget* aWidget,
 
 GtkStyleContext*
 CreateCSSNode(const char* aName, GtkStyleContext* aParentStyle, GType aType)
 {
   static auto sGtkWidgetPathIterSetObjectName =
     reinterpret_cast<void (*)(GtkWidgetPath *, gint, const char *)>
     (dlsym(RTLD_DEFAULT, "gtk_widget_path_iter_set_object_name"));
 
-  GtkWidgetPath* path = aParentStyle ?
-    gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle)) :
-    gtk_widget_path_new();
+  GtkWidgetPath* path;
+  if (aParentStyle) {
+    path = gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle));
+    // Copy classes from the parent style context to its corresponding node in
+    // the path, because GTK will only match against ancestor classes if they
+    // are on the path.
+    GList* classes = gtk_style_context_list_classes(aParentStyle);
+    for (GList* link = classes; link; link = link->next) {
+      gtk_widget_path_iter_add_class(path, -1, static_cast<gchar*>(link->data));
+    }
+    g_list_free(classes);
+  } else {
+    path = gtk_widget_path_new();
+  }
 
   gtk_widget_path_append_type(path, aType);
 
   if (sGtkWidgetPathIterSetObjectName) {
     (*sGtkWidgetPathIterSetObjectName)(path, -1, aName);
   }
 
   GtkStyleContext *context = gtk_style_context_new();
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -575,16 +575,17 @@ STUB(gtk_style_context_set_state)
 STUB(gtk_style_properties_lookup_property)
 STUB(gtk_tree_view_column_get_button)
 STUB(gtk_widget_get_preferred_size)
 STUB(gtk_widget_get_state_flags)
 STUB(gtk_widget_get_style_context)
 STUB(gtk_widget_path_append_type)
 STUB(gtk_widget_path_copy)
 STUB(gtk_widget_path_free)
+STUB(gtk_widget_path_iter_add_class)
 STUB(gtk_widget_path_new)
 STUB(gtk_widget_path_unref)
 STUB(gtk_widget_set_visual)
 STUB(gtk_app_chooser_dialog_new_for_content_type)
 STUB(gtk_app_chooser_get_type)
 STUB(gtk_app_chooser_get_app_info)
 STUB(gtk_app_chooser_dialog_get_type)
 STUB(gtk_app_chooser_dialog_set_heading)