X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkcssimage.c;h=a89402e2a7ff93ee0eccdc265a85688e5422ce01;hb=9d0febc9a64a5bfb0fcfc3a88de4757f6c1ff090;hp=232c2ae65c6609846e62a7f6b8a2457b4f80c41b;hpb=2bb899b5c02d09b860e3cebc70511b1a0cfd03a2;p=~andy%2Fgtk diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c index 232c2ae65..a89402e2a 100644 --- a/gtk/gtkcssimage.c +++ b/gtk/gtkcssimage.c @@ -12,8 +12,7 @@ * 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 . * * Authors: Benjamin Otte */ @@ -24,6 +23,7 @@ /* for the types only */ #include "gtk/gtkcssimagegradientprivate.h" +#include "gtk/gtkcssimagelinearprivate.h" #include "gtk/gtkcssimageurlprivate.h" #include "gtk/gtkcssimagewin32private.h" @@ -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; @@ -323,34 +322,65 @@ _gtk_css_image_new_parse (GtkCssParser *parser, } image_types[] = { { "url", _gtk_css_image_url_get_type }, { "-gtk-gradient", _gtk_css_image_gradient_get_type }, - { "-gtk-win32-theme-part", _gtk_css_image_win32_get_type } + { "-gtk-win32-theme-part", _gtk_css_image_win32_get_type }, + { "linear-gradient", _gtk_css_image_linear_get_type }, + { "repeating-linear-gradient", _gtk_css_image_linear_get_type } }; 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; }