dom/smil/nsSMILParserUtils.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:fec6e54cf361
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef NS_SMILPARSERUTILS_H_
7 #define NS_SMILPARSERUTILS_H_
8
9 #include "nsTArray.h"
10 #include "nsStringFwd.h"
11
12 class nsISMILAttr;
13 class nsSMILKeySpline;
14 class nsSMILTimeValue;
15 class nsSMILValue;
16 class nsSMILRepeatCount;
17 class nsSMILTimeValueSpecParams;
18
19 namespace mozilla {
20 namespace dom {
21 class SVGAnimationElement;
22 }
23 }
24
25 /**
26 * Common parsing utilities for the SMIL module. There is little re-use here; it
27 * simply serves to simplify other classes by moving parsing outside and to aid
28 * unit testing.
29 */
30 class nsSMILParserUtils
31 {
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<nsSMILKeySpline>& aKeySplines);
43
44 // Used for parsing the |keyTimes| and |keyPoints| attributes.
45 static bool ParseSemicolonDelimitedProgressList(const nsAString& aSpec,
46 bool aNonDecreasing,
47 FallibleTArray<double>& aArray);
48
49 static bool ParseValues(const nsAString& aSpec,
50 const mozilla::dom::SVGAnimationElement* aSrcElement,
51 const nsISMILAttr& aAttribute,
52 FallibleTArray<nsSMILValue>& 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 nsSMILRepeatCount& aResult);
62
63 static bool ParseTimeValueSpecParams(const nsAString& aSpec,
64 nsSMILTimeValueSpecParams& 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 nsSMILTimeValue* aResult);
77
78 /*
79 * This method checks whether the given string looks like a negative number.
80 * Specifically, it checks whether the string looks matches the pattern
81 * "[whitespace]*-[numeral].*" If the string matches this pattern, this
82 * method returns the index of the first character after the '-' sign
83 * (i.e. the index of the absolute value). If not, this method returns -1.
84 */
85 static int32_t CheckForNegativeNumber(const nsAString& aStr);
86 };
87
88 #endif // NS_SMILPARSERUTILS_H_

mercurial