bug 1384701 get system font name and size from widget style context instead of GtkSettings r=manishearth
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 04 Sep 2017 21:33:21 +1200
changeset 428635 143ef903d8f6310a4405b456a63cdd7cca858a54
parent 428634 4166c5ecc5d77aec3307cc2c8058cdd7d1590991
child 428636 e711937ff6fa74fd4da55382d7df24647aaa4462
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmanishearth
bugs1384701
milestone57.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 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;