Bug 989965 - Resolve style for pseudo-elements correctly when style rules that have user action pseudo-classes on them are present. r=bzbarsky, a=sledru
authorCameron McCormack <cam@mcc.id.au>
Wed, 02 Apr 2014 15:08:52 +1100
changeset 183618 b5185eeba69ddb2d21c3fb4d2a80e43ebb6175a7
parent 183617 071d2fbd0caa74d57c65eb6439d75345eba4e1cc
child 183619 d75416f219162c09d0ef1a1d56bd0f44c7d33924
push id3422
push userryanvm@gmail.com
push dateThu, 03 Apr 2014 18:35:46 +0000
treeherdermozilla-beta@cc734bdf4e41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, sledru
bugs989965
milestone29.0
Bug 989965 - Resolve style for pseudo-elements correctly when style rules that have user action pseudo-classes on them are present. r=bzbarsky, a=sledru
layout/style/crashtests/989965-1.html
layout/style/crashtests/crashtests.list
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsRuleProcessorData.h
new file mode 100644
--- /dev/null
+++ b/layout/style/crashtests/989965-1.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<body>
+<style>
+::-moz-placeholder { color: red; }
+::-moz-placeholder:focus { color: green; }
+</style>
+<script>
+window.getComputedStyle(document.body, "::-moz-placeholder").color;
+</script>
--- a/layout/style/crashtests/crashtests.list
+++ b/layout/style/crashtests/crashtests.list
@@ -96,8 +96,9 @@ load 862113.html
 load 867487.html
 load 880862.html
 load 873222.html
 load 915440.html
 load 927734-1.html
 load 930270-1.html
 load 930270-2.html
 load 945048-1.html
+load 989965-1.html
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -2430,16 +2430,29 @@ void ContentEnumFunc(const RuleValue& va
     // The selector is for a rule in a scoped style sheet, and the subject
     // of the selector matching is not in its scope.
     return;
   }
   nsCSSSelector* selector = aSelector;
   if (selector->IsPseudoElement()) {
     PseudoElementRuleProcessorData* pdata =
       static_cast<PseudoElementRuleProcessorData*>(data);
+    if (!pdata->mPseudoElement && selector->mPseudoClassList) {
+      // We can get here when calling getComputedStyle(aElt, aPseudo) if:
+      //
+      //   * aPseudo is a pseudo-element that supports a user action
+      //     pseudo-class, like "::-moz-placeholder";
+      //   * there is a style rule that uses a pseudo-class on this
+      //     pseudo-element in the document, like ::-moz-placeholder:hover; and
+      //   * aElt does not have such a pseudo-element.
+      //
+      // We know that the selector can't match, since there is no element for
+      // the user action pseudo-class to match against.
+      return;
+    }
     if (!StateSelectorMatches(pdata->mPseudoElement, aSelector, nodeContext,
                               data->mTreeMatchContext)) {
       return;
     }
     selector = selector->mNext;
   }
   if (SelectorMatches(data->mElement, selector, nodeContext,
                       data->mTreeMatchContext)) {
--- a/layout/style/nsRuleProcessorData.h
+++ b/layout/style/nsRuleProcessorData.h
@@ -486,21 +486,16 @@ struct MOZ_STACK_CLASS PseudoElementRule
       mPseudoType(aPseudoType),
       mPseudoElement(aPseudoElement)
   {
     NS_PRECONDITION(aPseudoType <
                       nsCSSPseudoElements::ePseudo_PseudoElementCount,
                     "invalid aPseudoType value");
     NS_PRECONDITION(aTreeMatchContext.mForStyling, "Styling here!");
     NS_PRECONDITION(aRuleWalker, "Must have rule walker");
-    NS_PRECONDITION(!(!aPseudoElement &&
-                      nsCSSPseudoElements::PseudoElementSupportsUserActionState
-                                                                 (aPseudoType)),
-                    "aPseudoElement must be specified if the pseudo supports "
-                    ":hover and :active");
   }
 
   nsCSSPseudoElements::Type mPseudoType;
   mozilla::dom::Element* const mPseudoElement; // weak ref
 };
 
 struct MOZ_STACK_CLASS AnonBoxRuleProcessorData : public RuleProcessorData {
   AnonBoxRuleProcessorData(nsPresContext* aPresContext,