Bug 1375767 - Don't use nsCSSPseudoElements::GetPseudoType() r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 23 Jun 2017 17:05:37 +0900
changeset 599497 5d8f173a0a17bad7154869d9746eab1d09976e00
parent 599416 7455c74d833a9db4e02be17eda14588c7ef0de76
child 599498 61c092f78dbd990292ceb9cab2d6d896f2150c2e
push id65549
push userhikezoe@mozilla.com
push dateFri, 23 Jun 2017 08:09:20 +0000
reviewersbirtles
bugs1375767
milestone56.0a1
Bug 1375767 - Don't use nsCSSPseudoElements::GetPseudoType() r?birtles It iterates over all pseudo types if a given element is not pseudo. We should use IsGeneratedContentContainerForBefore() or IsGeneratedContentContainerForAfter instead. MozReview-Commit-ID: 51Jnl4e8M2V
layout/style/ServoBindings.cpp
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -520,16 +520,31 @@ PseudoTagAndCorrectElementForAnimation(c
   if (aElementOrPseudo->IsGeneratedContentContainerForAfter()) {
     aElementOrPseudo = aElementOrPseudo->GetParent()->AsElement();
     return nsCSSPseudoElements::after;
   }
 
   return nullptr;
 }
 
+static CSSPseudoElementType
+GetPseudoTypeFromElementForAnimation(const Element*& aElementOrPseudo) {
+  if (aElementOrPseudo->IsGeneratedContentContainerForBefore()) {
+    aElementOrPseudo = aElementOrPseudo->GetParent()->AsElement();
+    return CSSPseudoElementType::before;
+  }
+
+  if (aElementOrPseudo->IsGeneratedContentContainerForAfter()) {
+    aElementOrPseudo = aElementOrPseudo->GetParent()->AsElement();
+    return CSSPseudoElementType::after;
+  }
+
+  return CSSPseudoElementType::NotPseudo;
+}
+
 bool
 Gecko_GetAnimationRule(RawGeckoElementBorrowed aElement,
                        EffectCompositor::CascadeLevel aCascadeLevel,
                        RawServoAnimationValueMapBorrowedMut aAnimationValues)
 {
   MOZ_ASSERT(aElement);
 
   nsIDocument* doc = aElement->GetComposedDoc();
@@ -537,22 +552,18 @@ Gecko_GetAnimationRule(RawGeckoElementBo
     return false;
   }
   nsPresContext* presContext = doc->GetShell()->GetPresContext();
   if (!presContext || !presContext->IsDynamic()) {
     // For print or print preview, ignore animations.
     return false;
   }
 
-  nsIAtom* pseudoTag = PseudoTagAndCorrectElementForAnimation(aElement);
-
   CSSPseudoElementType pseudoType =
-    nsCSSPseudoElements::GetPseudoType(
-      pseudoTag,
-      nsCSSProps::EnabledState::eIgnoreEnabledState);
+    GetPseudoTypeFromElementForAnimation(aElement);
 
   return presContext->EffectCompositor()
     ->GetServoAnimationRule(aElement,
                             pseudoType,
                             aCascadeLevel,
                             aAnimationValues);
 }
 
@@ -576,20 +587,18 @@ Gecko_UpdateAnimations(RawGeckoElementBo
     return;
   }
 
   nsPresContext* presContext = nsContentUtils::GetContextForContent(aElement);
   if (!presContext || !presContext->IsDynamic()) {
     return;
   }
 
-  nsIAtom* pseudoTag = PseudoTagAndCorrectElementForAnimation(aElement);
   CSSPseudoElementType pseudoType =
-    nsCSSPseudoElements::GetPseudoType(pseudoTag,
-                                       CSSEnabledState::eForAllContent);
+    GetPseudoTypeFromElementForAnimation(aElement);
 
   if (aTasks & UpdateAnimationsTasks::CSSAnimations) {
     presContext->AnimationManager()->
       UpdateAnimations(const_cast<dom::Element*>(aElement), pseudoType,
                        aComputedValues);
   }
 
   // aComputedValues might be nullptr if the target element is now in a
@@ -624,20 +633,18 @@ Gecko_UpdateAnimations(RawGeckoElementBo
                                 EffectCompositor::RestyleType::Standard,
                                 EffectCompositor::CascadeLevel::Animations);
   }
 }
 
 bool
 Gecko_ElementHasAnimations(RawGeckoElementBorrowed aElement)
 {
-  nsIAtom* pseudoTag = PseudoTagAndCorrectElementForAnimation(aElement);
   CSSPseudoElementType pseudoType =
-    nsCSSPseudoElements::GetPseudoType(pseudoTag,
-                                       CSSEnabledState::eForAllContent);
+    GetPseudoTypeFromElementForAnimation(aElement);
 
   return !!EffectSet::GetEffectSet(aElement, pseudoType);
 }
 
 bool
 Gecko_ElementHasCSSAnimations(RawGeckoElementBorrowed aElement)
 {
   nsIAtom* pseudoTag = PseudoTagAndCorrectElementForAnimation(aElement);