Bug 1311257 - Add FFI functions to get progress value and current position in a segment. r?birtles
Two functions added in this patch get progress value from ComputedTiming
or get the position in a given AnimationPropertySegment.
Without these FFIs, we need to expose Maybe<> and Nullable<> and handle
them in Rust.
MozReview-Commit-ID: IXYWlqEQyVR
--- a/layout/style/ServoBindingTypes.h
+++ b/layout/style/ServoBindingTypes.h
@@ -24,16 +24,18 @@ namespace mozilla {
struct StyleAnimation;
namespace css {
struct URLExtraData;
} // namespace css
namespace dom {
class Element;
class StyleChildrenIterator;
} // namespace dom
+struct AnimationPropertySegment;
+struct ComputedTiming;
struct Keyframe;
struct PropertyStyleAnimationValuePair;
using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>;
} // namespace mozilla
class nsCSSValue;
struct nsFontFaceRuleContainer;
class nsIDocument;
@@ -49,16 +51,18 @@ typedef mozilla::dom::Element RawGeckoEl
typedef nsIDocument RawGeckoDocument;
typedef nsPresContext RawGeckoPresContext;
typedef mozilla::css::URLExtraData RawGeckoURLExtraData;
typedef nsTArray<mozilla::Keyframe> RawGeckoKeyframeList;
typedef nsTArray<mozilla::ComputedKeyframeValues> RawGeckoComputedKeyframeValuesList;
typedef nsTArray<mozilla::PropertyStyleAnimationValuePair> RawGeckoAnimationValueList;
typedef nsStyleAutoArray<mozilla::StyleAnimation> RawGeckoStyleAnimationList;
typedef nsTArray<nsFontFaceRuleContainer> RawGeckoFontFaceRuleList;
+typedef mozilla::AnimationPropertySegment RawGeckoAnimationPropertySegment;
+typedef mozilla::ComputedTiming RawGeckoComputedTiming;
// We have these helper types so that we can directly generate
// things like &T or Borrowed<T> on the Rust side in the function, providing
// additional safety benefits.
//
// FFI has a problem with templated types, so we just use raw pointers here.
//
// The "Borrowed" types generate &T or Borrowed<T> in the nullable case.
@@ -126,16 +130,18 @@ DECL_BORROWED_REF_TYPE_FOR(RawGeckoPresC
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoAnimationValueList)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoKeyframeList)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoKeyframeList)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoComputedKeyframeValuesList)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoStyleAnimationList)
DECL_BORROWED_MUT_REF_TYPE_FOR(nsTimingFunction)
DECL_BORROWED_REF_TYPE_FOR(nsTimingFunction)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoFontFaceRuleList)
+DECL_BORROWED_REF_TYPE_FOR(RawGeckoAnimationPropertySegment)
+DECL_BORROWED_REF_TYPE_FOR(RawGeckoComputedTiming)
#undef DECL_ARC_REF_TYPE_FOR
#undef DECL_OWNED_REF_TYPE_FOR
#undef DECL_NULLABLE_OWNED_REF_TYPE_FOR
#undef DECL_BORROWED_REF_TYPE_FOR
#undef DECL_NULLABLE_BORROWED_REF_TYPE_FOR
#undef DECL_BORROWED_MUT_REF_TYPE_FOR
#undef DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -508,16 +508,38 @@ Gecko_ElementHasCSSAnimations(RawGeckoEl
CSSEnabledState::eForAllContent);
nsAnimationManager::CSSAnimationCollection* collection =
nsAnimationManager::CSSAnimationCollection
::GetAnimationCollection(aElement, pseudoType);
return collection && !collection->mAnimations.IsEmpty();
}
+double
+Gecko_GetProgressFromComputedTiming(RawGeckoComputedTimingBorrowed aComputedTiming)
+{
+ return aComputedTiming->mProgress.Value();
+}
+
+double
+Gecko_GetPositionInSegment(RawGeckoAnimationPropertySegmentBorrowed aSegment,
+ double aProgress,
+ ComputedTimingFunction::BeforeFlag aBeforeFlag)
+{
+ MOZ_ASSERT(aSegment->mFromKey < aSegment->mToKey,
+ "The segment from key should be less than to key");
+
+ double positionInSegment =
+ (aProgress - aSegment->mFromKey) / (aSegment->mToKey - aSegment->mFromKey);
+
+ return ComputedTimingFunction::GetPortion(aSegment->mTimingFunction,
+ positionInSegment,
+ aBeforeFlag);
+}
+
void
Gecko_FillAllBackgroundLists(nsStyleImageLayers* aLayers, uint32_t aMaxLen)
{
nsRuleNode::FillAllBackgroundLists(*aLayers, aMaxLen);
}
void
Gecko_FillAllMaskLists(nsStyleImageLayers* aLayers, uint32_t aMaxLen)
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -9,16 +9,17 @@
#include <stdint.h>
#include "mozilla/ServoTypes.h"
#include "mozilla/ServoBindingTypes.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/css/SheetParsingMode.h"
#include "mozilla/EffectCompositor.h"
+#include "mozilla/ComputedTimingFunction.h"
#include "nsChangeHint.h"
#include "nsCSSPseudoClasses.h"
#include "nsStyleStruct.h"
/*
* API for Servo to access Gecko data structures. This file must compile as valid
* C code in order for the binding generator to parse it.
*
@@ -188,16 +189,21 @@ void Gecko_UpdateAnimations(RawGeckoElem
nsIAtom* aPseudoTagOrNull,
ServoComputedValuesBorrowedOrNull aComputedValues,
ServoComputedValuesBorrowedOrNull aParentComputedValues,
mozilla::UpdateAnimationsTasks aTaskBits);
bool Gecko_ElementHasAnimations(RawGeckoElementBorrowed aElement,
nsIAtom* aPseudoTagOrNull);
bool Gecko_ElementHasCSSAnimations(RawGeckoElementBorrowed aElement,
nsIAtom* aPseudoTagOrNull);
+double Gecko_GetProgressFromComputedTiming(RawGeckoComputedTimingBorrowed aComputedTiming);
+double Gecko_GetPositionInSegment(
+ RawGeckoAnimationPropertySegmentBorrowed aSegment,
+ double aProgress,
+ mozilla::ComputedTimingFunction::BeforeFlag aBeforeFlag);
// Atoms.
nsIAtom* Gecko_Atomize(const char* aString, uint32_t aLength);
void Gecko_AddRefAtom(nsIAtom* aAtom);
void Gecko_ReleaseAtom(nsIAtom* aAtom);
const uint16_t* Gecko_GetAtomAsUTF16(nsIAtom* aAtom, uint32_t* aLength);
bool Gecko_AtomEqualsUTF8(nsIAtom* aAtom, const char* aString, uint32_t aLength);
bool Gecko_AtomEqualsUTF8IgnoreCase(nsIAtom* aAtom, const char* aString, uint32_t aLength);