mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1360063 - Expose the parsing code for nsSVGViewBoxRect as a method. r=longsonr
MozReview-Commit-ID: J3xv6VyvYgg --HG-- extra : rebase_source : 007fbb2a151fd1d846fef4522c8ade002267427f
This commit is contained in:
parent
a696cd2ae6
commit
0ddff2c13d
@ -32,6 +32,41 @@ nsSVGViewBoxRect::operator==(const nsSVGViewBoxRect& aOther) const
|
||||
height == aOther.height);
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsSVGViewBoxRect::FromString(const nsAString& aStr, nsSVGViewBoxRect *aViewBox)
|
||||
{
|
||||
if (aStr.EqualsLiteral("none")) {
|
||||
aViewBox->none = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
||||
tokenizer(aStr, ',',
|
||||
nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
|
||||
float vals[NUM_VIEWBOX_COMPONENTS];
|
||||
uint32_t i;
|
||||
for (i = 0; i < NUM_VIEWBOX_COMPONENTS && tokenizer.hasMoreTokens(); ++i) {
|
||||
if (!SVGContentUtils::ParseNumber(tokenizer.nextToken(), vals[i])) {
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != NUM_VIEWBOX_COMPONENTS || // Too few values.
|
||||
tokenizer.hasMoreTokens() || // Too many values.
|
||||
tokenizer.separatorAfterCurrentToken()) { // Trailing comma.
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
|
||||
aViewBox->x = vals[0];
|
||||
aViewBox->y = vals[1];
|
||||
aViewBox->width = vals[2];
|
||||
aViewBox->height = vals[3];
|
||||
aViewBox->none = false;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Cycle collection macros for nsSVGViewBox */
|
||||
|
||||
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(nsSVGViewBox::DOMBaseVal, mSVGElement)
|
||||
@ -132,40 +167,6 @@ nsSVGViewBox::SetBaseValue(const nsSVGViewBoxRect& aRect,
|
||||
}
|
||||
}
|
||||
|
||||
static nsresult
|
||||
ToSVGViewBoxRect(const nsAString& aStr, nsSVGViewBoxRect *aViewBox)
|
||||
{
|
||||
if (aStr.EqualsLiteral("none")) {
|
||||
aViewBox->none = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
||||
tokenizer(aStr, ',',
|
||||
nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
|
||||
float vals[NUM_VIEWBOX_COMPONENTS];
|
||||
uint32_t i;
|
||||
for (i = 0; i < NUM_VIEWBOX_COMPONENTS && tokenizer.hasMoreTokens(); ++i) {
|
||||
if (!SVGContentUtils::ParseNumber(tokenizer.nextToken(), vals[i])) {
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != NUM_VIEWBOX_COMPONENTS || // Too few values.
|
||||
tokenizer.hasMoreTokens() || // Too many values.
|
||||
tokenizer.separatorAfterCurrentToken()) { // Trailing comma.
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
|
||||
aViewBox->x = vals[0];
|
||||
aViewBox->y = vals[1];
|
||||
aViewBox->width = vals[2];
|
||||
aViewBox->height = vals[3];
|
||||
aViewBox->none = false;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSVGViewBox::SetBaseValueString(const nsAString& aValue,
|
||||
nsSVGElement *aSVGElement,
|
||||
@ -173,7 +174,7 @@ nsSVGViewBox::SetBaseValueString(const nsAString& aValue,
|
||||
{
|
||||
nsSVGViewBoxRect viewBox;
|
||||
|
||||
nsresult rv = ToSVGViewBoxRect(aValue, &viewBox);
|
||||
nsresult rv = nsSVGViewBoxRect::FromString(aValue, &viewBox);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
@ -318,7 +319,7 @@ nsSVGViewBox::SMILViewBox
|
||||
bool& aPreventCachingOfSandwich) const
|
||||
{
|
||||
nsSVGViewBoxRect viewBox;
|
||||
nsresult res = ToSVGViewBoxRect(aStr, &viewBox);
|
||||
nsresult res = nsSVGViewBoxRect::FromString(aStr, &viewBox);
|
||||
if (NS_FAILED(res)) {
|
||||
return res;
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ struct nsSVGViewBoxRect
|
||||
nsSVGViewBoxRect(const nsSVGViewBoxRect& rhs) :
|
||||
x(rhs.x), y(rhs.y), width(rhs.width), height(rhs.height), none(rhs.none) {}
|
||||
bool operator==(const nsSVGViewBoxRect& aOther) const;
|
||||
|
||||
static nsresult FromString(const nsAString& aStr, nsSVGViewBoxRect *aViewBox);
|
||||
};
|
||||
|
||||
class nsSVGViewBox
|
||||
|
Loading…
Reference in New Issue
Block a user