1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/nsSMILParserUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NS_SMILPARSERUTILS_H_ 1.10 +#define NS_SMILPARSERUTILS_H_ 1.11 + 1.12 +#include "nsTArray.h" 1.13 +#include "nsStringFwd.h" 1.14 + 1.15 +class nsISMILAttr; 1.16 +class nsSMILKeySpline; 1.17 +class nsSMILTimeValue; 1.18 +class nsSMILValue; 1.19 +class nsSMILRepeatCount; 1.20 +class nsSMILTimeValueSpecParams; 1.21 + 1.22 +namespace mozilla { 1.23 +namespace dom { 1.24 +class SVGAnimationElement; 1.25 +} 1.26 +} 1.27 + 1.28 +/** 1.29 + * Common parsing utilities for the SMIL module. There is little re-use here; it 1.30 + * simply serves to simplify other classes by moving parsing outside and to aid 1.31 + * unit testing. 1.32 + */ 1.33 +class nsSMILParserUtils 1.34 +{ 1.35 +public: 1.36 + // Abstract helper-class for assisting in parsing |values| attribute 1.37 + class MOZ_STACK_CLASS GenericValueParser { 1.38 + public: 1.39 + virtual bool Parse(const nsAString& aValueStr) = 0; 1.40 + }; 1.41 + 1.42 + static const nsDependentSubstring TrimWhitespace(const nsAString& aString); 1.43 + 1.44 + static bool ParseKeySplines(const nsAString& aSpec, 1.45 + FallibleTArray<nsSMILKeySpline>& aKeySplines); 1.46 + 1.47 + // Used for parsing the |keyTimes| and |keyPoints| attributes. 1.48 + static bool ParseSemicolonDelimitedProgressList(const nsAString& aSpec, 1.49 + bool aNonDecreasing, 1.50 + FallibleTArray<double>& aArray); 1.51 + 1.52 + static bool ParseValues(const nsAString& aSpec, 1.53 + const mozilla::dom::SVGAnimationElement* aSrcElement, 1.54 + const nsISMILAttr& aAttribute, 1.55 + FallibleTArray<nsSMILValue>& aValuesArray, 1.56 + bool& aPreventCachingOfSandwich); 1.57 + 1.58 + // Generic method that will run some code on each sub-section of an animation 1.59 + // element's "values" list. 1.60 + static bool ParseValuesGeneric(const nsAString& aSpec, 1.61 + GenericValueParser& aParser); 1.62 + 1.63 + static bool ParseRepeatCount(const nsAString& aSpec, 1.64 + nsSMILRepeatCount& aResult); 1.65 + 1.66 + static bool ParseTimeValueSpecParams(const nsAString& aSpec, 1.67 + nsSMILTimeValueSpecParams& aResult); 1.68 + 1.69 + /* 1.70 + * Parses a clock value as defined in the SMIL Animation specification. 1.71 + * If parsing succeeds the returned value will be a non-negative, definite 1.72 + * time value i.e. IsDefinite will return true. 1.73 + * 1.74 + * @param aSpec The string containing a clock value, e.g. "10s" 1.75 + * @param aResult The parsed result. [OUT] 1.76 + * @return true if parsing succeeded, otherwise false. 1.77 + */ 1.78 + static bool ParseClockValue(const nsAString& aSpec, 1.79 + nsSMILTimeValue* aResult); 1.80 + 1.81 + /* 1.82 + * This method checks whether the given string looks like a negative number. 1.83 + * Specifically, it checks whether the string looks matches the pattern 1.84 + * "[whitespace]*-[numeral].*" If the string matches this pattern, this 1.85 + * method returns the index of the first character after the '-' sign 1.86 + * (i.e. the index of the absolute value). If not, this method returns -1. 1.87 + */ 1.88 + static int32_t CheckForNegativeNumber(const nsAString& aStr); 1.89 +}; 1.90 + 1.91 +#endif // NS_SMILPARSERUTILS_H_