SMILParserUtils.h (3372B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_SMIL_SMILPARSERUTILS_H_ 8 #define DOM_SMIL_SMILPARSERUTILS_H_ 9 10 #include "SMILTimeValue.h" 11 #include "nsStringFwd.h" 12 #include "nsTArray.h" 13 14 namespace mozilla { 15 16 class SMILAttr; 17 class SMILKeySpline; 18 class SMILRepeatCount; 19 class SMILTimeValueSpecParams; 20 class SMILValue; 21 22 namespace dom { 23 class SVGAnimationElement; 24 } // namespace dom 25 26 /** 27 * Common parsing utilities for the SMIL module. There is little re-use here; it 28 * simply serves to simplify other classes by moving parsing outside and to aid 29 * unit testing. 30 */ 31 class SMILParserUtils { 32 public: 33 // Abstract helper-class for assisting in parsing |values| attribute 34 class MOZ_STACK_CLASS GenericValueParser { 35 public: 36 virtual bool Parse(const nsAString& aValueStr) = 0; 37 }; 38 39 static const nsDependentSubstring TrimWhitespace(const nsAString& aString); 40 41 static bool ParseKeySplines(const nsAString& aSpec, 42 FallibleTArray<SMILKeySpline>& aKeySplines); 43 44 // Used for parsing the |keyTimes| and |keyPoints| attributes. 45 static bool ParseSemicolonDelimitedProgressList( 46 const nsAString& aSpec, bool aNonDecreasing, 47 FallibleTArray<double>& aArray); 48 49 static bool ParseValues(const nsAString& aSpec, 50 const mozilla::dom::SVGAnimationElement* aSrcElement, 51 const SMILAttr& aAttribute, 52 FallibleTArray<SMILValue>& aValuesArray, 53 bool& aPreventCachingOfSandwich); 54 55 // Generic method that will run some code on each sub-section of an animation 56 // element's "values" list. 57 static bool ParseValuesGeneric(const nsAString& aSpec, 58 GenericValueParser& aParser); 59 60 static bool ParseRepeatCount(const nsAString& aSpec, 61 SMILRepeatCount& aResult); 62 63 static bool ParseTimeValueSpecParams(const nsAString& aSpec, 64 SMILTimeValueSpecParams& aResult); 65 66 /* 67 * Parses a clock value as defined in the SMIL Animation specification. 68 * If parsing succeeds the returned value will be a non-negative, definite 69 * time value i.e. IsDefinite will return true. 70 * 71 * @param aSpec The string containing a clock value, e.g. "10s" 72 * @param aResult The parsed result. [OUT] 73 * @return true if parsing succeeded, otherwise false. 74 */ 75 static bool ParseClockValue(const nsAString& aSpec, 76 SMILTimeValue::Rounding aRounding, 77 SMILTimeValue* aResult); 78 79 /* 80 * This method checks whether the given string looks like a negative number. 81 * Specifically, it checks whether the string looks matches the pattern 82 * "[whitespace]*-[numeral].*" If the string matches this pattern, this 83 * method returns the index of the first character after the '-' sign 84 * (i.e. the index of the absolute value). If not, this method returns -1. 85 */ 86 static int32_t CheckForNegativeNumber(const nsAString& aStr); 87 }; 88 89 } // namespace mozilla 90 91 #endif // DOM_SMIL_SMILPARSERUTILS_H_