diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-05-27 00:26:19 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-05-27 00:26:19 +0000 |
commit | 090da931105b942a42a610f0cb92c9f2cd3e7cfc (patch) | |
tree | 127dbc359afe9c984b9852974de1ea6dac00ba36 /src/parse/properties/positioning.c | |
parent | 23ed45441ad9ed4d66852aaa724dc5bd245c9a21 (diff) | |
download | libcss-090da931105b942a42a610f0cb92c9f2cd3e7cfc.tar.gz libcss-090da931105b942a42a610f0cb92c9f2cd3e7cfc.tar.bz2 |
Move float and alignment property parsers into positioning.c
svn path=/trunk/libcss/; revision=7568
Diffstat (limited to 'src/parse/properties/positioning.c')
-rw-r--r-- | src/parse/properties/positioning.c | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/src/parse/properties/positioning.c b/src/parse/properties/positioning.c index 2e69744..7ed12ec 100644 --- a/src/parse/properties/positioning.c +++ b/src/parse/properties/positioning.c @@ -317,3 +317,186 @@ css_error parse_top(css_language *c, return CSS_OK; } +css_error parse_clear(css_language *c, + const parserutils_vector *vector, int *ctx, + css_style **result) +{ + css_error error; + const css_token *ident; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + + /* IDENT (left, right, both, none, inherit) */ + ident = parserutils_vector_iterate(vector, ctx); + 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[RIGHT]) { + value = CLEAR_RIGHT; + } else if (ident->ilower == c->strings[LEFT]) { + value = CLEAR_LEFT; + } else if (ident->ilower == c->strings[BOTH]) { + value = CLEAR_BOTH; + } else if (ident->ilower == c->strings[NONE]) { + value = CLEAR_NONE; + } else + return CSS_INVALID; + + opv = buildOPV(CSS_PROP_CLEAR, flags, value); + + /* Allocate result */ + error = css_stylesheet_style_create(c->sheet, sizeof(opv), result); + if (error != CSS_OK) + return error; + + /* Copy the bytecode to it */ + memcpy((*result)->bytecode, &opv, sizeof(opv)); + + return CSS_OK; +} + +css_error parse_float(css_language *c, + const parserutils_vector *vector, int *ctx, + css_style **result) +{ + css_error error; + const css_token *ident; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + + /* IDENT (left, right, none, inherit) */ + ident = parserutils_vector_iterate(vector, ctx); + 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[LEFT]) { + value = FLOAT_LEFT; + } else if (ident->ilower == c->strings[RIGHT]) { + value = FLOAT_RIGHT; + } else if (ident->ilower == c->strings[NONE]) { + value = FLOAT_NONE; + } else + return CSS_INVALID; + + opv = buildOPV(CSS_PROP_FLOAT, flags, value); + + /* Allocate result */ + error = css_stylesheet_style_create(c->sheet, sizeof(opv), result); + if (error != CSS_OK) + return error; + + /* Copy the bytecode to it */ + memcpy((*result)->bytecode, &opv, sizeof(opv)); + + return CSS_OK; +} + +css_error parse_vertical_align(css_language *c, + const parserutils_vector *vector, int *ctx, + css_style **result) +{ + css_error error; + const css_token *token; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + css_fixed length = 0; + uint32_t unit = 0; + uint32_t required_size; + + /* length | percentage | IDENT(baseline, sub, super, top, text-top, + * middle, bottom, text-bottom, inherit) + */ + token = parserutils_vector_peek(vector, *ctx); + if (token == NULL) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[INHERIT]) { + parserutils_vector_iterate(vector, ctx); + flags = FLAG_INHERIT; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[BASELINE]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_BASELINE; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[SUB]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_SUB; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[SUPER]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_SUPER; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[TOP]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_TOP; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[TEXT_TOP]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_TEXT_TOP; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[MIDDLE]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_MIDDLE; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[BOTTOM]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_BOTTOM; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[TEXT_BOTTOM]) { + parserutils_vector_iterate(vector, ctx); + value = VERTICAL_ALIGN_TEXT_BOTTOM; + } else { + error = parse_unit_specifier(c, vector, ctx, UNIT_PX, + &length, &unit); + if (error != CSS_OK) + return error; + + if (unit & UNIT_ANGLE || unit & UNIT_TIME || unit & UNIT_FREQ) + return CSS_INVALID; + + value = VERTICAL_ALIGN_SET; + } + + error = parse_important(c, vector, ctx, &flags); + if (error != CSS_OK) + return error; + + opv = buildOPV(CSS_PROP_VERTICAL_ALIGN, flags, value); + + required_size = sizeof(opv); + if ((flags & FLAG_INHERIT) == false && value == VERTICAL_ALIGN_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 == VERTICAL_ALIGN_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; +} + |