diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-14 11:34:45 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-14 11:34:45 +0000 |
commit | be460d4477d8955063bf834377d8e934cc507a3d (patch) | |
tree | f3bf0f79d709950b515266e4bfdb9556de9973af /src | |
parent | 48ec2d9eab392794845b666f7b261e4db38fd1e9 (diff) | |
download | libcss-be460d4477d8955063bf834377d8e934cc507a3d.tar.gz libcss-be460d4477d8955063bf834377d8e934cc507a3d.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/language.c | 62 | ||||
-rw-r--r-- | src/stylesheet.c | 26 | ||||
-rw-r--r-- | src/stylesheet.h | 3 |
3 files changed, 90 insertions, 1 deletions
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 { diff --git a/src/stylesheet.c b/src/stylesheet.c index ce971bc..6d01e18 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -700,6 +700,32 @@ css_error css_stylesheet_rule_set_charset(css_stylesheet *sheet, } /** + * Set the imported stylesheet associated with a rule + * + * \param sheet The stylesheet context + * \param rule The rule to add to (must be of type CSS_RULE_IMPORT) + * \param import The imported sheet + * \return CSS_OK on success, appropriate error otherwise + */ +css_error css_stylesheet_rule_set_import(css_stylesheet *sheet, + css_rule *rule, css_stylesheet *import) +{ + css_rule_import *r = (css_rule_import *) rule; + + if (sheet == NULL || rule == NULL || import == NULL) + return CSS_BADPARM; + + /* Ensure rule is a CSS_RULE_IMPORT */ + if (rule->type != CSS_RULE_IMPORT) + return CSS_INVALID; + + /* Set the rule's sheet field */ + r->sheet = import; + + return CSS_OK; +} + +/** * Add a rule to a stylesheet * * \param sheet The stylesheet to add to diff --git a/src/stylesheet.h b/src/stylesheet.h index ff32d97..a7b1cfd 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -209,6 +209,9 @@ css_error css_stylesheet_rule_append_style(css_stylesheet *sheet, css_error css_stylesheet_rule_set_charset(css_stylesheet *sheet, css_rule *rule, const parserutils_hash_entry *charset); +css_error css_stylesheet_rule_set_import(css_stylesheet *sheet, + css_rule *rule, css_stylesheet *import); + /** \todo registering other rule-type data with css_rules */ css_error css_stylesheet_add_rule(css_stylesheet *sheet, css_rule *rule); |