Bug 1343753 - Part 5: Support ServoComputedValues in ExtractNonDiscreteComputedValue. draft
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 12 Apr 2017 16:31:12 +0800
changeset 561127 bea62c1372c2c5b434feb356570ec2bcd12f1d1d
parent 561126 5372efd7341b75961ded0ac56e81015d1d7fa9b8
child 561128 7fe78acbe55c3b10204d1ffb5a9ff8c0244bc59e
push id53643
push userbmo:boris.chiou@gmail.com
push dateWed, 12 Apr 2017 08:51:47 +0000
bugs1343753
milestone55.0a1
Bug 1343753 - Part 5: Support ServoComputedValues in ExtractNonDiscreteComputedValue. We use ServoComputedStyleValues as the argument here, instead of ServoComputedValues, because I will use template for nsStyleContext and ServoComputedValuesWithParent in UpdateTransitions() and ConsiderInitiatingTransition(). Besides, add an FFI to check if a proeprty is discrete animation type. MozReview-Commit-ID: 7VtcMDtgl55
layout/style/ServoBindingList.h
layout/style/nsTransitionManager.cpp
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -138,16 +138,18 @@ SERVO_BINDING_FUNC(Servo_GetComputedKeyf
 SERVO_BINDING_FUNC(Servo_AnimationValueMap_Push, void,
                    RawServoAnimationValueMapBorrowed,
                    nsCSSPropertyID property,
                    RawServoAnimationValueBorrowed value)
 SERVO_BINDING_FUNC(Servo_ComputedValues_ExtractAnimationValue,
                    RawServoAnimationValueStrong,
                    ServoComputedValuesBorrowed computed_values,
                    nsCSSPropertyID property)
+SERVO_BINDING_FUNC(Servo_Property_IsDiscreteAnimatable, bool,
+                   nsCSSPropertyID property)
 
 // AnimationValues handling
 SERVO_BINDING_FUNC(Servo_AnimationValues_Interpolate,
                    RawServoAnimationValueStrong,
                    RawServoAnimationValueBorrowed from,
                    RawServoAnimationValueBorrowed to,
                    double progress)
 SERVO_BINDING_FUNC(Servo_AnimationValues_IsInterpolable, bool,
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -429,22 +429,39 @@ CSSTransition::SetEffectFromStyle(dom::A
 NS_IMPL_CYCLE_COLLECTION(nsTransitionManager, mEventDispatcher)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTransitionManager, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTransitionManager, Release)
 
 static inline bool
 ExtractNonDiscreteComputedValue(nsCSSPropertyID aProperty,
                                 nsStyleContext* aStyleContext,
-                                StyleAnimationValue& aComputedValue)
+                                AnimationValue& aAnimationValue)
 {
   return (nsCSSProps::kAnimTypeTable[aProperty] != eStyleAnimType_Discrete ||
           aProperty == eCSSProperty_visibility) &&
          StyleAnimationValue::ExtractComputedValue(aProperty, aStyleContext,
-                                                   aComputedValue);
+                                                   aAnimationValue.mGecko);
+}
+
+static inline bool
+ExtractNonDiscreteComputedValue(nsCSSPropertyID aProperty,
+                                const ServoComputedValuesWithParent&
+                                  aComputedStyle,
+                                AnimationValue& aAnimationValue)
+{
+  if (Servo_Property_IsDiscreteAnimatable(aProperty) &&
+      aProperty != eCSSProperty_visibility) {
+    return false;
+  }
+
+  aAnimationValue.mServo =
+    Servo_ComputedValues_ExtractAnimationValue(aComputedStyle.mCurrentStyle,
+                                               aProperty).Consume();
+  return !!aAnimationValue.mServo;
 }
 
 void
 nsTransitionManager::StyleContextChanged(dom::Element *aElement,
                                          nsStyleContext *aOldStyleContext,
                                          RefPtr<nsStyleContext>* aNewStyleContext /* inout */)
 {
   nsStyleContext* newStyleContext = *aNewStyleContext;
@@ -695,31 +712,31 @@ nsTransitionManager::UpdateTransitions(
           allTransitionProperties.AddProperty(property);
         }
       }
     }
 
     OwningCSSTransitionPtrArray& animations = aElementTransitions->mAnimations;
     size_t i = animations.Length();
     MOZ_ASSERT(i != 0, "empty transitions list?");
-    StyleAnimationValue currentValue;
+    AnimationValue currentValue;
     do {
       --i;
       CSSTransition* anim = animations[i];
           // properties no longer in 'transition-property'
       if ((checkProperties &&
            !allTransitionProperties.HasProperty(anim->TransitionProperty())) ||
           // properties whose computed values changed but for which we
           // did not start a new transition (because delay and
           // duration are both zero, or because the new value is not
           // interpolable); a new transition would have anim->ToValue()
           // matching currentValue
           !ExtractNonDiscreteComputedValue(anim->TransitionProperty(),
                                            aNewStyleContext, currentValue) ||
-          currentValue != anim->ToValue().mGecko) {
+          currentValue != anim->ToValue()) {
         // stop the transition
         if (anim->HasCurrentEffect()) {
           EffectSet* effectSet =
             EffectSet::GetEffectSet(aElement,
                                     aNewStyleContext->GetPseudoType());
           if (effectSet) {
             effectSet->UpdateAnimationGeneration(mPresContext);
           }
@@ -817,20 +834,18 @@ nsTransitionManager::ConsiderInitiatingT
   if (nsCSSProps::kAnimTypeTable[aProperty] == eStyleAnimType_None) {
     return;
   }
 
   dom::DocumentTimeline* timeline = aElement->OwnerDoc()->Timeline();
 
   AnimationValue startValue, endValue;
   bool haveValues =
-    ExtractNonDiscreteComputedValue(aProperty, aOldStyleContext,
-                                    startValue.mGecko) &&
-    ExtractNonDiscreteComputedValue(aProperty, aNewStyleContext,
-                                    endValue.mGecko);
+    ExtractNonDiscreteComputedValue(aProperty, aOldStyleContext, startValue) &&
+    ExtractNonDiscreteComputedValue(aProperty, aNewStyleContext, endValue);
 
   bool haveChange = startValue != endValue;
 
   bool shouldAnimate =
     haveValues &&
     haveChange &&
     startValue.IsInterpolableWith(aProperty, endValue);
 
@@ -1083,18 +1098,17 @@ nsTransitionManager::PruneCompletedTrans
     if (anim->HasCurrentEffect()) {
       continue;
     }
 
     // Since effect is a finished transition, we know it didn't
     // influence style.
     AnimationValue currentValue;
     if (!ExtractNonDiscreteComputedValue(anim->TransitionProperty(),
-                                         aNewStyleContext,
-                                         currentValue.mGecko) ||
+                                         aNewStyleContext, currentValue) ||
         currentValue != anim->ToValue()) {
       anim->CancelFromStyle();
       animations.RemoveElementAt(i);
     }
   } while (i != 0);
 
   if (collection->mAnimations.IsEmpty()) {
     collection->Destroy();