diff options
-rw-r--r-- | gtk/gtkcssimageurl.c | 27 | ||||
-rw-r--r-- | testsuite/reftests/data-url.css | 3 | ||||
-rw-r--r-- | testsuite/reftests/data-url.ref.ui | 12 | ||||
-rw-r--r-- | testsuite/reftests/data-url.ui | 8 | ||||
-rw-r--r-- | testsuite/reftests/meson.build | 3 |
5 files changed, 53 insertions, 0 deletions
diff --git a/gtk/gtkcssimageurl.c b/gtk/gtkcssimageurl.c index e46dd0ac9b..361844394d 100644 --- a/gtk/gtkcssimageurl.c +++ b/gtk/gtkcssimageurl.c @@ -27,6 +27,8 @@ #include "gtkcssimagepaintableprivate.h" #include "gtkstyleproviderprivate.h" +#include "gtk/css/gtkcssdataurlprivate.h" + G_DEFINE_TYPE (GtkCssImageUrl, _gtk_css_image_url, GTK_TYPE_CSS_IMAGE) static GtkCssImage * @@ -52,6 +54,31 @@ gtk_css_image_url_load_image (GtkCssImageUrl *url, g_free (resource_path); g_free (uri); } + else if (g_file_has_uri_scheme (url->file, "data")) + { + GInputStream *stream; + char *uri; + GdkPixbuf *pixbuf; + GBytes *bytes; + + uri = g_file_get_uri (url->file); + texture = NULL; + + bytes = gtk_css_data_url_parse (uri, NULL, &local_error); + if (bytes) + { + stream = g_memory_input_stream_new_from_bytes (bytes); + pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &local_error); + g_object_unref (stream); + if (pixbuf != NULL) + { + texture = gdk_texture_new_for_pixbuf (pixbuf); + g_object_unref (pixbuf); + } + } + + g_free (uri); + } else { texture = gdk_texture_new_from_file (url->file, &local_error); diff --git a/testsuite/reftests/data-url.css b/testsuite/reftests/data-url.css new file mode 100644 index 0000000000..94d9625690 --- /dev/null +++ b/testsuite/reftests/data-url.css @@ -0,0 +1,3 @@ +.background { + background: red url('data:,<svg><rect width="20" height="20" style="fill:lime"/></svg>'); +} diff --git a/testsuite/reftests/data-url.ref.ui b/testsuite/reftests/data-url.ref.ui new file mode 100644 index 0000000000..7a09474075 --- /dev/null +++ b/testsuite/reftests/data-url.ref.ui @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <object class="GtkWindow"> + <property name="type">popup</property> + <child> + <object class="GtkPicture"> + <property name="can-shrink">0</property> + <property name="paintable">green-20x20.png</property> + </object> + </child> + </object> +</interface> diff --git a/testsuite/reftests/data-url.ui b/testsuite/reftests/data-url.ui new file mode 100644 index 0000000000..6fa417228a --- /dev/null +++ b/testsuite/reftests/data-url.ui @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <object class="GtkWindow" id="window1"> + <property name="width_request">20</property> + <property name="height_request">20</property> + <property name="type">popup</property> + </object> +</interface> diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build index 3bbfe1abdd..6039ae709f 100644 --- a/testsuite/reftests/meson.build +++ b/testsuite/reftests/meson.build @@ -194,6 +194,9 @@ testdata = [ 'css-multi-state.css', 'css-multi-state.ref.ui', 'css-multi-state.ui', + 'data-url.css', + 'data-url.ref.ui', + 'data-url.ui', 'fixed-widget-stacking.ref.ui', 'fixed-widget-stacking.ui', 'flipping-icons.ref.ui', |