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/. */
7 #ifndef DOM_SMIL_SMILPARSERUTILS_H_
8 #define DOM_SMIL_SMILPARSERUTILS_H_
11 #include "nsStringFwd.h"
17 class SMILRepeatCount
;
19 class SMILTimeValueSpecParams
;
23 class SVGAnimationElement
;
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
31 class SMILParserUtils
{
33 // Abstract helper-class for assisting in parsing |values| attribute
34 class MOZ_STACK_CLASS GenericValueParser
{
36 virtual bool Parse(const nsAString
& aValueStr
) = 0;
39 static const nsDependentSubstring
TrimWhitespace(const nsAString
& aString
);
41 static bool ParseKeySplines(const nsAString
& aSpec
,
42 FallibleTArray
<SMILKeySpline
>& aKeySplines
);
44 // Used for parsing the |keyTimes| and |keyPoints| attributes.
45 static bool ParseSemicolonDelimitedProgressList(
46 const nsAString
& aSpec
, bool aNonDecreasing
,
47 FallibleTArray
<double>& aArray
);
49 static bool ParseValues(const nsAString
& aSpec
,
50 const mozilla::dom::SVGAnimationElement
* aSrcElement
,
51 const SMILAttr
& aAttribute
,
52 FallibleTArray
<SMILValue
>& aValuesArray
,
53 bool& aPreventCachingOfSandwich
);
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
);
60 static bool ParseRepeatCount(const nsAString
& aSpec
,
61 SMILRepeatCount
& aResult
);
63 static bool ParseTimeValueSpecParams(const nsAString
& aSpec
,
64 SMILTimeValueSpecParams
& aResult
);
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.
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.
75 static bool ParseClockValue(const nsAString
& aSpec
, SMILTimeValue
* aResult
);
78 * This method checks whether the given string looks like a negative number.
79 * Specifically, it checks whether the string looks matches the pattern
80 * "[whitespace]*-[numeral].*" If the string matches this pattern, this
81 * method returns the index of the first character after the '-' sign
82 * (i.e. the index of the absolute value). If not, this method returns -1.
84 static int32_t CheckForNegativeNumber(const nsAString
& aStr
);
87 } // namespace mozilla
89 #endif // DOM_SMIL_SMILPARSERUTILS_H_