diff --git a/gtk/gtkcssimageurl.c b/gtk/gtkcssimageurl.c index 8fa2965a42..b12d8c56bf 100644 --- a/gtk/gtkcssimageurl.c +++ b/gtk/gtkcssimageurl.c @@ -72,7 +72,7 @@ gtk_css_image_url_parse (GtkCssImage *image, 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; diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c index 7d3fa95274..bedfdec1c1 100644 --- a/gtk/gtkcssparser.c +++ b/gtk/gtkcssparser.c @@ -125,6 +125,49 @@ _gtk_css_parser_get_position (GtkCssParser *parser) return parser->data - parser->line_start; } +static GFile * +gtk_css_parser_get_base_file (GtkCssParser *parser) +{ + GFile *base; + + if (parser->file) + { + base = g_file_get_parent (parser->file); + } + else + { + char *dir = g_get_current_dir (); + base = g_file_new_for_path (dir); + g_free (dir); + } + + return base; +} + +GFile * +_gtk_css_parser_get_file_for_path (GtkCssParser *parser, + const char *path) +{ + GFile *base, *file; + + g_return_val_if_fail (parser != NULL, NULL); + g_return_val_if_fail (path != NULL, NULL); + + base = gtk_css_parser_get_base_file (parser); + file = g_file_resolve_relative_path (base, path); + g_object_unref (base); + + return file; +} + +GFile * +_gtk_css_parser_get_file (GtkCssParser *parser) +{ + g_return_val_if_fail (parser != NULL, NULL); + + return parser->file; +} + void _gtk_css_parser_take_error (GtkCssParser *parser, GError *error) @@ -781,8 +824,7 @@ _gtk_css_parser_try_hash_color (GtkCssParser *parser, } GFile * -_gtk_css_parser_read_url (GtkCssParser *parser, - GFile *base) +_gtk_css_parser_read_url (GtkCssParser *parser) { gchar *path; char *scheme; @@ -836,7 +878,7 @@ _gtk_css_parser_read_url (GtkCssParser *parser, } } - file = g_file_resolve_relative_path (base, path); + file = _gtk_css_parser_get_file_for_path (parser, path); g_free (path); return file; diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h index 8609531f02..3c6f3ba81b 100644 --- a/gtk/gtkcssparserprivate.h +++ b/gtk/gtkcssparserprivate.h @@ -47,6 +47,9 @@ void _gtk_css_parser_error_full (GtkCssParser *parser guint _gtk_css_parser_get_line (GtkCssParser *parser); guint _gtk_css_parser_get_position (GtkCssParser *parser); +GFile * _gtk_css_parser_get_file (GtkCssParser *parser); +GFile * _gtk_css_parser_get_file_for_path (GtkCssParser *parser, + const char *path); gboolean _gtk_css_parser_is_eof (GtkCssParser *parser); gboolean _gtk_css_parser_begins_with (GtkCssParser *parser, @@ -87,8 +90,7 @@ gboolean _gtk_css_parser_try_hash_color (GtkCssParser *parser gboolean _gtk_css_parser_has_number (GtkCssParser *parser); char * _gtk_css_parser_read_string (GtkCssParser *parser); char * _gtk_css_parser_read_value (GtkCssParser *parser); -GFile * _gtk_css_parser_read_url (GtkCssParser *parser, - GFile *base); +GFile * _gtk_css_parser_read_url (GtkCssParser *parser); void _gtk_css_parser_skip_whitespace (GtkCssParser *parser); void _gtk_css_parser_resync (GtkCssParser *parser, diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index 6ed7ddefc1..31bf88953f 100644 --- a/gtk/gtkcssprovider.c +++ b/gtk/gtkcssprovider.c @@ -1899,8 +1899,7 @@ parse_import (GtkCssScanner *scanner) } else { - file = _gtk_css_parser_read_url (scanner->parser, - gtk_css_scanner_get_base_url (scanner)); + file = _gtk_css_parser_read_url (scanner->parser); } if (file == NULL) diff --git a/gtk/gtkcssstylefuncs.c b/gtk/gtkcssstylefuncs.c index 7456442934..538079dd27 100644 --- a/gtk/gtkcssstylefuncs.c +++ b/gtk/gtkcssstylefuncs.c @@ -725,7 +725,7 @@ pattern_value_parse (GtkCssParser *parser, cairo_t *cr; cairo_matrix_t matrix; - file = _gtk_css_parser_read_url (parser, base); + file = _gtk_css_parser_read_url (parser); if (file == NULL) return FALSE;