From 63b6455f7365507ce502369b738ecc09e54e25ed Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sun, 13 Apr 2003 12:50:10 +0000 Subject: [project @ 2003-04-13 12:50:10 by bursa] style element, CSS fixes, id selectors. svn path=/import/netsurf/; revision=124 --- css/css.h | 3 ++- css/parser.y | 8 ++++---- css/ruleset.c | 55 ++++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 16 deletions(-) (limited to 'css') diff --git a/css/css.h b/css/css.h index c0b92ac65..2e89345c5 100644 --- a/css/css.h +++ b/css/css.h @@ -1,5 +1,5 @@ /** - * $Id: css.h,v 1.5 2003/04/06 18:09:34 bursa Exp $ + * $Id: css.h,v 1.6 2003/04/13 12:50:10 bursa Exp $ */ #ifndef _NETSURF_CSS_CSS_H_ @@ -190,5 +190,6 @@ void css_get_style(struct content *c, struct css_selector * selector, void css_cascade(struct css_style * const style, const struct css_style * const apply); void css_merge(struct css_style * const style, const struct css_style * const apply); void css_parse_property_list(struct css_style * style, char * str); +colour named_colour(const char *name); #endif diff --git a/css/parser.y b/css/parser.y index 50d793dad..81414e5d0 100644 --- a/css/parser.y +++ b/css/parser.y @@ -1,5 +1,5 @@ /** - * $Id: parser.y,v 1.6 2003/04/06 18:09:34 bursa Exp $ + * $Id: parser.y,v 1.7 2003/04/13 12:50:10 bursa Exp $ */ /* @@ -51,7 +51,7 @@ block_body ::= block_body SEMI. ruleset ::= selector_list(A) LBRACE declaration_list(B) RBRACE. { css_add_ruleset(param->stylesheet, A, B); css_free_node(B); } -ruleset ::= any_list_1(A) LBRACE declaration_list(B) RBRACE. +/*ruleset ::= any_list_1(A) LBRACE declaration_list(B) RBRACE. { css_free_node(A); css_free_node(B); } /* not CSS2 */ ruleset ::= LBRACE declaration_list(A) RBRACE. /* this form of ruleset not used in CSS2 @@ -120,8 +120,8 @@ any_list(A) ::= . { A = 0; } any_list(A) ::= any(B) any_list(C). { B->next = C; A = B; } -any_list_1(A) ::= any(B) any_list(C). - { B->next = C; A = B; } +/*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); } any(A) ::= NUMBER(B). diff --git a/css/ruleset.c b/css/ruleset.c index 57f4f6946..0fa366f3e 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -1,5 +1,5 @@ /** - * $Id: ruleset.c,v 1.6 2003/04/10 21:44:45 bursa Exp $ + * $Id: ruleset.c,v 1.7 2003/04/13 12:50:10 bursa Exp $ */ #include @@ -62,25 +62,26 @@ static const struct property_entry property_table[] = { { "width", parse_width }, }; -/* table of standard colour names: MUST be sorted by colour name */ +/* table of standard colour names: MUST be sorted by colour name + * note: colour is 0xbbggrr */ static const struct colour_entry colour_table[] = { - { "aqua", 0x00ffff }, + { "aqua", 0xffff00 }, { "black", 0x000000 }, - { "blue", 0x0000ff }, + { "blue", 0xff0000 }, { "fuchsia", 0xff00ff }, { "gray", 0x808080 }, { "green", 0x008000 }, { "lime", 0x00ff00 }, - { "maroon", 0x800000 }, - { "navy", 0x000080 }, - { "olive", 0x808000 }, + { "maroon", 0x000080 }, + { "navy", 0x800000 }, + { "olive", 0x008080 }, { "purple", 0x800080 }, - { "red", 0xff0000 }, + { "red", 0x0000ff }, { "silver", 0xc0c0c0 }, - { "teal", 0x008080 }, + { "teal", 0x808000 }, { "transparent", TRANSPARENT }, { "white", 0xffffff }, - { "yellow", 0xffff00 }, + { "yellow", 0x00ffff }, }; /* table of font sizes: MUST be sorted by name */ @@ -112,6 +113,26 @@ void css_add_ruleset(struct content *c, for (sel = selector; sel != 0; sel = next_sel) { next_sel = sel->next; + /*LOG(("+++")); + for (n = sel; n != 0; n = n->right) { + struct 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; + default: fprintf(stderr, "unexpected node"); + } + } + fprintf(stderr, " "); + } + fprintf(stderr, "\n");*/ + + /* skip empty selectors */ + if (sel->left == 0 && sel->data == 0) + continue; + /* check if this selector is already present */ hash = css_hash(sel->data); for (n = stylesheet->rule[hash]; n != 0; n = n->next) @@ -160,7 +181,7 @@ int compare_selectors(struct node *n0, struct node *n1) { struct node *m0, *m1; unsigned int count0 = 0, count1 = 0; - + /* compare element name */ if (!((n0->data == 0 && n1->data == 0) || (n0->data != 0 && n1->data != 0 && strcmp(n0->data, n1->data) == 0))) @@ -216,6 +237,18 @@ int parse_length(struct css_length * const length, const struct node * const v) } +colour named_colour(const char *name) +{ + struct colour_entry *col; + col = bsearch(name, colour_table, + sizeof(colour_table) / sizeof(colour_table[0]), + sizeof(colour_table[0]), strcasecmp); + if (col == 0) + return TRANSPARENT; + return col->col; +} + + colour parse_colour(const struct node * const v) { colour c = TRANSPARENT; -- cgit v1.2.3