From cb3356b35e3aed6da9f6b664a98c14c0bfd258a2 Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Sun, 13 Dec 2020 01:34:35 +0000 Subject: [PATCH] Bug 1470983 - Prelude: Remove use of gtk_widget_get_settings in LookAndFeel. r=heycam The GTK nsLookAndFeel implementation uses `gtk_widget_get_settings` on temporary widgets that aren't attached to anything, which the documentation says not to do. Empirically, this seems to return the same settings object as `gtk_settings_get_default`. Explicitly using `gtk_settings_get_default` is useful for remote look-and-feel, so that the parent process can register for property changes on that object to know when to update the child processes. Differential Revision: https://phabricator.services.mozilla.com/D94535 --- widget/gtk/mozgtk/mozgtk.c | 1 - widget/gtk/nsLookAndFeel.cpp | 11 ++--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/widget/gtk/mozgtk/mozgtk.c b/widget/gtk/mozgtk/mozgtk.c index 8cc4da33f6b2..0b2e3fd49468 100644 --- a/widget/gtk/mozgtk/mozgtk.c +++ b/widget/gtk/mozgtk/mozgtk.c @@ -462,7 +462,6 @@ STUB(gtk_widget_get_parent) STUB(gtk_widget_get_parent_window) STUB(gtk_widget_get_realized) STUB(gtk_widget_get_screen) -STUB(gtk_widget_get_settings) STUB(gtk_widget_get_style) STUB(gtk_widget_get_toplevel) STUB(gtk_widget_get_type) diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index 8c92f6ca3c86..cd80cb077c50 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -615,13 +615,10 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { aResult = 0; break; case IntID::SelectTextfieldsOnKeyFocus: { - GtkWidget* entry; GtkSettings* settings; gboolean select_on_focus; - entry = gtk_entry_new(); - g_object_ref_sink(entry); - settings = gtk_widget_get_settings(entry); + settings = gtk_settings_get_default(); g_object_get(settings, "gtk-entry-select-on-focus", &select_on_focus, nullptr); @@ -630,8 +627,6 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { else aResult = 0; - gtk_widget_destroy(entry); - g_object_unref(entry); } break; case IntID::ScrollToClick: { GtkSettings* settings; @@ -671,11 +666,9 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { break; case IntID::DragThresholdX: case IntID::DragThresholdY: { - GtkWidget* box = gtk_hbox_new(FALSE, 5); gint threshold = 0; - g_object_get(gtk_widget_get_settings(box), "gtk-dnd-drag-threshold", + g_object_get(gtk_settings_get_default(), "gtk-dnd-drag-threshold", &threshold, nullptr); - g_object_ref_sink(box); aResult = threshold; } break;