diff --git a/dom/animation/ComputedTimingFunction.h b/dom/animation/ComputedTimingFunction.h index f2ad110b219b..488d5cc4bade 100644 --- a/dom/animation/ComputedTimingFunction.h +++ b/dom/animation/ComputedTimingFunction.h @@ -8,12 +8,12 @@ #define mozilla_ComputedTimingFunction_h #include "nsDebug.h" -#include "nsSMILKeySpline.h" // nsSMILKeySpline #include "nsStringFwd.h" #include "nsTimingFunction.h" #include "mozilla/Assertions.h" #include "mozilla/Maybe.h" +#include "mozilla/SMILKeySpline.h" namespace mozilla { @@ -56,7 +56,7 @@ class ComputedTimingFunction { // https://drafts.csswg.org/css-easing/#before-flag enum class BeforeFlag { Unset, Set }; double GetValue(double aPortion, BeforeFlag aBeforeFlag) const; - const nsSMILKeySpline* GetFunction() const { + const SMILKeySpline* GetFunction() const { NS_ASSERTION(HasSpline(), "Type mismatch"); return &mTimingFunction; } @@ -110,7 +110,7 @@ class ComputedTimingFunction { : mType(Type::Step), mSteps{aSteps, aPos} {} Type mType; - nsSMILKeySpline mTimingFunction; + SMILKeySpline mTimingFunction; StepFunc mSteps; }; diff --git a/dom/smil/SMILAnimationController.cpp b/dom/smil/SMILAnimationController.cpp index 3381888d81b9..ffabf3089bb7 100644 --- a/dom/smil/SMILAnimationController.cpp +++ b/dom/smil/SMILAnimationController.cpp @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "mozilla/SMILAnimationController.h" +#include "SMILAnimationController.h" #include @@ -20,7 +20,7 @@ #include "nsIPresShellInlines.h" #include "nsITimer.h" #include "SMILCompositor.h" -#include "nsSMILCSSProperty.h" +#include "SMILCSSProperty.h" using namespace mozilla::dom; diff --git a/dom/smil/SMILAnimationFunction.cpp b/dom/smil/SMILAnimationFunction.cpp index cad266810793..a2ee23adb15c 100644 --- a/dom/smil/SMILAnimationFunction.cpp +++ b/dom/smil/SMILAnimationFunction.cpp @@ -7,11 +7,11 @@ #include "SMILAnimationFunction.h" #include "mozilla/dom/SVGAnimationElement.h" +#include "mozilla/SMILParserUtils.h" #include "mozilla/SMILTimedElement.h" #include "mozilla/Move.h" #include "nsISMILAttr.h" #include "SMILCSSValueType.h" -#include "nsSMILParserUtils.h" #include "SMILNullType.h" #include "nsAttrValueInlines.h" #include "nsGkAtoms.h" @@ -636,7 +636,7 @@ double SMILAnimationFunction::ScaleIntervalProgress(double aProgress, MOZ_ASSERT(aIntervalIndex < mKeySplines.Length(), "Invalid interval index"); - nsSMILKeySpline const& spline = mKeySplines[aIntervalIndex]; + SMILKeySpline const& spline = mKeySplines[aIntervalIndex]; return spline.GetSplineValue(aProgress); } @@ -713,8 +713,8 @@ nsresult SMILAnimationFunction::GetValues(const nsISMILAttr& aSMILAttr, nsAutoString attValue; GetAttr(nsGkAtoms::values, attValue); bool preventCachingOfSandwich = false; - if (!nsSMILParserUtils::ParseValues(attValue, mAnimationElement, aSMILAttr, - result, preventCachingOfSandwich)) { + if (!SMILParserUtils::ParseValues(attValue, mAnimationElement, aSMILAttr, + result, preventCachingOfSandwich)) { return NS_ERROR_FAILURE; } @@ -940,7 +940,7 @@ nsresult SMILAnimationFunction::SetKeySplines(const nsAString& aKeySplines, mHasChanged = true; - if (!nsSMILParserUtils::ParseKeySplines(aKeySplines, mKeySplines)) { + if (!SMILParserUtils::ParseKeySplines(aKeySplines, mKeySplines)) { mKeySplines.Clear(); return NS_ERROR_FAILURE; } @@ -961,8 +961,8 @@ nsresult SMILAnimationFunction::SetKeyTimes(const nsAString& aKeyTimes, mHasChanged = true; - if (!nsSMILParserUtils::ParseSemicolonDelimitedProgressList(aKeyTimes, true, - mKeyTimes)) { + if (!SMILParserUtils::ParseSemicolonDelimitedProgressList(aKeyTimes, true, + mKeyTimes)) { mKeyTimes.Clear(); return NS_ERROR_FAILURE; } diff --git a/dom/smil/SMILAnimationFunction.h b/dom/smil/SMILAnimationFunction.h index 00af6f42f091..51fac8b37fe8 100644 --- a/dom/smil/SMILAnimationFunction.h +++ b/dom/smil/SMILAnimationFunction.h @@ -8,15 +8,15 @@ #define NS_SMILANIMATIONFUNCTION_H_ #include "mozilla/SMILTargetIdentifier.h" -#include "nsISMILAttr.h" -#include "nsGkAtoms.h" -#include "nsString.h" -#include "nsSMILTimeValue.h" -#include "nsSMILKeySpline.h" -#include "nsSMILValue.h" -#include "nsTArray.h" #include "nsAttrValue.h" +#include "nsGkAtoms.h" +#include "nsISMILAttr.h" +#include "SMILKeySpline.h" +#include "nsSMILTimeValue.h" #include "nsSMILTypes.h" +#include "nsSMILValue.h" +#include "nsString.h" +#include "nsTArray.h" namespace mozilla { namespace dom { @@ -401,7 +401,7 @@ class SMILAnimationFunction { static nsAttrValue::EnumTable sAccumulateTable[]; FallibleTArray mKeyTimes; - FallibleTArray mKeySplines; + FallibleTArray mKeySplines; // These are the parameters provided by the previous sample. Currently we // perform lazy calculation. That is, we only calculate the result if and when diff --git a/dom/smil/nsSMILCSSProperty.cpp b/dom/smil/SMILCSSProperty.cpp similarity index 91% rename from dom/smil/nsSMILCSSProperty.cpp rename to dom/smil/SMILCSSProperty.cpp index 20c325c2c675..6b8f266bad47 100644 --- a/dom/smil/nsSMILCSSProperty.cpp +++ b/dom/smil/SMILCSSProperty.cpp @@ -6,7 +6,7 @@ /* representation of a SMIL-animatable CSS property on an element */ -#include "nsSMILCSSProperty.h" +#include "SMILCSSProperty.h" #include "mozilla/dom/Element.h" #include "mozilla/Move.h" @@ -17,21 +17,20 @@ #include "nsSMILValue.h" #include "nsCSSProps.h" -using namespace mozilla; -using namespace mozilla::dom; +namespace mozilla { // Class Methods -nsSMILCSSProperty::nsSMILCSSProperty(nsCSSPropertyID aPropID, Element* aElement, - ComputedStyle* aBaseComputedStyle) +SMILCSSProperty::SMILCSSProperty(nsCSSPropertyID aPropID, Element* aElement, + ComputedStyle* aBaseComputedStyle) : mPropID(aPropID), mElement(aElement), mBaseComputedStyle(aBaseComputedStyle) { MOZ_ASSERT(IsPropertyAnimatable(mPropID), - "Creating a nsSMILCSSProperty for a property " + "Creating a SMILCSSProperty for a property " "that's not supported for animation"); } -nsSMILValue nsSMILCSSProperty::GetBaseValue() const { +nsSMILValue SMILCSSProperty::GetBaseValue() const { // To benefit from Return Value Optimization and avoid copy constructor calls // due to our use of return-by-value, we must return the exact same object // from ALL return points. This function must only return THIS variable: @@ -73,7 +72,7 @@ nsSMILValue nsSMILCSSProperty::GetBaseValue() const { return baseValue; } -nsresult nsSMILCSSProperty::ValueFromString( +nsresult SMILCSSProperty::ValueFromString( const nsAString& aStr, const SVGAnimationElement* aSrcElement, nsSMILValue& aValue, bool& aPreventCachingOfSandwich) const { NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE); @@ -94,12 +93,12 @@ nsresult nsSMILCSSProperty::ValueFromString( return NS_OK; } -nsresult nsSMILCSSProperty::SetAnimValue(const nsSMILValue& aValue) { +nsresult SMILCSSProperty::SetAnimValue(const nsSMILValue& aValue) { NS_ENSURE_TRUE(IsPropertyAnimatable(mPropID), NS_ERROR_FAILURE); return mElement->SMILOverrideStyle()->SetSMILValue(mPropID, aValue); } -void nsSMILCSSProperty::ClearAnimValue() { +void SMILCSSProperty::ClearAnimValue() { // Put empty string in override style for our property mElement->SMILOverrideStyle()->SetPropertyValue(mPropID, EmptyString(), nullptr); @@ -107,7 +106,7 @@ void nsSMILCSSProperty::ClearAnimValue() { // Based on http://www.w3.org/TR/SVG/propidx.html // static -bool nsSMILCSSProperty::IsPropertyAnimatable(nsCSSPropertyID aPropID) { +bool SMILCSSProperty::IsPropertyAnimatable(nsCSSPropertyID aPropID) { // Bug 1353918: Drop this check if (!Servo_Property_IsAnimatable(aPropID)) { return false; @@ -198,3 +197,5 @@ bool nsSMILCSSProperty::IsPropertyAnimatable(nsCSSPropertyID aPropID) { return false; } } + +} // namespace mozilla diff --git a/dom/smil/nsSMILCSSProperty.h b/dom/smil/SMILCSSProperty.h similarity index 83% rename from dom/smil/nsSMILCSSProperty.h rename to dom/smil/SMILCSSProperty.h index c021ac3f7c96..00ce7a557c56 100644 --- a/dom/smil/nsSMILCSSProperty.h +++ b/dom/smil/SMILCSSProperty.h @@ -20,17 +20,16 @@ class ComputedStyle; namespace dom { class Element; } // namespace dom -} // namespace mozilla /** - * nsSMILCSSProperty: Implements the nsISMILAttr interface for SMIL animations + * SMILCSSProperty: Implements the nsISMILAttr interface for SMIL animations * that target CSS properties. Represents a particular animation-targeted CSS * property on a particular element. */ -class nsSMILCSSProperty : public nsISMILAttr { +class SMILCSSProperty : public nsISMILAttr { public: /** - * Constructs a new nsSMILCSSProperty. + * Constructs a new SMILCSSProperty. * @param aPropID The CSS property we're interested in animating. * @param aElement The element whose CSS property is being animated. * @param aBaseComputedStyle The ComputedStyle to use when getting the base @@ -38,14 +37,13 @@ class nsSMILCSSProperty : public nsISMILAttr { * called, an empty nsSMILValue initialized with * the SMILCSSValueType will be returned. */ - nsSMILCSSProperty(nsCSSPropertyID aPropID, mozilla::dom::Element* aElement, - mozilla::ComputedStyle* aBaseComputedStyle); + SMILCSSProperty(nsCSSPropertyID aPropID, dom::Element* aElement, + ComputedStyle* aBaseComputedStyle); // nsISMILAttr methods virtual nsresult ValueFromString( - const nsAString& aStr, - const mozilla::dom::SVGAnimationElement* aSrcElement, nsSMILValue& aValue, - bool& aPreventCachingOfSandwich) const override; + const nsAString& aStr, const dom::SVGAnimationElement* aSrcElement, + nsSMILValue& aValue, bool& aPreventCachingOfSandwich) const override; virtual nsSMILValue GetBaseValue() const override; virtual nsresult SetAnimValue(const nsSMILValue& aValue) override; virtual void ClearAnimValue() override; @@ -69,14 +67,16 @@ class nsSMILCSSProperty : public nsISMILAttr { // alive for my lifetime because a nsISMILAttr (like me) only lives as long // as the Compositing step, and DOM elements don't get a chance to die during // that time. - mozilla::dom::Element* mElement; + dom::Element* mElement; // The style to use when fetching base styles. // // As with mElement, since an nsISMILAttr only lives as long as the // compositing step and since ComposeAttribute holds an owning reference to // the base ComputedStyle, we can use a non-owning reference here. - mozilla::ComputedStyle* mBaseComputedStyle; + ComputedStyle* mBaseComputedStyle; }; +} // namespace mozilla + #endif // NS_SMILCSSPROPERTY_H_ diff --git a/dom/smil/SMILCSSValueType.cpp b/dom/smil/SMILCSSValueType.cpp index 56d6b3299208..eb650d707f77 100644 --- a/dom/smil/SMILCSSValueType.cpp +++ b/dom/smil/SMILCSSValueType.cpp @@ -10,7 +10,6 @@ #include "nsComputedDOMStyle.h" #include "nsString.h" -#include "nsSMILParserUtils.h" #include "nsSMILValue.h" #include "nsCSSProps.h" #include "nsCSSValue.h" @@ -21,6 +20,7 @@ #include "mozilla/StyleAnimationValue.h" // For AnimationValue #include "mozilla/ServoCSSParser.h" #include "mozilla/ServoStyleSet.h" +#include "mozilla/SMILParserUtils.h" #include "mozilla/dom/BaseKeyframeTypesBinding.h" // For CompositeOperation #include "mozilla/dom/Element.h" #include "nsDebug.h" diff --git a/dom/smil/SMILCompositor.cpp b/dom/smil/SMILCompositor.cpp index 21fc3ece51ef..0354dcf07f2e 100644 --- a/dom/smil/SMILCompositor.cpp +++ b/dom/smil/SMILCompositor.cpp @@ -9,7 +9,7 @@ #include "nsComputedDOMStyle.h" #include "nsCSSProps.h" #include "nsHashKeys.h" -#include "nsSMILCSSProperty.h" +#include "SMILCSSProperty.h" namespace mozilla { @@ -124,8 +124,8 @@ UniquePtr SMILCompositor::CreateSMILAttr( nsCSSPropertyID propID = GetCSSPropertyToAnimate(); if (propID != eCSSProperty_UNKNOWN) { - return MakeUnique(propID, mKey.mElement.get(), - aBaseComputedStyle); + return MakeUnique(propID, mKey.mElement.get(), + aBaseComputedStyle); } return mKey.mElement->GetAnimatedAttr(mKey.mAttributeNamespaceID, @@ -140,7 +140,7 @@ nsCSSPropertyID SMILCompositor::GetCSSPropertyToAnimate() const { nsCSSPropertyID propID = nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName)); - if (!nsSMILCSSProperty::IsPropertyAnimatable(propID)) { + if (!SMILCSSProperty::IsPropertyAnimatable(propID)) { return eCSSProperty_UNKNOWN; } diff --git a/dom/smil/nsSMILKeySpline.cpp b/dom/smil/SMILKeySpline.cpp similarity index 79% rename from dom/smil/nsSMILKeySpline.cpp rename to dom/smil/SMILKeySpline.cpp index 569dbafe6d30..44dc919e215e 100644 --- a/dom/smil/nsSMILKeySpline.cpp +++ b/dom/smil/SMILKeySpline.cpp @@ -4,19 +4,21 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsSMILKeySpline.h" +#include "SMILKeySpline.h" #include #include +namespace mozilla { + #define NEWTON_ITERATIONS 4 #define NEWTON_MIN_SLOPE 0.02 #define SUBDIVISION_PRECISION 0.0000001 #define SUBDIVISION_MAX_ITERATIONS 10 -const double nsSMILKeySpline::kSampleStepSize = +const double SMILKeySpline::kSampleStepSize = 1.0 / double(kSplineTableSize - 1); -void nsSMILKeySpline::Init(double aX1, double aY1, double aX2, double aY2) { +void SMILKeySpline::Init(double aX1, double aY1, double aX2, double aY2) { mX1 = aX1; mY1 = aY1; mX2 = aX2; @@ -25,36 +27,35 @@ void nsSMILKeySpline::Init(double aX1, double aY1, double aX2, double aY2) { if (mX1 != mY1 || mX2 != mY2) CalcSampleValues(); } -double nsSMILKeySpline::GetSplineValue(double aX) const { +double SMILKeySpline::GetSplineValue(double aX) const { if (mX1 == mY1 && mX2 == mY2) return aX; return CalcBezier(GetTForX(aX), mY1, mY2); } -void nsSMILKeySpline::GetSplineDerivativeValues(double aX, double& aDX, - double& aDY) const { +void SMILKeySpline::GetSplineDerivativeValues(double aX, double& aDX, + double& aDY) const { double t = GetTForX(aX); aDX = GetSlope(t, mX1, mX2); aDY = GetSlope(t, mY1, mY2); } -void nsSMILKeySpline::CalcSampleValues() { +void SMILKeySpline::CalcSampleValues() { for (uint32_t i = 0; i < kSplineTableSize; ++i) { mSampleValues[i] = CalcBezier(double(i) * kSampleStepSize, mX1, mX2); } } -/*static*/ double nsSMILKeySpline::CalcBezier(double aT, double aA1, - double aA2) { +/*static*/ double SMILKeySpline::CalcBezier(double aT, double aA1, double aA2) { // use Horner's scheme to evaluate the Bezier polynomial return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; } -/*static*/ double nsSMILKeySpline::GetSlope(double aT, double aA1, double aA2) { +/*static*/ double SMILKeySpline::GetSlope(double aT, double aA1, double aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); } -double nsSMILKeySpline::GetTForX(double aX) const { +double SMILKeySpline::GetTForX(double aX) const { // Early return when aX == 1.0 to avoid floating-point inaccuracies. if (aX == 1.0) { return 1.0; @@ -85,7 +86,7 @@ double nsSMILKeySpline::GetTForX(double aX) const { } } -double nsSMILKeySpline::NewtonRaphsonIterate(double aX, double aGuessT) const { +double SMILKeySpline::NewtonRaphsonIterate(double aX, double aGuessT) const { // Refine guess with Newton-Raphson iteration for (uint32_t i = 0; i < NEWTON_ITERATIONS; ++i) { // We're trying to find where f(t) = aX, @@ -101,7 +102,7 @@ double nsSMILKeySpline::NewtonRaphsonIterate(double aX, double aGuessT) const { return aGuessT; } -double nsSMILKeySpline::BinarySubdivide(double aX, double aA, double aB) const { +double SMILKeySpline::BinarySubdivide(double aX, double aA, double aB) const { double currentX; double currentT; uint32_t i = 0; @@ -120,3 +121,5 @@ double nsSMILKeySpline::BinarySubdivide(double aX, double aA, double aB) const { return currentT; } + +} // namespace mozilla diff --git a/dom/smil/nsSMILKeySpline.h b/dom/smil/SMILKeySpline.h similarity index 86% rename from dom/smil/nsSMILKeySpline.h rename to dom/smil/SMILKeySpline.h index 8d533c480743..6636927fbb17 100644 --- a/dom/smil/nsSMILKeySpline.h +++ b/dom/smil/SMILKeySpline.h @@ -10,12 +10,14 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/PodOperations.h" +namespace mozilla { + /** * Utility class to provide scaling defined in a keySplines element. */ -class nsSMILKeySpline { +class SMILKeySpline { public: - nsSMILKeySpline() : mX1(0), mY1(0), mX2(0), mY2(0) { + SMILKeySpline() : mX1(0), mY1(0), mX2(0), mY2(0) { /* caller must call Init later */\ } @@ -25,10 +27,10 @@ class nsSMILKeySpline { * aX1, etc. are the x1, y1, x2, y2 cubic Bezier control points as defined * by SMILANIM 3.2.3. They must each be in the range 0.0 <= x <= 1.0 */ - nsSMILKeySpline(double aX1, double aY1, double aX2, double aY2) - : mX1(0), mY1(0), mX2(0), mY2(0) { - Init(aX1, aY1, aX2, aY2); - } + SMILKeySpline(double aX1, double aY1, double aX2, double aY2) + : mX1(0), mY1(0), mX2(0), mY2(0) { + Init(aX1, aY1, aX2, aY2); + } double X1() const { return mX1; } double Y1() const { return mY1; } @@ -47,14 +49,14 @@ class nsSMILKeySpline { void GetSplineDerivativeValues(double aX, double& aDX, double& aDY) const; - bool operator==(const nsSMILKeySpline& aOther) const { + bool operator==(const SMILKeySpline& aOther) const { return mX1 == aOther.mX1 && mY1 == aOther.mY1 && mX2 == aOther.mX2 && mY2 == aOther.mY2; } - bool operator!=(const nsSMILKeySpline& aOther) const { + bool operator!=(const SMILKeySpline& aOther) const { return !(*this == aOther); } - int32_t Compare(const nsSMILKeySpline& aRhs) const { + int32_t Compare(const SMILKeySpline& aRhs) const { if (mX1 != aRhs.mX1) return mX1 < aRhs.mX1 ? -1 : 1; if (mY1 != aRhs.mY1) return mY1 < aRhs.mY1 ? -1 : 1; if (mX2 != aRhs.mX2) return mX2 < aRhs.mX2 ? -1 : 1; @@ -100,4 +102,6 @@ class nsSMILKeySpline { static const double kSampleStepSize; }; +} // namespace mozilla + #endif // NS_SMILKEYSPLINE_H_ diff --git a/dom/smil/nsSMILParserUtils.cpp b/dom/smil/SMILParserUtils.cpp similarity index 92% rename from dom/smil/nsSMILParserUtils.cpp rename to dom/smil/SMILParserUtils.cpp index ff8dd2ec1242..cafd57251844 100644 --- a/dom/smil/nsSMILParserUtils.cpp +++ b/dom/smil/SMILParserUtils.cpp @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsSMILParserUtils.h" +#include "SMILParserUtils.h" #include "mozilla/SVGContentUtils.h" #include "mozilla/TextUtils.h" -#include "nsSMILKeySpline.h" +#include "SMILKeySpline.h" #include "nsISMILAttr.h" #include "nsSMILValue.h" #include "nsSMILTimeValue.h" @@ -17,13 +17,14 @@ #include "nsContentUtils.h" #include "nsCharSeparatedTokenizer.h" -using namespace mozilla; using namespace mozilla::dom; //------------------------------------------------------------------------------ // Helper functions and Constants namespace { +using namespace mozilla; + const uint32_t MSEC_PER_SEC = 1000; const uint32_t MSEC_PER_MIN = 1000 * 60; const uint32_t MSEC_PER_HOUR = 1000 * 60 * 60; @@ -396,10 +397,12 @@ bool ParseElementBaseTimeValueSpec(const nsAString& aSpec, } // namespace +namespace mozilla { + //------------------------------------------------------------------------------ // Implementation -const nsDependentSubstring nsSMILParserUtils::TrimWhitespace( +const nsDependentSubstring SMILParserUtils::TrimWhitespace( const nsAString& aString) { nsAString::const_iterator start, end; @@ -426,8 +429,8 @@ const nsDependentSubstring nsSMILParserUtils::TrimWhitespace( return Substring(start, end); } -bool nsSMILParserUtils::ParseKeySplines( - const nsAString& aSpec, FallibleTArray& aKeySplines) { +bool SMILParserUtils::ParseKeySplines( + const nsAString& aSpec, FallibleTArray& aKeySplines) { nsCharSeparatedTokenizerTemplate controlPointTokenizer(aSpec, ';'); while (controlPointTokenizer.hasMoreTokens()) { @@ -445,7 +448,7 @@ bool nsSMILParserUtils::ParseKeySplines( } if (tokenizer.hasMoreTokens() || tokenizer.separatorAfterCurrentToken() || !aKeySplines.AppendElement( - nsSMILKeySpline(values[0], values[1], values[2], values[3]), + SMILKeySpline(values[0], values[1], values[2], values[3]), fallible)) { return false; } @@ -454,7 +457,7 @@ bool nsSMILParserUtils::ParseKeySplines( return !aKeySplines.IsEmpty(); } -bool nsSMILParserUtils::ParseSemicolonDelimitedProgressList( +bool SMILParserUtils::ParseSemicolonDelimitedProgressList( const nsAString& aSpec, bool aNonDecreasing, FallibleTArray& aArray) { nsCharSeparatedTokenizerTemplate tokenizer( @@ -484,7 +487,7 @@ bool nsSMILParserUtils::ParseSemicolonDelimitedProgressList( // Helper class for ParseValues class MOZ_STACK_CLASS SMILValueParser - : public nsSMILParserUtils::GenericValueParser { + : public SMILParserUtils::GenericValueParser { public: SMILValueParser(const SVGAnimationElement* aSrcElement, const nsISMILAttr* aSMILAttr, @@ -518,11 +521,11 @@ class MOZ_STACK_CLASS SMILValueParser bool* mPreventCachingOfSandwich; }; -bool nsSMILParserUtils::ParseValues(const nsAString& aSpec, - const SVGAnimationElement* aSrcElement, - const nsISMILAttr& aAttribute, - FallibleTArray& aValuesArray, - bool& aPreventCachingOfSandwich) { +bool SMILParserUtils::ParseValues(const nsAString& aSpec, + const SVGAnimationElement* aSrcElement, + const nsISMILAttr& aAttribute, + FallibleTArray& aValuesArray, + bool& aPreventCachingOfSandwich) { // Assume all results can be cached, until we find one that can't. aPreventCachingOfSandwich = false; SMILValueParser valueParser(aSrcElement, &aAttribute, &aValuesArray, @@ -530,8 +533,8 @@ bool nsSMILParserUtils::ParseValues(const nsAString& aSpec, return ParseValuesGeneric(aSpec, valueParser); } -bool nsSMILParserUtils::ParseValuesGeneric(const nsAString& aSpec, - GenericValueParser& aParser) { +bool SMILParserUtils::ParseValuesGeneric(const nsAString& aSpec, + GenericValueParser& aParser) { nsCharSeparatedTokenizerTemplate tokenizer( aSpec, ';'); if (!tokenizer.hasMoreTokens()) { // Empty list @@ -547,9 +550,9 @@ bool nsSMILParserUtils::ParseValuesGeneric(const nsAString& aSpec, return true; } -bool nsSMILParserUtils::ParseRepeatCount(const nsAString& aSpec, - nsSMILRepeatCount& aResult) { - const nsAString& spec = nsSMILParserUtils::TrimWhitespace(aSpec); +bool SMILParserUtils::ParseRepeatCount(const nsAString& aSpec, + nsSMILRepeatCount& aResult) { + const nsAString& spec = SMILParserUtils::TrimWhitespace(aSpec); if (spec.EqualsLiteral("indefinite")) { aResult.SetIndefinite(); @@ -564,7 +567,7 @@ bool nsSMILParserUtils::ParseRepeatCount(const nsAString& aSpec, return true; } -bool nsSMILParserUtils::ParseTimeValueSpecParams( +bool SMILParserUtils::ParseTimeValueSpecParams( const nsAString& aSpec, nsSMILTimeValueSpecParams& aResult) { const nsAString& spec = TrimWhitespace(aSpec); @@ -594,15 +597,15 @@ bool nsSMILParserUtils::ParseTimeValueSpecParams( return ParseElementBaseTimeValueSpec(spec, aResult); } -bool nsSMILParserUtils::ParseClockValue(const nsAString& aSpec, - nsSMILTimeValue* aResult) { +bool SMILParserUtils::ParseClockValue(const nsAString& aSpec, + nsSMILTimeValue* aResult) { RangedPtr iter(SVGContentUtils::GetStartRangedPtr(aSpec)); RangedPtr end(SVGContentUtils::GetEndRangedPtr(aSpec)); return ::ParseClockValue(iter, end, aResult) && iter == end; } -int32_t nsSMILParserUtils::CheckForNegativeNumber(const nsAString& aStr) { +int32_t SMILParserUtils::CheckForNegativeNumber(const nsAString& aStr) { int32_t absValLocation = -1; RangedPtr start(SVGContentUtils::GetStartRangedPtr(aStr)); @@ -624,3 +627,5 @@ int32_t nsSMILParserUtils::CheckForNegativeNumber(const nsAString& aStr) { } return absValLocation; } + +} // namespace mozilla diff --git a/dom/smil/nsSMILParserUtils.h b/dom/smil/SMILParserUtils.h similarity index 96% rename from dom/smil/nsSMILParserUtils.h rename to dom/smil/SMILParserUtils.h index d269e3e5787f..4178e7755532 100644 --- a/dom/smil/nsSMILParserUtils.h +++ b/dom/smil/SMILParserUtils.h @@ -11,7 +11,7 @@ #include "nsStringFwd.h" class nsISMILAttr; -class nsSMILKeySpline; +class SMILKeySpline; class nsSMILTimeValue; class nsSMILValue; class nsSMILRepeatCount; @@ -21,14 +21,13 @@ namespace mozilla { namespace dom { class SVGAnimationElement; } // namespace dom -} // namespace mozilla /** * Common parsing utilities for the SMIL module. There is little re-use here; it * simply serves to simplify other classes by moving parsing outside and to aid * unit testing. */ -class nsSMILParserUtils { +class SMILParserUtils { public: // Abstract helper-class for assisting in parsing |values| attribute class MOZ_STACK_CLASS GenericValueParser { @@ -39,7 +38,7 @@ class nsSMILParserUtils { static const nsDependentSubstring TrimWhitespace(const nsAString& aString); static bool ParseKeySplines(const nsAString& aSpec, - FallibleTArray& aKeySplines); + FallibleTArray& aKeySplines); // Used for parsing the |keyTimes| and |keyPoints| attributes. static bool ParseSemicolonDelimitedProgressList( @@ -84,4 +83,6 @@ class nsSMILParserUtils { static int32_t CheckForNegativeNumber(const nsAString& aStr); }; +} // namespace mozilla + #endif // NS_SMILPARSERUTILS_H_ diff --git a/dom/smil/SMILTimedElement.cpp b/dom/smil/SMILTimedElement.cpp index a528c60916f2..e3c80e5f0226 100644 --- a/dom/smil/SMILTimedElement.cpp +++ b/dom/smil/SMILTimedElement.cpp @@ -11,6 +11,7 @@ #include "mozilla/DebugOnly.h" #include "mozilla/EventDispatcher.h" #include "mozilla/SMILAnimationFunction.h" +#include "mozilla/SMILParserUtils.h" #include "mozilla/SMILTimeContainer.h" #include "mozilla/TaskCategory.h" #include "mozilla/dom/SVGAnimationElement.h" @@ -18,7 +19,6 @@ #include "nsSMILTimeValue.h" #include "nsSMILTimeValueSpec.h" #include "nsSMILInstanceTime.h" -#include "nsSMILParserUtils.h" #include "nsGkAtoms.h" #include "nsReadableUtils.h" #include "nsMathUtils.h" @@ -849,14 +849,14 @@ nsresult SMILTimedElement::SetSimpleDuration(const nsAString& aDurSpec) { AutoIntervalUpdater updater(*this); nsSMILTimeValue duration; - const nsAString& dur = nsSMILParserUtils::TrimWhitespace(aDurSpec); + const nsAString& dur = SMILParserUtils::TrimWhitespace(aDurSpec); // SVG-specific: "For SVG's animation elements, if "media" is specified, the // attribute will be ignored." (SVG 1.1, section 19.2.6) if (dur.EqualsLiteral("media") || dur.EqualsLiteral("indefinite")) { duration.SetIndefinite(); } else { - if (!nsSMILParserUtils::ParseClockValue(dur, &duration) || + if (!SMILParserUtils::ParseClockValue(dur, &duration) || duration.GetMillis() == 0L) { mSimpleDur.SetIndefinite(); return NS_ERROR_FAILURE; @@ -881,12 +881,12 @@ nsresult SMILTimedElement::SetMin(const nsAString& aMinSpec) { AutoIntervalUpdater updater(*this); nsSMILTimeValue duration; - const nsAString& min = nsSMILParserUtils::TrimWhitespace(aMinSpec); + const nsAString& min = SMILParserUtils::TrimWhitespace(aMinSpec); if (min.EqualsLiteral("media")) { duration.SetMillis(0L); } else { - if (!nsSMILParserUtils::ParseClockValue(min, &duration)) { + if (!SMILParserUtils::ParseClockValue(min, &duration)) { mMin.SetMillis(0L); return NS_ERROR_FAILURE; } @@ -909,12 +909,12 @@ nsresult SMILTimedElement::SetMax(const nsAString& aMaxSpec) { AutoIntervalUpdater updater(*this); nsSMILTimeValue duration; - const nsAString& max = nsSMILParserUtils::TrimWhitespace(aMaxSpec); + const nsAString& max = SMILParserUtils::TrimWhitespace(aMaxSpec); if (max.EqualsLiteral("media") || max.EqualsLiteral("indefinite")) { duration.SetIndefinite(); } else { - if (!nsSMILParserUtils::ParseClockValue(max, &duration) || + if (!SMILParserUtils::ParseClockValue(max, &duration) || duration.GetMillis() == 0L) { mMax.SetIndefinite(); return NS_ERROR_FAILURE; @@ -952,7 +952,7 @@ nsresult SMILTimedElement::SetRepeatCount(const nsAString& aRepeatCountSpec) { nsSMILRepeatCount newRepeatCount; - if (nsSMILParserUtils::ParseRepeatCount(aRepeatCountSpec, newRepeatCount)) { + if (SMILParserUtils::ParseRepeatCount(aRepeatCountSpec, newRepeatCount)) { mRepeatCount = newRepeatCount; return NS_OK; } @@ -971,13 +971,12 @@ nsresult SMILTimedElement::SetRepeatDur(const nsAString& aRepeatDurSpec) { nsSMILTimeValue duration; - const nsAString& repeatDur = - nsSMILParserUtils::TrimWhitespace(aRepeatDurSpec); + const nsAString& repeatDur = SMILParserUtils::TrimWhitespace(aRepeatDurSpec); if (repeatDur.EqualsLiteral("indefinite")) { duration.SetIndefinite(); } else { - if (!nsSMILParserUtils::ParseClockValue(repeatDur, &duration)) { + if (!SMILParserUtils::ParseClockValue(repeatDur, &duration)) { mRepeatDur.SetUnresolved(); return NS_ERROR_FAILURE; } diff --git a/dom/smil/moz.build b/dom/smil/moz.build index 91d2efbef597..2b18b51f04b2 100644 --- a/dom/smil/moz.build +++ b/dom/smil/moz.build @@ -11,10 +11,8 @@ MOCHITEST_MANIFESTS += ['test/mochitest.ini'] EXPORTS += [ 'nsISMILAttr.h', - 'nsSMILCSSProperty.h', 'nsSMILInstanceTime.h', 'nsSMILInterval.h', - 'nsSMILKeySpline.h', 'nsSMILRepeatCount.h', 'nsSMILTimeValue.h', 'nsSMILTimeValueSpec.h', @@ -30,7 +28,9 @@ EXPORTS.mozilla += [ 'SMILAnimationController.h', 'SMILAnimationFunction.h', 'SMILCompositorTable.h', + 'SMILKeySpline.h', 'SMILMilestone.h', + 'SMILParserUtils.h', 'SMILSetAnimationFunction.h', 'SMILTargetIdentifier.h', 'SMILTimeContainer.h', @@ -42,11 +42,8 @@ EXPORTS.mozilla.dom += [ ] UNIFIED_SOURCES += [ - 'nsSMILCSSProperty.cpp', 'nsSMILInstanceTime.cpp', 'nsSMILInterval.cpp', - 'nsSMILKeySpline.cpp', - 'nsSMILParserUtils.cpp', 'nsSMILRepeatCount.cpp', 'nsSMILTimeValue.cpp', 'nsSMILTimeValueSpec.cpp', @@ -55,11 +52,14 @@ UNIFIED_SOURCES += [ 'SMILAnimationFunction.cpp', 'SMILBoolType.cpp', 'SMILCompositor.cpp', + 'SMILCSSProperty.cpp', 'SMILCSSValueType.cpp', 'SMILEnumType.cpp', 'SMILFloatType.cpp', 'SMILIntegerType.cpp', + 'SMILKeySpline.cpp', 'SMILNullType.cpp', + 'SMILParserUtils.cpp', 'SMILSetAnimationFunction.cpp', 'SMILStringType.cpp', 'SMILTimeContainer.cpp', diff --git a/dom/smil/nsSMILTimeValueSpec.cpp b/dom/smil/nsSMILTimeValueSpec.cpp index 05d940087ddf..6d4e971da31c 100644 --- a/dom/smil/nsSMILTimeValueSpec.cpp +++ b/dom/smil/nsSMILTimeValueSpec.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/EventListenerManager.h" +#include "mozilla/SMILParserUtils.h" #include "mozilla/SMILTimeContainer.h" #include "mozilla/SMILTimedElement.h" #include "mozilla/dom/Event.h" @@ -14,7 +15,6 @@ #include "nsSMILInterval.h" #include "nsSMILTimeValue.h" #include "nsSMILInstanceTime.h" -#include "nsSMILParserUtils.h" #include "nsString.h" #include @@ -53,7 +53,7 @@ nsresult nsSMILTimeValueSpec::SetSpec(const nsAString& aStringSpec, Element& aContextElement) { nsSMILTimeValueSpecParams params; - if (!nsSMILParserUtils::ParseTimeValueSpecParams(aStringSpec, params)) + if (!SMILParserUtils::ParseTimeValueSpecParams(aStringSpec, params)) return NS_ERROR_FAILURE; mParams = params; diff --git a/dom/smil/test/test_smilKeySplines.xhtml b/dom/smil/test/test_smilKeySplines.xhtml index 7a6a1aaa0d3d..89b63ffc4519 100644 --- a/dom/smil/test/test_smilKeySplines.xhtml +++ b/dom/smil/test/test_smilKeySplines.xhtml @@ -137,7 +137,7 @@ function testSimpleD(anim) { checkSample(4, 20); } -// Bug 501569 -- nsSMILKeySpline(1, 0, 0, 1) miscalculates values just under 0.5 +// Bug 501569 -- SMILKeySpline(1, 0, 0, 1) miscalculates values just under 0.5 function testSimpleE(anim) { anim.setAttribute('dur','10s'); anim.setAttribute('values', '0; 10'); diff --git a/dom/svg/SVGMotionSMILAnimationFunction.cpp b/dom/svg/SVGMotionSMILAnimationFunction.cpp index 142a81334efc..ede8b36fe254 100644 --- a/dom/svg/SVGMotionSMILAnimationFunction.cpp +++ b/dom/svg/SVGMotionSMILAnimationFunction.cpp @@ -5,13 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "SVGMotionSMILAnimationFunction.h" + #include "mozilla/dom/SVGAnimationElement.h" #include "mozilla/dom/SVGPathElement.h" // for nsSVGPathList #include "mozilla/dom/SVGMPathElement.h" #include "mozilla/gfx/2D.h" +#include "mozilla/SMILParserUtils.h" #include "nsAttrValue.h" #include "nsAttrValueInlines.h" -#include "nsSMILParserUtils.h" #include "SVGAngle.h" #include "SVGPathDataParser.h" #include "SVGMotionSMILType.h" @@ -154,7 +155,7 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromBasicAttrs( const nsAString& valuesStr = GetAttr(nsGkAtoms::values)->GetStringValue(); SVGMotionSMILPathUtils::MotionValueParser parser(&pathGenerator, &mPathVertices); - success = nsSMILParserUtils::ParseValuesGeneric(valuesStr, parser); + success = SMILParserUtils::ParseValuesGeneric(valuesStr, parser); } else if (HasAttr(nsGkAtoms::to) || HasAttr(nsGkAtoms::by)) { // Apply 'from' value (or a dummy 0,0 'from' value) if (HasAttr(nsGkAtoms::from)) { @@ -362,8 +363,8 @@ nsresult SVGMotionSMILAnimationFunction::SetKeyPoints( mHasChanged = true; - if (!nsSMILParserUtils::ParseSemicolonDelimitedProgressList(aKeyPoints, false, - mKeyPoints)) { + if (!SMILParserUtils::ParseSemicolonDelimitedProgressList(aKeyPoints, false, + mKeyPoints)) { mKeyPoints.Clear(); return NS_ERROR_FAILURE; } diff --git a/dom/svg/SVGMotionSMILPathUtils.h b/dom/svg/SVGMotionSMILPathUtils.h index d7931d5250bd..7591f44ea6e9 100644 --- a/dom/svg/SVGMotionSMILPathUtils.h +++ b/dom/svg/SVGMotionSMILPathUtils.h @@ -11,11 +11,11 @@ #define MOZILLA_SVGMOTIONSMILPATHUTILS_H_ #include "mozilla/Attributes.h" -#include "gfxPlatform.h" -#include "mozilla/gfx/2D.h" #include "mozilla/RefPtr.h" +#include "mozilla/SMILParserUtils.h" +#include "mozilla/gfx/2D.h" +#include "gfxPlatform.h" #include "nsDebug.h" -#include "nsSMILParserUtils.h" #include "nsStringFwd.h" #include "nsTArray.h" @@ -77,7 +77,7 @@ class SVGMotionSMILPathUtils { // Class to assist in passing each subcomponent of a |values| attribute to // a PathGenerator, for generating a corresponding Path. class MOZ_STACK_CLASS MotionValueParser - : public nsSMILParserUtils::GenericValueParser { + : public SMILParserUtils::GenericValueParser { public: MotionValueParser(PathGenerator* aPathGenerator, FallibleTArray* aPointDistances) @@ -88,7 +88,7 @@ class SVGMotionSMILPathUtils { "expecting point distances array to start empty"); } - // nsSMILParserUtils::GenericValueParser interface + // SMILParserUtils::GenericValueParser interface virtual bool Parse(const nsAString& aValueStr) override; protected: diff --git a/layout/generic/ScrollAnimationBezierPhysics.cpp b/layout/generic/ScrollAnimationBezierPhysics.cpp index a313f324da14..474929e22de1 100644 --- a/layout/generic/ScrollAnimationBezierPhysics.cpp +++ b/layout/generic/ScrollAnimationBezierPhysics.cpp @@ -90,7 +90,7 @@ void ScrollAnimationBezierPhysics::InitializeHistory(const TimeStamp& aTime) { } void ScrollAnimationBezierPhysics::InitTimingFunction( - nsSMILKeySpline& aTimingFunction, nscoord aCurrentPos, + SMILKeySpline& aTimingFunction, nscoord aCurrentPos, nscoord aCurrentVelocity, nscoord aDestination) { if (aDestination == aCurrentPos || gfxPrefs::SmoothScrollCurrentVelocityWeighting() == 0) { @@ -137,8 +137,8 @@ nsSize ScrollAnimationBezierPhysics::VelocityAt(const TimeStamp& aTime) { } nscoord ScrollAnimationBezierPhysics::VelocityComponent( - double aTimeProgress, const nsSMILKeySpline& aTimingFunction, - nscoord aStart, nscoord aDestination) const { + double aTimeProgress, const SMILKeySpline& aTimingFunction, nscoord aStart, + nscoord aDestination) const { double dt, dxy; aTimingFunction.GetSplineDerivativeValues(aTimeProgress, dt, dxy); if (dt == 0) return dxy >= 0 ? nscoord_MAX : nscoord_MIN; diff --git a/layout/generic/ScrollAnimationBezierPhysics.h b/layout/generic/ScrollAnimationBezierPhysics.h index 84e5e674220e..c3bf36ee71f0 100644 --- a/layout/generic/ScrollAnimationBezierPhysics.h +++ b/layout/generic/ScrollAnimationBezierPhysics.h @@ -8,7 +8,7 @@ #define mozilla_layout_ScrollAnimationBezierPhysics_h_ #include "ScrollAnimationPhysics.h" -#include "nsSMILKeySpline.h" +#include "mozilla/SMILKeySpline.h" namespace mozilla { @@ -53,7 +53,7 @@ class ScrollAnimationBezierPhysics final : public ScrollAnimationPhysics { } nscoord VelocityComponent(double aTimeProgress, - const nsSMILKeySpline& aTimingFunction, + const SMILKeySpline& aTimingFunction, nscoord aStart, nscoord aDestination) const; // Calculate duration, possibly dynamically according to events rate and @@ -63,7 +63,7 @@ class ScrollAnimationBezierPhysics final : public ScrollAnimationPhysics { // Initializes the timing function in such a way that the current velocity is // preserved. - void InitTimingFunction(nsSMILKeySpline& aTimingFunction, nscoord aCurrentPos, + void InitTimingFunction(SMILKeySpline& aTimingFunction, nscoord aCurrentPos, nscoord aCurrentVelocity, nscoord aDestination); // Initialize event history. @@ -84,8 +84,8 @@ class ScrollAnimationBezierPhysics final : public ScrollAnimationPhysics { nsPoint mStartPos; nsPoint mDestination; TimeDuration mDuration; - nsSMILKeySpline mTimingFunctionX; - nsSMILKeySpline mTimingFunctionY; + SMILKeySpline mTimingFunctionX; + SMILKeySpline mTimingFunctionY; bool mIsFirstIteration; }; diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 24c72eff57ca..596a81ce5a28 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -46,7 +46,6 @@ #include "mozilla/MathAlgorithms.h" #include "mozilla/Telemetry.h" #include "FrameLayerBuilder.h" -#include "nsSMILKeySpline.h" #include "nsSubDocumentFrame.h" #include "nsSVGOuterSVGFrame.h" #include "nsIObjectLoadingContent.h" diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 6b7ee8a15817..16a15ae1216c 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -394,7 +394,7 @@ static TimingFunction ToTimingFunction( } if (aCTF->HasSpline()) { - const nsSMILKeySpline* spline = aCTF->GetFunction(); + const SMILKeySpline* spline = aCTF->GetFunction(); return TimingFunction(CubicBezierFunction(spline->X1(), spline->Y1(), spline->X2(), spline->Y2())); }