From 2ea3b24b478619493b9d9884f9a7b95565861d22 Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Fri, 28 Jun 2013 18:48:13 -0700 Subject: [PATCH] Bug 653881 - Add a compatibility hack to allow elements to be optional when selecting via the child CSS selector. This allows old CSS selectors selecting default content to continue working in the new world. r=dbaron --HG-- extra : rebase_source : 4d538fcbd8a6b58408dc46835632a4664ba8d0d8 --- layout/reftests/dom/reftest.list | 2 + layout/reftests/dom/xbl-children-1-ref.xhtml | 16 ++++++++ layout/reftests/dom/xbl-children-1.xhtml | 39 ++++++++++++++++++++ layout/style/nsCSSRuleProcessor.cpp | 21 +++++++++++ 4 files changed, 78 insertions(+) create mode 100644 layout/reftests/dom/xbl-children-1-ref.xhtml create mode 100644 layout/reftests/dom/xbl-children-1.xhtml diff --git a/layout/reftests/dom/reftest.list b/layout/reftests/dom/reftest.list index 6a8c8c2e5bb..859c2a8f879 100644 --- a/layout/reftests/dom/reftest.list +++ b/layout/reftests/dom/reftest.list @@ -48,3 +48,5 @@ skip-if(B2G) == multipleinsertionpoints-insertmultiple.xhtml multipleinsertionpo == multipleappendwithxul.xhtml multipleappendwithxul-ref.xhtml == multipleappendwithinput.xhtml multipleappendwithinput-ref.xhtml == multipleappendwitheditable.xhtml multipleappendwitheditable-ref.xhtml + +skip-if(B2G) == xbl-children-1.xhtml xbl-children-1-ref.xhtml diff --git a/layout/reftests/dom/xbl-children-1-ref.xhtml b/layout/reftests/dom/xbl-children-1-ref.xhtml new file mode 100644 index 00000000000..db526e90142 --- /dev/null +++ b/layout/reftests/dom/xbl-children-1-ref.xhtml @@ -0,0 +1,16 @@ + + + + + +
text
+ + + diff --git a/layout/reftests/dom/xbl-children-1.xhtml b/layout/reftests/dom/xbl-children-1.xhtml new file mode 100644 index 00000000000..6d065b61a77 --- /dev/null +++ b/layout/reftests/dom/xbl-children-1.xhtml @@ -0,0 +1,39 @@ + + + + + + + + + + + TEXT + + + + + + + + + + + + + +
+ + diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 140b19af8f8..85a6ca0156b 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -2287,6 +2287,27 @@ static bool SelectorMatchesTree(Element* aPrevElement, // traverse further up the tree. aTreeMatchContext.PopStyleScopeForSelectorMatching(element); } + + // Compatibility hack: First try matching this selector as though the + // element wasn't in the tree to allow old selectors + // were written before participated in CSS selector + // matching to work. + if (selector->mOperator == '>' && + element->NodeInfo()->Equals(nsGkAtoms::children, + kNameSpaceID_XBL)) { + Element* styleScope = aTreeMatchContext.mCurrentStyleScope; + if (SelectorMatchesTree(element, selector, aTreeMatchContext, + aLookForRelevantLink)) { + // It matched, don't try matching on the element at + // all. + return true; + } + // We want to reset mCurrentStyleScope on aTreeMatchContext + // back to its state before the SelectorMatchesTree call, in + // case that call happens to traverse past the style scope element + // and sets it to null. + aTreeMatchContext.mCurrentStyleScope = styleScope; + } } } if (!element) {