mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 21:00:50 +00:00
Bug 436418, patch C1: SVG/SMIL animateMotion - add GenericValueParser helper class. r=roc
This commit is contained in:
parent
c722e28bb1
commit
f7ea03fbb8
@ -538,12 +538,60 @@ nsSMILParserUtils::ParseKeyTimes(const nsAString& aSpec,
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Helper class for ParseValues
|
||||
class SMILValueParser : public nsSMILParserUtils::GenericValueParser
|
||||
{
|
||||
public:
|
||||
SMILValueParser(const nsISMILAnimationElement* aSrcElement,
|
||||
const nsISMILAttr* aSMILAttr,
|
||||
nsTArray<nsSMILValue>* aValuesArray,
|
||||
PRBool* aCanCache) :
|
||||
mSrcElement(aSrcElement),
|
||||
mSMILAttr(aSMILAttr),
|
||||
mValuesArray(aValuesArray),
|
||||
mCanCache(aCanCache)
|
||||
{}
|
||||
|
||||
virtual nsresult Parse(const nsAString& aValueStr) {
|
||||
nsSMILValue newValue;
|
||||
PRBool tmpCanCache;
|
||||
nsresult rv = mSMILAttr->ValueFromString(aValueStr, mSrcElement,
|
||||
newValue, tmpCanCache);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!mValuesArray->AppendElement(newValue)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
if (!tmpCanCache) {
|
||||
*mCanCache = PR_FALSE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
protected:
|
||||
const nsISMILAnimationElement* mSrcElement;
|
||||
const nsISMILAttr* mSMILAttr;
|
||||
nsTArray<nsSMILValue>* mValuesArray;
|
||||
PRBool* mCanCache;
|
||||
};
|
||||
|
||||
nsresult
|
||||
nsSMILParserUtils::ParseValues(const nsAString& aSpec,
|
||||
const nsISMILAnimationElement* aSrcElement,
|
||||
const nsISMILAttr& aAttribute,
|
||||
nsTArray<nsSMILValue>& aValuesArray,
|
||||
PRBool& aCanCache)
|
||||
{
|
||||
// Assume all results can be cached, until we find one that can't.
|
||||
aCanCache = PR_TRUE;
|
||||
SMILValueParser valueParser(aSrcElement, &aAttribute,
|
||||
&aValuesArray, &aCanCache);
|
||||
return ParseValuesGeneric(aSpec, valueParser);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSMILParserUtils::ParseValuesGeneric(const nsAString& aSpec,
|
||||
GenericValueParser& aParser)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
@ -552,9 +600,6 @@ nsSMILParserUtils::ParseValues(const nsAString& aSpec,
|
||||
const PRUnichar* substrEnd = nsnull;
|
||||
const PRUnichar* next = nsnull;
|
||||
|
||||
// Assume all results can be cached, until we find one that can't.
|
||||
aCanCache = PR_TRUE;
|
||||
|
||||
while (start != end) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
@ -579,21 +624,10 @@ nsSMILParserUtils::ParseValues(const nsAString& aSpec,
|
||||
while (substrEnd != start && NS_IS_SPACE(*(substrEnd-1)))
|
||||
--substrEnd;
|
||||
|
||||
nsSMILValue newValue;
|
||||
PRBool tmpCanCache;
|
||||
rv = aAttribute.ValueFromString(Substring(start, substrEnd),
|
||||
aSrcElement, newValue, tmpCanCache);
|
||||
rv = aParser.Parse(Substring(start, substrEnd));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
if (!aValuesArray.AppendElement(newValue)) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
if (!tmpCanCache) {
|
||||
aCanCache = PR_FALSE;
|
||||
}
|
||||
|
||||
start = next;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,12 @@ class nsSMILTimeValueSpecParams;
|
||||
class nsSMILParserUtils
|
||||
{
|
||||
public:
|
||||
// Abstract helper-class for assisting in parsing |values| attribute
|
||||
class GenericValueParser {
|
||||
public:
|
||||
virtual nsresult Parse(const nsAString& aValueStr) = 0;
|
||||
};
|
||||
|
||||
static nsresult ParseKeySplines(const nsAString& aSpec,
|
||||
nsTArray<double>& aSplineArray);
|
||||
|
||||
@ -69,6 +75,11 @@ public:
|
||||
nsTArray<nsSMILValue>& aValuesArray,
|
||||
PRBool& aCanCache);
|
||||
|
||||
// Generic method that will run some code on each sub-section of an animation
|
||||
// element's "values" list.
|
||||
static nsresult ParseValuesGeneric(const nsAString& aSpec,
|
||||
GenericValueParser& aParser);
|
||||
|
||||
static nsresult ParseRepeatCount(const nsAString& aSpec,
|
||||
nsSMILRepeatCount& aResult);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user