From 4ccdd4c7d275b3734ea11adec95a0d28d3ddfda6 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Tue, 7 Oct 2003 21:34:27 +0000 Subject: [project @ 2003-10-07 21:34:27 by bursa] Implement white-space property, rename struct node to struct css_node and NODE_* to CSS_NODE_*. svn path=/import/netsurf/; revision=347 --- css/css.c | 102 +++++++++++++++++++----------------- css/css.h | 100 +++++++++++++++++------------------ css/css_enums | 2 +- css/parser.y | 94 ++++++++++++++++----------------- css/ruleset.c | 164 +++++++++++++++++++++++++++++++--------------------------- 5 files changed, 242 insertions(+), 220 deletions(-) (limited to 'css') diff --git a/css/css.c b/css/css.c index 892cf9211..7afdee9d1 100644 --- a/css/css.c +++ b/css/css.c @@ -33,8 +33,8 @@ struct decl { static void css_atimport_callback(content_msg msg, struct content *css, void *p1, void *p2, const char *error); -static bool css_match_rule(struct node *rule, xmlNode *element); - +static bool css_match_rule(struct css_node *rule, xmlNode *element); + const struct css_style css_base_style = { 0xffffff, CSS_CLEAR_NONE, @@ -47,7 +47,8 @@ const struct css_style css_base_style = { { CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } }, { CSS_LINE_HEIGHT_ABSOLUTE, { 1.3 } }, CSS_TEXT_ALIGN_LEFT, - { CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } } + { CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } }, + CSS_WHITE_SPACE_NORMAL }; const struct css_style css_empty_style = { @@ -62,7 +63,8 @@ const struct css_style css_empty_style = { { CSS_HEIGHT_INHERIT, { 1, CSS_UNIT_EM } }, { CSS_LINE_HEIGHT_INHERIT, { 1.3 } }, CSS_TEXT_ALIGN_INHERIT, - { CSS_WIDTH_INHERIT, { { 1, CSS_UNIT_EM } } } + { CSS_WIDTH_INHERIT, { { 1, CSS_UNIT_EM } } }, + CSS_WHITE_SPACE_INHERIT }; const struct css_style css_blank_style = { @@ -77,7 +79,8 @@ const struct css_style css_blank_style = { { CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } }, { CSS_LINE_HEIGHT_INHERIT, { 1.3 } }, CSS_TEXT_ALIGN_INHERIT, - { CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } } + { CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } }, + CSS_WHITE_SPACE_INHERIT }; @@ -170,8 +173,8 @@ void css_reformat(struct content *c, unsigned int width, unsigned int height) void css_destroy(struct content *c) { unsigned int i; - struct node *r; - + struct css_node *r; + for (i = 0; i != HASH_SIZE; i++) { for (r = c->data.css.css->rule[i]; r != 0; r = r->next) xfree(r->style); @@ -195,23 +198,23 @@ void css_destroy(struct content *c) * parser support functions */ -struct node * css_new_node(node_type type, char *data, - struct node *left, struct node *right) +struct css_node * css_new_node(css_node_type type, char *data, + struct css_node *left, struct css_node *right) { - struct node *node = xcalloc(1, sizeof(*node)); + struct css_node *node = xcalloc(1, sizeof(*node)); node->type = type; node->data = data; node->data2 = 0; node->left = left; node->right = right; node->next = 0; - node->comb = COMB_NONE; + node->comb = CSS_COMB_NONE; node->style = 0; node->specificity = 0; return node; } -void css_free_node(struct node *node) +void css_free_node(struct css_node *node) { if (node == 0) return; @@ -235,7 +238,7 @@ char *css_unquote(char *s) } -void css_atimport(struct content *c, struct node *node) +void css_atimport(struct content *c, struct css_node *node) { char *s, *url; int string = 0, screen = 1; @@ -245,7 +248,7 @@ void css_atimport(struct content *c, struct node *node) /* uri(...) or "..." */ switch (node->type) { - case NODE_URI: + case CSS_NODE_URI: LOG(("URI '%s'", node->data)); for (s = node->data + 4; *s == ' ' || *s == '\t' || *s == '\r' || @@ -267,7 +270,7 @@ void css_atimport(struct content *c, struct node *node) else *(s + 1) = 0; break; - case NODE_STRING: + case CSS_NODE_STRING: LOG(("STRING '%s'", node->data)); url = xstrdup(node->data); break; @@ -278,7 +281,7 @@ void css_atimport(struct content *c, struct node *node) /* media not specified, 'screen', or 'all' */ for (node = node->next; node != 0; node = node->next) { screen = 0; - if (node->type != NODE_IDENT) { + if (node->type != CSS_NODE_IDENT) { free(url); return; } @@ -288,7 +291,7 @@ void css_atimport(struct content *c, struct node *node) break; } node = node->next; - if (node == 0 || node->type != NODE_COMMA) { + if (node == 0 || node->type != CSS_NODE_COMMA) { free(url); return; } @@ -377,7 +380,7 @@ void css_get_style(struct content *css, xmlNode *element, struct css_style *style) { struct css_stylesheet *stylesheet = css->data.css.css; - struct node *rule; + struct css_node *rule; unsigned int hash, i; /* imported stylesheets */ @@ -403,12 +406,12 @@ void css_get_style(struct content *css, xmlNode *element, * Determine if a rule applies to an element. */ -bool css_match_rule(struct node *rule, xmlNode *element) +bool css_match_rule(struct css_node *rule, xmlNode *element) { bool match; char *s, *word, *space; unsigned int i; - struct node *detail; + struct css_node *detail; xmlNode *anc, *prev; assert(element->type == XML_ELEMENT_NODE); @@ -419,13 +422,13 @@ bool css_match_rule(struct node *rule, xmlNode *element) for (detail = rule->left; detail; detail = detail->next) { match = false; switch (detail->type) { - case NODE_ID: + case CSS_NODE_ID: s = (char *) xmlGetProp(element, (const xmlChar *) "id"); if (s && strcasecmp(detail->data + 1, s) == 0) match = true; break; - case NODE_CLASS: + case CSS_NODE_CLASS: s = (char *) xmlGetProp(element, (const xmlChar *) "class"); if (s) { word = s; @@ -442,21 +445,21 @@ bool css_match_rule(struct node *rule, xmlNode *element) } break; - case NODE_ATTRIB: + case CSS_NODE_ATTRIB: /* matches if an attribute is present */ s = (char *) xmlGetProp(element, (const xmlChar *) detail->data); if (s) match = true; break; - case NODE_ATTRIB_EQ: + case CSS_NODE_ATTRIB_EQ: /* matches if an attribute has a certain value */ s = (char *) xmlGetProp(element, (const xmlChar *) detail->data); if (s && strcasecmp(detail->data2, s) == 0) match = true; break; - case NODE_ATTRIB_INC: + case CSS_NODE_ATTRIB_INC: /* matches if one of the space separated words * in the attribute is equal */ s = (char *) xmlGetProp(element, (const xmlChar *) detail->data); @@ -475,7 +478,7 @@ bool css_match_rule(struct node *rule, xmlNode *element) } break; - case NODE_ATTRIB_DM: + case CSS_NODE_ATTRIB_DM: /* matches if a prefix up to a hyphen matches */ s = (char *) xmlGetProp(element, (const xmlChar *) detail->data); if (s) { @@ -497,16 +500,16 @@ bool css_match_rule(struct node *rule, xmlNode *element) if (!rule->right) return true; - + switch (rule->comb) { - case COMB_ANCESTOR: + case CSS_COMB_ANCESTOR: for (anc = element->parent; anc; anc = anc->parent) if (anc->type == XML_ELEMENT_NODE && css_match_rule(rule->right, anc)) return true; break; - case COMB_PRECEDED: + case CSS_COMB_PRECEDED: for (prev = element->prev; prev && prev->type != XML_ELEMENT_NODE; prev = prev->prev) @@ -516,7 +519,7 @@ bool css_match_rule(struct node *rule, xmlNode *element) return css_match_rule(rule->right, prev); break; - case COMB_PARENT: + case CSS_COMB_PARENT: for (anc = element->parent; anc && anc->type != XML_ELEMENT_NODE; anc = anc->parent) @@ -618,6 +621,7 @@ void css_dump_style(const struct css_style * const style) default: fprintf(stderr, "UNKNOWN"); break; } fprintf(stderr, "; "); + fprintf(stderr, "white-space: %s; ", css_white_space_name[style->white_space]); fprintf(stderr, "}"); } @@ -625,7 +629,7 @@ void css_dump_style(const struct css_style * const style) void css_dump_stylesheet(const struct css_stylesheet * stylesheet) { unsigned int i; - struct node *r, *n, *m; + struct css_node *r, *n, *m; for (i = 0; i != HASH_SIZE; i++) { fprintf(stderr, "hash %i:\n", i); for (r = stylesheet->rule[i]; r != 0; r = r->next) { @@ -634,12 +638,12 @@ void css_dump_stylesheet(const struct css_stylesheet * stylesheet) fprintf(stderr, "%s", n->data); for (m = n->left; m != 0; m = m->next) { switch (m->type) { - case NODE_ID: fprintf(stderr, "%s", m->data); break; - case NODE_CLASS: fprintf(stderr, ".%s", m->data); break; - case NODE_ATTRIB: fprintf(stderr, "[%s]", m->data); break; - case NODE_ATTRIB_EQ: fprintf(stderr, "[%s=%s]", m->data, m->data2); break; - case NODE_ATTRIB_INC: fprintf(stderr, "[%s~=%s]", m->data, m->data2); break; - case NODE_ATTRIB_DM: fprintf(stderr, "[%s|=%s]", m->data, m->data2); break; + case CSS_NODE_ID: fprintf(stderr, "%s", m->data); break; + case CSS_NODE_CLASS: fprintf(stderr, ".%s", m->data); break; + case CSS_NODE_ATTRIB: fprintf(stderr, "[%s]", m->data); break; + case CSS_NODE_ATTRIB_EQ: fprintf(stderr, "[%s=%s]", m->data, m->data2); break; + case CSS_NODE_ATTRIB_INC: fprintf(stderr, "[%s~=%s]", m->data, m->data2); break; + case CSS_NODE_ATTRIB_DM: fprintf(stderr, "[%s|=%s]", m->data, m->data2); break; default: fprintf(stderr, "unexpected node"); } } @@ -671,6 +675,10 @@ void css_cascade(struct css_style * const style, const struct css_style * const style->display = apply->display; if (apply->float_ != CSS_FLOAT_INHERIT) style->float_ = apply->float_; + if (apply->font_style != CSS_FONT_STYLE_INHERIT) + style->font_style = apply->font_style; + if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT) + style->font_weight = apply->font_weight; if (apply->height.height != CSS_HEIGHT_INHERIT) style->height = apply->height; if (apply->line_height.size != CSS_LINE_HEIGHT_INHERIT) @@ -679,10 +687,8 @@ void css_cascade(struct css_style * const style, const struct css_style * const style->text_align = apply->text_align; if (apply->width.width != CSS_WIDTH_INHERIT) style->width = apply->width; - if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT) - style->font_weight = apply->font_weight; - if (apply->font_style != CSS_FONT_STYLE_INHERIT) - style->font_style = apply->font_style; + if (apply->white_space != CSS_WHITE_SPACE_INHERIT) + style->white_space = apply->white_space; /* font-size */ f = apply->font_size.value.percent / 100; @@ -736,6 +742,12 @@ void css_merge(struct css_style * const style, const struct css_style * const ap style->display = apply->display; if (apply->float_ != CSS_FLOAT_INHERIT) style->float_ = apply->float_; + if (apply->font_size.size != CSS_FONT_SIZE_INHERIT) + style->font_size = apply->font_size; + if (apply->font_style != CSS_FONT_STYLE_INHERIT) + style->font_style = apply->font_style; + if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT) + style->font_weight = apply->font_weight; if (apply->height.height != CSS_HEIGHT_INHERIT) style->height = apply->height; if (apply->line_height.size != CSS_LINE_HEIGHT_INHERIT) @@ -744,12 +756,8 @@ void css_merge(struct css_style * const style, const struct css_style * const ap style->text_align = apply->text_align; if (apply->width.width != CSS_WIDTH_INHERIT) style->width = apply->width; - if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT) - style->font_weight = apply->font_weight; - if (apply->font_style != CSS_FONT_STYLE_INHERIT) - style->font_style = apply->font_style; - if (apply->font_size.size != CSS_FONT_SIZE_INHERIT) - style->font_size = apply->font_size; + if (apply->white_space != CSS_WHITE_SPACE_INHERIT) + style->white_space = apply->white_space; } diff --git a/css/css.h b/css/css.h index 8b0c5b3b4..ae5d88433 100644 --- a/css/css.h +++ b/css/css.h @@ -78,6 +78,8 @@ struct css_style { float percent; } value; } width; + + css_white_space white_space; }; struct css_stylesheet; @@ -104,50 +106,50 @@ extern const struct css_style css_blank_style; #ifdef CSS_INTERNALS typedef enum { - NODE_BLOCK, - NODE_DECLARATION, - NODE_IDENT, - NODE_NUMBER, - NODE_PERCENTAGE, - NODE_DIMENSION, - NODE_STRING, - NODE_DELIM, - NODE_URI, - NODE_HASH, - NODE_UNICODE_RANGE, - NODE_INCLUDES, - NODE_FUNCTION, - NODE_DASHMATCH, - NODE_COLON, - NODE_COMMA, - NODE_PLUS, - NODE_GT, - NODE_PAREN, - NODE_BRAC, - NODE_SELECTOR, - NODE_ID, - NODE_CLASS, - NODE_ATTRIB, - NODE_ATTRIB_EQ, - NODE_ATTRIB_INC, - NODE_ATTRIB_DM, -} node_type; + CSS_NODE_BLOCK, + CSS_NODE_DECLARATION, + CSS_NODE_IDENT, + CSS_NODE_NUMBER, + CSS_NODE_PERCENTAGE, + CSS_NODE_DIMENSION, + CSS_NODE_STRING, + CSS_NODE_DELIM, + CSS_NODE_URI, + CSS_NODE_HASH, + CSS_NODE_UNICODE_RANGE, + CSS_NODE_INCLUDES, + CSS_NODE_FUNCTION, + CSS_NODE_DASHMATCH, + CSS_NODE_COLON, + CSS_NODE_COMMA, + CSS_NODE_PLUS, + CSS_NODE_GT, + CSS_NODE_PAREN, + CSS_NODE_BRAC, + CSS_NODE_SELECTOR, + CSS_NODE_ID, + CSS_NODE_CLASS, + CSS_NODE_ATTRIB, + CSS_NODE_ATTRIB_EQ, + CSS_NODE_ATTRIB_INC, + CSS_NODE_ATTRIB_DM, +} css_node_type; typedef enum { - COMB_NONE, - COMB_ANCESTOR, - COMB_PARENT, - COMB_PRECEDED, -} combinator; - -struct node { - node_type type; + CSS_COMB_NONE, + CSS_COMB_ANCESTOR, + CSS_COMB_PARENT, + CSS_COMB_PRECEDED, +} css_combinator; + +struct css_node { + css_node_type type; char *data; char *data2; - struct node *left; - struct node *right; - struct node *next; - combinator comb; + struct css_node *left; + struct css_node *right; + struct css_node *next; + css_combinator comb; struct css_style *style; unsigned long specificity; }; @@ -159,13 +161,13 @@ struct node { struct css_stylesheet { yyscan_t lexer; void *parser; - struct node *rule[HASH_SIZE]; + struct css_node *rule[HASH_SIZE]; }; struct parse_params { int ruleset_only; struct content *stylesheet; - struct node *declaration; + struct css_node *declaration; }; #endif @@ -185,15 +187,15 @@ void css_destroy(struct content *c); #ifdef CSS_INTERNALS -struct node * css_new_node(node_type type, char *data, - struct node *left, struct node *right); -void css_free_node(struct node *node); +struct css_node * css_new_node(css_node_type type, char *data, + struct css_node *left, struct css_node *right); +void css_free_node(struct css_node *node); char *css_unquote(char *s); -void css_atimport(struct content *c, struct node *node); +void css_atimport(struct content *c, struct css_node *node); void css_add_ruleset(struct content *c, - struct node *selector, - struct node *declaration); -void css_add_declarations(struct css_style *style, struct node *declaration); + struct css_node *selector, + struct css_node *declaration); +void css_add_declarations(struct css_style *style, struct css_node *declaration); unsigned int css_hash(const char *s); void css_parser_Trace(FILE *TraceFILE, char *zTracePrompt); diff --git a/css/css_enums b/css/css_enums index 56f5c63ab..19b626026 100644 --- a/css/css_enums +++ b/css/css_enums @@ -18,4 +18,4 @@ css_text_align inherit left right center justify css_text_decoration none blink line_through overline underline css_text_transform none capitalize lowercase uppercase css_vertical_align baseline bottom middle sub super text_bottom text_top top percent -css_white_space normal nowrap pre +css_white_space inherit normal nowrap pre diff --git a/css/parser.y b/css/parser.y index 75706eb16..108a172dd 100644 --- a/css/parser.y +++ b/css/parser.y @@ -69,19 +69,19 @@ selector_list(A) ::= selector_list(B) COMMA selector(C). selector(A) ::= simple_selector(B). { A = B; } -selector(A) ::= selector(B) combinator(C) simple_selector(D). +selector(A) ::= selector(B) css_combinator(C) simple_selector(D). { D->right = B; D->comb = C; A = D; A->specificity += B->specificity; } -combinator(A) ::= . - { A = COMB_ANCESTOR; } -combinator(A) ::= PLUS. - { A = COMB_PRECEDED; } -combinator(A) ::= GT. - { A = COMB_PARENT; } +css_combinator(A) ::= . + { A = CSS_COMB_ANCESTOR; } +css_combinator(A) ::= PLUS. + { A = CSS_COMB_PRECEDED; } +css_combinator(A) ::= GT. + { A = CSS_COMB_PARENT; } simple_selector(A) ::= element_name(B) detail_list(C). - { A = css_new_node(NODE_SELECTOR, B, C, 0); + { A = css_new_node(CSS_NODE_SELECTOR, B, C, 0); A->specificity = (B ? 1 : 0) + (C ? C->specificity : 0); } element_name(A) ::= . @@ -92,31 +92,31 @@ element_name(A) ::= IDENT(B). detail_list(A) ::= . { A = 0; } detail_list(A) ::= HASH(B) detail_list(C). - { A = css_new_node(NODE_ID, B, 0, 0); + { A = css_new_node(CSS_NODE_ID, B, 0, 0); A->specificity = 0x10000 + (C ? C->specificity : 0); A->next = C; } detail_list(A) ::= DOT IDENT(B) detail_list(C). - { A = css_new_node(NODE_CLASS, B, 0, 0); + { A = css_new_node(CSS_NODE_CLASS, B, 0, 0); A->specificity = 0x100 + (C ? C->specificity : 0); A->next = C; } detail_list(A) ::= LBRAC IDENT(B) RBRAC detail_list(C). - { A = css_new_node(NODE_ATTRIB, B, 0, 0); + { A = css_new_node(CSS_NODE_ATTRIB, B, 0, 0); A->specificity = 0x100 + (C ? C->specificity : 0); A->next = C; } detail_list(A) ::= LBRAC IDENT(B) EQUALS IDENT(C) RBRAC detail_list(D). - { A = css_new_node(NODE_ATTRIB_EQ, B, 0, 0); A->data2 = C; + { A = css_new_node(CSS_NODE_ATTRIB_EQ, B, 0, 0); A->data2 = C; A->specificity = 0x100 + (D ? D->specificity : 0); A->next = D; } detail_list(A) ::= LBRAC IDENT(B) EQUALS STRING(C) RBRAC detail_list(D). - { A = css_new_node(NODE_ATTRIB_EQ, B, 0, 0); A->data2 = css_unquote(C); + { A = css_new_node(CSS_NODE_ATTRIB_EQ, B, 0, 0); A->data2 = css_unquote(C); A->specificity = 0x100 + (D ? D->specificity : 0); A->next = D; } detail_list(A) ::= LBRAC IDENT(B) INCLUDES IDENT(C) RBRAC detail_list(D). - { A = css_new_node(NODE_ATTRIB_INC, B, 0, 0); A->data2 = C; + { A = css_new_node(CSS_NODE_ATTRIB_INC, B, 0, 0); A->data2 = C; A->specificity = 0x100 + (D ? D->specificity : 0); A->next = D; } detail_list(A) ::= LBRAC IDENT(B) INCLUDES STRING(C) RBRAC detail_list(D). - { A = css_new_node(NODE_ATTRIB_INC, B, 0, 0); A->data2 = css_unquote(C); + { A = css_new_node(CSS_NODE_ATTRIB_INC, B, 0, 0); A->data2 = css_unquote(C); A->specificity = 0x100 + (D ? D->specificity : 0); A->next = D; } detail_list(A) ::= LBRAC IDENT(B) DASHMATCH IDENT(C) RBRAC detail_list(D). - { A = css_new_node(NODE_ATTRIB_DM, B, 0, 0); A->data2 = C; + { A = css_new_node(CSS_NODE_ATTRIB_DM, B, 0, 0); A->data2 = C; A->specificity = 0x100 + (D ? D->specificity : 0); A->next = D; } detail_list(A) ::= LBRAC IDENT(B) DASHMATCH STRING(C) RBRAC detail_list(D). - { A = css_new_node(NODE_ATTRIB_DM, B, 0, 0); A->data2 = css_unquote(C); + { A = css_new_node(CSS_NODE_ATTRIB_DM, B, 0, 0); A->data2 = css_unquote(C); A->specificity = 0x100 + (D ? D->specificity : 0); A->next = D; } /* TODO: pseudo */ @@ -130,7 +130,7 @@ declaration_list(A) ::= declaration(B) SEMI declaration_list(C). { B->next = C; A = B; } declaration(A) ::= property(B) COLON value(C). - { A = css_new_node(NODE_DECLARATION, B, C, 0); } + { A = css_new_node(CSS_NODE_DECLARATION, B, C, 0); } property(A) ::= IDENT(B). { A = B; } @@ -151,41 +151,41 @@ any_list(A) ::= any(B) any_list(C). /*any_list_1(A) ::= any(B) any_list(C). { B->next = C; A = B; }*/ any(A) ::= IDENT(B). - { A = css_new_node(NODE_IDENT, B, 0, 0); } + { A = css_new_node(CSS_NODE_IDENT, B, 0, 0); } any(A) ::= NUMBER(B). - { A = css_new_node(NODE_NUMBER, B, 0, 0); } + { A = css_new_node(CSS_NODE_NUMBER, B, 0, 0); } any(A) ::= PERCENTAGE(B). - { A = css_new_node(NODE_PERCENTAGE, B, 0, 0); } + { A = css_new_node(CSS_NODE_PERCENTAGE, B, 0, 0); } any(A) ::= DIMENSION(B). - { A = css_new_node(NODE_DIMENSION, B, 0, 0); } + { A = css_new_node(CSS_NODE_DIMENSION, B, 0, 0); } any(A) ::= STRING(B). - { A = css_new_node(NODE_STRING, css_unquote(B), 0, 0); } + { A = css_new_node(CSS_NODE_STRING, css_unquote(B), 0, 0); } any(A) ::= DELIM(B). - { A = css_new_node(NODE_DELIM, B, 0, 0); } + { A = css_new_node(CSS_NODE_DELIM, B, 0, 0); } any(A) ::= URI(B). - { A = css_new_node(NODE_URI, B, 0, 0); } + { A = css_new_node(CSS_NODE_URI, B, 0, 0); } any(A) ::= HASH(B). - { A = css_new_node(NODE_HASH, B, 0, 0); } + { A = css_new_node(CSS_NODE_HASH, B, 0, 0); } any(A) ::= UNICODE_RANGE(B). - { A = css_new_node(NODE_UNICODE_RANGE, B, 0, 0); } + { A = css_new_node(CSS_NODE_UNICODE_RANGE, B, 0, 0); } any(A) ::= INCLUDES. - { A = css_new_node(NODE_INCLUDES, 0, 0, 0); } + { A = css_new_node(CSS_NODE_INCLUDES, 0, 0, 0); } any(A) ::= FUNCTION(B). - { A = css_new_node(NODE_FUNCTION, B, 0, 0); } + { A = css_new_node(CSS_NODE_FUNCTION, B, 0, 0); } any(A) ::= DASHMATCH. - { A = css_new_node(NODE_DASHMATCH, 0, 0, 0); } + { A = css_new_node(CSS_NODE_DASHMATCH, 0, 0, 0); } any(A) ::= COLON. - { A = css_new_node(NODE_COLON, 0, 0, 0); } + { A = css_new_node(CSS_NODE_COLON, 0, 0, 0); } any(A) ::= COMMA. - { A = css_new_node(NODE_COMMA, 0, 0, 0); } + { A = css_new_node(CSS_NODE_COMMA, 0, 0, 0); } any(A) ::= PLUS. - { A = css_new_node(NODE_PLUS, 0, 0, 0); } + { A = css_new_node(CSS_NODE_PLUS, 0, 0, 0); } any(A) ::= GT. - { A = css_new_node(NODE_GT, 0, 0, 0); } + { A = css_new_node(CSS_NODE_GT, 0, 0, 0); } any(A) ::= LPAREN any_list(B) RPAREN. - { A = css_new_node(NODE_PAREN, 0, B, 0); } + { A = css_new_node(CSS_NODE_PAREN, 0, B, 0); } any(A) ::= LBRAC any_list(B) RBRAC. - { A = css_new_node(NODE_BRAC, 0, B, 0); } + { A = css_new_node(CSS_NODE_BRAC, 0, B, 0); } /* lemon directives */ @@ -201,17 +201,17 @@ any(A) ::= LBRAC any_list(B) RBRAC. %token_type { char* } %token_destructor { xfree($$); } -%type selector_list { struct node * } -%type selector { struct node * } -%type combinator { combinator } -%type simple_selector { struct node * } -%type detail_list { struct node * } -%type declaration_list { struct node * } -%type declaration { struct node * } -%type value { struct node * } -%type any_list { struct node * } -%type any_list_1 { struct node * } -%type any { struct node * } +%type selector_list { struct css_node * } +%type selector { struct css_node * } +%type css_combinator { css_combinator } +%type simple_selector { struct css_node * } +%type detail_list { struct css_node * } +%type declaration_list { struct css_node * } +%type declaration { struct css_node * } +%type value { struct css_node * } +%type any_list { struct css_node * } +%type any_list_1 { struct css_node * } +%type any { struct css_node * } %destructor selector_list { css_free_node($$); } %destructor selector { css_free_node($$); } diff --git a/css/ruleset.c b/css/ruleset.c index f330bd535..81ab6734c 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -19,7 +19,7 @@ struct property_entry { const char name[20]; - void (*parse) (struct css_style * const s, const struct node * const v); + void (*parse) (struct css_style * const s, const struct css_node * const v); }; struct colour_entry { @@ -33,24 +33,25 @@ struct font_size_entry { }; -static int compare_selectors(const struct node *n0, const struct node *n1); +static int compare_selectors(const struct css_node *n0, const struct css_node *n1); static int parse_length(struct css_length * const length, - const struct node * const v, bool non_negative); -static colour parse_colour(const struct node * const v); -static void parse_background(struct css_style * const s, const struct node * v); -static void parse_background_color(struct css_style * const s, const struct node * const v); -static void parse_clear(struct css_style * const s, const struct node * const v); -static void parse_color(struct css_style * const s, const struct node * const v); -static void parse_display(struct css_style * const s, const struct node * const v); -static void parse_float(struct css_style * const s, const struct node * const v); -static void parse_font(struct css_style * const s, const struct node * v); -static void parse_font_size(struct css_style * const s, const struct node * const v); -static void parse_font_style(struct css_style * const s, const struct node * const v); -static void parse_font_weight(struct css_style * const s, const struct node * const v); -static void parse_height(struct css_style * const s, const struct node * const v); -static void parse_line_height(struct css_style * const s, const struct node * const v); -static void parse_text_align(struct css_style * const s, const struct node * const v); -static void parse_width(struct css_style * const s, const struct node * const v); + const struct css_node * const v, bool non_negative); +static colour parse_colour(const struct css_node * const v); +static void parse_background(struct css_style * const s, const struct css_node * v); +static void parse_background_color(struct css_style * const s, const struct css_node * const v); +static void parse_clear(struct css_style * const s, const struct css_node * const v); +static void parse_color(struct css_style * const s, const struct css_node * const v); +static void parse_display(struct css_style * const s, const struct css_node * const v); +static void parse_float(struct css_style * const s, const struct css_node * const v); +static void parse_font(struct css_style * const s, const struct css_node * v); +static void parse_font_size(struct css_style * const s, const struct css_node * const v); +static void parse_font_style(struct css_style * const s, const struct css_node * const v); +static void parse_font_weight(struct css_style * const s, const struct css_node * const v); +static void parse_height(struct css_style * const s, const struct css_node * const v); +static void parse_line_height(struct css_style * const s, const struct css_node * const v); +static void parse_text_align(struct css_style * const s, const struct css_node * const v); +static void parse_width(struct css_style * const s, const struct css_node * const v); +static void parse_white_space(struct css_style * const s, const struct css_node * const v); /* table of property parsers: MUST be sorted by property name */ @@ -68,6 +69,7 @@ static const struct property_entry property_table[] = { { "height", parse_height }, { "line-height", parse_line_height }, { "text-align", parse_text_align }, + { "white-space", parse_white_space }, { "width", parse_width }, }; @@ -111,12 +113,12 @@ static const struct font_size_entry font_size_table[] = { */ void css_add_ruleset(struct content *c, - struct node *selector, - struct node *declaration) + struct css_node *selector, + struct css_node *declaration) { bool found; struct css_stylesheet *stylesheet = c->data.css.css; - struct node *n, *sel, *next_sel, *prev; + struct css_node *n, *sel, *next_sel, *prev; struct css_style *style; unsigned int hash; @@ -125,13 +127,13 @@ void css_add_ruleset(struct content *c, /*LOG(("+++")); for (n = sel; n != 0; n = n->right) { - struct node *m; + struct css_node *m; if (n->data != 0) fprintf(stderr, "%s", n->data); for (m = n->left; m != 0; m = m->next) { switch (m->type) { - case NODE_ID: fprintf(stderr, "%s", m->data); break; - case NODE_CLASS: fprintf(stderr, ".%s", m->data); break; + case CSS_NODE_ID: fprintf(stderr, "%s", m->data); break; + case CSS_NODE_CLASS: fprintf(stderr, ".%s", m->data); break; default: fprintf(stderr, "unexpected node"); } } @@ -186,12 +188,12 @@ void css_add_ruleset(struct content *c, } -void css_add_declarations(struct css_style *style, struct node *declaration) +void css_add_declarations(struct css_style *style, struct css_node *declaration) { - struct node *n; + struct css_node *n; for (n = declaration; n != 0; n = n->next) { struct property_entry *p; - assert(n->type == NODE_DECLARATION && n->data != 0 && n->left != 0); + assert(n->type == CSS_NODE_DECLARATION && n->data != 0 && n->left != 0); p = bsearch(n->data, property_table, sizeof(property_table) / sizeof(property_table[0]), sizeof(property_table[0]), strcasecmp); @@ -202,9 +204,9 @@ void css_add_declarations(struct css_style *style, struct node *declaration) } -int compare_selectors(const struct node *n0, const struct node *n1) +int compare_selectors(const struct css_node *n0, const struct css_node *n1) { - struct node *m0, *m1; + struct css_node *m0, *m1; unsigned int count0 = 0, count1 = 0; /* compare element name */ @@ -239,7 +241,7 @@ int compare_selectors(const struct node *n0, const struct node *n1) } /* compare ancestors */ - if (n0->comb == COMB_NONE) + if (n0->comb == CSS_COMB_NONE) return 1; return compare_selectors(n0->right, n1->right); @@ -251,14 +253,14 @@ int compare_selectors(const struct node *n0, const struct node *n1) * property parsers */ -/* TODO: consider NODE_NUMBER whenever a value may be '0' */ +/* TODO: consider CSS_NODE_NUMBER whenever a value may be '0' */ int parse_length(struct css_length * const length, - const struct node * const v, bool non_negative) + const struct css_node * const v, bool non_negative) { css_unit u; float value; - if (v->type != NODE_DIMENSION) + if (v->type != CSS_NODE_DIMENSION) return 1; u = css_unit_parse(v->data + strspn(v->data, "0123456789+-.")); if (u == CSS_UNIT_UNKNOWN) @@ -284,7 +286,7 @@ colour named_colour(const char *name) } -colour parse_colour(const struct node * const v) +colour parse_colour(const struct css_node * const v) { colour c = CSS_COLOR_NONE; int len; @@ -292,7 +294,7 @@ colour parse_colour(const struct node * const v) struct colour_entry *col; switch (v->type) { - case NODE_HASH: + case CSS_NODE_HASH: len = strlen(v->data); if (len == 4) { if (sscanf(v->data + 1, "%1x%1x%1x", &r, &g, &b) == 3) @@ -303,11 +305,11 @@ colour parse_colour(const struct node * const v) } break; - case NODE_FUNCTION: + case CSS_NODE_FUNCTION: /* TODO: rgb(r, g, b) */ break; - case NODE_IDENT: + case CSS_NODE_IDENT: col = bsearch(v->data, colour_table, sizeof(colour_table) / sizeof(colour_table[0]), sizeof(colour_table[0]), strcasecmp); @@ -323,14 +325,14 @@ colour parse_colour(const struct node * const v) } -void parse_background(struct css_style * const s, const struct node * v) +void parse_background(struct css_style * const s, const struct css_node * v) { colour c; for (; v; v = v->next) { switch (v->type) { - case NODE_HASH: - case NODE_FUNCTION: - case NODE_IDENT: + case CSS_NODE_HASH: + case CSS_NODE_FUNCTION: + case CSS_NODE_IDENT: c = parse_colour(v); if (c != CSS_COLOR_NONE) s->background_color = c; @@ -341,51 +343,51 @@ void parse_background(struct css_style * const s, const struct node * v) } } -void parse_background_color(struct css_style * const s, const struct node * const v) +void parse_background_color(struct css_style * const s, const struct css_node * const v) { colour c = parse_colour(v); if (c != CSS_COLOR_NONE) s->background_color = c; } -void parse_clear(struct css_style * const s, const struct node * const v) +void parse_clear(struct css_style * const s, const struct css_node * const v) { css_clear z; - if (v->type != NODE_IDENT || v->next != 0) + if (v->type != CSS_NODE_IDENT || v->next != 0) return; z = css_clear_parse(v->data); if (z != CSS_CLEAR_UNKNOWN) s->clear = z; } -void parse_color(struct css_style * const s, const struct node * const v) +void parse_color(struct css_style * const s, const struct css_node * const v) { colour c = parse_colour(v); if (c != CSS_COLOR_NONE) s->color = c; } -void parse_display(struct css_style * const s, const struct node * const v) +void parse_display(struct css_style * const s, const struct css_node * const v) { css_display z; - if (v->type != NODE_IDENT || v->next != 0) + if (v->type != CSS_NODE_IDENT || v->next != 0) return; z = css_display_parse(v->data); if (z != CSS_DISPLAY_UNKNOWN) s->display = z; } -void parse_float(struct css_style * const s, const struct node * const v) +void parse_float(struct css_style * const s, const struct css_node * const v) { css_float z; - if (v->type != NODE_IDENT || v->next != 0) + if (v->type != CSS_NODE_IDENT || v->next != 0) return; z = css_float_parse(v->data); if (z != CSS_FLOAT_UNKNOWN) s->float_ = z; } -void parse_font(struct css_style * const s, const struct node * v) +void parse_font(struct css_style * const s, const struct css_node * v) { css_font_style fs; css_font_weight fw; @@ -395,7 +397,7 @@ void parse_font(struct css_style * const s, const struct node * v) s->line_height.value.absolute = 1.3; for (; v; v = v->next) { switch (v->type) { - case NODE_IDENT: + case CSS_NODE_IDENT: /* font-style, font-variant, or font-weight */ fs = css_font_style_parse(v->data); if (fs != CSS_FONT_STYLE_UNKNOWN) { @@ -407,11 +409,11 @@ void parse_font(struct css_style * const s, const struct node * v) s->font_weight = fw; break; } - case NODE_PERCENTAGE: - case NODE_DIMENSION: + case CSS_NODE_PERCENTAGE: + case CSS_NODE_DIMENSION: parse_font_size(s, v); break; - case NODE_DELIM: + case CSS_NODE_DELIM: if (v->data[0] == '/' && v->data[1] == 0 && v->next) { v = v->next; @@ -424,11 +426,11 @@ void parse_font(struct css_style * const s, const struct node * v) } } -void parse_font_size(struct css_style * const s, const struct node * const v) +void parse_font_size(struct css_style * const s, const struct css_node * const v) { struct font_size_entry *fs; switch (v->type) { - case NODE_IDENT: + case CSS_NODE_IDENT: fs = bsearch(v->data, font_size_table, sizeof(font_size_table) / sizeof(font_size_table[0]), sizeof(font_size_table[0]), strcasecmp); @@ -445,12 +447,12 @@ void parse_font_size(struct css_style * const s, const struct node * const v) } break; - case NODE_PERCENTAGE: + case CSS_NODE_PERCENTAGE: s->font_size.size = CSS_FONT_SIZE_PERCENT; s->font_size.value.percent = atof(v->data); break; - case NODE_DIMENSION: + case CSS_NODE_DIMENSION: if (parse_length(&s->font_size.value.length, v, true) == 0) s->font_size.size = CSS_FONT_SIZE_LENGTH; break; @@ -460,68 +462,78 @@ void parse_font_size(struct css_style * const s, const struct node * const v) } } -void parse_font_style(struct css_style * const s, const struct node * const v) +void parse_font_style(struct css_style * const s, const struct css_node * const v) { css_font_style z; - if (v->type != NODE_IDENT || v->next != 0) + if (v->type != CSS_NODE_IDENT || v->next != 0) return; z = css_font_style_parse(v->data); if (z != CSS_FONT_STYLE_UNKNOWN) s->font_style = z; } -void parse_font_weight(struct css_style * const s, const struct node * const v) +void parse_font_weight(struct css_style * const s, const struct css_node * const v) { css_font_weight z; - if (v->type != NODE_IDENT || v->next != 0) + if (v->type != CSS_NODE_IDENT || v->next != 0) return; z = css_font_weight_parse(v->data); if (z != CSS_FONT_WEIGHT_UNKNOWN) s->font_weight = z; } -void parse_height(struct css_style * const s, const struct node * const v) +void parse_height(struct css_style * const s, const struct css_node * const v) { - if (v->type == NODE_IDENT && strcasecmp(v->data, "auto") == 0) + if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "auto") == 0) s->height.height = CSS_HEIGHT_AUTO; - else if (v->type == NODE_DIMENSION && parse_length(&s->height.length, v, true) == 0) + else if (v->type == CSS_NODE_DIMENSION && parse_length(&s->height.length, v, true) == 0) s->height.height = CSS_HEIGHT_LENGTH; } -void parse_line_height(struct css_style * const s, const struct node * const v) +void parse_line_height(struct css_style * const s, const struct css_node * const v) { - if (v->type == NODE_IDENT && strcasecmp(v->data, "normal") == 0) { + if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "normal") == 0) { s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE; s->line_height.value.absolute = 1.3; - } else if (v->type == NODE_PERCENTAGE) { + } else if (v->type == CSS_NODE_PERCENTAGE) { s->line_height.size = CSS_LINE_HEIGHT_PERCENT; s->line_height.value.percent = atof(v->data); - } else if (v->type == NODE_DIMENSION && + } else if (v->type == CSS_NODE_DIMENSION && parse_length(&s->line_height.value.length, v, true) == 0) { s->line_height.size = CSS_LINE_HEIGHT_LENGTH; - } else if (v->type == NODE_NUMBER) { + } else if (v->type == CSS_NODE_NUMBER) { s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE; s->line_height.value.absolute = atof(v->data); } } -void parse_text_align(struct css_style * const s, const struct node * const v) +void parse_text_align(struct css_style * const s, const struct css_node * const v) { css_text_align z; - if (v->type != NODE_IDENT || v->next != 0) + if (v->type != CSS_NODE_IDENT || v->next != 0) return; z = css_text_align_parse(v->data); if (z != CSS_TEXT_ALIGN_UNKNOWN) s->text_align = z; } -void parse_width(struct css_style * const s, const struct node * const v) +void parse_width(struct css_style * const s, const struct css_node * const v) { - if (v->type == NODE_IDENT && strcasecmp(v->data, "auto") == 0) + if (v->type == CSS_NODE_IDENT && strcasecmp(v->data, "auto") == 0) s->width.width = CSS_WIDTH_AUTO; - else if (v->type == NODE_PERCENTAGE) { + else if (v->type == CSS_NODE_PERCENTAGE) { s->width.width = CSS_WIDTH_PERCENT; s->width.value.percent = atof(v->data); - } else if (v->type == NODE_DIMENSION && + } else if (v->type == CSS_NODE_DIMENSION && parse_length(&s->width.value.length, v, true) == 0) s->width.width = CSS_WIDTH_LENGTH; } + +void parse_white_space(struct css_style * const s, const struct css_node * const v) +{ + css_white_space z; + if (v->type != CSS_NODE_IDENT || v->next != 0) + return; + z = css_white_space_parse(v->data); + if (z != CSS_WHITE_SPACE_UNKNOWN) + s->white_space = z; +} -- cgit v1.2.3