Bug 1328787 - Part 4: Add Gecko_AnimationAppendKeyframe. r?heycam
This is a function which is called in Servo_StyleSet_FillKeyframesForName to
append a Gecko's Keyframe into nsTArray<Keyframe>.
Without this function we need to end up exposing ComputedTimingFunction class
and Maybe<> as FFI.
MozReview-Commit-ID: 2EpltR4rMVh
--- a/layout/style/ServoBindingTypes.h
+++ b/layout/style/ServoBindingTypes.h
@@ -20,31 +20,33 @@ struct RawServoStyleSet;
#undef SERVO_ARC_TYPE
namespace mozilla {
class ServoElementSnapshot;
namespace dom {
class Element;
class StyleChildrenIterator;
} // namespace dom
+struct Keyframe;
struct PropertyStyleAnimationValuePair;
} // namespace mozilla
class nsCSSValue;
class nsIDocument;
class nsINode;
class nsPresContext;
using mozilla::dom::StyleChildrenIterator;
using mozilla::ServoElementSnapshot;
typedef nsINode RawGeckoNode;
typedef mozilla::dom::Element RawGeckoElement;
typedef nsIDocument RawGeckoDocument;
typedef nsPresContext RawGeckoPresContext;
+typedef nsTArray<mozilla::Keyframe> RawGeckoKeyframeList;
typedef nsTArray<mozilla::PropertyStyleAnimationValuePair> RawGeckoAnimationValueList;
typedef nsTArray<const RawServoAnimationValue*> RawServoAnimationValueBorrowedList;
// 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.
@@ -107,16 +109,17 @@ DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawG
DECL_BORROWED_MUT_REF_TYPE_FOR(StyleChildrenIterator)
DECL_BORROWED_MUT_REF_TYPE_FOR(ServoElementSnapshot)
DECL_BORROWED_REF_TYPE_FOR(nsCSSValue)
DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSValue)
DECL_OWNED_REF_TYPE_FOR(RawGeckoPresContext)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoPresContext)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoAnimationValueList)
DECL_BORROWED_REF_TYPE_FOR(RawServoAnimationValueBorrowedList)
+DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoKeyframeList)
#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/ServoBindingTypes.h.rej
+++ b/layout/style/ServoBindingTypes.h.rej
@@ -1,38 +1,10 @@
--- ServoBindingTypes.h
+++ ServoBindingTypes.h
-@@ -36,16 +36,17 @@ class nsPresContext;
- using mozilla::dom::StyleChildrenIterator;
- using mozilla::ServoElementSnapshot;
-
- typedef nsINode RawGeckoNode;
- typedef mozilla::dom::Element RawGeckoElement;
- typedef nsIDocument RawGeckoDocument;
- typedef nsPresContext RawGeckoPresContext;
- typedef nsTArray<mozilla::PropertyStyleAnimationValuePair> RawGeckoAnimationValueList;
-+typedef nsTArray<const RawServoAnimationValue*> RawServoAnimationValueBorrowedList;
-
- // 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.
-@@ -105,16 +106,17 @@ DECL_BORROWED_REF_TYPE_FOR(RawGeckoDocum
- DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawGeckoDocument)
- DECL_BORROWED_MUT_REF_TYPE_FOR(StyleChildrenIterator)
- DECL_BORROWED_MUT_REF_TYPE_FOR(ServoElementSnapshot)
- DECL_BORROWED_REF_TYPE_FOR(nsCSSValue)
- DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSValue)
+@@ -110,6 +112,7 @@ DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSValu
DECL_OWNED_REF_TYPE_FOR(RawGeckoPresContext)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoPresContext)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoAnimationValueList)
-+DECL_BORROWED_REF_TYPE_FOR(RawServoAnimationValueBorrowedList)
++DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoKeyframeList)
#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
@@ -27,16 +27,17 @@
#include "nsRuleNode.h"
#include "nsString.h"
#include "nsStyleStruct.h"
#include "nsStyleUtil.h"
#include "nsTArray.h"
#include "mozilla/EffectCompositor.h"
#include "mozilla/EventStates.h"
+#include "mozilla/Keyframe.h"
#include "mozilla/ServoAnimationRule.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/ServoRestyleManager.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/DeclarationBlockInlines.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ElementInlines.h"
@@ -942,16 +943,32 @@ void
Gecko_EnsureStyleAnimationArrayLength(void* aArray, size_t aLen)
{
auto base =
reinterpret_cast<nsStyleAutoArray<StyleAnimation>*>(aArray);
base->EnsureLengthAtLeast(aLen);
}
+Keyframe*
+Gecko_AnimationAppendKeyframe(RawGeckoKeyframeListBorrowedMut aKeyframes,
+ float aOffset,
+ const nsTimingFunction* aTimingFunction)
+{
+ Keyframe* keyframe = aKeyframes->AppendElement();
+ keyframe->mOffset.emplace(aOffset);
+ if (aTimingFunction &&
+ aTimingFunction->mType != nsTimingFunction::Type::Linear) {
+ keyframe->mTimingFunction.emplace();
+ keyframe->mTimingFunction->Init(*aTimingFunction);
+ }
+
+ return keyframe;
+}
+
void
Gecko_ResetStyleCoord(nsStyleUnit* aUnit, nsStyleUnion* aValue)
{
nsStyleCoord::Reset(*aUnit, *aValue);
}
void
Gecko_SetStyleCoordCalcValue(nsStyleUnit* aUnit, nsStyleUnion* aValue, nsStyleCoord::CalcValue aCalc)
--- a/layout/style/ServoBindings.cpp.rej
+++ b/layout/style/ServoBindings.cpp.rej
@@ -1,22 +1,10 @@
--- ServoBindings.cpp
+++ ServoBindings.cpp
-@@ -24,17 +25,19 @@
- #include "nsNameSpaceManager.h"
- #include "nsNetUtil.h"
- #include "nsRuleNode.h"
- #include "nsString.h"
- #include "nsStyleStruct.h"
- #include "nsStyleUtil.h"
+@@ -30,6 +30,7 @@
#include "nsTArray.h"
-+#include "mozilla/EffectCompositor.h"
#include "mozilla/EventStates.h"
-+#include "mozilla/ServoAnimationRule.h"
++#include "mozilla/Keyframe.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/ServoRestyleManager.h"
#include "mozilla/StyleAnimationValue.h"
- #include "mozilla/DeclarationBlockInlines.h"
- #include "mozilla/dom/Element.h"
- #include "mozilla/dom/ElementInlines.h"
-
- using namespace mozilla;
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -29,16 +29,17 @@
class nsIAtom;
class nsIPrincipal;
class nsIURI;
struct nsFont;
namespace mozilla {
class ServoStyleSheet;
class FontFamilyList;
enum FontFamilyType : uint32_t;
+ struct Keyframe;
}
using mozilla::FontFamilyList;
using mozilla::FontFamilyType;
using mozilla::ServoElementSnapshot;
struct nsMediaFeature;
struct nsStyleList;
struct nsStyleImage;
struct nsStyleGradientStop;
@@ -262,16 +263,20 @@ void Gecko_ClearPODTArray(void* array, s
void Gecko_ClearStyleContents(nsStyleContent* content);
void Gecko_CopyStyleContentsFrom(nsStyleContent* content, const nsStyleContent* other);
void Gecko_EnsureImageLayersLength(nsStyleImageLayers* layers, size_t len,
nsStyleImageLayers::LayerType layer_type);
void Gecko_EnsureStyleAnimationArrayLength(void* array, size_t len);
+mozilla::Keyframe* Gecko_AnimationAppendKeyframe(RawGeckoKeyframeListBorrowedMut keyframes,
+ float offset,
+ const nsTimingFunction* timingFunction);
+
// Clean up pointer-based coordinates
void Gecko_ResetStyleCoord(nsStyleUnit* unit, nsStyleUnion* value);
// Set an nsStyleCoord to a computed `calc()` value
void Gecko_SetStyleCoordCalcValue(nsStyleUnit* unit, nsStyleUnion* value, nsStyleCoord::CalcValue calc);
void Gecko_CopyClipPathValueFrom(mozilla::StyleClipPath* dst, const mozilla::StyleClipPath* src);