From d4cb5817e1e6a84311e0a6bd9797dca4da09eabd Mon Sep 17 00:00:00 2001 From: Martin Stransky Date: Mon, 28 Nov 2016 06:44:00 -0500 Subject: [PATCH] Bug 1320686 - [nsLookAndFeel] Get styles for menu label, button text and combobox text colors from WidgetCache. r=karlt --HG-- extra : rebase_source : 5eb0800de3da5ebb6e2deb1095c50aa218afd6e3 --- widget/gtk/nsLookAndFeel.cpp | 53 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index 13f9c6ce987e..13f79db2422a 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -1153,22 +1153,17 @@ nsLookAndFeel::Init() sInfoText = GDK_RGBA_TO_NS_RGBA(color); ReleaseStyleContext(style); - // menu foreground & menu background - GtkWidget *accel_label = gtk_accel_label_new("M"); - GtkWidget *menuitem = gtk_menu_item_new(); - GtkWidget *menu = gtk_menu_new(); - - g_object_ref_sink(menu); - - gtk_container_add(GTK_CONTAINER(menuitem), accel_label); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); - - style = gtk_widget_get_style_context(accel_label); - gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color); - sMenuText = GDK_RGBA_TO_NS_RGBA(color); - gtk_style_context_get_color(style, GTK_STATE_FLAG_INSENSITIVE, &color); - sMenuTextInactive = GDK_RGBA_TO_NS_RGBA(color); - g_object_unref(menu); + style = ClaimStyleContext(MOZ_GTK_MENUITEM); + { + GtkStyleContext* accelStyle = + CreateStyleForWidget(gtk_accel_label_new("M"), style); + gtk_style_context_get_color(accelStyle, GTK_STATE_FLAG_NORMAL, &color); + sMenuText = GDK_RGBA_TO_NS_RGBA(color); + gtk_style_context_get_color(accelStyle, GTK_STATE_FLAG_INSENSITIVE, &color); + sMenuTextInactive = GDK_RGBA_TO_NS_RGBA(color); + g_object_unref(accelStyle); + } + ReleaseStyleContext(style); style = ClaimStyleContext(MOZ_GTK_MENUPOPUP); gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color); @@ -1191,9 +1186,6 @@ nsLookAndFeel::Init() GtkWidget *combobox = gtk_combo_box_new(); GtkWidget *comboboxLabel = gtk_label_new("M"); gtk_container_add(GTK_CONTAINER(combobox), comboboxLabel); -#else - GtkWidget *combobox = gtk_combo_box_new_with_entry(); - GtkWidget *comboboxLabel = gtk_bin_get_child(GTK_BIN(combobox)); #endif GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP); GtkWidget *treeView = gtk_tree_view_new(); @@ -1207,7 +1199,9 @@ nsLookAndFeel::Init() gtk_container_add(GTK_CONTAINER(parent), button); gtk_container_add(GTK_CONTAINER(parent), treeView); gtk_container_add(GTK_CONTAINER(parent), linkButton); +#if (MOZ_WIDGET_GTK == 2) gtk_container_add(GTK_CONTAINER(parent), combobox); +#endif gtk_container_add(GTK_CONTAINER(parent), menuBar); gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), menuBarItem); gtk_container_add(GTK_CONTAINER(window), parent); @@ -1307,17 +1301,24 @@ nsLookAndFeel::Init() sTextSelectedText = GDK_RGBA_TO_NS_RGBA(color); ReleaseStyleContext(style); - // Button text, background, border - style = gtk_widget_get_style_context(label); - gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color); - sButtonText = GDK_RGBA_TO_NS_RGBA(color); - gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color); - sButtonHoverText = GDK_RGBA_TO_NS_RGBA(color); + // Button text color + style = ClaimStyleContext(MOZ_GTK_BUTTON); + { + GtkStyleContext* labelStyle = + CreateStyleForWidget(gtk_label_new("M"), style); + gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_NORMAL, &color); + sButtonText = GDK_RGBA_TO_NS_RGBA(color); + gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_PRELIGHT, &color); + sButtonHoverText = GDK_RGBA_TO_NS_RGBA(color); + g_object_unref(labelStyle); + } + ReleaseStyleContext(style); // Combobox text color - style = gtk_widget_get_style_context(comboboxLabel); + style = ClaimStyleContext(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA); gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color); sComboBoxText = GDK_RGBA_TO_NS_RGBA(color); + ReleaseStyleContext(style); // Menubar text and hover text colors style = ClaimStyleContext(MOZ_GTK_MENUBARITEM);