Bug 1340005 - Part 6: Move AppendTransformFunction into AnimationValue struct. draft
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 17 Oct 2017 13:11:19 +0800
changeset 687791 5fde0912aee04c4f2d3d5d3bf31c140d9b0957cc
parent 687790 51351e4877f110d86c4e2eb7e37cc3ada8f96f8f
child 687792 73d3c5bfbe2996543250e5e6335e49a9981fdb9a
push id86604
push userbmo:boris.chiou@gmail.com
push dateFri, 27 Oct 2017 19:27:11 +0000
bugs1340005
milestone58.0a1
Bug 1340005 - Part 6: Move AppendTransformFunction into AnimationValue struct. MozReview-Commit-ID: KhjKXxkllEF
gfx/layers/AnimationHelper.cpp
layout/style/StyleAnimationValue.cpp
layout/style/StyleAnimationValue.h
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -341,111 +341,107 @@ CreateCSSValueList(const InfallibleTArra
   nsAutoPtr<nsCSSValueList> result;
   nsCSSValueList** resultTail = getter_Transfers(result);
   for (uint32_t i = 0; i < aFunctions.Length(); i++) {
     RefPtr<nsCSSValue::Array> arr;
     switch (aFunctions[i].type()) {
       case TransformFunction::TRotationX:
       {
         const CSSAngle& angle = aFunctions[i].get_RotationX().angle();
-        arr = StyleAnimationValue::AppendTransformFunction(eCSSKeyword_rotatex,
-                                                           resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotatex,
+                                                    resultTail);
         SetCSSAngle(angle, arr->Item(1));
         break;
       }
       case TransformFunction::TRotationY:
       {
         const CSSAngle& angle = aFunctions[i].get_RotationY().angle();
-        arr = StyleAnimationValue::AppendTransformFunction(eCSSKeyword_rotatey,
-                                                           resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotatey,
+                                                      resultTail);
         SetCSSAngle(angle, arr->Item(1));
         break;
       }
       case TransformFunction::TRotationZ:
       {
         const CSSAngle& angle = aFunctions[i].get_RotationZ().angle();
-        arr = StyleAnimationValue::AppendTransformFunction(eCSSKeyword_rotatez,
-                                                           resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotatez,
+                                                      resultTail);
         SetCSSAngle(angle, arr->Item(1));
         break;
       }
       case TransformFunction::TRotation:
       {
         const CSSAngle& angle = aFunctions[i].get_Rotation().angle();
-        arr = StyleAnimationValue::AppendTransformFunction(eCSSKeyword_rotate,
-                                                           resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotate,
+                                                      resultTail);
         SetCSSAngle(angle, arr->Item(1));
         break;
       }
       case TransformFunction::TRotation3D:
       {
         float x = aFunctions[i].get_Rotation3D().x();
         float y = aFunctions[i].get_Rotation3D().y();
         float z = aFunctions[i].get_Rotation3D().z();
         const CSSAngle& angle = aFunctions[i].get_Rotation3D().angle();
-        arr =
-          StyleAnimationValue::AppendTransformFunction(eCSSKeyword_rotate3d,
-                                                       resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_rotate3d,
+                                                      resultTail);
         arr->Item(1).SetFloatValue(x, eCSSUnit_Number);
         arr->Item(2).SetFloatValue(y, eCSSUnit_Number);
         arr->Item(3).SetFloatValue(z, eCSSUnit_Number);
         SetCSSAngle(angle, arr->Item(4));
         break;
       }
       case TransformFunction::TScale:
       {
-        arr =
-          StyleAnimationValue::AppendTransformFunction(eCSSKeyword_scale3d,
-                                                       resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_scale3d,
+                                                      resultTail);
         arr->Item(1).SetFloatValue(aFunctions[i].get_Scale().x(), eCSSUnit_Number);
         arr->Item(2).SetFloatValue(aFunctions[i].get_Scale().y(), eCSSUnit_Number);
         arr->Item(3).SetFloatValue(aFunctions[i].get_Scale().z(), eCSSUnit_Number);
         break;
       }
       case TransformFunction::TTranslation:
       {
-        arr =
-          StyleAnimationValue::AppendTransformFunction(eCSSKeyword_translate3d,
-                                                       resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_translate3d,
+                                                      resultTail);
         arr->Item(1).SetFloatValue(aFunctions[i].get_Translation().x(), eCSSUnit_Pixel);
         arr->Item(2).SetFloatValue(aFunctions[i].get_Translation().y(), eCSSUnit_Pixel);
         arr->Item(3).SetFloatValue(aFunctions[i].get_Translation().z(), eCSSUnit_Pixel);
         break;
       }
       case TransformFunction::TSkewX:
       {
         const CSSAngle& x = aFunctions[i].get_SkewX().x();
-        arr = StyleAnimationValue::AppendTransformFunction(eCSSKeyword_skewx,
-                                                           resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_skewx,
+                                                      resultTail);
         SetCSSAngle(x, arr->Item(1));
         break;
       }
       case TransformFunction::TSkewY:
       {
         const CSSAngle& y = aFunctions[i].get_SkewY().y();
-        arr = StyleAnimationValue::AppendTransformFunction(eCSSKeyword_skewy,
-                                                           resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_skewy,
+                                                      resultTail);
         SetCSSAngle(y, arr->Item(1));
         break;
       }
       case TransformFunction::TSkew:
       {
         const CSSAngle& x = aFunctions[i].get_Skew().x();
         const CSSAngle& y = aFunctions[i].get_Skew().y();
-        arr = StyleAnimationValue::AppendTransformFunction(eCSSKeyword_skew,
-                                                           resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_skew,
+                                                      resultTail);
         SetCSSAngle(x, arr->Item(1));
         SetCSSAngle(y, arr->Item(2));
         break;
       }
       case TransformFunction::TTransformMatrix:
       {
-        arr =
-          StyleAnimationValue::AppendTransformFunction(eCSSKeyword_matrix3d,
-                                                       resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_matrix3d,
+                                                      resultTail);
         const gfx::Matrix4x4& matrix = aFunctions[i].get_TransformMatrix().value();
         arr->Item(1).SetFloatValue(matrix._11, eCSSUnit_Number);
         arr->Item(2).SetFloatValue(matrix._12, eCSSUnit_Number);
         arr->Item(3).SetFloatValue(matrix._13, eCSSUnit_Number);
         arr->Item(4).SetFloatValue(matrix._14, eCSSUnit_Number);
         arr->Item(5).SetFloatValue(matrix._21, eCSSUnit_Number);
         arr->Item(6).SetFloatValue(matrix._22, eCSSUnit_Number);
         arr->Item(7).SetFloatValue(matrix._23, eCSSUnit_Number);
@@ -458,19 +454,18 @@ CreateCSSValueList(const InfallibleTArra
         arr->Item(14).SetFloatValue(matrix._42, eCSSUnit_Number);
         arr->Item(15).SetFloatValue(matrix._43, eCSSUnit_Number);
         arr->Item(16).SetFloatValue(matrix._44, eCSSUnit_Number);
         break;
       }
       case TransformFunction::TPerspective:
       {
         float perspective = aFunctions[i].get_Perspective().value();
-        arr =
-          StyleAnimationValue::AppendTransformFunction(eCSSKeyword_perspective,
-                                                       resultTail);
+        arr = AnimationValue::AppendTransformFunction(eCSSKeyword_perspective,
+                                                      resultTail);
         arr->Item(1).SetFloatValue(perspective, eCSSUnit_Pixel);
         break;
       }
       default:
         NS_ASSERTION(false, "All functions should be implemented?");
     }
   }
   if (aFunctions.Length() == 0) {
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -2127,42 +2127,26 @@ AddTransformScale(double aCoeff1, const 
   MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Number, "unexpected unit");
 
   float v1 = aValue1.GetFloatValue() - 1.0f,
         v2 = aValue2.GetFloatValue() - 1.0f;
   float result = v1 * aCoeff1 + v2 * aCoeff2;
   aResult.SetFloatValue(EnsureNotNan(result + 1.0f), eCSSUnit_Number);
 }
 
-/* static */ already_AddRefed<nsCSSValue::Array>
-StyleAnimationValue::AppendTransformFunction(nsCSSKeyword aTransformFunction,
-                                             nsCSSValueList**& aListTail)
-{
-  RefPtr<nsCSSValue::Array> arr = AppendFunction(aTransformFunction);
-  nsCSSValueList *item = new nsCSSValueList;
-  item->mValue.SetArrayValue(arr, eCSSUnit_Function);
-
-  *aListTail = item;
-  aListTail = &item->mNext;
-
-  return arr.forget();
-}
-
 static nsCSSValueList*
 AddDifferentTransformLists(double aCoeff1, const nsCSSValueList* aList1,
                            double aCoeff2, const nsCSSValueList* aList2,
                            nsCSSKeyword aOperatorType)
 {
   nsAutoPtr<nsCSSValueList> result;
   nsCSSValueList **resultTail = getter_Transfers(result);
 
   RefPtr<nsCSSValue::Array> arr;
-  arr =
-    StyleAnimationValue::AppendTransformFunction(aOperatorType,
-                                                 resultTail);
+  arr = AnimationValue::AppendTransformFunction(aOperatorType, resultTail);
 
   if (aCoeff1 == 0) {
     // If the first coeffient is zero, we don't need to care about the first
     // list at all.
     arr->Item(1).Reset();
   } else if (aList1 == aList2) {
     // If we have the same list, clear the first list, add the first coefficient
     // into the second one so that we can simply multiply the second list by the
@@ -2612,17 +2596,17 @@ AddTransformLists(double aCoeff1, const 
 
     nsCSSKeyword tfunc = nsStyleTransformMatrix::TransformFunctionOf(a1);
     RefPtr<nsCSSValue::Array> arr;
     if (tfunc != eCSSKeyword_matrix &&
         tfunc != eCSSKeyword_matrix3d &&
         tfunc != eCSSKeyword_interpolatematrix &&
         tfunc != eCSSKeyword_rotate3d &&
         tfunc != eCSSKeyword_perspective) {
-      arr = StyleAnimationValue::AppendTransformFunction(tfunc, resultTail);
+      arr = AnimationValue::AppendTransformFunction(tfunc, resultTail);
     }
 
     switch (tfunc) {
       case eCSSKeyword_translate3d: {
           MOZ_ASSERT(a1->Count() == 4, "unexpected count");
           MOZ_ASSERT(a2->Count() == 4, "unexpected count");
           AddTransformTranslate(aCoeff1, a1->Item(1), aCoeff2, a2->Item(1),
                                 arr->Item(1));
@@ -2696,34 +2680,34 @@ AddTransformLists(double aCoeff1, const 
         vector2.Normalize();
 
         // Handle rotate3d with matched (normalized) vectors,
         // otherwise fallthrough to the next switch statement
         // and do matrix decomposition.
         if (vector1 == vector2) {
           // We skipped appending a transform function above for rotate3d,
           // so do it now.
-          arr = StyleAnimationValue::AppendTransformFunction(tfunc, resultTail);
+          arr = AnimationValue::AppendTransformFunction(tfunc, resultTail);
           arr->Item(1).SetFloatValue(vector1.x, eCSSUnit_Number);
           arr->Item(2).SetFloatValue(vector1.y, eCSSUnit_Number);
           arr->Item(3).SetFloatValue(vector1.z, eCSSUnit_Number);
 
           AddCSSValueAngle(aCoeff1, a1->Item(4), aCoeff2, a2->Item(4),
                            arr->Item(4));
           break;
         }
         MOZ_FALLTHROUGH;
       }
       case eCSSKeyword_matrix:
       case eCSSKeyword_matrix3d:
       case eCSSKeyword_perspective:
         if (aCoeff1 == 0.0 && aCoeff2 == 0.0) {
           // Special case. If both coefficients are 0.0, we should apply an
           // identity transform function.
-          arr = StyleAnimationValue::AppendTransformFunction(tfunc, resultTail);
+          arr = AnimationValue::AppendTransformFunction(tfunc, resultTail);
 
           if (tfunc == eCSSKeyword_rotate3d) {
             arr->Item(1).SetFloatValue(0.0, eCSSUnit_Number);
             arr->Item(2).SetFloatValue(0.0, eCSSUnit_Number);
             arr->Item(3).SetFloatValue(1.0, eCSSUnit_Number);
             arr->Item(4).SetFloatValue(0.0, eCSSUnit_Radian);
           } else if (tfunc == eCSSKeyword_perspective) {
             // The parameter of the identity perspective function is
@@ -5544,8 +5528,22 @@ AnimationValue::Transform(StyleBackendTy
     case StyleBackendType::Gecko:
       result.mGecko.SetTransformValue(&aList);
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Unsupported style backend");
   }
   return result;
 }
+
+/* static */ already_AddRefed<nsCSSValue::Array>
+AnimationValue::AppendTransformFunction(nsCSSKeyword aTransformFunction,
+                                        nsCSSValueList**& aListTail)
+{
+  RefPtr<nsCSSValue::Array> arr = AppendFunction(aTransformFunction);
+  nsCSSValueList *item = new nsCSSValueList;
+  item->mValue.SetArrayValue(arr, eCSSUnit_Function);
+
+  *aListTail = item;
+  aListTail = &item->mNext;
+
+  return arr.forget();
+}
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -289,20 +289,16 @@ public:
    * @param [out] aComputedValue The resulting computed value.
    * @return true on success, false on failure.
    */
   static MOZ_MUST_USE bool ExtractComputedValue(
     nsCSSPropertyID aProperty,
     mozilla::GeckoStyleContext* aStyleContext,
     StyleAnimationValue& aComputedValue);
 
-  static already_AddRefed<nsCSSValue::Array>
-    AppendTransformFunction(nsCSSKeyword aTransformFunction,
-                            nsCSSValueList**& aListTail);
-
   /**
    * The types and values for the values that we extract and animate.
    */
   enum Unit {
     eUnit_Null, // not initialized
     eUnit_Normal,
     eUnit_Auto,
     eUnit_None,
@@ -640,16 +636,20 @@ struct AnimationValue
                                    dom::Element* aElement);
 
   // Create an AnimationValue from an opacity value.
   static AnimationValue Opacity(StyleBackendType aBackendType, float aOpacity);
   // Create an AnimationValue from a transform list.
   static AnimationValue Transform(StyleBackendType aBackendType,
                                   nsCSSValueSharedList& aList);
 
+  static already_AddRefed<nsCSSValue::Array>
+  AppendTransformFunction(nsCSSKeyword aTransformFunction,
+                          nsCSSValueList**& aListTail);
+
   // mGecko and mServo are mutually exclusive: only one or the other should
   // ever be set.
   // FIXME: After obsoleting StyleAnimationValue, we should remove mGecko, and
   // make AnimationValue a wrapper of RawServoAnimationValue to hide these
   // FFIs.
   StyleAnimationValue mGecko;
   RefPtr<RawServoAnimationValue> mServo;
 };