summaryrefslogtreecommitdiff
path: root/src/parse/language.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-01-14 11:34:45 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-01-14 11:34:45 +0000
commitbe460d4477d8955063bf834377d8e934cc507a3d (patch)
treef3bf0f79d709950b515266e4bfdb9556de9973af /src/parse/language.c
parent48ec2d9eab392794845b666f7b261e4db38fd1e9 (diff)
downloadlibcss-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/parse/language.c')
-rw-r--r--src/parse/language.c62
1 files changed, 61 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 {