]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssimageurl.c
quartz: merge the clipboard storing code from gtk-2-24
[~andy/gtk] / gtk / gtkcssimageurl.c
index 2f1cca9a4743170c8b09136d56ce55e2ce2bc263..92126d3859383e3d0640bfdec2ef902556ed00c8 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Benjamin Otte <otte@gnome.org>
  */
 
 #include "config.h"
 
+#include <string.h>
+
 #include "gtkcssimageurlprivate.h"
 
 #include "gtkcssprovider.h"
@@ -61,25 +62,45 @@ gtk_css_image_url_draw (GtkCssImage        *image,
 
 static gboolean
 gtk_css_image_url_parse (GtkCssImage  *image,
-                         GtkCssParser *parser,
-                         GFile        *base)
+                         GtkCssParser *parser)
 {
   GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
   GdkPixbuf *pixbuf;
   GFile *file;
-  char *path;
   cairo_t *cr;
   GError *error = NULL;
+  GFileInputStream *input;
 
-  file = _gtk_css_parser_read_url (parser, base);
+  file = _gtk_css_parser_read_url (parser);
   if (file == NULL)
     return FALSE;
 
-  path = g_file_get_path (file);
+  /* We special case resources here so we can use
+     gdk_pixbuf_new_from_resource, which in turn has some special casing
+     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
+  if (g_file_has_uri_scheme (file, "resource"))
+    {
+      char *uri = g_file_get_uri (file);
+      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
+
+      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
+      g_free (resource_path);
+      g_free (uri);
+    }
+  else
+    {
+      input = g_file_read (file, NULL, &error);
+      if (input == NULL)
+       {
+         _gtk_css_parser_take_error (parser, error);
+         return FALSE;
+       }
+
+      pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
+      g_object_unref (input);
+    }
   g_object_unref (file);
 
-  pixbuf = gdk_pixbuf_new_from_file (path, &error);
-  g_free (path);
   if (pixbuf == NULL)
     {
       _gtk_css_parser_take_error (parser, error);