static PRUint64 PackPreserveAspectRatio(const SVGPreserveAspectRatio& par) { // All preserveAspectRatio values are enum values (do not interpolate), so we // can safely collate them and treat them as a single enum as for SMIL. PRUint64 packed = 0; packed |= PRUint64(par.GetDefer() ? 1 : 0) << 16; packed |= PRUint64(par.GetAlign()) << 8; packed |= PRUint64(par.GetMeetOrSlice()); return packed; }
static nsresult ToPreserveAspectRatio(const nsAString &aString, SVGPreserveAspectRatio *aValue) { if (aString.IsEmpty() || NS_IsAsciiWhitespace(aString[0])) { return NS_ERROR_DOM_SYNTAX_ERR; } nsWhitespaceTokenizer tokenizer(aString); if (!tokenizer.hasMoreTokens()) { return NS_ERROR_DOM_SYNTAX_ERR; } const nsAString &token = tokenizer.nextToken(); nsresult rv; SVGPreserveAspectRatio val; val.SetDefer(token.EqualsLiteral("defer")); if (val.GetDefer()) { if (!tokenizer.hasMoreTokens()) { return NS_ERROR_DOM_SYNTAX_ERR; } rv = val.SetAlign(GetAlignForString(tokenizer.nextToken())); } else { rv = val.SetAlign(GetAlignForString(token)); } if (NS_FAILED(rv)) { return NS_ERROR_DOM_SYNTAX_ERR; } if (tokenizer.hasMoreTokens()) { rv = val.SetMeetOrSlice(GetMeetOrSliceForString(tokenizer.nextToken())); if (NS_FAILED(rv)) { return NS_ERROR_DOM_SYNTAX_ERR; } } else { val.SetMeetOrSlice(nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET); } if (tokenizer.hasMoreTokens()) { return NS_ERROR_DOM_SYNTAX_ERR; } *aValue = val; return NS_OK; }