mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 14:30:15 +00:00
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.
This commit is contained in:
parent
4b7ca9602d
commit
a43553ab86
@ -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,17 +326,51 @@ _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;
|
||||
}
|
||||
|
||||
/**
|
||||
* _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;
|
||||
}
|
||||
|
||||
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))
|
||||
@ -347,10 +380,5 @@ _gtk_css_image_new_parse (GtkCssParser *parser,
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
_gtk_css_parser_error (parser, "Not a valid image");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,7 @@ struct _GtkCssImageClass
|
||||
|
||||
GType _gtk_css_image_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gboolean _gtk_css_image_can_parse (GtkCssParser *parser);
|
||||
GtkCssImage * _gtk_css_image_new_parse (GtkCssParser *parser,
|
||||
GFile *base);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user