From 2fd83187539a1091a2118707f6a7e714200a6d23 Mon Sep 17 00:00:00 2001 From: "dbaron@dbaron.org" Date: Wed, 5 Mar 2008 16:06:15 -0800 Subject: [PATCH] Fix greediness of A ~ B C selector matching. b=420814 r+sr=bzbarsky a=beltzner --- layout/style/nsCSSRuleProcessor.cpp | 9 ++- layout/style/test/Makefile.in | 1 + layout/style/test/test_selectors.html | 83 +++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 layout/style/test/test_selectors.html diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 48a567ba149a..c8ad1e24732e 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -1620,10 +1620,15 @@ static PRBool SelectorMatchesTree(RuleProcessorData& aPrevData, } if (SelectorMatches(*data, selector, 0, nsnull)) { // to avoid greedy matching, we need to recur if this is a - // descendant combinator and the next combinator is not + // descendant or general sibling combinator and the next + // combinator is different, but we can make an exception for + // sibling, then parent, since a sibling's parent is always the + // same. if ((NS_IS_GREEDY_OPERATOR(selector->mOperator)) && (selector->mNext) && - (!NS_IS_GREEDY_OPERATOR(selector->mNext->mOperator))) { + (selector->mNext->mOperator != selector->mOperator) && + !(selector->mOperator == '~' && + selector->mNext->mOperator == PRUnichar(0))) { // pretend the selector didn't match, and step through content // while testing the same selector diff --git a/layout/style/test/Makefile.in b/layout/style/test/Makefile.in index 37f02402804f..298a2a17dea7 100644 --- a/layout/style/test/Makefile.in +++ b/layout/style/test/Makefile.in @@ -102,6 +102,7 @@ _TEST_FILES = test_bug73586.html \ test_parse_rule.html \ test_property_database.html \ test_property_syntax_errors.html \ + test_selectors.html \ test_style_struct_copy_constructors.html \ test_value_storage.html \ test_value_computation.html \ diff --git a/layout/style/test/test_selectors.html b/layout/style/test/test_selectors.html new file mode 100644 index 000000000000..5ecc85245a07 --- /dev/null +++ b/layout/style/test/test_selectors.html @@ -0,0 +1,83 @@ + + + + Test for CSS Selectors + + + + + +

+
+
+
+ + +