michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NS_SMILPARSERUTILS_H_ michael@0: #define NS_SMILPARSERUTILS_H_ michael@0: michael@0: #include "nsTArray.h" michael@0: #include "nsStringFwd.h" michael@0: michael@0: class nsISMILAttr; michael@0: class nsSMILKeySpline; michael@0: class nsSMILTimeValue; michael@0: class nsSMILValue; michael@0: class nsSMILRepeatCount; michael@0: class nsSMILTimeValueSpecParams; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class SVGAnimationElement; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Common parsing utilities for the SMIL module. There is little re-use here; it michael@0: * simply serves to simplify other classes by moving parsing outside and to aid michael@0: * unit testing. michael@0: */ michael@0: class nsSMILParserUtils michael@0: { michael@0: public: michael@0: // Abstract helper-class for assisting in parsing |values| attribute michael@0: class MOZ_STACK_CLASS GenericValueParser { michael@0: public: michael@0: virtual bool Parse(const nsAString& aValueStr) = 0; michael@0: }; michael@0: michael@0: static const nsDependentSubstring TrimWhitespace(const nsAString& aString); michael@0: michael@0: static bool ParseKeySplines(const nsAString& aSpec, michael@0: FallibleTArray& aKeySplines); michael@0: michael@0: // Used for parsing the |keyTimes| and |keyPoints| attributes. michael@0: static bool ParseSemicolonDelimitedProgressList(const nsAString& aSpec, michael@0: bool aNonDecreasing, michael@0: FallibleTArray& aArray); michael@0: michael@0: static bool ParseValues(const nsAString& aSpec, michael@0: const mozilla::dom::SVGAnimationElement* aSrcElement, michael@0: const nsISMILAttr& aAttribute, michael@0: FallibleTArray& aValuesArray, michael@0: bool& aPreventCachingOfSandwich); michael@0: michael@0: // Generic method that will run some code on each sub-section of an animation michael@0: // element's "values" list. michael@0: static bool ParseValuesGeneric(const nsAString& aSpec, michael@0: GenericValueParser& aParser); michael@0: michael@0: static bool ParseRepeatCount(const nsAString& aSpec, michael@0: nsSMILRepeatCount& aResult); michael@0: michael@0: static bool ParseTimeValueSpecParams(const nsAString& aSpec, michael@0: nsSMILTimeValueSpecParams& aResult); michael@0: michael@0: /* michael@0: * Parses a clock value as defined in the SMIL Animation specification. michael@0: * If parsing succeeds the returned value will be a non-negative, definite michael@0: * time value i.e. IsDefinite will return true. michael@0: * michael@0: * @param aSpec The string containing a clock value, e.g. "10s" michael@0: * @param aResult The parsed result. [OUT] michael@0: * @return true if parsing succeeded, otherwise false. michael@0: */ michael@0: static bool ParseClockValue(const nsAString& aSpec, michael@0: nsSMILTimeValue* aResult); michael@0: michael@0: /* michael@0: * This method checks whether the given string looks like a negative number. michael@0: * Specifically, it checks whether the string looks matches the pattern michael@0: * "[whitespace]*-[numeral].*" If the string matches this pattern, this michael@0: * method returns the index of the first character after the '-' sign michael@0: * (i.e. the index of the absolute value). If not, this method returns -1. michael@0: */ michael@0: static int32_t CheckForNegativeNumber(const nsAString& aStr); michael@0: }; michael@0: michael@0: #endif // NS_SMILPARSERUTILS_H_