From e990b88d1f9fdae173e9c71c9c0e4887689fedbd Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 26 Nov 2008 23:47:30 +0000 Subject: width svn path=/trunk/libcss/; revision=5803 --- src/parse/css21props.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) (limited to 'src/parse') diff --git a/src/parse/css21props.c b/src/parse/css21props.c index 82a5d30..df621ac 100644 --- a/src/parse/css21props.c +++ b/src/parse/css21props.c @@ -4233,10 +4233,62 @@ css_error parse_width(css_css21 *c, const parserutils_vector *vector, int *ctx, css_style **result) { - UNUSED(c); - UNUSED(vector); - UNUSED(ctx); - UNUSED(result); + css_error error; + const css_token *token; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + fixed length = 0; + uint32_t unit = 0; + uint32_t required_size; + + /* length | percentage | IDENT(auto, inherit) */ + token = parserutils_vector_peek(vector, *ctx); + if (token == NULL) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT && + token->lower.ptr == c->strings[INHERIT]) { + parserutils_vector_iterate(vector, ctx); + flags = FLAG_INHERIT; + } else if (token->type == CSS_TOKEN_IDENT && + token->lower.ptr == c->strings[AUTO]) { + parserutils_vector_iterate(vector, ctx); + value = WIDTH_AUTO; + } else { + error = parse_unit_specifier(c, vector, ctx, &length, &unit); + if (error != CSS_OK) + return error; + + if (unit & UNIT_ANGLE || unit & UNIT_TIME || unit & UNIT_FREQ) + return CSS_INVALID; + + value = WIDTH_SET; + } + + error = parse_important(c, vector, ctx, &flags); + if (error != CSS_OK) + return error; + + opv = buildOPV(OP_WIDTH, flags, value); + + required_size = sizeof(opv); + if ((flags & FLAG_INHERIT) == false && value == WIDTH_SET) + required_size += sizeof(length) + sizeof(unit); + + /* Allocate result */ + error = css_stylesheet_style_create(c->sheet, required_size, result); + if (error != CSS_OK) + return error; + + /* Copy the bytecode to it */ + memcpy((*result)->bytecode, &opv, sizeof(opv)); + if ((flags & FLAG_INHERIT) == false && value == WIDTH_SET) { + memcpy(((uint8_t *) (*result)->bytecode) + sizeof(opv), + &length, sizeof(length)); + memcpy(((uint8_t *) (*result)->bytecode) + sizeof(opv) + + sizeof(length), &unit, sizeof(unit)); + } return CSS_OK; } -- cgit v1.2.3