diff options
author | Benjamin Otte <otte@redhat.com> | 2012-01-04 18:42:38 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-01-09 18:37:58 +0100 |
commit | a43553ab86b1fd195c50414ecc2b0f52eaffda4f (patch) | |
tree | 077e24cfe9ea39ebc23fe4c6284f7e3b97692937 /gtk/gtkcssimage.c | |
parent | 4b7ca9602da729d870b45d7ab5e5de6abe5c802a (diff) | |
download | gtk+-a43553ab86b1fd195c50414ecc2b0f52eaffda4f.tar.gz |
cssimage: Add _gtk_css_image_can_parse()
Looks at the first token of the stream to see if this looks like an
image declaration. If it does: return %TRUE.
Diffstat (limited to 'gtk/gtkcssimage.c')
-rw-r--r-- | gtk/gtkcssimage.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c index 232c2ae65c..97be237551 100644 --- a/gtk/gtkcssimage.c +++ b/gtk/gtkcssimage.c @@ -313,9 +313,8 @@ _gtk_css_image_get_surface (GtkCssImage *image, return result; } -GtkCssImage * -_gtk_css_image_new_parse (GtkCssParser *parser, - GFile *base) +GType +gtk_css_image_get_parser_type (GtkCssParser *parser) { static const struct { const char *prefix; @@ -327,30 +326,59 @@ _gtk_css_image_new_parse (GtkCssParser *parser, }; guint i; - g_return_val_if_fail (parser != NULL, NULL); - g_return_val_if_fail (G_IS_FILE (base), NULL); - for (i = 0; i < G_N_ELEMENTS (image_types); i++) { if (_gtk_css_parser_has_prefix (parser, image_types[i].prefix)) - { - GtkCssImage *image; - GtkCssImageClass *klass; + return image_types[i].type_func (); + } - image = g_object_new (image_types[i].type_func (), NULL); + return G_TYPE_INVALID; +} - klass = GTK_CSS_IMAGE_GET_CLASS (image); - if (!klass->parse (image, parser, base)) - { - g_object_unref (image); - return NULL; - } +/** + * _gtk_css_image_can_parse: + * @parser: a css parser + * + * Checks if the parser can potentially parse the given stream as an + * image from looking at the first token of @parser. This is useful for + * implementing shorthand properties. A successful parse of an image + * can not be guaranteed. + * + * Returns: %TURE if it looks like an image. + **/ +gboolean +_gtk_css_image_can_parse (GtkCssParser *parser) +{ + return gtk_css_image_get_parser_type (parser) != G_TYPE_INVALID; +} - return image; - } +GtkCssImage * +_gtk_css_image_new_parse (GtkCssParser *parser, + GFile *base) +{ + GtkCssImageClass *klass; + GtkCssImage *image; + GType image_type; + + g_return_val_if_fail (parser != NULL, NULL); + g_return_val_if_fail (G_IS_FILE (base), NULL); + + image_type = gtk_css_image_get_parser_type (parser); + if (image_type == G_TYPE_INVALID) + { + _gtk_css_parser_error (parser, "Not a valid image"); + return NULL; + } + + image = g_object_new (image_type, NULL); + + klass = GTK_CSS_IMAGE_GET_CLASS (image); + if (!klass->parse (image, parser, base)) + { + g_object_unref (image); + return NULL; } - _gtk_css_parser_error (parser, "Not a valid image"); - return NULL; + return image; } |