bug 1384701 get system font name and size from widget style context instead of GtkSettings r?manishearth draft
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 04 Sep 2017 21:33:21 +1200
changeset 658902 9ae5fc31ecf1873039e111949f22734e6fdf944b
parent 658901 750b4d22f7c6638ec0dd2354a6f71df6f2adfc18
child 658903 d1a6e488a164235a86ed03d8de003e31709fe0e6
child 658922 83607395b6dfce4a99860f2b78cd67c7a83c0828
push id77927
push userktomlinson@mozilla.com
push dateTue, 05 Sep 2017 05:44:06 +0000
reviewersmanishearth
bugs1384701
milestone57.0a1
bug 1384701 get system font name and size from widget style context instead of GtkSettings r?manishearth gtk_widget_get_settings() returns the same settings for all widgets [1] but GTK actually uses specific fonts for each widget [2]. [1] https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.19#n11637 [2] https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.19#n10334 Changing to GtkStyleContext* will also make this easier to use from code where the GtkStyleContext exists but not the GtkWidget, such as EnsureInit() in a future patch. MozReview-Commit-ID: 3NuTL5wRzm5
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -706,30 +706,27 @@ nsLookAndFeel::GetFloatImpl(FloatID aID,
     return res;
 }
 
 static void
 GetSystemFontInfo(GtkWidget *aWidget,
                   nsString *aFontName,
                   gfxFontStyle *aFontStyle)
 {
-    GtkSettings *settings = gtk_widget_get_settings(aWidget);
-
     aFontStyle->style       = NS_FONT_STYLE_NORMAL;
 
-    gchar *fontname;
-    g_object_get(settings, "gtk-font-name", &fontname, nullptr);
-
+    // As in
+    // https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?h=3.22.19#n10333
+    GtkStyleContext *style = gtk_widget_get_style_context(aWidget);
     PangoFontDescription *desc;
-    desc = pango_font_description_from_string(fontname);
+    gtk_style_context_get(style, gtk_style_context_get_state(style),
+                          "font", &desc, nullptr);
 
     aFontStyle->systemFont = true;
 
-    g_free(fontname);
-
     NS_NAMED_LITERAL_STRING(quote, "\"");
     NS_ConvertUTF8toUTF16 family(pango_font_description_get_family(desc));
     *aFontName = quote + family + quote;
 
     aFontStyle->weight = pango_font_description_get_weight(desc);
 
     // FIXME: Set aFontStyle->stretch correctly!
     aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;