From 64da6774c29191a3af3ca328598b0b0e58252f8b Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Wed, 11 Jul 2007 17:16:19 +0300 Subject: [PATCH] CSS: Count nested blocks when skipping. When skipping "@media print { #foo {bar: baz} pre {white-space: normal} }", the previous code would look for the first "{" and then the first "}", and fail to skip the "pre" rule. Seen at support.microsoft.com. I originally posted this change as part of attachment 383 to bug 722. --- src/document/css/parser.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/document/css/parser.c b/src/document/css/parser.c index 9e301e0c..9715f924 100644 --- a/src/document/css/parser.c +++ b/src/document/css/parser.c @@ -90,12 +90,23 @@ ride_on: } } +static void +skip_css_block(struct scanner *scanner) +{ + if (skip_css_tokens(scanner, '{')) { + const int preclimit = get_css_precedence('}'); + int depth = 1; + struct scanner_token *token = get_scanner_token(scanner); -/* TODO: We should handle support for skipping blocks better like "{ { } }" - * will be handled correctly. --jonas */ -#define skip_css_block(scanner) \ - if (skip_css_tokens(scanner, '{')) skip_css_tokens(scanner, '}'); - + while (token && token->precedence <= preclimit && depth > 0) { + if (token->type == '{') + ++depth; + else if (token->type == '}') + --depth; + token = get_next_scanner_token(scanner); + } + } +} /* Atrules grammer: *