[project @ 2003-04-05 16:24:43 by bursa]
Re-implement style attributes. svn path=/import/netsurf/; revision=114
This commit is contained in:
parent
004f6c31e3
commit
75768e6700
36
css/css.c
36
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);
|
||||
¶m);
|
||||
}
|
||||
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, ¶m);
|
||||
|
||||
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("{"), ¶m);
|
||||
|
||||
buffer = css__scan_string(str, lexer);
|
||||
while ((token = css_lex(lexer))) {
|
||||
css_parser_(parser, token,
|
||||
strdup(css_get_text(lexer)),
|
||||
¶m);
|
||||
}
|
||||
css__delete_buffer(buffer, lexer);
|
||||
css_parser_(parser, RBRACE, strdup("}"), ¶m);
|
||||
css_parser_(parser, 0, 0, ¶m);
|
||||
|
||||
css_parser_Free(parser, free);
|
||||
css_lex_destroy(lexer);
|
||||
|
||||
css_add_declarations(style, param.declaration);
|
||||
|
||||
css_free_node(param.declaration);
|
||||
}
|
||||
|
||||
|
||||
|
|
12
css/css.h
12
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
|
||||
|
||||
|
|
13
css/parser.y
13
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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue