summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-06-27 10:50:14 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2010-06-27 10:50:14 +0000
commitea203a6dd8a241d33e4bd1a6b076006cac715776 (patch)
tree2d9865400039f23182e413e0354d239083c48538 /src
parente86173f4bf6e029af6ea0f1348c6b934a1b488f8 (diff)
downloadlibcss-ea203a6dd8a241d33e4bd1a6b076006cac715776.tar.gz
libcss-ea203a6dd8a241d33e4bd1a6b076006cac715776.tar.bz2
Remove ownerNode and ownerRule fields from stylesheet objects.
These prevent stylesheets being used in multiple contexts simultaneously. Their values can be inferred from the context in which the stylesheet is used. Replace use of ownerRule to backtrack in style selection with a (fixed-size) stack of rules to process. This prevents crashes when a sheet that was previously imported somewhere is reused as a top-level sheet. svn path=/trunk/libcss/; revision=10581
Diffstat (limited to 'src')
-rw-r--r--src/select/select.c14
-rw-r--r--src/stylesheet.c2
-rw-r--r--src/stylesheet.h3
3 files changed, 11 insertions, 8 deletions
diff --git a/src/select/select.c b/src/select/select.c
index b2820c8..411081e 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -496,6 +496,9 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
{
const css_stylesheet *s = sheet;
const css_rule *rule = s->rule_list;
+ uint32_t sp = 0;
+#define IMPORT_STACK_SIZE 256
+ const css_rule *import_stack[IMPORT_STACK_SIZE];
do {
/* Find first non-charset rule, if we're at the list head */
@@ -514,6 +517,10 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
if (import->sheet != NULL &&
(import->media & state->media) != 0) {
/* It's applicable, so process it */
+ assert(sp < IMPORT_STACK_SIZE - 1);
+
+ import_stack[sp++] = rule;
+
s = import->sheet;
rule = s->rule_list;
} else {
@@ -537,9 +544,10 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
return error;
/* Find next sheet to process */
- if (s->ownerRule != NULL) {
- rule = s->ownerRule->next;
- s = s->ownerRule->parent;
+ if (sp > 0) {
+ sp--;
+ rule = import_stack[sp]->next;
+ s = import_stack[sp]->parent;
} else {
s = NULL;
}
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 20cc91f..eed4735 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -361,8 +361,6 @@ css_error css_stylesheet_register_import(css_stylesheet *parent,
if (r->type == CSS_RULE_IMPORT && i->sheet == NULL) {
i->sheet = import;
- import->ownerRule = r;
-
return CSS_OK;
}
}
diff --git a/src/stylesheet.h b/src/stylesheet.h
index b708257..2c6caac 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -157,9 +157,6 @@ struct css_stylesheet {
char *url; /**< URL of this sheet */
char *title; /**< Title of this sheet */
- void *ownerNode; /**< Owning node in document */
- css_rule *ownerRule; /**< Owning rule in parent */
-
css_language_level level; /**< Language level of sheet */
css_parser *parser; /**< Core parser for sheet */
void *parser_frontend; /**< Frontend parser */