Bug 1417354 - Add a method to clear all pending restyle requests for a given element and its pseudos. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 21 Feb 2018 07:00:20 +0900
changeset 757656 ead17f3b2a3d39e9aa6d0ea9f20b510667b7c861
parent 757655 30d32a79d3632fa4ceb2ab8e431f029575a0e265
child 757657 2742e6272badba1c405d6541620470ff4e7bca6a
child 757659 2aa9457070b15dd74bf3b954c0c8b51e7ccf4e1c
push id99825
push userhikezoe@mozilla.com
push dateWed, 21 Feb 2018 01:05:51 +0000
reviewersbirtles
bugs1417354
milestone60.0a1
Bug 1417354 - Add a method to clear all pending restyle requests for a given element and its pseudos. r?birtles MozReview-Commit-ID: DZkbwUPiPTd
dom/animation/EffectCompositor.cpp
dom/animation/EffectCompositor.h
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -361,16 +361,44 @@ EffectCompositor::PostRestyleForThrottle
       PostRestyleForAnimation(iter.Key().mElement,
                               iter.Key().mPseudoType,
                               cascadeLevel);
       postedRestyle = true;
     }
   }
 }
 
+void
+EffectCompositor::ClearRestyleRequestsFor(Element* aElement)
+{
+  MOZ_ASSERT(aElement);
+
+  auto& elementsToRestyle = mElementsToRestyle[CascadeLevel::Animations];
+
+  CSSPseudoElementType pseudoType = aElement->GetPseudoElementType();
+  if (pseudoType == CSSPseudoElementType::NotPseudo) {
+    PseudoElementHashEntry::KeyType notPseudoKey =
+      { aElement, CSSPseudoElementType::NotPseudo };
+    PseudoElementHashEntry::KeyType beforePseudoKey =
+      { aElement, CSSPseudoElementType::before };
+    PseudoElementHashEntry::KeyType afterPseudoKey =
+      { aElement, CSSPseudoElementType::after };
+
+    elementsToRestyle.Remove(notPseudoKey);
+    elementsToRestyle.Remove(beforePseudoKey);
+    elementsToRestyle.Remove(afterPseudoKey);
+  } else if (pseudoType == CSSPseudoElementType::before ||
+             pseudoType == CSSPseudoElementType::after) {
+    Element* parentElement = aElement->GetParentElement();
+    MOZ_ASSERT(parentElement);
+    PseudoElementHashEntry::KeyType key = { parentElement, pseudoType };
+    elementsToRestyle.Remove(key);
+  }
+}
+
 template<typename StyleType>
 void
 EffectCompositor::UpdateEffectProperties(StyleType* aStyleType,
                                          Element* aElement,
                                          CSSPseudoElementType aPseudoType)
 {
   EffectSet* effectSet = EffectSet::GetEffectSet(aElement, aPseudoType);
   if (!effectSet) {
--- a/dom/animation/EffectCompositor.h
+++ b/dom/animation/EffectCompositor.h
@@ -116,16 +116,20 @@ public:
                                CSSPseudoElementType aPseudoType,
                                CascadeLevel aCascadeLevel);
 
   // Posts an animation restyle for any elements whose animation style rule
   // is out of date but for which an animation restyle has not yet been
   // posted because updates on the main thread are throttled.
   void PostRestyleForThrottledAnimations();
 
+  // Clear all pending restyle requests for the given (pseudo-) element (and its
+  // ::before and ::after elements if the given element is not pseudo).
+  void ClearRestyleRequestsFor(dom::Element* aElement);
+
   // Called when computed style on the specified (pseudo-) element might
   // have changed so that any context-sensitive values stored within
   // animation effects (e.g. em-based endpoints used in keyframe effects)
   // can be re-resolved to computed values.
   template<typename StyleType>
   void UpdateEffectProperties(StyleType* aStyleType,
                               dom::Element* aElement,
                               CSSPseudoElementType aPseudoType);