summaryrefslogtreecommitdiff
path: root/css
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-04-05 16:24:43 +0000
committerJames Bursa <james@netsurf-browser.org>2003-04-05 16:24:43 +0000
commit75768e67001bcf292f9e8bbbe8139a7432835092 (patch)
treea242d019452df8740e902ad7f32a518a0ad4e81f /css
parent004f6c31e32e1297946935370bdc0be2fe5ae259 (diff)
downloadnetsurf-75768e67001bcf292f9e8bbbe8139a7432835092.tar.gz
netsurf-75768e67001bcf292f9e8bbbe8139a7432835092.tar.bz2
[project @ 2003-04-05 16:24:43 by bursa]
Re-implement style attributes. svn path=/import/netsurf/; revision=114
Diffstat (limited to 'css')
-rw-r--r--css/css.c36
-rw-r--r--css/css.h12
-rw-r--r--css/parser.y13
-rw-r--r--css/ruleset.c29
4 files changed, 69 insertions, 21 deletions
diff --git a/css/css.c b/css/css.c
index d9d0c9967..117292d93 100644
--- a/css/css.c
+++ b/css/css.c
@@ -1,5 +1,5 @@
/**
- * $Id: css.c,v 1.2 2003/04/05 15:35:55 bursa Exp $
+ * $Id: css.c,v 1.3 2003/04/05 16:24:43 bursa Exp $
*/
#include <assert.h>
@@ -9,6 +9,7 @@
#define CSS_INTERNALS
#include "netsurf/content/content.h"
#include "netsurf/css/css.h"
+#include "netsurf/css/parser.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
@@ -88,6 +89,7 @@ void css_process_data(struct content *c, char *data, unsigned long size)
{
int token;
YY_BUFFER_STATE buffer;
+ struct parse_params param = {0, c->data.css, 0};
LOG(("content %p, size %lu", c, size));
@@ -95,7 +97,7 @@ void css_process_data(struct content *c, char *data, unsigned long size)
while ((token = css_lex(c->data.css->lexer))) {
css_parser_(c->data.css->parser, token,
strdup(css_get_text(c->data.css->lexer)),
- c->data.css);
+ &param);
}
css__delete_buffer(buffer, c->data.css->lexer);
}
@@ -103,9 +105,11 @@ void css_process_data(struct content *c, char *data, unsigned long size)
int css_convert(struct content *c, unsigned int width, unsigned int height)
{
+ struct parse_params param = {0, c->data.css, 0};
+
LOG(("content %p", c));
- css_parser_(c->data.css->parser, 0, 0, c->data.css);
+ css_parser_(c->data.css->parser, 0, 0, &param);
css_parser_Free(c->data.css->parser, free);
css_lex_destroy(c->data.css->lexer);
@@ -230,6 +234,32 @@ not_matched:
void css_parse_property_list(struct css_style * style, char * str)
{
+ yyscan_t lexer;
+ void *parser;
+ YY_BUFFER_STATE buffer;
+ int token;
+ struct parse_params param = {1, 0, 0};
+
+ css_lex_init(&lexer);
+ parser = css_parser_Alloc(malloc);
+ css_parser_(parser, LBRACE, strdup("{"), &param);
+
+ buffer = css__scan_string(str, lexer);
+ while ((token = css_lex(lexer))) {
+ css_parser_(parser, token,
+ strdup(css_get_text(lexer)),
+ &param);
+ }
+ css__delete_buffer(buffer, lexer);
+ css_parser_(parser, RBRACE, strdup("}"), &param);
+ css_parser_(parser, 0, 0, &param);
+
+ css_parser_Free(parser, free);
+ css_lex_destroy(lexer);
+
+ css_add_declarations(style, param.declaration);
+
+ css_free_node(param.declaration);
}
diff --git a/css/css.h b/css/css.h
index 133f485eb..78d0b8a56 100644
--- a/css/css.h
+++ b/css/css.h
@@ -1,5 +1,5 @@
/**
- * $Id: css.h,v 1.2 2003/04/05 15:35:55 bursa Exp $
+ * $Id: css.h,v 1.3 2003/04/05 16:24:43 bursa Exp $
*/
#ifndef _NETSURF_CSS_CSS_H_
@@ -144,6 +144,12 @@ struct css_stylesheet {
struct node *rule[HASH_SIZE];
};
+struct parse_params {
+ int ruleset_only;
+ struct css_stylesheet *stylesheet;
+ struct node *declaration;
+};
+
#endif
/**
@@ -167,12 +173,14 @@ void css_free_node(struct node *node);
void css_add_ruleset(struct css_stylesheet *stylesheet,
struct node *selector,
struct node *declaration);
+void css_add_declarations(struct css_style *style, struct node *declaration);
unsigned int css_hash(const char *s);
void css_parser_Trace(FILE *TraceFILE, char *zTracePrompt);
void *css_parser_Alloc(void *(*mallocProc)(int));
void css_parser_Free(void *p, void (*freeProc)(void*));
-void css_parser_(void *yyp, int yymajor, char* yyminor, struct css_stylesheet *stylesheet);
+void css_parser_(void *yyp, int yymajor, char* yyminor,
+ struct parse_params *param);
#endif
diff --git a/css/parser.y b/css/parser.y
index 5b9751036..8625c900f 100644
--- a/css/parser.y
+++ b/css/parser.y
@@ -1,5 +1,5 @@
/**
- * $Id: parser.y,v 1.4 2003/04/04 15:19:31 bursa Exp $
+ * $Id: parser.y,v 1.5 2003/04/05 16:24:43 bursa Exp $
*/
/*
@@ -46,12 +46,15 @@ block_body ::= block_body ATKEYWORD.
block_body ::= block_body SEMI.
ruleset ::= selector_list(A) LBRACE declaration_list(B) RBRACE.
- { css_add_ruleset(stylesheet, A, B);
+ { css_add_ruleset(param->stylesheet, A, B);
css_free_node(B); }
ruleset ::= any_list_1(A) LBRACE declaration_list(B) RBRACE.
{ css_free_node(A); css_free_node(B); } /* not CSS2 */
-ruleset ::= LBRACE declaration_list RBRACE.
- /* this form of ruleset not used in CSS2 */
+ruleset ::= LBRACE declaration_list(A) RBRACE.
+ /* this form of ruleset not used in CSS2
+ used to parse style attributes (ruleset_only = 1) */
+ { if (param->ruleset_only) param->declaration = A;
+ else css_free_node(A); }
selector_list(A) ::= selector(B).
{ A = B; }
@@ -156,7 +159,7 @@ any(A) ::= LBRAC any_list(B) RBRAC.
/* lemon directives */
-%extra_argument { struct css_stylesheet *stylesheet }
+%extra_argument { struct parse_params *param }
%include {
#define CSS_INTERNALS
#include "netsurf/css/scanner.h"
diff --git a/css/ruleset.c b/css/ruleset.c
index 32bb235a3..d9c713d87 100644
--- a/css/ruleset.c
+++ b/css/ruleset.c
@@ -1,5 +1,5 @@
/**
- * $Id: ruleset.c,v 1.2 2003/04/05 15:35:55 bursa Exp $
+ * $Id: ruleset.c,v 1.3 2003/04/05 16:24:43 bursa Exp $
*/
#include <assert.h>
@@ -130,16 +130,23 @@ void css_add_ruleset(struct css_stylesheet *stylesheet,
}
/* fill in the declarations */
- for (n = declaration; n != 0; n = n->next) {
- struct property_entry *p;
- assert(n->type == 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);
- if (p == 0)
- continue;
- p->parse(style, n->left);
- }
+ css_add_declarations(style, declaration);
+ }
+}
+
+
+void css_add_declarations(struct css_style *style, struct node *declaration)
+{
+ struct 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);
+ p = bsearch(n->data, property_table,
+ sizeof(property_table) / sizeof(property_table[0]),
+ sizeof(property_table[0]), strcasecmp);
+ if (p == 0)
+ continue;
+ p->parse(style, n->left);
}
}