forked from AuroraMiddleware/gtk
cssprovider: Keep base url in the scanner
And provide a nice function to query it. Simplifies a bunch of code.
This commit is contained in:
parent
84ba8255fc
commit
5cf6a8a23f
@ -789,6 +789,7 @@ struct SelectorStyleInfo
|
|||||||
struct _GtkCssScannerPrivate
|
struct _GtkCssScannerPrivate
|
||||||
{
|
{
|
||||||
GFile *file;
|
GFile *file;
|
||||||
|
GFile *base;
|
||||||
GSList *state;
|
GSList *state;
|
||||||
GSList *cur_selectors;
|
GSList *cur_selectors;
|
||||||
GHashTable *cur_properties;
|
GHashTable *cur_properties;
|
||||||
@ -1159,7 +1160,16 @@ gtk_css_scanner_new (GFile *file,
|
|||||||
priv = scanner->user_data = g_slice_new0 (GtkCssScannerPrivate);
|
priv = scanner->user_data = g_slice_new0 (GtkCssScannerPrivate);
|
||||||
|
|
||||||
if (file)
|
if (file)
|
||||||
priv->file = g_object_ref (file);
|
{
|
||||||
|
priv->file = g_object_ref (file);
|
||||||
|
priv->base = g_file_get_parent (file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *dir = g_get_current_dir ();
|
||||||
|
priv->base = g_file_new_for_path (dir);
|
||||||
|
g_free (dir);
|
||||||
|
}
|
||||||
|
|
||||||
priv->cur_properties = g_hash_table_new_full (g_str_hash,
|
priv->cur_properties = g_hash_table_new_full (g_str_hash,
|
||||||
g_str_equal,
|
g_str_equal,
|
||||||
@ -1195,6 +1205,14 @@ gtk_css_scanner_new (GFile *file,
|
|||||||
return scanner;
|
return scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GFile *
|
||||||
|
gtk_css_scanner_get_base_url (GScanner *scanner)
|
||||||
|
{
|
||||||
|
GtkCssScannerPrivate *priv = scanner->user_data;
|
||||||
|
|
||||||
|
return priv->base;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_css_provider_init (GtkCssProvider *css_provider)
|
gtk_css_provider_init (GtkCssProvider *css_provider)
|
||||||
{
|
{
|
||||||
@ -2217,8 +2235,7 @@ parse_rule (GtkCssProvider *css_provider,
|
|||||||
{
|
{
|
||||||
gboolean loaded;
|
gboolean loaded;
|
||||||
gchar *path = NULL;
|
gchar *path = NULL;
|
||||||
GFile *base, *actual;
|
GFile *actual;
|
||||||
char *dirname;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
gtk_css_scanner_push_scope (scanner, SCOPE_VALUE);
|
gtk_css_scanner_push_scope (scanner, SCOPE_VALUE);
|
||||||
@ -2235,16 +2252,10 @@ parse_rule (GtkCssProvider *css_provider,
|
|||||||
return G_TOKEN_IDENTIFIER;
|
return G_TOKEN_IDENTIFIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scanner->input_name)
|
actual = _gtk_css_parse_url (gtk_css_scanner_get_base_url (scanner),
|
||||||
dirname = g_path_get_dirname (scanner->input_name);
|
path,
|
||||||
else
|
NULL,
|
||||||
dirname = g_get_current_dir ();
|
&error);
|
||||||
|
|
||||||
base = g_file_new_for_path (dirname);
|
|
||||||
g_free (dirname);
|
|
||||||
|
|
||||||
actual = _gtk_css_parse_url (base, path, NULL, &error);
|
|
||||||
g_object_unref (base);
|
|
||||||
|
|
||||||
if (actual == NULL)
|
if (actual == NULL)
|
||||||
{
|
{
|
||||||
@ -2502,26 +2513,11 @@ parse_rule (GtkCssProvider *css_provider,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GFile *base;
|
|
||||||
char *dirname;
|
|
||||||
gboolean success;
|
|
||||||
|
|
||||||
if (scanner->input_name)
|
if (_gtk_css_value_from_string (val,
|
||||||
dirname = g_path_get_dirname (scanner->input_name);
|
gtk_css_scanner_get_base_url (scanner),
|
||||||
else
|
value_str,
|
||||||
dirname = g_get_current_dir ();
|
&error))
|
||||||
|
|
||||||
base = g_file_new_for_path (dirname);
|
|
||||||
g_free (dirname);
|
|
||||||
|
|
||||||
success = _gtk_css_value_from_string (val,
|
|
||||||
base,
|
|
||||||
value_str,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
g_object_unref (base);
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
g_hash_table_insert (priv->cur_properties, prop, val);
|
g_hash_table_insert (priv->cur_properties, prop, val);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user