Bug 1273706 - Part 10: Expose StyleAnimationValue::StyleCoordToValue and StyleCoordToCSSValue. draft
authorJonathan Chan <jyc@eqv.io>
Thu, 18 Aug 2016 15:28:10 -0700
changeset 402899 aea3ba284453b6b6cd1ef7c54f3746a739938d78
parent 402898 ab7c3d32f8deb753ffbde444beb0ecbfce8cde87
child 402900 6508bc57aa61423ba1238ccca5c8471bb4964399
push id26775
push userjchan@mozilla.com
push dateThu, 18 Aug 2016 22:38:41 +0000
bugs1273706
milestone51.0a1
Bug 1273706 - Part 10: Expose StyleAnimationValue::StyleCoordToValue and StyleCoordToCSSValue. Currently these are used by StyleAnimationValue internally in ExtractComputedValue only. A later patch in this series will use them for converting nsStyleCoords to StyleAnimationValues and for converting nsStyleCoords to strings (by way of nsCSSValue::AppendToString). Also add support for eStyleUnit_Integer to StyleCoordToCSSValue, because we use nsStyleCoords to store <integer>s too. MozReview-Commit-ID: L1zTPOxq88Z
layout/style/StyleAnimationValue.cpp
layout/style/StyleAnimationValue.h
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -3274,17 +3274,19 @@ ExtractBorderColor(nsStyleContext* aStyl
     GetBorderColor(aSide, color, foreground);
   if (foreground) {
     // FIXME: should add test for this
     color = aStyleContext->StyleColor()->mColor;
   }
   aComputedValue.SetColorValue(color);
 }
 
-static bool
+namespace mozilla {
+
+bool
 StyleCoordToValue(const nsStyleCoord& aCoord, StyleAnimationValue& aValue)
 {
   switch (aCoord.GetUnit()) {
     case eStyleUnit_Normal:
       aValue.SetNormalValue();
       break;
     case eStyleUnit_Auto:
       aValue.SetAutoValue();
@@ -3317,17 +3319,17 @@ StyleCoordToValue(const nsStyleCoord& aC
       break;
     }
     default:
       return false;
   }
   return true;
 }
 
-static bool
+bool
 StyleCoordToCSSValue(const nsStyleCoord& aCoord, nsCSSValue& aCSSValue)
 {
   switch (aCoord.GetUnit()) {
     case eStyleUnit_Coord:
       nscoordToCSSValue(aCoord.GetCoordValue(), aCSSValue);
       break;
     case eStyleUnit_Factor:
       aCSSValue.SetFloatValue(aCoord.GetFactorValue(), eCSSUnit_Number);
@@ -3345,23 +3347,28 @@ StyleCoordToCSSValue(const nsStyleCoord&
       aCSSValue.SetFloatValue(aCoord.GetAngleValue(), eCSSUnit_Grad);
       break;
     case eStyleUnit_Radian:
       aCSSValue.SetFloatValue(aCoord.GetAngleValue(), eCSSUnit_Radian);
       break;
     case eStyleUnit_Turn:
       aCSSValue.SetFloatValue(aCoord.GetAngleValue(), eCSSUnit_Turn);
       break;
+    case eStyleUnit_Integer:
+      aCSSValue.SetIntValue(aCoord.GetIntValue(), eCSSUnit_Integer);
+      break;
     default:
       MOZ_ASSERT(false, "unexpected unit");
       return false;
   }
   return true;
 }
 
+} // namespace mozilla
+
 static void
 SetPositionValue(const nsStyleImageLayers::Position& aPos, nsCSSValue& aCSSValue)
 {
   RefPtr<nsCSSValue::Array> posArray = nsCSSValue::Array::Create(4);
   aCSSValue.SetArrayValue(posArray.get(), eCSSUnit_Array);
 
   // NOTE: Array entries #0 and #2 here are intentionally left untouched, with
   // eCSSUnit_Null.  The purpose of these entries in our specified-style
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -15,30 +15,36 @@
 #include "nsCoord.h"
 #include "nsColor.h"
 #include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #include "nsTArray.h"
 
 class nsIFrame;
 class nsStyleContext;
+class nsStyleCoord;
 class gfx3DMatrix;
 
 namespace mozilla {
 
 namespace css {
 class StyleRule;
 } // namespace css
 
 namespace dom {
 class Element;
 } // namespace dom
 
 enum class CSSPseudoElementType : uint8_t;
 struct PropertyStyleAnimationValuePair;
+class StyleAnimationValue;
+
+bool StyleCoordToValue(const nsStyleCoord& aCoord,
+                       StyleAnimationValue& aValue);
+bool StyleCoordToCSSValue(const nsStyleCoord& aCoord, nsCSSValue& aValue);
 
 /**
  * Utility class to handle animated style values
  */
 class StyleAnimationValue {
 public:
   // Mathematical methods
   // --------------------