Bug 1343753 - Part 10: Make StyleDisplay as the function argument of StyleContextChanged. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 10 Mar 2017 11:35:38 +0800
changeset 496700 dba7d6d756af6488bbf229ce301c44c4f811a171
parent 496699 ad1c0bcd42535f0f840262a7062fbe188039c648
child 548668 49a08159d6eb7812dd786ef176f23b330aa0f25e
push id48657
push userbmo:boris.chiou@gmail.com
push dateFri, 10 Mar 2017 12:49:36 +0000
bugs1343753
milestone55.0a1
Bug 1343753 - Part 10: Make StyleDisplay as the function argument of StyleContextChanged. We have different ways to get StyleDisplay between Gecko and Servo, so its better to get it in {Gecko|Servo}RestyleManager, and pass it as the parameter to StyleContextChanged(). MozReview-Commit-ID: Chxpg20ha6V
layout/base/GeckoRestyleManager.cpp
layout/style/nsTransitionManager.cpp
layout/style/nsTransitionManager.h
--- a/layout/base/GeckoRestyleManager.cpp
+++ b/layout/base/GeckoRestyleManager.cpp
@@ -657,17 +657,18 @@ GeckoRestyleManager::TryInitiatingTransi
   if (!aContent || !aContent->IsElement()) {
     return false;
   }
 
   // Notify the transition manager.  If it starts a transition,
   // it might modify the new style context.
   RefPtr<nsStyleContext> sc = *aNewStyleContext;
   aPresContext->TransitionManager()->StyleContextChanged(
-    aContent->AsElement(), aOldStyleContext, aNewStyleContext);
+    sc->StyleDisplay(), aContent->AsElement(),
+    aOldStyleContext, aNewStyleContext);
   return *aNewStyleContext != sc;
 }
 
 static dom::Element*
 ElementForStyleContext(nsIContent* aParentContent,
                        nsIFrame* aFrame,
                        CSSPseudoElementType aPseudoType)
 {
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -455,19 +455,21 @@ ExtractNonDiscreteComputedValue(nsCSSPro
 
   aAnimationValue.mServo =
     Servo_AnimationValue_Extract(aProperty,
                                  aComputedStyle.mCurrentStyle).Consume();
   return !!aAnimationValue.mServo;
 }
 
 void
-nsTransitionManager::StyleContextChanged(dom::Element *aElement,
-                                         nsStyleContext *aOldStyleContext,
-                                         RefPtr<nsStyleContext>* aNewStyleContext /* inout */)
+nsTransitionManager::StyleContextChanged(const nsStyleDisplay* aDisp,
+                                         dom::Element* aElement,
+                                         nsStyleContext* aOldStyleContext,
+                                         RefPtr<nsStyleContext>*
+                                           aNewStyleContext /* inout */)
 {
   nsStyleContext* newStyleContext = *aNewStyleContext;
 
   NS_PRECONDITION(aOldStyleContext->GetPseudo() == newStyleContext->GetPseudo(),
                   "pseudo type mismatch");
 
   if (mInAnimationOnlyStyleUpdate) {
     // If we're doing an animation-only style update, return, since the
@@ -504,17 +506,16 @@ nsTransitionManager::StyleContextChanged
   }
 
   // NOTE: Things in this function (and ConsiderInitiatingTransition)
   // should never call PeekStyleData because we don't preserve gotten
   // structs across reframes.
 
   // Return sooner (before the startedAny check below) for the most
   // common case: no transitions specified or running.
-  const nsStyleDisplay *disp = newStyleContext->StyleDisplay();
   CSSPseudoElementType pseudoType = newStyleContext->GetPseudoType();
   if (pseudoType != CSSPseudoElementType::NotPseudo) {
     if (pseudoType != CSSPseudoElementType::before &&
         pseudoType != CSSPseudoElementType::after) {
       return;
     }
 
     NS_ASSERTION((pseudoType == CSSPseudoElementType::before &&
@@ -526,18 +527,18 @@ nsTransitionManager::StyleContextChanged
     // Else the element we want to use from now on is the element the
     // :before or :after is attached to.
     aElement = aElement->GetParent()->AsElement();
   }
 
   CSSTransitionCollection* collection =
     CSSTransitionCollection::GetAnimationCollection(aElement, pseudoType);
   if (!collection &&
-      disp->mTransitionPropertyCount == 1 &&
-      disp->mTransitions[0].GetCombinedDuration() <= 0.0f) {
+      aDisp->mTransitionPropertyCount == 1 &&
+      aDisp->mTransitions[0].GetCombinedDuration() <= 0.0f) {
     return;
   }
 
   // FIXME: Bug 1341372, remove this assertion.
   MOZ_ASSERT(mPresContext->RestyleManager()->IsGecko(),
              "ServoRestyleManager should not use nsTransitionManager "
              "for transitions");
   if (collection &&
@@ -595,20 +596,20 @@ nsTransitionManager::StyleContextChanged
         nullptr
       };
       ServoComputedStyleValues newStyle = {
         afterChangeStyle->StyleSource().AsServoComputedValues(),
         afterChangeStyle->GetParent()
           ? afterChangeStyle->GetParent()->StyleSource().AsServoComputedValues()
           : nullptr
       };
-      startedAny = UpdateTransitions(disp, target, collection,
+      startedAny = UpdateTransitions(aDisp, target, collection,
                                      oldStyle, newStyle);
     } else {
-      startedAny = UpdateTransitions(disp, target, collection,
+      startedAny = UpdateTransitions(aDisp, target, collection,
                                      aOldStyleContext, afterChangeStyle.get());
     }
   }
 
   MOZ_ASSERT(!startedAny || collection,
              "must have element transitions if we started any transitions");
 
   EffectCompositor::CascadeLevel cascadeLevel =
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -362,18 +362,19 @@ public:
    * pseudos, aElement is expected to be the generated before/after
    * element.
    *
    * It may modify the new style context (by replacing
    * *aNewStyleContext) to cover up some of the changes for the duration
    * of the restyling of descendants.  If it does, this function will
    * take care of causing the necessary restyle afterwards.
    */
-  void StyleContextChanged(mozilla::dom::Element *aElement,
-                           nsStyleContext *aOldStyleContext,
+  void StyleContextChanged(const nsStyleDisplay* aDisp,
+                           mozilla::dom::Element* aElement,
+                           nsStyleContext* aOldStyleContext,
                            RefPtr<nsStyleContext>* aNewStyleContext /* inout */);
 
   /**
    * When we're resolving style for an element that previously didn't have
    * style, we might have some old finished transitions for it, if,
    * say, it was display:none for a while, but previously displayed.
    *
    * This method removes any finished transitions that don't match the