no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / dom / smil / SMILParserUtils.h
blobf1ac4ba51d62c6cd290f52b0ca6df3ef6636a481
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_
10 #include "nsTArray.h"
11 #include "nsStringFwd.h"
12 #include "SMILTimeValue.h"
14 namespace mozilla {
16 class SMILAttr;
17 class SMILKeySpline;
18 class SMILRepeatCount;
19 class SMILTimeValueSpecParams;
20 class SMILValue;
22 namespace dom {
23 class SVGAnimationElement;
24 } // namespace dom
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.
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;
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,
76 SMILTimeValue::Rounding aRounding,
77 SMILTimeValue* aResult);
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.
86 static int32_t CheckForNegativeNumber(const nsAString& aStr);
89 } // namespace mozilla
91 #endif // DOM_SMIL_SMILPARSERUTILS_H_