From be460d4477d8955063bf834377d8e934cc507a3d Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 14 Jan 2009 11:34:45 +0000 Subject: Make @import actually create a rule and attempt some kind of fetch logic. There's still a bunch of outstanding functionality here (like URL resolution and media list parsing). Also, there's currently no way of telling the client to stop fetching data for a stylesheet (and, more importantly, not to attempt to access the stylesheet again as it's about to be destroyed) svn path=/trunk/libcss/; revision=6062 --- src/parse/language.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'src/parse/language.c') diff --git a/src/parse/language.c b/src/parse/language.c index c583c51..6f43f25 100644 --- a/src/parse/language.c +++ b/src/parse/language.c @@ -403,6 +403,10 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector) } } else if (atkeyword->ilower == c->strings[IMPORT]) { if (c->state != HAD_RULE) { + css_rule *rule; + css_stylesheet *import; + css_error error; + /* any0 = (STRING | URI) ws * (IDENT ws (',' ws IDENT ws)* )? */ const css_token *uri = @@ -417,7 +421,63 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector) if (parserutils_vector_peek(vector, ctx) != NULL) { } - /** \todo trigger fetch of imported sheet */ + error = css_stylesheet_rule_create(c->sheet, + CSS_RULE_IMPORT, &rule); + if (error != CSS_OK) + return error; + + /** \todo resolve URI */ + char url[uri->idata->len + 1]; + memcpy(url, uri->idata->data, uri->idata->len); + url[uri->idata->len] = '\0'; + + /* Create imported sheet */ + /** \todo Replace CSS_MEDIA_ALL with the result of + * parsing the media list */ + error = css_stylesheet_create(c->sheet->level, NULL, + url, NULL, c->sheet->origin, + CSS_MEDIA_ALL, + c->sheet->import, c->sheet->import_pw, + c->alloc, c->pw, &import); + if (error != CSS_OK) { + css_stylesheet_rule_destroy(c->sheet, rule); + return error; + } + + /* Trigger fetch of imported sheet */ + if (c->sheet->import != NULL) { + error = c->sheet->import(c->sheet->import_pw, + url, import); + if (error != CSS_OK) { + css_stylesheet_destroy(import); + css_stylesheet_rule_destroy(c->sheet, + rule); + return error; + } + } + + error = css_stylesheet_rule_set_import(c->sheet, rule, + import); + if (error != CSS_OK) { + /** \todo we need to tell the client to stop + * doing stuff with the imported sheet */ + css_stylesheet_destroy(import); + css_stylesheet_rule_destroy(c->sheet, rule); + return error; + } + + /* Imported sheet is now owned by the rule */ + + error = css_stylesheet_add_rule(c->sheet, rule); + if (error != CSS_OK) { + /** \todo we need to tell the client to stop + * doing stuff with the imported sheet */ + css_stylesheet_rule_destroy(c->sheet, rule); + return error; + } + + /* Rule is now owned by the sheet, + * so no need to destroy it */ c->state = BEFORE_RULES; } else { -- cgit v1.2.3