[Xfce4-commits] <midori:master> Use style classes for location entry in GTK+3

Christian Dywan noreply at xfce.org
Sat Dec 17 16:52:02 CET 2011


Updating branch refs/heads/master
         to 1126ec1088acd2f9ec10c8fa396ebb6d61222006 (commit)
       from de26c19a010a1c0466b92d100399bbe620c414c9 (commit)

commit 1126ec1088acd2f9ec10c8fa396ebb6d61222006
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Dec 17 10:46:03 2011 +0100

    Use style classes for location entry in GTK+3
    
    The classes are .security_trusted and .security_unknown.

 midori/midori-locationaction.c |   47 ++++++++++++++++++++++++++++++++++------
 1 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index f380b6d..698d9e9 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -763,6 +763,30 @@ midori_location_action_create_tool_item (GtkAction* action)
     gtk_widget_show (entry);
     gtk_container_add (GTK_CONTAINER (alignment), entry);
 
+    #if GTK_CHECK_VERSION (3, 0, 0)
+    {
+    static const gchar default_style[] =
+        ".security_unknown {\n"
+        "background-image: none;\n"
+        "background-color: #ef7070;\n"
+        "color: #000;\n"
+        "}\n"
+        ".security_trusted {\n"
+        "background-image: none;\n"
+        "background-color: #d1eeb9;\n"
+        "color: #000;\n"
+        "}\n";
+    GtkCssProvider* css_provider;
+    GtkStyleContext* context;
+
+    css_provider = gtk_css_provider_new ();
+    context = gtk_widget_get_style_context (entry);
+    gtk_css_provider_load_from_data (css_provider, default_style, -1, NULL);
+    gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (css_provider),
+                                    GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
+    }
+    #endif
+
     return toolitem;
 }
 
@@ -1677,13 +1701,22 @@ midori_location_action_set_security_hint (MidoriLocationAction* location_action,
 
         {
         #if GTK_CHECK_VERSION (3, 0, 0)
-        GdkRGBA color = { 0 };
-        if (bg_color) gdk_rgba_parse (&color, bg_color);
-        gtk_widget_override_background_color (entry,
-            GTK_STATE_FLAG_NORMAL, bg_color ? &color : NULL);
-        if (fg_color) gdk_rgba_parse (&color, fg_color);
-        gtk_widget_override_color (entry,
-            GTK_STATE_FLAG_NORMAL, fg_color ? &color : NULL);
+        GtkStyleContext* context = gtk_widget_get_style_context (entry);
+        if (hint == MIDORI_SECURITY_UNKNOWN)
+        {
+            gtk_style_context_add_class (context, "security_unknown");
+            gtk_style_context_remove_class (context, "security_trusted");
+        }
+        else if (hint == MIDORI_SECURITY_TRUSTED)
+        {
+            gtk_style_context_add_class (context, "security_trusted");
+            gtk_style_context_remove_class (context, "security_unknown");
+        }
+        else if (hint == MIDORI_SECURITY_NONE)
+        {
+            gtk_style_context_remove_class (context, "security_unknown");
+            gtk_style_context_remove_class (context, "security_trusted");
+        }
         #else
         GdkColor color = { 0 };
         if (bg_color) gdk_color_parse (bg_color, &color);


More information about the Xfce4-commits mailing list