]> spindle.queued.net Git - midori/commitdiff
Use style classes for location entry in GTK+3
authorChristian Dywan <christian@twotoasts.de>
Sat, 17 Dec 2011 09:46:03 +0000 (10:46 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sat, 17 Dec 2011 09:46:03 +0000 (10:46 +0100)
The classes are .security_trusted and .security_unknown.

midori/midori-locationaction.c

index f380b6dd74584223e1467ac04b2af926c62df25a..698d9e9ab8bf109620215c6e01f587850cda0153 100644 (file)
@@ -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);