diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2008-12-03 16:00:32 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2008-12-03 16:00:32 +0000 |
commit | e14ee0baa1b7f2bfdca10fa5852385a200746c7d (patch) | |
tree | c2999575403b45b8d246ceb8291357ad18a4b6a0 /src | |
parent | 23aa9cd7d8154c822335531f0619acce43f544b8 (diff) | |
download | libcss-e14ee0baa1b7f2bfdca10fa5852385a200746c7d.tar.gz libcss-e14ee0baa1b7f2bfdca10fa5852385a200746c7d.tar.bz2 |
Changes to the encoding of content in bytecode to better match the spec.
Beginnings of a content property parser.
svn path=/trunk/libcss/; revision=5874
Diffstat (limited to 'src')
-rw-r--r-- | src/bytecode/opcodes.h | 6 | ||||
-rw-r--r-- | src/parse/properties.c | 259 | ||||
-rw-r--r-- | src/parse/propstrings.h | 10 |
3 files changed, 268 insertions, 7 deletions
diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h index 330489e..790b93b 100644 --- a/src/bytecode/opcodes.h +++ b/src/bytecode/opcodes.h @@ -140,7 +140,11 @@ enum op_content { CONTENT_STRING = 0x0080, CONTENT_URI = 0x0081, CONTENT_COUNTER = 0x0082, - CONTENT_ATTR = 0x0083, + CONTENT_COUNTERS = 0x0083, + CONTENT_ATTR = 0x0084, + + CONTENT_COUNTER_STYLE_SHIFT = 8, + CONTENT_COUNTERS_STYLE_SHIFT = 8, CONTENT_NORMAL = 0x0000, CONTENT_NONE = 0x0001, diff --git a/src/parse/properties.c b/src/parse/properties.c index 9f6e69a..9b27408 100644 --- a/src/parse/properties.c +++ b/src/parse/properties.c @@ -1489,11 +1489,260 @@ css_error parse_content(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { - /** \todo content */ - 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; + uint32_t required_size = sizeof(opv); + int temp_ctx = *ctx; + + /* IDENT(normal, none, inherit) | + * [ + * IDENT(open-quote, close-quote, no-open-quote, no-close-quote) | + * STRING | URI | + * FUNCTION(attr) IDENT ')' | + * FUNCTION(counter) IDENT IDENT? ')' | + * FUNCTION(counters) IDENT STRING IDENT? ')' + * ]+ + */ + + /* Pass 1: Calculate required size & validate input */ + token = parserutils_vector_peek(vector, temp_ctx); + if (token == NULL) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[INHERIT]) { + flags = FLAG_INHERIT; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[NORMAL]) { + value = CONTENT_NORMAL; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[NONE]) { + value = CONTENT_NONE; + } else { + bool done_value = false; + + while (token != NULL && tokenIsChar(token, '!') == false) { + if (token->type == CSS_TOKEN_IDENT && + token->ilower == + c->strings[OPEN_QUOTE]) { + if (done_value == false) { + value = CONTENT_OPEN_QUOTE; + } else { + required_size += sizeof(opv); + } + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == + c->strings[CLOSE_QUOTE]) { + if (done_value == false) { + value = CONTENT_CLOSE_QUOTE; + } else { + required_size += sizeof(opv); + } + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == + c->strings[NO_OPEN_QUOTE]) { + if (done_value == false) { + value = CONTENT_NO_OPEN_QUOTE; + } else { + required_size += sizeof(opv); + } + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == + c->strings[NO_CLOSE_QUOTE]) { + if (done_value == false) { + value = CONTENT_NO_CLOSE_QUOTE; + } else { + required_size += sizeof(opv); + } + } else if (token->type == CSS_TOKEN_STRING) { + if (done_value == false) { + value = CONTENT_STRING; + } else { + required_size += sizeof(opv); + } + + required_size += + sizeof(parserutils_hash_entry *); + } else if (token->type == CSS_TOKEN_URI) { + if (done_value == false) { + value = CONTENT_URI; + } else { + required_size += sizeof(opv); + } + + required_size += + sizeof(parserutils_hash_entry *); + } else if (token->type == CSS_TOKEN_FUNCTION && + token->ilower == c->strings[ATTR]) { + if (done_value == false) { + value = CONTENT_ATTR; + } else { + required_size += sizeof(opv); + } + + parserutils_vector_iterate(vector, &temp_ctx); + + consumeWhitespace(vector, &temp_ctx); + + /* Expect IDENT */ + token = parserutils_vector_iterate(vector, + &temp_ctx); + if (token == NULL || + token->type != CSS_TOKEN_IDENT) + return CSS_INVALID; + + consumeWhitespace(vector, &temp_ctx); + + /* Expect ')' */ + token = parserutils_vector_peek(vector, + temp_ctx); + if (token == NULL || tokenIsChar(token, ')') == + false) + return CSS_INVALID; + + required_size += + sizeof(parserutils_hash_entry *); + } else if (token->type == CSS_TOKEN_FUNCTION && + token->ilower == c->strings[COUNTER]) { + if (done_value == false) { + value = CONTENT_COUNTER; + } else { + required_size += sizeof(opv); + } + + parserutils_vector_iterate(vector, &temp_ctx); + + consumeWhitespace(vector, &temp_ctx); + + /* Expect IDENT */ + token = parserutils_vector_iterate(vector, + &temp_ctx); + if (token == NULL || + token->type != CSS_TOKEN_IDENT) + return CSS_INVALID; + + consumeWhitespace(vector, &temp_ctx); + + /* Possible IDENT */ + token = parserutils_vector_peek(vector, + temp_ctx); + if (token == NULL || + (token->type != CSS_TOKEN_IDENT && + tokenIsChar(token, ')') == + false)) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT) { + /** \todo validate list-style-type */ + if (done_value == false) { + /** \todo or style into value */ + } + + parserutils_vector_iterate(vector, + &temp_ctx); + + consumeWhitespace(vector, &temp_ctx); + + token = parserutils_vector_peek(vector, + temp_ctx); + if (token == NULL || tokenIsChar(token, + ')') == false) + return CSS_INVALID; + } + + required_size += + sizeof(parserutils_hash_entry *); + } else if (token->type == CSS_TOKEN_FUNCTION && + token->ilower == c->strings[COUNTERS]) { + if (done_value == false) { + value = CONTENT_COUNTERS; + } else { + required_size += sizeof(opv); + } + + parserutils_vector_iterate(vector, &temp_ctx); + + consumeWhitespace(vector, &temp_ctx); + + /* Expect IDENT */ + token = parserutils_vector_iterate(vector, + &temp_ctx); + if (token == NULL || + token->type != CSS_TOKEN_IDENT) + return CSS_INVALID; + + consumeWhitespace(vector, &temp_ctx); + + /* Expect STRING */ + token = parserutils_vector_iterate(vector, + &temp_ctx); + if (token == NULL || + token->type != CSS_TOKEN_STRING) + return CSS_INVALID; + + consumeWhitespace(vector, &temp_ctx); + + /* Possible IDENT */ + token = parserutils_vector_peek(vector, + temp_ctx); + if (token == NULL || + (token->type != CSS_TOKEN_IDENT && + tokenIsChar(token, ')') == + false)) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT) { + /** \todo validate list-style-type */ + if (done_value == false) { + /** \todo or style into value */ + } + + parserutils_vector_iterate(vector, + &temp_ctx); + + consumeWhitespace(vector, &temp_ctx); + + token = parserutils_vector_peek(vector, + temp_ctx); + if (token == NULL || tokenIsChar(token, + ')') == false) + return CSS_INVALID; + } + + required_size += + 2 * sizeof(parserutils_hash_entry *); + } else { + return CSS_INVALID; + } + + done_value = true; + + parserutils_vector_iterate(vector, &temp_ctx); + + consumeWhitespace(vector, &temp_ctx); + + token = parserutils_vector_peek(vector, temp_ctx); + } + + /* Add on extra space for list terminator */ + required_size += sizeof(opv); + } + + error = parse_important(c, vector, &temp_ctx, &flags); + if (error != CSS_OK) + return error; + + opv = buildOPV(OP_CONTENT, flags, value); + + /* Allocate result */ + error = css_stylesheet_style_create(c->sheet, required_size, result); + if (error != CSS_OK) + return error; + + /** \todo Pass 2: construct bytecode */ return CSS_OK; } diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h index 2942578..7d999c4 100644 --- a/src/parse/propstrings.h +++ b/src/parse/propstrings.h @@ -63,7 +63,8 @@ enum { UPPERCASE, LOWERCASE, EMBED, BIDI_OVERRIDE, BASELINE, SUB, SUPER, TEXT_TOP, MIDDLE, TEXT_BOTTOM, SILENT, X_SOFT, SOFT, LOUD, X_LOUD, PRE, NOWRAP, PRE_WRAP, PRE_LINE, LEFTWARDS, RIGHTWARDS, LEFT_SIDE, - FAR_LEFT, FAR_RIGHT, RIGHT_SIDE, BEHIND, RECT, + FAR_LEFT, FAR_RIGHT, RIGHT_SIDE, BEHIND, RECT, OPEN_QUOTE, CLOSE_QUOTE, + NO_OPEN_QUOTE, NO_CLOSE_QUOTE, ATTR, COUNTER, COUNTERS, LAST_KNOWN }; @@ -313,6 +314,13 @@ static struct { { "right-side", SLEN("right-side") }, { "behind", SLEN("behind") }, { "rect", SLEN("rect") }, + { "open-quote", SLEN("open-quote") }, + { "close-quote", SLEN("close-quote") }, + { "no-open-quote", SLEN("no-open-quote") }, + { "no-close-quote", SLEN("no-close-quote") }, + { "attr", SLEN("attr") }, + { "counter", SLEN("counter") }, + { "counters", SLEN("counters") }, }; #endif |