diff --git a/dom/svg/nsSVGViewBox.cpp b/dom/svg/nsSVGViewBox.cpp index a71c6747005c..207b861663a6 100644 --- a/dom/svg/nsSVGViewBox.cpp +++ b/dom/svg/nsSVGViewBox.cpp @@ -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 + 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 - 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; } diff --git a/dom/svg/nsSVGViewBox.h b/dom/svg/nsSVGViewBox.h index 1e799e919377..3bec46cab7f7 100644 --- a/dom/svg/nsSVGViewBox.h +++ b/dom/svg/nsSVGViewBox.h @@ -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