]> spindle.queued.net Git - midori/commitdiff
Render stock:// as pixbufs and pass as data URIs
authorChristian Dywan <christian@twotoasts.de>
Thu, 20 May 2010 23:17:43 +0000 (01:17 +0200)
committerChristian Dywan <christian@twotoasts.de>
Fri, 21 May 2010 00:23:15 +0000 (02:23 +0200)
Stock icons do not match filenames in many icon themes and the
appropriate sizes may not be available. Thus we now always
render the icon through the theme engine and encode it as a
data URI with BASE64/ PNG.

As a side effect, we use stock sizes now instead of pixel sizes,
where 1 means menu size, 4 means button size and 6 dialog size;
the value 16 is translated to 4 to keep existing files working.

data/speeddial-head.html
midori/midori-view.c

index 2e015076ee28836aba9dea1cb7f4d8812d2eb04d..6d5814fdd05d8b7a81ebd3978d69de42851b609c 100644 (file)
         margin-bottom: -17px;
         margin-left: 180px;
         margin-top: 2px;
-        background: url({stock}/16/gtk-close) 98% 70% no-repeat;
+        background: url({stock}/1/gtk-close) 98% 70% no-repeat;
         cursor: pointer;
         z-index: -4;
         opacity: 0.6;
 
     .activated p {
         cursor: text;
-        background: url({stock}/16/gtk-edit) 98% 70% no-repeat;
+        background: url({stock}/1/gtk-edit) 98% 70% no-repeat;
         opacity: 0.6;
         color: rgba(0,0,0,1);
     }
index 89f068c030b48aba6230ff0474253af20aef61cc..cc183b2c43186f6af32ea6988ee0fd471aefe07a 100644 (file)
@@ -1117,13 +1117,13 @@ midori_view_web_view_resource_request_cb (WebKitWebView*         web_view,
     }
     else if (g_str_has_prefix (uri, "stock://"))
     {
-        GtkIconTheme* icon_theme = gtk_icon_theme_get_default ();
+        GdkPixbuf* pixbuf;
         const gchar* icon_name = &uri[8] ? &uri[8] : "";
-        gint icon_size = 22;
-        GtkIconInfo* info;
+        gint icon_size = GTK_ICON_SIZE_MENU;
 
         if (g_ascii_isalpha (icon_name[0]))
-            icon_size = strstr (icon_name, "dialog") ? 48 : 22;
+            icon_size = strstr (icon_name, "dialog") ?
+                GTK_ICON_SIZE_DIALOG : GTK_ICON_SIZE_BUTTON;
         else if (g_ascii_isdigit (icon_name[0]))
         {
             guint i = 0;
@@ -1132,21 +1132,38 @@ midori_view_web_view_resource_request_cb (WebKitWebView*         web_view,
                 {
                     gchar* size = g_strndup (icon_name, i - 1);
                     icon_size = atoi (size);
+                    /* Compatibility: map pixel to symbolic size */
+                    if (icon_size == 16)
+                        icon_size = GTK_ICON_SIZE_MENU;
                     g_free (size);
                     icon_name = &icon_name[i];
                 }
         }
 
-        if ((info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, icon_size, 0)))
+        pixbuf = gtk_widget_render_icon (GTK_WIDGET (view), icon_name, icon_size, NULL);
+        if (!pixbuf)
+            pixbuf = gtk_widget_render_icon (GTK_WIDGET (view),
+                GTK_STOCK_MISSING_IMAGE, icon_size, NULL);
+        if (pixbuf)
         {
-            const gchar* filename = gtk_icon_info_get_filename (info);
-            if (filename)
-            {
-                gchar* file_uri = g_filename_to_uri (filename, NULL, NULL);
-                webkit_network_request_set_uri (request, file_uri);
-                g_free (file_uri);
-            }
-            gtk_icon_info_free (info);
+            gboolean success;
+            gchar* buffer;
+            gsize buffer_size;
+            gchar* encoded;
+            gchar* data_uri;
+
+            success = gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &buffer_size, "png", NULL, NULL);
+            g_object_unref (pixbuf);
+            if (!success)
+                return;
+
+            encoded = g_base64_encode ((guchar*)buffer, buffer_size);
+            g_free (buffer);
+            data_uri = g_strconcat ("data:image/png;base64,", encoded, NULL);
+            g_free (encoded);
+            webkit_network_request_set_uri (request, data_uri);
+            g_free (data_uri);
+            return;
         }
     }
 }