From 4ff509a419cf48774d31f27e11a59edef1fd52d2 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 18 Jun 2009 20:07:47 +0000 Subject: Centralise !important handling. Document background-attachment parser and make it behave correctly. svn path=/trunk/libcss/; revision=7856 --- src/parse/properties/background.c | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src/parse/properties/background.c') diff --git a/src/parse/properties/background.c b/src/parse/properties/background.c index 46ddf73..491b092 100644 --- a/src/parse/properties/background.c +++ b/src/parse/properties/background.c @@ -13,10 +13,25 @@ #include "parse/properties/properties.h" #include "parse/properties/utils.h" +/** + * Parse background-attachment + * + * \param c Parsing context + * \param vector Vector of tokens to process + * \param ctx Pointer to vector iteration context + * \param result Pointer to location to receive resulting style + * \return CSS_OK on success, + * CSS_NOMEM on memory exhaustion, + * CSS_INVALID if the input is not a valid background-attachment + * + * Post condition: \a *ctx is updated with the next token to process + * If the input is invalid, then \a *ctx remains unchanged. + */ css_error parse_background_attachment(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { + int orig_ctx = *ctx; css_error error; const css_token *ident; uint8_t flags = 0; @@ -25,12 +40,10 @@ css_error parse_background_attachment(css_language *c, /* IDENT (fixed, scroll, inherit) */ ident = parserutils_vector_iterate(vector, ctx); - if (ident == NULL || ident->type != CSS_TOKEN_IDENT) + if (ident == NULL || ident->type != CSS_TOKEN_IDENT) { + *ctx = orig_ctx; return CSS_INVALID; - - error = parse_important(c, vector, ctx, &flags); - if (error != CSS_OK) - return error; + } if (ident->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; @@ -38,15 +51,19 @@ css_error parse_background_attachment(css_language *c, value = BACKGROUND_ATTACHMENT_FIXED; } else if (ident->ilower == c->strings[SCROLL]) { value = BACKGROUND_ATTACHMENT_SCROLL; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_BACKGROUND_ATTACHMENT, flags, value); /* Allocate result */ error = css_stylesheet_style_create(c->sheet, sizeof(opv), result); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } /* Copy the bytecode to it */ memcpy((*result)->bytecode, &opv, sizeof(opv)); @@ -87,10 +104,6 @@ css_error parse_background_color(css_language *c, value = BACKGROUND_COLOR_SET; } - error = parse_important(c, vector, ctx, &flags); - if (error != CSS_OK) - return error; - opv = buildOPV(CSS_PROP_BACKGROUND_COLOR, flags, value); required_size = sizeof(opv); @@ -129,10 +142,6 @@ css_error parse_background_image(css_language *c, token->type != CSS_TOKEN_URI)) return CSS_INVALID; - error = parse_important(c, vector, ctx, &flags); - if (error != CSS_OK) - return error; - if (token->type == CSS_TOKEN_IDENT && token->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; @@ -283,10 +292,6 @@ css_error parse_background_position(css_language *c, } } - error = parse_important(c, vector, ctx, &flags); - if (error != CSS_OK) - return error; - opv = buildOPV(CSS_PROP_BACKGROUND_POSITION, flags, value[0] | value[1]); required_size = sizeof(opv); @@ -337,10 +342,6 @@ css_error parse_background_repeat(css_language *c, if (ident == NULL || ident->type != CSS_TOKEN_IDENT) return CSS_INVALID; - error = parse_important(c, vector, ctx, &flags); - if (error != CSS_OK) - return error; - if (ident->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; } else if (ident->ilower == c->strings[NO_REPEAT]) { -- cgit v1.2.3