void nsSVGNumberPair::GetBaseValueString(nsAString &aValueAsString) const { aValueAsString.Truncate(); aValueAsString.AppendFloat(mBaseVal[0]); if (mBaseVal[0] != mBaseVal[1]) { aValueAsString.AppendLiteral(", "); aValueAsString.AppendFloat(mBaseVal[1]); } }
void StyleInfo::TextIndent(nsAString& aValue) { aValue.Truncate(); const nsStyleCoord& styleCoord = mStyleContext->GetStyleText()->mTextIndent; nscoord coordVal; switch (styleCoord.GetUnit()) { case eStyleUnit_Coord: coordVal = styleCoord.GetCoordValue(); break; case eStyleUnit_Percent: { nsIFrame* frame = mElement->GetPrimaryFrame(); nsIFrame* containerFrame = frame->GetContainingBlock(); nscoord percentageBase = containerFrame->GetContentRect().width; coordVal = NSCoordSaturatingMultiply(percentageBase, styleCoord.GetPercentValue()); break; } } aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal)); aValue.AppendLiteral("px"); }
void nsNumberControlFrame::GetValueOfAnonTextControl(nsAString& aValue) { if (!mTextField) { aValue.Truncate(); return; } HTMLInputElement::FromContent(mTextField)->GetValue(aValue); #ifdef ENABLE_INTL_API // Here we need to de-localize any number typed in by the user. That is, we // need to convert it from the number format of the user's language, region, // etc. to the format that the HTML 5 spec defines to be a "valid // floating-point number": // // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#floating-point-numbers // // so that it can be parsed by functions like HTMLInputElement:: // StringToDecimal (the HTML-5-conforming parsing function) which don't know // how to handle numbers that are formatted differently (for example, with // non-ASCII digits, with grouping separator characters or with a decimal // separator character other than '.'). // // We need to be careful to avoid normalizing numbers that are already // formatted for a locale that matches the format of HTML 5's "valid // floating-point number" and have no grouping separator characters. (In // other words we want to return the number as specified by the user, not the // de-localized serialization, since the latter will normalize the value.) // For example, if the user's locale is English and the user types in "2e2" // then inputElement.value should be "2e2" and not "100". This is because // content (and tests) expect us to avoid "normalizing" the number that the // user types in if it's not necessary in order to make sure it conforms to // HTML 5's "valid floating-point number" format. // // Note that we also need to be careful when trying to avoid normalization. // For example, just because "1.234" _looks_ like a valid floating-point // number according to the spec does not mean that it should be returned // as-is. If the user's locale is German, then this represents the value // 1234, not 1.234, so it still needs to be de-localized. Alternatively, if // the user's locale is English and they type in "1,234" we _do_ need to // normalize the number to "1234" because HTML 5's valid floating-point // number format does not allow the ',' grouping separator. We can detect all // the cases where we need to convert by seeing if the locale-specific // parsing function understands the user input to mean the same thing as the // HTML-5-conforming parsing function. If so, then we should return the value // as-is to avoid normalization. Otherwise, we return the de-localized // serialization. ICUUtils::LanguageTagIterForContent langTagIter(mContent); double value = ICUUtils::ParseNumber(aValue, langTagIter); if (NS_finite(value) && value != HTMLInputElement::StringToDecimal(aValue).toDouble()) { aValue.Truncate(); aValue.AppendFloat(value); } #endif // else, we return whatever FromContent put into aValue (the number as typed // in by the user) }
void StyleInfo::Margin(css::Side aSide, nsAString& aValue) { aValue.Truncate(); nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide); aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal)); aValue.AppendLiteral("px"); }
void nsNumberControlFrame::GetValueOfAnonTextControl(nsAString& aValue) { if (!mTextField) { aValue.Truncate(); return; } HTMLInputElement::FromContent(mTextField)->GetValue(aValue); #ifdef ENABLE_INTL_API // Here we need to de-localize any number typed in by the user. That is, we // need to convert it from the number format of the user's language, region, // etc. to the format that the HTML 5 spec defines to be a "valid // floating-point number": // // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#floating-point-numbers // // This is necessary to allow the number that we return to be parsed by // functions like HTMLInputElement::StringToDecimal (the HTML-5-conforming // parsing function) which don't know how to handle numbers that are // formatted differently (for example, with non-ASCII digits, with grouping // separator characters or with a decimal separator character other than // '.'). ICUUtils::LanguageTagIterForContent langTagIter(mContent); double value = ICUUtils::ParseNumber(aValue, langTagIter); if (!IsFinite(value)) { aValue.Truncate(); return; } if (value == HTMLInputElement::StringToDecimal(aValue).toDouble()) { // We want to preserve the formatting of the number as typed in by the user // whenever possible. Since the localized serialization parses to the same // number as the de-localized serialization, we can do that. This helps // prevent normalization of input such as "2e2" (which would otherwise be // converted to "200"). Content relies on this. // // Typically we will only get here for locales in which numbers are // formatted in the same way as they are for HTML5's "valid floating-point // number" format. return; } // We can't preserve the formatting, otherwise functions such as // HTMLInputElement::StringToDecimal would incorrectly process the number // input by the user. For example, "12.345" with lang=de de-localizes as // 12345, but HTMLInputElement::StringToDecimal would mistakenly parse it as // 12.345. Another example would be "12,345" with lang=de which de-localizes // as 12.345, but HTMLInputElement::StringToDecimal would parse it to NaN. aValue.Truncate(); aValue.AppendFloat(value); #endif }
void StyleInfo::TextIndent(nsAString& aValue) { aValue.Truncate(); const nsStyleCoord& styleCoord = mStyleContext->GetStyleText()->mTextIndent; nscoord coordVal = 0; switch (styleCoord.GetUnit()) { case eStyleUnit_Coord: coordVal = styleCoord.GetCoordValue(); break; case eStyleUnit_Percent: { nsIFrame* frame = mElement->GetPrimaryFrame(); nsIFrame* containerFrame = frame->GetContainingBlock(); nscoord percentageBase = containerFrame->GetContentRect().width; coordVal = NSCoordSaturatingMultiply(percentageBase, styleCoord.GetPercentValue()); break; } case eStyleUnit_Null: case eStyleUnit_Normal: case eStyleUnit_Auto: case eStyleUnit_None: case eStyleUnit_Factor: case eStyleUnit_Degree: case eStyleUnit_Grad: case eStyleUnit_Radian: case eStyleUnit_Turn: case eStyleUnit_Integer: case eStyleUnit_Enumerated: case eStyleUnit_Calc: break; } aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal)); aValue.AppendLiteral("px"); }
void nsSVGNumber2::GetBaseValueString(nsAString & aValueAsString) { aValueAsString.Truncate(); aValueAsString.AppendFloat(mBaseVal); }
void nsAttrValue::ToString(nsAString& aResult) const { MiscContainer* cont = nsnull; if (BaseType() == eOtherBase) { cont = GetMiscContainer(); void* ptr = MISC_STR_PTR(cont); if (ptr) { if (static_cast<ValueBaseType>(cont->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) == eStringBase) { nsStringBuffer* str = static_cast<nsStringBuffer*>(ptr); if (str) { str->ToString(str->StorageSize()/sizeof(PRUnichar) - 1, aResult); return; } } else { nsIAtom *atom = static_cast<nsIAtom*>(ptr); atom->ToString(aResult); return; } } } switch(Type()) { case eString: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { str->ToString(str->StorageSize()/sizeof(PRUnichar) - 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, PR_FALSE); break; } case ePercent: { nsAutoString intStr; intStr.AppendInt(cont ? cont->mPercent : GetIntInternal()); aResult = intStr + NS_LITERAL_STRING("%"); break; } case eCSSStyleRule: { aResult.Truncate(); MiscContainer *container = GetMiscContainer(); css::Declaration *decl = container->mCSSStyleRule->GetDeclaration(); if (decl) { decl->ToString(aResult); } const_cast<nsAttrValue*>(this)->SetMiscAtomOrString(&aResult); break; } case eSVGValue: { GetMiscContainer()->mSVGValue->GetValueString(aResult); break; } case eDoubleValue: { aResult.Truncate(); aResult.AppendFloat(GetDoubleValue()); 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 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 nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult) const { // eCSSProperty_UNKNOWN gets used for some recursive calls below. NS_ABORT_IF_FALSE((0 <= aProperty && aProperty <= eCSSProperty_COUNT_no_shorthands) || aProperty == eCSSProperty_UNKNOWN, "property ID out of range"); nsCSSUnit unit = GetUnit(); if (unit == eCSSUnit_Null) { return; } if (eCSSUnit_String <= unit && unit <= eCSSUnit_Attr) { if (unit == eCSSUnit_Attr) { aResult.AppendLiteral("attr("); } nsAutoString buffer; GetStringValue(buffer); if (unit == eCSSUnit_String) { nsStyleUtil::AppendEscapedCSSString(buffer, aResult); } else if (unit == eCSSUnit_Families) { // XXX We really need to do *some* escaping. aResult.Append(buffer); } else { nsStyleUtil::AppendEscapedCSSIdent(buffer, aResult); } } else if (eCSSUnit_Array <= unit && unit <= eCSSUnit_Steps) { switch (unit) { case eCSSUnit_Counter: aResult.AppendLiteral("counter("); break; case eCSSUnit_Counters: aResult.AppendLiteral("counters("); break; case eCSSUnit_Cubic_Bezier: aResult.AppendLiteral("cubic-bezier("); break; case eCSSUnit_Steps: aResult.AppendLiteral("steps("); break; default: break; } nsCSSValue::Array *array = GetArrayValue(); bool mark = false; for (size_t i = 0, i_end = array->Count(); i < i_end; ++i) { if (mark && array->Item(i).GetUnit() != eCSSUnit_Null) { if (unit == eCSSUnit_Array && eCSSProperty_transition_timing_function != aProperty) aResult.AppendLiteral(" "); else aResult.AppendLiteral(", "); } if (unit == eCSSUnit_Steps && i == 1) { NS_ABORT_IF_FALSE(array->Item(i).GetUnit() == eCSSUnit_Enumerated && (array->Item(i).GetIntValue() == NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START || array->Item(i).GetIntValue() == NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_END), "unexpected value"); if (array->Item(i).GetIntValue() == NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START) { aResult.AppendLiteral("start"); } else { aResult.AppendLiteral("end"); } continue; } nsCSSProperty prop = ((eCSSUnit_Counter <= unit && unit <= eCSSUnit_Counters) && i == array->Count() - 1) ? eCSSProperty_list_style_type : aProperty; if (array->Item(i).GetUnit() != eCSSUnit_Null) { array->Item(i).AppendToString(prop, aResult); mark = true; } } if (eCSSUnit_Array == unit && aProperty == eCSSProperty_transition_timing_function) { aResult.AppendLiteral(")"); } } /* Although Function is backed by an Array, we'll handle it separately * because it's a bit quirky. */ else if (eCSSUnit_Function == unit) { const nsCSSValue::Array* array = GetArrayValue(); NS_ABORT_IF_FALSE(array->Count() >= 1, "Functions must have at least one element for the name."); /* Append the function name. */ const nsCSSValue& functionName = array->Item(0); if (functionName.GetUnit() == eCSSUnit_Enumerated) { // We assume that the first argument is always of nsCSSKeyword type. const nsCSSKeyword functionId = static_cast<nsCSSKeyword>(functionName.GetIntValue()); nsStyleUtil::AppendEscapedCSSIdent( NS_ConvertASCIItoUTF16(nsCSSKeywords::GetStringValue(functionId)), aResult); } else { functionName.AppendToString(aProperty, aResult); } aResult.AppendLiteral("("); /* Now, step through the function contents, writing each of them as we go. */ for (size_t index = 1; index < array->Count(); ++index) { array->Item(index).AppendToString(aProperty, aResult); /* If we're not at the final element, append a comma. */ if (index + 1 != array->Count()) aResult.AppendLiteral(", "); } /* Finally, append the closing parenthesis. */ aResult.AppendLiteral(")"); } else if (IsCalcUnit()) { NS_ABORT_IF_FALSE(GetUnit() == eCSSUnit_Calc, "unexpected unit"); CSSValueSerializeCalcOps ops(aProperty, aResult); css::SerializeCalc(*this, ops); } else if (eCSSUnit_Integer == unit) { aResult.AppendInt(GetIntValue(), 10); } else if (eCSSUnit_Enumerated == unit) { if (eCSSProperty_text_decoration_line == aProperty) { PRInt32 intValue = GetIntValue(); if (NS_STYLE_TEXT_DECORATION_LINE_NONE == intValue) { AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue), aResult); } else { // Ignore the "override all" internal value. // (It doesn't have a string representation.) intValue &= ~NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL; nsStyleUtil::AppendBitmaskCSSValue( aProperty, intValue, NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE, NS_STYLE_TEXT_DECORATION_LINE_PREF_ANCHORS, aResult); } } else if (eCSSProperty_marks == aProperty) { PRInt32 intValue = GetIntValue(); if (intValue == NS_STYLE_PAGE_MARKS_NONE) { AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue), aResult); } else { nsStyleUtil::AppendBitmaskCSSValue(aProperty, intValue, NS_STYLE_PAGE_MARKS_CROP, NS_STYLE_PAGE_MARKS_REGISTER, aResult); } } else if (eCSSProperty_unicode_bidi == aProperty) { PR_STATIC_ASSERT(NS_STYLE_UNICODE_BIDI_NORMAL == 0); PRInt32 intValue = GetIntValue(); if (NS_STYLE_UNICODE_BIDI_NORMAL == intValue) { AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue), aResult); } else { nsStyleUtil::AppendBitmaskCSSValue( aProperty, intValue, NS_STYLE_UNICODE_BIDI_EMBED, NS_STYLE_UNICODE_BIDI_PLAINTEXT, aResult); } } else { const nsAFlatCString& name = nsCSSProps::LookupPropertyValue(aProperty, GetIntValue()); AppendASCIItoUTF16(name, aResult); } } else if (eCSSUnit_EnumColor == unit) { // we can lookup the property in the ColorTable and then // get a string mapping the name nsCAutoString str; if (nsCSSProps::GetColorName(GetIntValue(), str)){ AppendASCIItoUTF16(str, aResult); } else { NS_ABORT_IF_FALSE(false, "bad color value"); } } else if (eCSSUnit_Color == unit) { nscolor color = GetColorValue(); if (color == NS_RGBA(0, 0, 0, 0)) { // Use the strictest match for 'transparent' so we do correct // round-tripping of all other rgba() values. aResult.AppendLiteral("transparent"); } else { PRUint8 a = NS_GET_A(color); if (a < 255) { aResult.AppendLiteral("rgba("); } else { aResult.AppendLiteral("rgb("); } NS_NAMED_LITERAL_STRING(comma, ", "); aResult.AppendInt(NS_GET_R(color), 10); aResult.Append(comma); aResult.AppendInt(NS_GET_G(color), 10); aResult.Append(comma); aResult.AppendInt(NS_GET_B(color), 10); if (a < 255) { aResult.Append(comma); aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a)); } aResult.Append(PRUnichar(')')); } } else if (eCSSUnit_URL == unit || eCSSUnit_Image == unit) { aResult.Append(NS_LITERAL_STRING("url(")); nsStyleUtil::AppendEscapedCSSString( nsDependentString(GetOriginalURLValue()), aResult); aResult.Append(NS_LITERAL_STRING(")")); } else if (eCSSUnit_Element == unit) { aResult.Append(NS_LITERAL_STRING("-moz-element(#")); nsAutoString tmpStr; GetStringValue(tmpStr); nsStyleUtil::AppendEscapedCSSIdent(tmpStr, aResult); aResult.Append(NS_LITERAL_STRING(")")); } else if (eCSSUnit_Percent == unit) { aResult.AppendFloat(GetPercentValue() * 100.0f); } else if (eCSSUnit_Percent < unit) { // length unit aResult.AppendFloat(GetFloatValue()); } else if (eCSSUnit_Gradient == unit) { nsCSSValueGradient* gradient = GetGradientValue(); if (gradient->mIsRepeating) { if (gradient->mIsRadial) aResult.AppendLiteral("-moz-repeating-radial-gradient("); else aResult.AppendLiteral("-moz-repeating-linear-gradient("); } else { if (gradient->mIsRadial) aResult.AppendLiteral("-moz-radial-gradient("); else aResult.AppendLiteral("-moz-linear-gradient("); } if (gradient->mIsToCorner) { aResult.AppendLiteral("to"); NS_ABORT_IF_FALSE(gradient->mBgPos.mXValue.GetUnit() == eCSSUnit_Enumerated && gradient->mBgPos.mYValue.GetUnit() == eCSSUnit_Enumerated, "unexpected unit"); if (!(gradient->mBgPos.mXValue.GetIntValue() & NS_STYLE_BG_POSITION_CENTER)) { aResult.AppendLiteral(" "); gradient->mBgPos.mXValue.AppendToString(eCSSProperty_background_position, aResult); } if (!(gradient->mBgPos.mYValue.GetIntValue() & NS_STYLE_BG_POSITION_CENTER)) { aResult.AppendLiteral(" "); gradient->mBgPos.mYValue.AppendToString(eCSSProperty_background_position, aResult); } aResult.AppendLiteral(", "); } else if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None || gradient->mBgPos.mYValue.GetUnit() != eCSSUnit_None || gradient->mAngle.GetUnit() != eCSSUnit_None) { if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) { gradient->mBgPos.mXValue.AppendToString(eCSSProperty_background_position, aResult); aResult.AppendLiteral(" "); } if (gradient->mBgPos.mXValue.GetUnit() != eCSSUnit_None) { gradient->mBgPos.mYValue.AppendToString(eCSSProperty_background_position, aResult); aResult.AppendLiteral(" "); } if (gradient->mAngle.GetUnit() != eCSSUnit_None) { gradient->mAngle.AppendToString(aProperty, aResult); } aResult.AppendLiteral(", "); } if (gradient->mIsRadial && (gradient->mRadialShape.GetUnit() != eCSSUnit_None || gradient->mRadialSize.GetUnit() != eCSSUnit_None)) { if (gradient->mRadialShape.GetUnit() != eCSSUnit_None) { NS_ABORT_IF_FALSE(gradient->mRadialShape.GetUnit() == eCSSUnit_Enumerated, "bad unit for radial gradient shape"); PRInt32 intValue = gradient->mRadialShape.GetIntValue(); NS_ABORT_IF_FALSE(intValue != NS_STYLE_GRADIENT_SHAPE_LINEAR, "radial gradient with linear shape?!"); AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue, nsCSSProps::kRadialGradientShapeKTable), aResult); aResult.AppendLiteral(" "); } if (gradient->mRadialSize.GetUnit() != eCSSUnit_None) { NS_ABORT_IF_FALSE(gradient->mRadialSize.GetUnit() == eCSSUnit_Enumerated, "bad unit for radial gradient size"); PRInt32 intValue = gradient->mRadialSize.GetIntValue(); AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(intValue, nsCSSProps::kRadialGradientSizeKTable), aResult); } aResult.AppendLiteral(", "); } for (PRUint32 i = 0 ;;) { gradient->mStops[i].mColor.AppendToString(aProperty, aResult); if (gradient->mStops[i].mLocation.GetUnit() != eCSSUnit_None) { aResult.AppendLiteral(" "); gradient->mStops[i].mLocation.AppendToString(aProperty, aResult); } if (++i == gradient->mStops.Length()) { break; } aResult.AppendLiteral(", "); } aResult.AppendLiteral(")"); } else if (eCSSUnit_Pair == unit) { GetPairValue().AppendToString(aProperty, aResult); } else if (eCSSUnit_Triplet == unit) { GetTripletValue().AppendToString(aProperty, aResult); } else if (eCSSUnit_Rect == unit) { GetRectValue().AppendToString(aProperty, aResult); } else if (eCSSUnit_List == unit || eCSSUnit_ListDep == unit) { GetListValue()->AppendToString(aProperty, aResult); } else if (eCSSUnit_PairList == unit || eCSSUnit_PairListDep == unit) { GetPairListValue()->AppendToString(aProperty, aResult); } switch (unit) { case eCSSUnit_Null: break; case eCSSUnit_Auto: aResult.AppendLiteral("auto"); break; case eCSSUnit_Inherit: aResult.AppendLiteral("inherit"); break; case eCSSUnit_Initial: aResult.AppendLiteral("-moz-initial"); break; case eCSSUnit_None: aResult.AppendLiteral("none"); break; case eCSSUnit_Normal: aResult.AppendLiteral("normal"); break; case eCSSUnit_System_Font: aResult.AppendLiteral("-moz-use-system-font"); break; case eCSSUnit_All: aResult.AppendLiteral("all"); break; case eCSSUnit_Dummy: case eCSSUnit_DummyInherit: NS_ABORT_IF_FALSE(false, "should never serialize"); break; case eCSSUnit_String: break; case eCSSUnit_Ident: break; case eCSSUnit_Families: break; case eCSSUnit_URL: break; case eCSSUnit_Image: break; case eCSSUnit_Element: break; case eCSSUnit_Array: break; case eCSSUnit_Attr: case eCSSUnit_Cubic_Bezier: case eCSSUnit_Steps: case eCSSUnit_Counter: case eCSSUnit_Counters: aResult.Append(PRUnichar(')')); break; case eCSSUnit_Local_Font: break; case eCSSUnit_Font_Format: break; case eCSSUnit_Function: break; case eCSSUnit_Calc: break; case eCSSUnit_Calc_Plus: break; case eCSSUnit_Calc_Minus: break; case eCSSUnit_Calc_Times_L: break; case eCSSUnit_Calc_Times_R: break; case eCSSUnit_Calc_Divided: break; case eCSSUnit_Integer: break; case eCSSUnit_Enumerated: break; case eCSSUnit_EnumColor: break; case eCSSUnit_Color: break; case eCSSUnit_Percent: aResult.Append(PRUnichar('%')); break; case eCSSUnit_Number: break; case eCSSUnit_Gradient: break; case eCSSUnit_Pair: break; case eCSSUnit_Triplet: break; case eCSSUnit_Rect: break; case eCSSUnit_List: break; case eCSSUnit_ListDep: break; case eCSSUnit_PairList: break; case eCSSUnit_PairListDep: break; case eCSSUnit_Inch: aResult.AppendLiteral("in"); break; case eCSSUnit_Millimeter: aResult.AppendLiteral("mm"); break; case eCSSUnit_PhysicalMillimeter: aResult.AppendLiteral("mozmm"); break; case eCSSUnit_Centimeter: aResult.AppendLiteral("cm"); break; case eCSSUnit_Point: aResult.AppendLiteral("pt"); break; case eCSSUnit_Pica: aResult.AppendLiteral("pc"); break; case eCSSUnit_EM: aResult.AppendLiteral("em"); break; case eCSSUnit_XHeight: aResult.AppendLiteral("ex"); break; case eCSSUnit_Char: aResult.AppendLiteral("ch"); break; case eCSSUnit_RootEM: aResult.AppendLiteral("rem"); break; case eCSSUnit_Pixel: aResult.AppendLiteral("px"); break; case eCSSUnit_Degree: aResult.AppendLiteral("deg"); break; case eCSSUnit_Grad: aResult.AppendLiteral("grad"); break; case eCSSUnit_Radian: aResult.AppendLiteral("rad"); break; case eCSSUnit_Hertz: aResult.AppendLiteral("Hz"); break; case eCSSUnit_Kilohertz: aResult.AppendLiteral("kHz"); break; case eCSSUnit_Seconds: aResult.Append(PRUnichar('s')); break; case eCSSUnit_Milliseconds: aResult.AppendLiteral("ms"); 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; } } }
// Convenient way to append things as floats, not doubles. We use this because // we only want to output about 6 digits of precision for our matrix() // functions, to preserve the behavior we used to have when we used // AppendPrintf. static void AppendFloat(nsAString& aStr, float f) { aStr.AppendFloat(f); }