void nsAttrValue::ToString(nsAString& aResult) const { MiscContainer* cont = nullptr; if (BaseType() == eOtherBase) { cont = GetMiscContainer(); if (cont->GetString(aResult)) { return; } } switch(Type()) { case eString: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { str->ToString(str->StorageSize()/sizeof(char16_t) - 1, aResult); } else { aResult.Truncate(); } break; } case eAtom: { nsIAtom *atom = static_cast<nsIAtom*>(GetPtr()); atom->ToString(aResult); break; } case eInteger: { nsAutoString intStr; intStr.AppendInt(GetIntegerValue()); aResult = intStr; break; } #ifdef DEBUG case eColor: { NS_NOTREACHED("color attribute without string data"); aResult.Truncate(); break; } #endif case eEnum: { GetEnumString(aResult, false); break; } case ePercent: { nsAutoString intStr; intStr.AppendInt(cont ? cont->mValue.mPercent : GetIntInternal()); aResult = intStr + NS_LITERAL_STRING("%"); break; } case eCSSStyleRule: { aResult.Truncate(); MiscContainer *container = GetMiscContainer(); css::Declaration *decl = container->mValue.mCSSStyleRule->GetDeclaration(); if (decl) { decl->ToString(aResult); } const_cast<nsAttrValue*>(this)->SetMiscAtomOrString(&aResult); break; } case eDoubleValue: { aResult.Truncate(); aResult.AppendFloat(GetDoubleValue()); break; } case eSVGAngle: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGAngle, aResult); break; } case eSVGIntegerPair: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGIntegerPair, aResult); break; } case eSVGLength: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGLength, aResult); break; } case eSVGLengthList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGLengthList, aResult); break; } case eSVGNumberList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGNumberList, aResult); break; } case eSVGNumberPair: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGNumberPair, aResult); break; } case eSVGPathData: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGPathData, aResult); break; } case eSVGPointList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGPointList, aResult); break; } case eSVGPreserveAspectRatio: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGPreserveAspectRatio, aResult); break; } case eSVGStringList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGStringList, aResult); break; } case eSVGTransformList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGTransformList, aResult); break; } case eSVGViewBox: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGViewBox, aResult); break; } default: { aResult.Truncate(); break; } } }
void nsAttrValue::ToString(nsAString& aResult) const { MiscContainer* cont = nullptr; if (BaseType() == eOtherBase) { cont = GetMiscContainer(); if (cont->GetString(aResult)) { return; } } switch(Type()) { case eString: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { str->ToString(str->StorageSize()/sizeof(char16_t) - 1, aResult); } else { aResult.Truncate(); } break; } case eAtom: { nsIAtom *atom = static_cast<nsIAtom*>(GetPtr()); atom->ToString(aResult); break; } case eInteger: { nsAutoString intStr; intStr.AppendInt(GetIntegerValue()); aResult = intStr; break; } #ifdef DEBUG case eColor: { NS_NOTREACHED("color attribute without string data"); aResult.Truncate(); break; } #endif case eEnum: { GetEnumString(aResult, false); break; } case ePercent: { nsAutoString intStr; intStr.AppendInt(cont ? cont->mValue.mPercent : GetIntInternal()); aResult = intStr + NS_LITERAL_STRING("%"); break; } case eCSSDeclaration: { aResult.Truncate(); MiscContainer *container = GetMiscContainer(); if (DeclarationBlock* decl = container->mValue.mCSSDeclaration) { decl->ToString(aResult); } // We can reach this during parallel style traversal. If that happens, // don't cache the string. The TLS overhead should't hurt us here, since // main thread consumers will subsequently use the cache, and // off-main-thread consumers only reach this in the rare case of selector // matching on the "style" attribute. if (!ServoStyleSet::IsInServoTraversal()) { const_cast<nsAttrValue*>(this)->SetMiscAtomOrString(&aResult); } break; } case eDoubleValue: { aResult.Truncate(); aResult.AppendFloat(GetDoubleValue()); break; } case eSVGAngle: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGAngle, aResult); break; } case eSVGIntegerPair: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGIntegerPair, aResult); break; } case eSVGLength: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGLength, aResult); break; } case eSVGLengthList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGLengthList, aResult); break; } case eSVGNumberList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGNumberList, aResult); break; } case eSVGNumberPair: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGNumberPair, aResult); break; } case eSVGPathData: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGPathData, aResult); break; } case eSVGPointList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGPointList, aResult); break; } case eSVGPreserveAspectRatio: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGPreserveAspectRatio, aResult); break; } case eSVGStringList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGStringList, aResult); break; } case eSVGTransformList: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGTransformList, aResult); break; } case eSVGViewBox: { SVGAttrValueWrapper::ToString(GetMiscContainer()->mValue.mSVGViewBox, aResult); break; } default: { aResult.Truncate(); break; } } }