Bug 1341372 - Part 3: Add FFIs for Triggering transitions. draft
authorBoris Chiou <boris.chiou@gmail.com>
Mon, 17 Apr 2017 14:29:31 +0800
changeset 563574 4c5042d1a0a6209f62e2eda99c9317c5da0f75ed
parent 563573 5ed611a3ef6e898c046bb52a6bf4f17fb5d7420e
child 563575 7e4a8bc1159720cef16f0a377e71ae4def039099
push id54353
push userbmo:boris.chiou@gmail.com
push dateMon, 17 Apr 2017 09:07:14 +0000
bugs1341372
milestone55.0a1
Bug 1341372 - Part 3: Add FFIs for Triggering transitions. We add these FFIs for retrieving the existing transitions, so we can reduce the false alarms of triggering transitions from Servo: 1. Gecko_ElementTransitions_Length 2. Gecko_ElementTransitions_PropertyAt 3. Gecko_ElementTransitions_EndValueAt MozReview-Commit-ID: 9eLd8fxmNd9
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -540,16 +540,81 @@ Gecko_ElementHasCSSTransitions(RawGeckoE
                                        CSSEnabledState::eForAllContent);
   nsTransitionManager::CSSTransitionCollection* collection =
     nsTransitionManager::CSSTransitionCollection
                        ::GetAnimationCollection(aElement, pseudoType);
 
   return collection && !collection->mAnimations.IsEmpty();
 }
 
+size_t
+Gecko_ElementTransitions_Length(RawGeckoElementBorrowed aElement,
+                                nsIAtom* aPseudoTagOrNull)
+{
+  MOZ_ASSERT(!aPseudoTagOrNull ||
+             aPseudoTagOrNull == nsCSSPseudoElements::before ||
+             aPseudoTagOrNull == nsCSSPseudoElements::after);
+
+  CSSPseudoElementType pseudoType =
+    nsCSSPseudoElements::GetPseudoType(aPseudoTagOrNull,
+                                       CSSEnabledState::eForAllContent);
+  nsTransitionManager::CSSTransitionCollection* collection =
+    nsTransitionManager::CSSTransitionCollection
+                       ::GetAnimationCollection(aElement, pseudoType);
+
+  return collection ? collection->mAnimations.Length() : 0;
+}
+
+static CSSTransition*
+GetCurrentTransitionAt(RawGeckoElementBorrowed aElement,
+                       nsIAtom* aPseudoTagOrNull,
+                       size_t aIndex)
+{
+  MOZ_ASSERT(!aPseudoTagOrNull ||
+             aPseudoTagOrNull == nsCSSPseudoElements::before ||
+             aPseudoTagOrNull == nsCSSPseudoElements::after);
+
+  CSSPseudoElementType pseudoType =
+    nsCSSPseudoElements::GetPseudoType(aPseudoTagOrNull,
+                                       CSSEnabledState::eForAllContent);
+  nsTransitionManager::CSSTransitionCollection* collection =
+    nsTransitionManager::CSSTransitionCollection
+                       ::GetAnimationCollection(aElement, pseudoType);
+  if (!collection) {
+    return nullptr;
+  }
+  nsTArray<RefPtr<CSSTransition>>& transitions = collection->mAnimations;
+  return aIndex < transitions.Length()
+         ? transitions[aIndex].get()
+         : nullptr;
+}
+
+nsCSSPropertyID
+Gecko_ElementTransitions_PropertyAt(RawGeckoElementBorrowed aElement,
+                                    nsIAtom* aPseudoTagOrNull,
+                                    size_t aIndex)
+{
+  CSSTransition* transition = GetCurrentTransitionAt(aElement,
+                                                     aPseudoTagOrNull,
+                                                     aIndex);
+  return transition ? transition->TransitionProperty()
+                    : nsCSSPropertyID::eCSSProperty_UNKNOWN;
+}
+
+RawServoAnimationValueBorrowedOrNull
+Gecko_ElementTransitions_EndValueAt(RawGeckoElementBorrowed aElement,
+                                    nsIAtom* aPseudoTagOrNull,
+                                    size_t aIndex)
+{
+  CSSTransition* transition = GetCurrentTransitionAt(aElement,
+                                                     aPseudoTagOrNull,
+                                                     aIndex);
+  return transition ? transition->ToValue().mServo.get() : nullptr;
+}
+
 double
 Gecko_GetProgressFromComputedTiming(RawGeckoComputedTimingBorrowed aComputedTiming)
 {
   return aComputedTiming->mProgress.Value();
 }
 
 double
 Gecko_GetPositionInSegment(RawGeckoAnimationPropertySegmentBorrowed aSegment,
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -202,16 +202,26 @@ void Gecko_UpdateAnimations(RawGeckoElem
                             ServoComputedValuesBorrowedOrNull aParentComputedValues,
                             mozilla::UpdateAnimationsTasks aTaskBits);
 bool Gecko_ElementHasAnimations(RawGeckoElementBorrowed aElement,
                                 nsIAtom* aPseudoTagOrNull);
 bool Gecko_ElementHasCSSAnimations(RawGeckoElementBorrowed aElement,
                                    nsIAtom* aPseudoTagOrNull);
 bool Gecko_ElementHasCSSTransitions(RawGeckoElementBorrowed aElement,
                                     nsIAtom* aPseudoTagOrNull);
+size_t Gecko_ElementTransitions_Length(RawGeckoElementBorrowed aElement,
+                                       nsIAtom* aPseudoTagOrNull);
+nsCSSPropertyID Gecko_ElementTransitions_PropertyAt(
+  RawGeckoElementBorrowed aElement,
+  nsIAtom* aPseudoTagOrNull,
+  size_t aIndex);
+RawServoAnimationValueBorrowedOrNull Gecko_ElementTransitions_EndValueAt(
+  RawGeckoElementBorrowed aElement,
+  nsIAtom* aPseudoTagOrNull,
+  size_t aIndex);
 double Gecko_GetProgressFromComputedTiming(RawGeckoComputedTimingBorrowed aComputedTiming);
 double Gecko_GetPositionInSegment(
   RawGeckoAnimationPropertySegmentBorrowed aSegment,
   double aProgress,
   mozilla::ComputedTimingFunction::BeforeFlag aBeforeFlag);
 // Get servo's AnimationValue for |aProperty| from the cached base style
 // |aBaseStyles|.
 // |aBaseStyles| is nsRefPtrHashtable<nsUint32HashKey, RawServoAnimationValue>.