diff --git a/accessible/base/StyleInfo.cpp b/accessible/base/StyleInfo.cpp index a5a20afc75d5..294ed50562b4 100644 --- a/accessible/base/StyleInfo.cpp +++ b/accessible/base/StyleInfo.cpp @@ -21,12 +21,16 @@ StyleInfo::StyleInfo(dom::Element* aElement) : mElement(aElement) { void StyleInfo::Display(nsAString& aValue) { aValue.Truncate(); - mComputedStyle->GetComputedPropertyValue(eCSSProperty_display, aValue); + nsAutoCString value; + mComputedStyle->GetComputedPropertyValue(eCSSProperty_display, value); + CopyUTF8toUTF16(value, aValue); } void StyleInfo::TextAlign(nsAString& aValue) { aValue.Truncate(); - mComputedStyle->GetComputedPropertyValue(eCSSProperty_text_align, aValue); + nsAutoCString value; + mComputedStyle->GetComputedPropertyValue(eCSSProperty_text_align, value); + CopyUTF8toUTF16(value, aValue); } void StyleInfo::TextIndent(nsAString& aValue) { diff --git a/accessible/windows/sdn/sdnAccessible.cpp b/accessible/windows/sdn/sdnAccessible.cpp index 2d7f12d801ab..04643e229aed 100644 --- a/accessible/windows/sdn/sdnAccessible.cpp +++ b/accessible/windows/sdn/sdnAccessible.cpp @@ -220,7 +220,7 @@ sdnAccessible::get_computedStyle( for (index = realIndex = 0; index < length && realIndex < aMaxStyleProperties; index++) { nsAutoCString property; - nsAutoString value; + nsAutoCString value; // Ignore -moz-* properties. cssDecl->Item(index, property); @@ -230,7 +230,8 @@ sdnAccessible::get_computedStyle( if (!value.IsEmpty()) { aStyleProperties[realIndex] = ::SysAllocString(NS_ConvertUTF8toUTF16(property).get()); - aStyleValues[realIndex] = ::SysAllocString(value.get()); + aStyleValues[realIndex] = + ::SysAllocString(NS_ConvertUTF8toUTF16(value).get()); ++realIndex; } } @@ -256,12 +257,12 @@ sdnAccessible::get_computedStyleForProperties( uint32_t index = 0; for (index = 0; index < aNumStyleProperties; index++) { - nsAutoString value; + nsAutoCString value; if (aStyleProperties[index]) cssDecl->GetPropertyValue( NS_ConvertUTF16toUTF8(nsDependentString(aStyleProperties[index])), value); // Get property value - aStyleValues[index] = ::SysAllocString(value.get()); + aStyleValues[index] = ::SysAllocString(NS_ConvertUTF8toUTF16(value).get()); } return S_OK; diff --git a/dom/animation/ComputedTimingFunction.cpp b/dom/animation/ComputedTimingFunction.cpp index 954abb1ed91b..17b8de323d8b 100644 --- a/dom/animation/ComputedTimingFunction.cpp +++ b/dom/animation/ComputedTimingFunction.cpp @@ -167,7 +167,7 @@ int32_t ComputedTimingFunction::Compare( return 0; } -void ComputedTimingFunction::AppendToString(nsAString& aResult) const { +void ComputedTimingFunction::AppendToString(nsACString& aResult) const { nsTimingFunction timing; switch (mType) { case Type::CubicBezier: diff --git a/dom/animation/ComputedTimingFunction.h b/dom/animation/ComputedTimingFunction.h index 488d5cc4bade..8490854ff926 100644 --- a/dom/animation/ComputedTimingFunction.h +++ b/dom/animation/ComputedTimingFunction.h @@ -94,7 +94,7 @@ class ComputedTimingFunction { return !(*this == aOther); } int32_t Compare(const ComputedTimingFunction& aRhs) const; - void AppendToString(nsAString& aResult) const; + void AppendToString(nsACString& aResult) const; static double GetPortion(const Maybe& aFunction, double aPortion, BeforeFlag aBeforeFlag) { diff --git a/dom/animation/KeyframeEffect.cpp b/dom/animation/KeyframeEffect.cpp index ce11a5d54d99..90ffb572cb33 100644 --- a/dom/animation/KeyframeEffect.cpp +++ b/dom/animation/KeyframeEffect.cpp @@ -1037,12 +1037,11 @@ void DumpAnimationProperties( for (auto& p : aAnimationProperties) { printf("%s\n", nsCString(nsCSSProps::GetStringValue(p.mProperty)).get()); for (auto& s : p.mSegments) { - nsString fromValue, toValue; + nsAutoCString fromValue, toValue; s.mFromValue.SerializeSpecifiedValue(p.mProperty, aRawSet, fromValue); s.mToValue.SerializeSpecifiedValue(p.mProperty, aRawSet, toValue); - printf(" %f..%f: %s..%s\n", s.mFromKey, s.mToKey, - NS_ConvertUTF16toUTF8(fromValue).get(), - NS_ConvertUTF16toUTF8(toValue).get()); + printf(" %f..%f: %s..%s\n", s.mFromKey, s.mToKey, fromValue.get(), + toValue.get()); } } } @@ -1131,7 +1130,7 @@ static void CreatePropertyValue( aResult.mOffset = aOffset; if (!aValue.IsNull()) { - nsString stringValue; + nsAutoCString stringValue; aValue.SerializeSpecifiedValue(aProperty, aRawSet, stringValue); aResult.mValue.Construct(stringValue); } @@ -1140,7 +1139,7 @@ static void CreatePropertyValue( aResult.mEasing.Construct(); aTimingFunction->AppendToString(aResult.mEasing.Value()); } else { - aResult.mEasing.Construct(u"linear"_ns); + aResult.mEasing.Construct("linear"_ns); } aResult.mComposite = aComposite; @@ -1298,7 +1297,7 @@ void KeyframeEffect::GetKeyframes(JSContext* aCx, nsTArray& aResult, JS::Rooted keyframeObject(aCx, &keyframeJSValue.toObject()); for (const PropertyValuePair& propertyValue : keyframe.mPropertyValues) { - nsAutoString stringValue; + nsAutoCString stringValue; // Don't serialize the custom properties for this keyframe. if (propertyValue.mProperty == nsCSSPropertyID::eCSSPropertyExtra_variable) { @@ -1338,7 +1337,7 @@ void KeyframeEffect::GetKeyframes(JSContext* aCx, nsTArray& aResult, } JS::Rooted value(aCx); - if (!ToJSValue(aCx, stringValue, &value) || + if (!NonVoidUTF8StringToJsval(aCx, stringValue, &value) || !JS_DefineProperty(aCx, keyframeObject, name, value, JSPROP_ENUMERATE)) { aRv.Throw(NS_ERROR_FAILURE); diff --git a/dom/animation/KeyframeUtils.cpp b/dom/animation/KeyframeUtils.cpp index e138a5d0c88a..acb1a8f25726 100644 --- a/dom/animation/KeyframeUtils.cpp +++ b/dom/animation/KeyframeUtils.cpp @@ -60,7 +60,7 @@ enum class ListAllowance { eDisallow, eAllow }; */ struct PropertyValuesPair { nsCSSPropertyID mProperty; - nsTArray mValues; + nsTArray mValues; }; /** @@ -153,13 +153,13 @@ static bool GetPropertyValuesPairs(JSContext* aCx, static bool AppendStringOrStringSequenceToArray(JSContext* aCx, JS::Handle aValue, ListAllowance aAllowLists, - nsTArray& aValues); + nsTArray& aValues); -static bool AppendValueAsString(JSContext* aCx, nsTArray& aValues, +static bool AppendValueAsString(JSContext* aCx, nsTArray& aValues, JS::Handle aValue); static Maybe MakePropertyValuePair( - nsCSSPropertyID aProperty, const nsAString& aStringValue, + nsCSSPropertyID aProperty, const nsACString& aStringValue, dom::Document* aDocument); static bool HasValidOffsets(const nsTArray& aKeyframes); @@ -574,7 +574,7 @@ static bool GetPropertyValuesPairs(JSContext* aCx, static bool AppendStringOrStringSequenceToArray(JSContext* aCx, JS::Handle aValue, ListAllowance aAllowLists, - nsTArray& aValues) { + nsTArray& aValues) { if (aAllowLists == ListAllowance::eAllow && aValue.isObject()) { // The value is an object, and we want to allow lists; convert // aValue to (DOMString or sequence). @@ -613,17 +613,17 @@ static bool AppendStringOrStringSequenceToArray(JSContext* aCx, /** * Converts aValue to DOMString and appends it to aValues. */ -static bool AppendValueAsString(JSContext* aCx, nsTArray& aValues, +static bool AppendValueAsString(JSContext* aCx, nsTArray& aValues, JS::Handle aValue) { return ConvertJSValueToString(aCx, aValue, dom::eStringify, dom::eStringify, *aValues.AppendElement()); } static void ReportInvalidPropertyValueToConsole( - nsCSSPropertyID aProperty, const nsAString& aInvalidPropertyValue, + nsCSSPropertyID aProperty, const nsACString& aInvalidPropertyValue, dom::Document* aDoc) { AutoTArray params; - params.AppendElement(aInvalidPropertyValue); + params.AppendElement(NS_ConvertUTF8toUTF16(aInvalidPropertyValue)); CopyASCIItoUTF16(nsCSSProps::GetStringValue(aProperty), *params.AppendElement()); nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "Animation"_ns, @@ -642,7 +642,7 @@ static void ReportInvalidPropertyValueToConsole( * an invalid property value. */ static Maybe MakePropertyValuePair( - nsCSSPropertyID aProperty, const nsAString& aStringValue, + nsCSSPropertyID aProperty, const nsACString& aStringValue, dom::Document* aDocument) { MOZ_ASSERT(aDocument); Maybe result; @@ -1017,7 +1017,7 @@ static void GetKeyframeListFromPropertyIndexedKeyframe( size_t n = pair.mValues.Length() - 1; size_t i = 0; - for (const nsString& stringValue : pair.mValues) { + for (const nsCString& stringValue : pair.mValues) { // For single-valued lists, the single value should be added to a // keyframe with offset 1. double offset = n ? i++ / double(n) : 1; @@ -1097,7 +1097,7 @@ static void GetKeyframeListFromPropertyIndexedKeyframe( // This corresponds to step 5, "Otherwise," branch, substeps 7-11 of // https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument FallibleTArray> easings; - auto parseAndAppendEasing = [&](const nsString& easingString, + auto parseAndAppendEasing = [&](const nsACString& easingString, ErrorResult& aRv) { auto easing = TimingParams::ParseEasing(easingString, aRv); if (!aRv.Failed() && !easings.AppendElement(std::move(easing), fallible)) { @@ -1106,14 +1106,14 @@ static void GetKeyframeListFromPropertyIndexedKeyframe( }; auto& easing = keyframeDict.mEasing; - if (easing.IsString()) { - parseAndAppendEasing(easing.GetAsString(), aRv); + if (easing.IsUTF8String()) { + parseAndAppendEasing(easing.GetAsUTF8String(), aRv); if (aRv.Failed()) { aResult.Clear(); return; } } else { - for (const nsString& easingString : easing.GetAsStringSequence()) { + for (const auto& easingString : easing.GetAsUTF8StringSequence()) { parseAndAppendEasing(easingString, aRv); if (aRv.Failed()) { aResult.Clear(); diff --git a/dom/animation/TimingParams.cpp b/dom/animation/TimingParams.cpp index cc50a6920181..039d466438e5 100644 --- a/dom/animation/TimingParams.cpp +++ b/dom/animation/TimingParams.cpp @@ -190,11 +190,10 @@ TimingParams TimingParams::MergeOptionalEffectTiming( /* static */ Maybe TimingParams::ParseEasing( - const nsAString& aEasing, ErrorResult& aRv) { + const nsACString& aEasing, ErrorResult& aRv) { nsTimingFunction timingFunction; if (!ServoCSSParser::ParseEasing(aEasing, timingFunction)) { - aRv.ThrowTypeError( - NS_ConvertUTF16toUTF8(aEasing)); + aRv.ThrowTypeError(aEasing); return Nothing(); } diff --git a/dom/animation/TimingParams.h b/dom/animation/TimingParams.h index d06a249c9b4c..2bffc17c6790 100644 --- a/dom/animation/TimingParams.h +++ b/dom/animation/TimingParams.h @@ -119,7 +119,7 @@ struct TimingParams { } } - static Maybe ParseEasing(const nsAString& aEasing, + static Maybe ParseEasing(const nsACString& aEasing, ErrorResult& aRv); static StickyTimeDuration CalcActiveDuration( diff --git a/dom/base/AnonymousContent.cpp b/dom/base/AnonymousContent.cpp index 6bc3dc5c9e65..eadbba102642 100644 --- a/dom/base/AnonymousContent.cpp +++ b/dom/base/AnonymousContent.cpp @@ -179,7 +179,7 @@ bool AnonymousContent::WrapObject(JSContext* aCx, void AnonymousContent::GetComputedStylePropertyValue( const nsAString& aElementId, const nsACString& aPropertyName, - DOMString& aResult, ErrorResult& aRv) { + nsACString& aResult, ErrorResult& aRv) { Element* element = GetElementById(aElementId); if (!element) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); @@ -215,7 +215,7 @@ void AnonymousContent::SetStyle(const nsACString& aProperty, nsGenericHTMLElement* element = nsGenericHTMLElement::FromNode(mContentNode); nsCOMPtr declaration = element->Style(); - declaration->SetProperty(aProperty, aValue, u""_ns, IgnoreErrors()); + declaration->SetProperty(aProperty, aValue, ""_ns, IgnoreErrors()); } } // namespace mozilla::dom diff --git a/dom/base/AnonymousContent.h b/dom/base/AnonymousContent.h index d871f01816b4..5096605a1664 100644 --- a/dom/base/AnonymousContent.h +++ b/dom/base/AnonymousContent.h @@ -75,7 +75,7 @@ class AnonymousContent final { void GetComputedStylePropertyValue(const nsAString& aElementId, const nsACString& aPropertyName, - DOMString& aResult, ErrorResult& aRv); + nsACString& aResult, ErrorResult& aRv); void GetTargetIdForEvent(Event& aEvent, DOMString& aResult); diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp index d39626991364..cd046afbd8e4 100644 --- a/dom/base/DOMIntersectionObserver.cpp +++ b/dom/base/DOMIntersectionObserver.cpp @@ -189,15 +189,14 @@ DOMIntersectionObserver::CreateLazyLoadObserver(Document& aDocument) { return observer.forget(); } -bool DOMIntersectionObserver::SetRootMargin(const nsAString& aString) { +bool DOMIntersectionObserver::SetRootMargin(const nsACString& aString) { return Servo_IntersectionObserverRootMargin_Parse(&aString, &mRootMargin); } nsISupports* DOMIntersectionObserver::GetParentObject() const { return mOwner; } -void DOMIntersectionObserver::GetRootMargin(DOMString& aRetVal) { - nsString& retVal = aRetVal; - Servo_IntersectionObserverRootMargin_ToString(&mRootMargin, &retVal); +void DOMIntersectionObserver::GetRootMargin(nsACString& aRetVal) { + Servo_IntersectionObserverRootMargin_ToString(&mRootMargin, &aRetVal); } void DOMIntersectionObserver::GetThresholds(nsTArray& aRetVal) { diff --git a/dom/base/DOMIntersectionObserver.h b/dom/base/DOMIntersectionObserver.h index 2d159eb96411..627c41ecbe0d 100644 --- a/dom/base/DOMIntersectionObserver.h +++ b/dom/base/DOMIntersectionObserver.h @@ -110,7 +110,9 @@ class DOMIntersectionObserver final : public nsISupports, nsINode* GetRoot() const { return mRoot; } - void GetRootMargin(DOMString& aRetVal); + void GetRootMargin(nsACString&); + bool SetRootMargin(const nsACString&); + void GetThresholds(nsTArray& aRetVal); void Observe(Element& aTarget); void Unobserve(Element& aTarget); @@ -120,8 +122,6 @@ class DOMIntersectionObserver final : public nsISupports, void TakeRecords(nsTArray>& aRetVal); - bool SetRootMargin(const nsAString& aString); - void Update(Document* aDocument, DOMHighResTimeStamp time); MOZ_CAN_RUN_SCRIPT void Notify(); diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index e52ee13f1ec3..a3b63c2e46ff 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -8736,7 +8736,7 @@ void Document::DoNotifyPossibleTitleChange() { } already_AddRefed Document::MatchMedia( - const nsAString& aMediaQueryList, CallerType aCallerType) { + const nsACString& aMediaQueryList, CallerType aCallerType) { RefPtr result = new MediaQueryList(this, aMediaQueryList, aCallerType); diff --git a/dom/base/Document.h b/dom/base/Document.h index 509d4387921a..6ad82c390e98 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -2471,7 +2471,7 @@ class Document : public nsINode, * Support for window.matchMedia() */ - already_AddRefed MatchMedia(const nsAString& aMediaQueryList, + already_AddRefed MatchMedia(const nsACString& aMediaQueryList, CallerType aCallerType); LinkedList& MediaQueryLists() { return mDOMMediaQueryLists; } diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp index b956e8227b08..e0b059c4adfa 100644 --- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -562,7 +562,9 @@ void nsAttrValue::ToString(nsAString& aResult) const { aResult.Truncate(); MiscContainer* container = GetMiscContainer(); if (DeclarationBlock* decl = container->mValue.mCSSDeclaration) { - decl->ToString(aResult); + nsAutoCString result; + decl->ToString(result); + CopyUTF8toUTF16(result, aResult); } // This can be reached during parallel selector matching with attribute diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 262c334deb2c..db916f24cf65 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -2171,11 +2171,14 @@ nsDOMWindowUtils::GetVisitedDependentComputedStyle( ENSURE_SUCCESS(rv, rv.StealNSResult()); } + nsAutoCString result; + static_cast(decl.get())->SetExposeVisitedStyle(true); nsresult rv = - decl->GetPropertyValue(NS_ConvertUTF16toUTF8(aPropertyName), aResult); + decl->GetPropertyValue(NS_ConvertUTF16toUTF8(aPropertyName), result); static_cast(decl.get())->SetExposeVisitedStyle(false); + CopyUTF8toUTF16(result, aResult); return rv; } @@ -2822,8 +2825,10 @@ nsDOMWindowUtils::ComputeAnimationDistance(Element* aElement, return NS_ERROR_ILLEGAL_VALUE; } - AnimationValue v1 = AnimationValue::FromString(property, aValue1, aElement); - AnimationValue v2 = AnimationValue::FromString(property, aValue2, aElement); + AnimationValue v1 = AnimationValue::FromString( + property, NS_ConvertUTF16toUTF8(aValue1), aElement); + AnimationValue v2 = AnimationValue::FromString( + property, NS_ConvertUTF16toUTF8(aValue2), aElement); if (v1.IsNull() || v2.IsNull()) { return NS_ERROR_ILLEGAL_VALUE; } @@ -2883,8 +2888,10 @@ nsDOMWindowUtils::GetUnanimatedComputedStyle(Element* aElement, if (!aElement->GetComposedDoc()) { return NS_ERROR_FAILURE; } + nsAutoCString result; Servo_AnimationValue_Serialize(value, propertyID, - presShell->StyleSet()->RawSet(), &aResult); + presShell->StyleSet()->RawSet(), &result); + CopyUTF8toUTF16(result, aResult); return NS_OK; } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index a28b13305745..28412dc9592a 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -3539,7 +3539,7 @@ void nsGlobalWindowInner::CancelAnimationFrame(int32_t aHandle, } already_AddRefed nsGlobalWindowInner::MatchMedia( - const nsAString& aMediaQueryList, CallerType aCallerType, + const nsACString& aMediaQueryList, CallerType aCallerType, ErrorResult& aError) { ENSURE_ACTIVE_DOCUMENT(aError, nullptr); return mDoc->MatchMedia(aMediaQueryList, aCallerType); diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index e34f90c04d49..5d86b50c41cd 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -737,7 +737,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget, mozilla::ErrorResult& aError) override; mozilla::dom::VisualViewport* VisualViewport(); already_AddRefed MatchMedia( - const nsAString& aQuery, mozilla::dom::CallerType aCallerType, + const nsACString& aQuery, mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aError); nsScreen* GetScreen(mozilla::ErrorResult& aError); void MoveTo(int32_t aXPos, int32_t aYPos, diff --git a/dom/bindings/GenerateCSS2PropertiesWebIDL.py b/dom/bindings/GenerateCSS2PropertiesWebIDL.py index 8bb71f53ffda..0c6639263b64 100644 --- a/dom/bindings/GenerateCSS2PropertiesWebIDL.py +++ b/dom/bindings/GenerateCSS2PropertiesWebIDL.py @@ -10,8 +10,10 @@ import runpy # Generates a line of WebIDL with the given spelling of the property name # (whether camelCase, _underscorePrefixed, etc.) and the given array of # extended attributes. + + def generateLine(propName, extendedAttrs): - return " [%s] attribute [TreatNullAs=EmptyString] DOMString %s;\n" % ( + return " [%s] attribute [TreatNullAs=EmptyString] UTF8String %s;\n" % ( ", ".join(extendedAttrs), propName, ) diff --git a/dom/canvas/BasicRenderingContext2D.h b/dom/canvas/BasicRenderingContext2D.h index 6a36d685fcac..f8e389261911 100644 --- a/dom/canvas/BasicRenderingContext2D.h +++ b/dom/canvas/BasicRenderingContext2D.h @@ -66,13 +66,13 @@ class BasicRenderingContext2D { // CanvasFillStrokeStyles // virtual void GetStrokeStyle( - OwningStringOrCanvasGradientOrCanvasPattern& aValue) = 0; + OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue) = 0; virtual void SetStrokeStyle( - const StringOrCanvasGradientOrCanvasPattern& aValue) = 0; + const UTF8StringOrCanvasGradientOrCanvasPattern& aValue) = 0; virtual void GetFillStyle( - OwningStringOrCanvasGradientOrCanvasPattern& aValue) = 0; + OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue) = 0; virtual void SetFillStyle( - const StringOrCanvasGradientOrCanvasPattern& aValue) = 0; + const UTF8StringOrCanvasGradientOrCanvasPattern& aValue) = 0; virtual already_AddRefed CreateLinearGradient(double aX0, double aY0, double aX1, @@ -92,8 +92,8 @@ class BasicRenderingContext2D { virtual void SetShadowOffsetY(double aShadowOffsetY) = 0; virtual double ShadowBlur() = 0; virtual void SetShadowBlur(double aShadowBlur) = 0; - virtual void GetShadowColor(nsAString& aShadowColor) = 0; - virtual void SetShadowColor(const nsAString& aShadowColor) = 0; + virtual void GetShadowColor(nsACString& aShadowColor) = 0; + virtual void SetShadowColor(const nsACString& aShadowColor) = 0; // // CanvasRect diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index e9c124196eac..b2130bc1ab16 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1054,12 +1054,12 @@ void CanvasRenderingContext2D::RemoveShutdownObserver() { } } -void CanvasRenderingContext2D::SetStyleFromString(const nsAString& aStr, +void CanvasRenderingContext2D::SetStyleFromString(const nsACString& aStr, Style aWhichStyle) { MOZ_ASSERT(!aStr.IsVoid()); nscolor color; - if (!ParseColor(NS_ConvertUTF16toUTF8(aStr), &color)) { + if (!ParseColor(aStr, &color)) { return; } @@ -1067,30 +1067,31 @@ void CanvasRenderingContext2D::SetStyleFromString(const nsAString& aStr, } void CanvasRenderingContext2D::GetStyleAsUnion( - OwningStringOrCanvasGradientOrCanvasPattern& aValue, Style aWhichStyle) { + OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue, + Style aWhichStyle) { const ContextState& state = CurrentState(); if (state.patternStyles[aWhichStyle]) { aValue.SetAsCanvasPattern() = state.patternStyles[aWhichStyle]; } else if (state.gradientStyles[aWhichStyle]) { aValue.SetAsCanvasGradient() = state.gradientStyles[aWhichStyle]; } else { - StyleColorToString(state.colorStyles[aWhichStyle], aValue.SetAsString()); + StyleColorToString(state.colorStyles[aWhichStyle], + aValue.SetAsUTF8String()); } } // static void CanvasRenderingContext2D::StyleColorToString(const nscolor& aColor, - nsAString& aStr) { + nsACString& aStr) { + aStr.Truncate(); // We can't reuse the normal CSS color stringification code, // because the spec calls for a different algorithm for canvas. if (NS_GET_A(aColor) == 255) { - CopyUTF8toUTF16(nsPrintfCString("#%02x%02x%02x", NS_GET_R(aColor), - NS_GET_G(aColor), NS_GET_B(aColor)), - aStr); + aStr.AppendPrintf("#%02x%02x%02x", NS_GET_R(aColor), NS_GET_G(aColor), + NS_GET_B(aColor)); } else { - CopyUTF8toUTF16(nsPrintfCString("rgba(%d, %d, %d, ", NS_GET_R(aColor), - NS_GET_G(aColor), NS_GET_B(aColor)), - aStr); + aStr.AppendPrintf("rgba(%d, %d, %d, ", NS_GET_R(aColor), NS_GET_G(aColor), + NS_GET_B(aColor)); aStr.AppendFloat(nsStyleUtil::ColorComponentToFloat(NS_GET_A(aColor))); aStr.Append(')'); } @@ -1991,9 +1992,10 @@ void CanvasRenderingContext2D::GetMozCurrentTransformInverse( // void CanvasRenderingContext2D::SetStyleFromUnion( - const StringOrCanvasGradientOrCanvasPattern& aValue, Style aWhichStyle) { - if (aValue.IsString()) { - SetStyleFromString(aValue.GetAsString(), aWhichStyle); + const UTF8StringOrCanvasGradientOrCanvasPattern& aValue, + Style aWhichStyle) { + if (aValue.IsUTF8String()) { + SetStyleFromString(aValue.GetAsUTF8String(), aWhichStyle); return; } @@ -2193,9 +2195,9 @@ already_AddRefed CanvasRenderingContext2D::CreatePattern( // // shadows // -void CanvasRenderingContext2D::SetShadowColor(const nsAString& aShadowColor) { +void CanvasRenderingContext2D::SetShadowColor(const nsACString& aShadowColor) { nscolor color; - if (!ParseColor(NS_ConvertUTF16toUTF8(aShadowColor), &color)) { + if (!ParseColor(aShadowColor, &color)) { return; } @@ -2207,7 +2209,7 @@ void CanvasRenderingContext2D::SetShadowColor(const nsAString& aShadowColor) { // static already_AddRefed CreateDeclarationForServo( - nsCSSPropertyID aProperty, const nsAString& aPropertyValue, + nsCSSPropertyID aProperty, const nsACString& aPropertyValue, Document* aDocument) { ServoCSSParser::ParsingEnvironment env{aDocument->DefaultStyleAttrURLData(), aDocument->GetCompatibilityMode(), @@ -2234,13 +2236,13 @@ static already_AddRefed CreateDeclarationForServo( } static already_AddRefed CreateFontDeclarationForServo( - const nsAString& aFont, Document* aDocument) { + const nsACString& aFont, Document* aDocument) { return CreateDeclarationForServo(eCSSProperty_font, aFont, aDocument); } static already_AddRefed GetFontStyleForServo( - Element* aElement, const nsAString& aFont, PresShell* aPresShell, - nsAString& aOutUsedFont, ErrorResult& aError) { + Element* aElement, const nsACString& aFont, PresShell* aPresShell, + nsACString& aOutUsedFont, ErrorResult& aError) { RefPtr declarations = CreateFontDeclarationForServo(aFont, aPresShell->GetDocument()); if (!declarations) { @@ -2271,7 +2273,7 @@ static already_AddRefed GetFontStyleForServo( } } else { RefPtr declarations = - CreateFontDeclarationForServo(u"10px sans-serif"_ns, + CreateFontDeclarationForServo("10px sans-serif"_ns, aPresShell->GetDocument()); MOZ_ASSERT(declarations); @@ -2297,12 +2299,13 @@ static already_AddRefed GetFontStyleForServo( } static already_AddRefed -CreateFilterDeclarationForServo(const nsAString& aFilter, Document* aDocument) { +CreateFilterDeclarationForServo(const nsACString& aFilter, + Document* aDocument) { return CreateDeclarationForServo(eCSSProperty_filter, aFilter, aDocument); } static already_AddRefed ResolveFilterStyleForServo( - const nsAString& aFilterString, const ComputedStyle* aParentStyle, + const nsACString& aFilterString, const ComputedStyle* aParentStyle, PresShell* aPresShell, ErrorResult& aError) { RefPtr declarations = CreateFilterDeclarationForServo(aFilterString, aPresShell->GetDocument()); @@ -2326,7 +2329,7 @@ static already_AddRefed ResolveFilterStyleForServo( } bool CanvasRenderingContext2D::ParseFilter( - const nsAString& aString, StyleOwnedSlice& aFilterChain, + const nsACString& aString, StyleOwnedSlice& aFilterChain, ErrorResult& aError) { if (!mCanvasElement && !mDocShell) { NS_WARNING( @@ -2341,7 +2344,7 @@ bool CanvasRenderingContext2D::ParseFilter( return false; } - nsAutoString usedFont; // unused + nsAutoCString usedFont; // unused RefPtr parentStyle = GetFontStyleForServo( mCanvasElement, GetFont(), presShell, usedFont, aError); @@ -2359,7 +2362,7 @@ bool CanvasRenderingContext2D::ParseFilter( return true; } -void CanvasRenderingContext2D::SetFilter(const nsAString& aFilter, +void CanvasRenderingContext2D::SetFilter(const nsACString& aFilter, ErrorResult& aError) { StyleOwnedSlice filterChain; if (ParseFilter(aFilter, filterChain, aError)) { @@ -3182,12 +3185,12 @@ void CanvasRenderingContext2D::TransformWillUpdate() { // text // -void CanvasRenderingContext2D::SetFont(const nsAString& aFont, +void CanvasRenderingContext2D::SetFont(const nsACString& aFont, ErrorResult& aError) { SetFontInternal(aFont, aError); } -bool CanvasRenderingContext2D::SetFontInternal(const nsAString& aFont, +bool CanvasRenderingContext2D::SetFontInternal(const nsACString& aFont, ErrorResult& aError) { /* * If font is defined with relative units (e.g. ems) and the parent @@ -3210,7 +3213,7 @@ bool CanvasRenderingContext2D::SetFontInternal(const nsAString& aFont, return false; } - nsString usedFont; + nsCString usedFont; RefPtr sc = GetFontStyleForServo(mCanvasElement, aFont, presShell, usedFont, aError); if (!sc) { @@ -4010,7 +4013,7 @@ gfxFontGroup* CanvasRenderingContext2D::GetCurrentFontStyle() { // use lazy initilization for the font group since it's rather expensive if (!CurrentState().fontGroup) { ErrorResult err; - constexpr auto kDefaultFontStyle = u"10px sans-serif"_ns; + constexpr auto kDefaultFontStyle = "10px sans-serif"_ns; static float kDefaultFontSize = 10.0; RefPtr presShell = GetPresShell(); bool fontUpdated = SetFontInternal(kDefaultFontStyle, err); diff --git a/dom/canvas/CanvasRenderingContext2D.h b/dom/canvas/CanvasRenderingContext2D.h index 592821d0fb89..ea020a61768e 100644 --- a/dom/canvas/CanvasRenderingContext2D.h +++ b/dom/canvas/CanvasRenderingContext2D.h @@ -46,8 +46,8 @@ typedef HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOr CanvasImageSource; class ImageBitmap; class ImageData; -class StringOrCanvasGradientOrCanvasPattern; -class OwningStringOrCanvasGradientOrCanvasPattern; +class UTF8StringOrCanvasGradientOrCanvasPattern; +class OwningUTF8StringOrCanvasGradientOrCanvasPattern; class TextMetrics; class CanvasGradient; class CanvasPath; @@ -130,22 +130,22 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, mozilla::ErrorResult& aError) override; void GetStrokeStyle( - OwningStringOrCanvasGradientOrCanvasPattern& aValue) override { + OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue) override { GetStyleAsUnion(aValue, Style::STROKE); } void SetStrokeStyle( - const StringOrCanvasGradientOrCanvasPattern& aValue) override { + const UTF8StringOrCanvasGradientOrCanvasPattern& aValue) override { SetStyleFromUnion(aValue, Style::STROKE); } void GetFillStyle( - OwningStringOrCanvasGradientOrCanvasPattern& aValue) override { + OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue) override { GetStyleAsUnion(aValue, Style::FILL); } void SetFillStyle( - const StringOrCanvasGradientOrCanvasPattern& aValue) override { + const UTF8StringOrCanvasGradientOrCanvasPattern& aValue) override { SetStyleFromUnion(aValue, Style::FILL); } @@ -179,14 +179,14 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, } } - void GetShadowColor(nsAString& aShadowColor) override { + void GetShadowColor(nsACString& aShadowColor) override { StyleColorToString(CurrentState().shadowColor, aShadowColor); } - void GetFilter(nsAString& aFilter) { aFilter = CurrentState().filterString; } + void GetFilter(nsACString& aFilter) { aFilter = CurrentState().filterString; } - void SetShadowColor(const nsAString& aShadowColor) override; - void SetFilter(const nsAString& aFilter, mozilla::ErrorResult& aError); + void SetShadowColor(const nsACString& aShadowColor) override; + void SetFilter(const nsACString& aFilter, mozilla::ErrorResult& aError); void ClearRect(double aX, double aY, double aW, double aH) override; void FillRect(double aX, double aY, double aW, double aH) override; void StrokeRect(double aX, double aY, double aW, double aH) override; @@ -277,9 +277,9 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, } } - void GetFont(nsAString& aFont) { aFont = GetFont(); } + void GetFont(nsACString& aFont) { aFont = GetFont(); } - void SetFont(const nsAString& aFont, mozilla::ErrorResult& aError); + void SetFont(const nsACString& aFont, mozilla::ErrorResult& aError); void GetTextAlign(nsAString& aTextAlign); void SetTextAlign(const nsAString& aTextAlign); void GetTextBaseline(nsAString& aTextBaseline); @@ -371,9 +371,9 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, void SetLineDashOffset(double aOffset) override; double LineDashOffset() const override; - void GetMozTextStyle(nsAString& aMozTextStyle) { GetFont(aMozTextStyle); } + void GetMozTextStyle(nsACString& aMozTextStyle) { GetFont(aMozTextStyle); } - void SetMozTextStyle(const nsAString& aMozTextStyle, + void SetMozTextStyle(const nsACString& aMozTextStyle, mozilla::ErrorResult& aError) { SetFont(aMozTextStyle, aError); } @@ -543,9 +543,10 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, void SetTransformInternal(const mozilla::gfx::Matrix& aTransform); // Some helpers. Doesn't modify a color on failure. - void SetStyleFromUnion(const StringOrCanvasGradientOrCanvasPattern& aValue, - Style aWhichStyle); - void SetStyleFromString(const nsAString& aStr, Style aWhichStyle); + void SetStyleFromUnion( + const UTF8StringOrCanvasGradientOrCanvasPattern& aValue, + Style aWhichStyle); + void SetStyleFromString(const nsACString& aStr, Style aWhichStyle); void SetStyleFromGradient(CanvasGradient& aGradient, Style aWhichStyle) { CurrentState().SetGradientStyle(aWhichStyle, &aGradient); @@ -555,21 +556,21 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, CurrentState().SetPatternStyle(aWhichStyle, &aPattern); } - void GetStyleAsUnion(OwningStringOrCanvasGradientOrCanvasPattern& aValue, + void GetStyleAsUnion(OwningUTF8StringOrCanvasGradientOrCanvasPattern& aValue, Style aWhichStyle); // Returns whether a color was successfully parsed. bool ParseColor(const nsACString& aString, nscolor* aColor); - static void StyleColorToString(const nscolor& aColor, nsAString& aStr); + static void StyleColorToString(const nscolor& aColor, nsACString& aStr); // Returns whether a filter was successfully parsed. - bool ParseFilter(const nsAString& aString, + bool ParseFilter(const nsACString& aString, StyleOwnedSlice& aFilterChain, ErrorResult& aError); // Returns whether the font was successfully updated. - bool SetFontInternal(const nsAString& aFont, mozilla::ErrorResult& aError); + bool SetFontInternal(const nsACString& aFont, mozilla::ErrorResult& aError); // Clears the target and updates mOpaque based on mOpaqueAttrValue and // mContextAttributesHasAlpha. @@ -682,7 +683,7 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, mozilla::gfx::Rect aDest, mozilla::gfx::Rect aSrc, gfx::IntSize aImgSize); - nsString& GetFont() { + nsCString& GetFont() { /* will initilize the value if not set, else does nothing */ GetCurrentFontStyle(); @@ -931,7 +932,7 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, EnumeratedArray> patternStyles; EnumeratedArray colorStyles; - nsString font; + nsCString font; TextAlign textAlign = TextAlign::START; TextBaseline textBaseline = TextBaseline::ALPHABETIC; @@ -952,7 +953,7 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal, mozilla::gfx::CapStyle lineCap = mozilla::gfx::CapStyle::BUTT; mozilla::gfx::JoinStyle lineJoin = mozilla::gfx::JoinStyle::MITER_OR_BEVEL; - nsString filterString = nsString(u"none"); + nsCString filterString{"none"}; StyleOwnedSlice filterChain; // RAII object that we obtain when we start to observer SVG filter elements // for rendering changes. When released we stop observing the SVG elements. diff --git a/dom/chrome-webidl/InspectorUtils.webidl b/dom/chrome-webidl/InspectorUtils.webidl index ce2243ae6a2e..52fdb176f0b8 100644 --- a/dom/chrome-webidl/InspectorUtils.webidl +++ b/dom/chrome-webidl/InspectorUtils.webidl @@ -23,8 +23,8 @@ namespace InspectorUtils { unsigned long getRelativeRuleLine(CSSRule rule); boolean hasRulesModifiedByCSSOM(CSSStyleSheet sheet); unsigned long getSelectorCount(CSSStyleRule rule); - [Throws] DOMString getSelectorText(CSSStyleRule rule, - unsigned long selectorIndex); + [Throws] UTF8String getSelectorText(CSSStyleRule rule, + unsigned long selectorIndex); [Throws] unsigned long long getSpecificity(CSSStyleRule rule, unsigned long selectorIndex); [Throws] boolean selectorMatchesElement( diff --git a/dom/html/HTMLFontElement.cpp b/dom/html/HTMLFontElement.cpp index 5db9f4344323..78937848d28d 100644 --- a/dom/html/HTMLFontElement.cpp +++ b/dom/html/HTMLFontElement.cpp @@ -54,7 +54,7 @@ void HTMLFontElement::MapAttributesIntoRule( const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::face); if (value && value->Type() == nsAttrValue::eString && !value->IsEmptyString()) { - aDecls.SetFontFamily(value->GetStringValue()); + aDecls.SetFontFamily(NS_ConvertUTF16toUTF8(value->GetStringValue())); } } // size: int diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 764ce82010dd..d2a36b7c7681 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -793,7 +793,8 @@ bool HTMLLinkElement::CheckPreloadAttrs(const nsAttrValue& aAs, // Check if media attribute is valid. if (!aMedia.IsEmpty()) { - RefPtr mediaList = MediaList::Create(aMedia); + RefPtr mediaList = + MediaList::Create(NS_ConvertUTF16toUTF8(aMedia)); if (!mediaList->Matches(*aDocument)) { return false; } diff --git a/dom/html/HTMLSourceElement.cpp b/dom/html/HTMLSourceElement.cpp index 477b76fd3312..d6a6a10e4817 100644 --- a/dom/html/HTMLSourceElement.cpp +++ b/dom/html/HTMLSourceElement.cpp @@ -53,17 +53,18 @@ bool HTMLSourceElement::WouldMatchMediaForDocument(const nsAString& aMedia, return true; } - RefPtr mediaList = MediaList::Create(aMedia); + RefPtr mediaList = + MediaList::Create(NS_ConvertUTF16toUTF8(aMedia)); return mediaList->Matches(*aDocument); } void HTMLSourceElement::UpdateMediaList(const nsAttrValue* aValue) { mMediaList = nullptr; - nsString mediaStr; - if (!aValue || (mediaStr = aValue->GetStringValue()).IsEmpty()) { + if (!aValue) { return; } + NS_ConvertUTF16toUTF8 mediaStr(aValue->GetStringValue()); mMediaList = MediaList::Create(mediaStr); } diff --git a/dom/mathml/MathMLElement.cpp b/dom/mathml/MathMLElement.cpp index 1734d4eedd36..f711ac866c38 100644 --- a/dom/mathml/MathMLElement.cpp +++ b/dom/mathml/MathMLElement.cpp @@ -541,7 +541,7 @@ void MathMLElement::MapMathMLAttributesInto( } if (value && value->Type() == nsAttrValue::eString && !aDecls.PropertyIsSet(eCSSProperty_font_family)) { - aDecls.SetFontFamily(value->GetStringValue()); + aDecls.SetFontFamily(NS_ConvertUTF16toUTF8(value->GetStringValue())); } // fontstyle diff --git a/dom/smil/SMILCSSValueType.cpp b/dom/smil/SMILCSSValueType.cpp index b7048b81228f..be2048b4e9c8 100644 --- a/dom/smil/SMILCSSValueType.cpp +++ b/dom/smil/SMILCSSValueType.cpp @@ -425,7 +425,8 @@ static ServoAnimationValues ValueFromStringHelper(nsCSSPropertyID aPropID, ServoCSSParser::ParsingEnvironment env = ServoCSSParser::GetParsingEnvironment(doc); RefPtr servoDeclarationBlock = - ServoCSSParser::ParseProperty(aPropID, aString, env, + ServoCSSParser::ParseProperty(aPropID, NS_ConvertUTF16toUTF8(aString), + env, ParsingMode::AllowUnitlessLength | ParsingMode::AllowAllNumericValues); if (!servoDeclarationBlock) { diff --git a/dom/webidl/AnimationEffect.webidl b/dom/webidl/AnimationEffect.webidl index 7cd50ce6f01a..2a20f941d760 100644 --- a/dom/webidl/AnimationEffect.webidl +++ b/dom/webidl/AnimationEffect.webidl @@ -33,7 +33,7 @@ dictionary EffectTiming { unrestricted double iterations = 1.0; (unrestricted double or DOMString) duration = "auto"; PlaybackDirection direction = "normal"; - DOMString easing = "linear"; + UTF8String easing = "linear"; }; dictionary OptionalEffectTiming { @@ -44,7 +44,7 @@ dictionary OptionalEffectTiming { unrestricted double iterations; (unrestricted double or DOMString) duration; PlaybackDirection direction; - DOMString easing; + UTF8String easing; }; dictionary ComputedEffectTiming : EffectTiming { diff --git a/dom/webidl/AnonymousContent.webidl b/dom/webidl/AnonymousContent.webidl index 14b803375a16..afada1091acd 100644 --- a/dom/webidl/AnonymousContent.webidl +++ b/dom/webidl/AnonymousContent.webidl @@ -83,7 +83,7 @@ interface AnonymousContent { * anonymous content. */ [Throws] - DOMString? getComputedStylePropertyValue(DOMString elementId, + UTF8String? getComputedStylePropertyValue(DOMString elementId, UTF8String propertyName); /** diff --git a/dom/webidl/BaseKeyframeTypes.webidl b/dom/webidl/BaseKeyframeTypes.webidl index 39575f3fec95..a6e94b1e3ab8 100644 --- a/dom/webidl/BaseKeyframeTypes.webidl +++ b/dom/webidl/BaseKeyframeTypes.webidl @@ -31,14 +31,14 @@ enum CompositeOperationOrAuto { "replace", "add", "accumulate", "auto" }; [GenerateInit] dictionary BasePropertyIndexedKeyframe { (double? or sequence) offset = []; - (DOMString or sequence) easing = []; + (UTF8String or sequence) easing = []; (CompositeOperationOrAuto or sequence) composite = []; }; [GenerateInit] dictionary BaseKeyframe { double? offset = null; - DOMString easing = "linear"; + UTF8String easing = "linear"; [Pref="dom.animations-api.compositing.enabled"] CompositeOperationOrAuto composite = "auto"; diff --git a/dom/webidl/CSSConditionRule.webidl b/dom/webidl/CSSConditionRule.webidl index c55d8b48862c..5ab3ae1dcda3 100644 --- a/dom/webidl/CSSConditionRule.webidl +++ b/dom/webidl/CSSConditionRule.webidl @@ -11,5 +11,5 @@ [Exposed=Window] interface CSSConditionRule : CSSGroupingRule { [SetterThrows] - attribute DOMString conditionText; + attribute UTF8String conditionText; }; diff --git a/dom/webidl/CSSCounterStyleRule.webidl b/dom/webidl/CSSCounterStyleRule.webidl index 27c63d95dc7f..a7678f0fd7eb 100644 --- a/dom/webidl/CSSCounterStyleRule.webidl +++ b/dom/webidl/CSSCounterStyleRule.webidl @@ -11,14 +11,14 @@ [Exposed=Window] interface CSSCounterStyleRule : CSSRule { attribute DOMString name; - attribute DOMString system; - attribute DOMString symbols; - attribute DOMString additiveSymbols; - attribute DOMString negative; - attribute DOMString prefix; - attribute DOMString suffix; - attribute DOMString range; - attribute DOMString pad; - attribute DOMString speakAs; - attribute DOMString fallback; + attribute UTF8String system; + attribute UTF8String symbols; + attribute UTF8String additiveSymbols; + attribute UTF8String negative; + attribute UTF8String prefix; + attribute UTF8String suffix; + attribute UTF8String range; + attribute UTF8String pad; + attribute UTF8String speakAs; + attribute UTF8String fallback; }; diff --git a/dom/webidl/CSSFontFeatureValuesRule.webidl b/dom/webidl/CSSFontFeatureValuesRule.webidl index 9f017acdd6e5..0eb6364d438d 100644 --- a/dom/webidl/CSSFontFeatureValuesRule.webidl +++ b/dom/webidl/CSSFontFeatureValuesRule.webidl @@ -12,7 +12,7 @@ [Exposed=Window] interface CSSFontFeatureValuesRule : CSSRule { [SetterThrows] - attribute DOMString fontFamily; + attribute UTF8String fontFamily; // Not yet implemented // readonly attribute CSSFontFeatureValuesMap annotation; @@ -26,5 +26,5 @@ interface CSSFontFeatureValuesRule : CSSRule { partial interface CSSFontFeatureValuesRule { // Gecko addition? [SetterThrows] - attribute DOMString valueText; + attribute UTF8String valueText; }; diff --git a/dom/webidl/CSSGroupingRule.webidl b/dom/webidl/CSSGroupingRule.webidl index cc993ad99292..5cf1d068e98b 100644 --- a/dom/webidl/CSSGroupingRule.webidl +++ b/dom/webidl/CSSGroupingRule.webidl @@ -12,7 +12,7 @@ interface CSSGroupingRule : CSSRule { [SameObject] readonly attribute CSSRuleList cssRules; [Throws] - unsigned long insertRule(DOMString rule, optional unsigned long index = 0); + unsigned long insertRule(UTF8String rule, optional unsigned long index = 0); [Throws] void deleteRule(unsigned long index); }; diff --git a/dom/webidl/CSSKeyframeRule.webidl b/dom/webidl/CSSKeyframeRule.webidl index 0c0e5eb0351a..6647b3fb2c7f 100644 --- a/dom/webidl/CSSKeyframeRule.webidl +++ b/dom/webidl/CSSKeyframeRule.webidl @@ -10,6 +10,6 @@ // https://drafts.csswg.org/css-animations/#interface-csskeyframerule [Exposed=Window] interface CSSKeyframeRule : CSSRule { - attribute DOMString keyText; + attribute UTF8String keyText; [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style; }; diff --git a/dom/webidl/CSSRule.webidl b/dom/webidl/CSSRule.webidl index 7ec418d7d848..57713c43bfa5 100644 --- a/dom/webidl/CSSRule.webidl +++ b/dom/webidl/CSSRule.webidl @@ -26,7 +26,7 @@ interface CSSRule { // const unsigned short MARGIN_RULE = 9; const unsigned short NAMESPACE_RULE = 10; readonly attribute unsigned short type; - attribute DOMString cssText; + attribute UTF8String cssText; readonly attribute CSSRule? parentRule; readonly attribute CSSStyleSheet? parentStyleSheet; }; diff --git a/dom/webidl/CSSStyleDeclaration.webidl b/dom/webidl/CSSStyleDeclaration.webidl index 80b50d0cf3cf..39d988c174e0 100644 --- a/dom/webidl/CSSStyleDeclaration.webidl +++ b/dom/webidl/CSSStyleDeclaration.webidl @@ -13,7 +13,7 @@ Exposed=Window] interface CSSStyleDeclaration { [CEReactions, SetterNeedsSubjectPrincipal=NonSystem, SetterThrows] - attribute DOMString cssText; + attribute UTF8String cssText; readonly attribute unsigned long length; getter UTF8String item(unsigned long index); @@ -22,12 +22,12 @@ interface CSSStyleDeclaration { sequence getCSSImageURLs(UTF8String property); [Throws] - DOMString getPropertyValue(UTF8String property); - DOMString getPropertyPriority(UTF8String property); + UTF8String getPropertyValue(UTF8String property); + UTF8String getPropertyPriority(UTF8String property); [CEReactions, NeedsSubjectPrincipal=NonSystem, Throws] - void setProperty(UTF8String property, [TreatNullAs=EmptyString] UTF8String value, optional [TreatNullAs=EmptyString] DOMString priority = ""); + void setProperty(UTF8String property, [TreatNullAs=EmptyString] UTF8String value, optional [TreatNullAs=EmptyString] UTF8String priority = ""); [CEReactions, Throws] - DOMString removeProperty(UTF8String property); + UTF8String removeProperty(UTF8String property); readonly attribute CSSRule? parentRule; }; diff --git a/dom/webidl/CSSStyleRule.webidl b/dom/webidl/CSSStyleRule.webidl index 8cf54327f429..739bd958bb20 100644 --- a/dom/webidl/CSSStyleRule.webidl +++ b/dom/webidl/CSSStyleRule.webidl @@ -10,6 +10,6 @@ // https://drafts.csswg.org/cssom/#the-cssstylerule-interface [Exposed=Window] interface CSSStyleRule : CSSRule { - attribute DOMString selectorText; + attribute UTF8String selectorText; [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style; }; diff --git a/dom/webidl/CSSStyleSheet.webidl b/dom/webidl/CSSStyleSheet.webidl index b02c8a3e0d02..b93589be489a 100644 --- a/dom/webidl/CSSStyleSheet.webidl +++ b/dom/webidl/CSSStyleSheet.webidl @@ -15,7 +15,7 @@ enum CSSStyleSheetParsingMode { }; dictionary CSSStyleSheetInit { - (MediaList or DOMString) media = ""; + (MediaList or UTF8String) media = ""; boolean disabled = false; UTF8String baseURL; }; @@ -31,7 +31,7 @@ interface CSSStyleSheet : StyleSheet { [ChromeOnly, BinaryName="parsingModeDOM"] readonly attribute CSSStyleSheetParsingMode parsingMode; [Throws, NeedsSubjectPrincipal] - unsigned long insertRule(DOMString rule, optional unsigned long index = 0); + unsigned long insertRule(UTF8String rule, optional unsigned long index = 0); [Throws, NeedsSubjectPrincipal] void deleteRule(unsigned long index); [Throws, Pref="layout.css.constructable-stylesheets.enabled"] @@ -45,5 +45,5 @@ interface CSSStyleSheet : StyleSheet { [Throws, NeedsSubjectPrincipal, BinaryName="deleteRule"] void removeRule(optional unsigned long index = 0); [Throws, NeedsSubjectPrincipal] - long addRule(optional DOMString selector = "undefined", optional DOMString style = "undefined", optional unsigned long index); + long addRule(optional UTF8String selector = "undefined", optional UTF8String style = "undefined", optional unsigned long index); }; diff --git a/dom/webidl/CanvasRenderingContext2D.webidl b/dom/webidl/CanvasRenderingContext2D.webidl index f65d1aae6843..5a3bcc2dbdb9 100644 --- a/dom/webidl/CanvasRenderingContext2D.webidl +++ b/dom/webidl/CanvasRenderingContext2D.webidl @@ -50,7 +50,7 @@ interface CanvasRenderingContext2D { attribute object mozCurrentTransformInverse; [SetterThrows] - attribute DOMString mozTextStyle; + attribute UTF8String mozTextStyle; // image smoothing mode -- if disabled, images won't be smoothed // if scaled. @@ -183,8 +183,8 @@ interface mixin CanvasImageSmoothing { interface mixin CanvasFillStrokeStyles { // colors and styles (see also the CanvasPathDrawingStyles interface) - attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black) - attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black) + attribute (UTF8String or CanvasGradient or CanvasPattern) strokeStyle; // (default black) + attribute (UTF8String or CanvasGradient or CanvasPattern) fillStyle; // (default black) [NewObject] CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1); [NewObject, Throws] @@ -200,12 +200,12 @@ interface mixin CanvasShadowStyles { attribute double shadowOffsetY; // (default 0) [LenientFloat] attribute double shadowBlur; // (default 0) - attribute DOMString shadowColor; // (default transparent black) + attribute UTF8String shadowColor; // (default transparent black) }; interface mixin CanvasFilters { [Pref="canvas.filters.enabled", SetterThrows] - attribute DOMString filter; // (default empty string = no filter) + attribute UTF8String filter; // (default empty string = no filter) }; interface mixin CanvasRect { @@ -295,7 +295,7 @@ interface mixin CanvasPathDrawingStyles { interface mixin CanvasTextDrawingStyles { // text [SetterThrows] - attribute DOMString font; // (default 10px sans-serif) + attribute UTF8String font; // (default 10px sans-serif) attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start") attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic") }; diff --git a/dom/webidl/FontFace.webidl b/dom/webidl/FontFace.webidl index e93e8d02b4f3..a8ba31014ea5 100644 --- a/dom/webidl/FontFace.webidl +++ b/dom/webidl/FontFace.webidl @@ -13,14 +13,14 @@ typedef (ArrayBuffer or ArrayBufferView) BinaryData; dictionary FontFaceDescriptors { - DOMString style = "normal"; - DOMString weight = "normal"; - DOMString stretch = "normal"; - DOMString unicodeRange = "U+0-10FFFF"; - DOMString variant = "normal"; - DOMString featureSettings = "normal"; - DOMString variationSettings = "normal"; - DOMString display = "auto"; + UTF8String style = "normal"; + UTF8String weight = "normal"; + UTF8String stretch = "normal"; + UTF8String unicodeRange = "U+0-10FFFF"; + UTF8String variant = "normal"; + UTF8String featureSettings = "normal"; + UTF8String variationSettings = "normal"; + UTF8String display = "auto"; }; enum FontFaceLoadStatus { "unloaded", "loading", "loaded", "error" }; @@ -31,19 +31,19 @@ enum FontFaceLoadStatus { "unloaded", "loading", "loaded", "error" }; Exposed=Window] interface FontFace { [Throws] - constructor(DOMString family, - (DOMString or BinaryData) source, + constructor(UTF8String family, + (UTF8String or BinaryData) source, optional FontFaceDescriptors descriptors = {}); - [SetterThrows] attribute DOMString family; - [SetterThrows] attribute DOMString style; - [SetterThrows] attribute DOMString weight; - [SetterThrows] attribute DOMString stretch; - [SetterThrows] attribute DOMString unicodeRange; - [SetterThrows] attribute DOMString variant; - [SetterThrows] attribute DOMString featureSettings; - [SetterThrows, Pref="layout.css.font-variations.enabled"] attribute DOMString variationSettings; - [SetterThrows, Pref="layout.css.font-display.enabled"] attribute DOMString display; + [SetterThrows] attribute UTF8String family; + [SetterThrows] attribute UTF8String style; + [SetterThrows] attribute UTF8String weight; + [SetterThrows] attribute UTF8String stretch; + [SetterThrows] attribute UTF8String unicodeRange; + [SetterThrows] attribute UTF8String variant; + [SetterThrows] attribute UTF8String featureSettings; + [SetterThrows, Pref="layout.css.font-variations.enabled"] attribute UTF8String variationSettings; + [SetterThrows, Pref="layout.css.font-display.enabled"] attribute UTF8String display; readonly attribute FontFaceLoadStatus status; diff --git a/dom/webidl/FontFaceSet.webidl b/dom/webidl/FontFaceSet.webidl index d6c8cabc2a35..0d702437fe1b 100644 --- a/dom/webidl/FontFaceSet.webidl +++ b/dom/webidl/FontFaceSet.webidl @@ -52,11 +52,11 @@ interface FontFaceSet : EventTarget { // check and start loads if appropriate // and fulfill promise when all loads complete - [NewObject] Promise> load(DOMString font, optional DOMString text = " "); + [NewObject] Promise> load(UTF8String font, optional DOMString text = " "); // return whether all fonts in the fontlist are loaded // (does not initiate load if not available) - [Throws] boolean check(DOMString font, optional DOMString text = " "); + [Throws] boolean check(UTF8String font, optional DOMString text = " "); // async notification that font loading and layout operations are done [Throws] readonly attribute Promise ready; diff --git a/dom/webidl/IntersectionObserver.webidl b/dom/webidl/IntersectionObserver.webidl index adef37bb1cdb..0a64ee74a909 100644 --- a/dom/webidl/IntersectionObserver.webidl +++ b/dom/webidl/IntersectionObserver.webidl @@ -36,7 +36,7 @@ interface IntersectionObserver { [Constant] readonly attribute Node? root; [Constant] - readonly attribute DOMString rootMargin; + readonly attribute UTF8String rootMargin; [Constant,Cached] readonly attribute sequence thresholds; void observe(Element target); @@ -57,7 +57,7 @@ dictionary IntersectionObserverEntryInit { }; dictionary IntersectionObserverInit { - (Element or Document)? root = null; - DOMString rootMargin = "0px"; + (Element or Document)? root = null; + UTF8String rootMargin = "0px"; (double or sequence) threshold = 0; }; diff --git a/dom/webidl/KeyframeEffect.webidl b/dom/webidl/KeyframeEffect.webidl index 63939452df06..d31aa74c1772 100644 --- a/dom/webidl/KeyframeEffect.webidl +++ b/dom/webidl/KeyframeEffect.webidl @@ -49,8 +49,8 @@ interface KeyframeEffect : AnimationEffect { // Non-standard extensions dictionary AnimationPropertyValueDetails { required double offset; - DOMString value; - DOMString easing; + UTF8String value; + UTF8String easing; required CompositeOperation composite; }; diff --git a/dom/webidl/MediaList.webidl b/dom/webidl/MediaList.webidl index 239ee183200e..af307b5d831d 100644 --- a/dom/webidl/MediaList.webidl +++ b/dom/webidl/MediaList.webidl @@ -7,12 +7,12 @@ [Exposed=Window] interface MediaList { - stringifier attribute [TreatNullAs=EmptyString] DOMString mediaText; + stringifier attribute [TreatNullAs=EmptyString] UTF8String mediaText; readonly attribute unsigned long length; - getter DOMString? item(unsigned long index); + getter UTF8String? item(unsigned long index); [Throws] - void deleteMedium(DOMString oldMedium); + void deleteMedium(UTF8String oldMedium); [Throws] - void appendMedium(DOMString newMedium); + void appendMedium(UTF8String newMedium); }; diff --git a/dom/webidl/MediaQueryList.webidl b/dom/webidl/MediaQueryList.webidl index bd4d34e0c757..5132cb6ca744 100644 --- a/dom/webidl/MediaQueryList.webidl +++ b/dom/webidl/MediaQueryList.webidl @@ -13,7 +13,7 @@ [ProbablyShortLivingWrapper, Exposed=Window] interface MediaQueryList : EventTarget { - readonly attribute DOMString media; + readonly attribute UTF8String media; readonly attribute boolean matches; [Throws] diff --git a/dom/webidl/MediaQueryListEvent.webidl b/dom/webidl/MediaQueryListEvent.webidl index 0e0bb44a2896..4f41ca480a05 100644 --- a/dom/webidl/MediaQueryListEvent.webidl +++ b/dom/webidl/MediaQueryListEvent.webidl @@ -11,11 +11,11 @@ interface MediaQueryListEvent : Event { constructor(DOMString type, optional MediaQueryListEventInit eventInitDict = {}); - readonly attribute DOMString media; + readonly attribute UTF8String media; readonly attribute boolean matches; }; dictionary MediaQueryListEventInit : EventInit { - DOMString media = ""; + UTF8String media = ""; boolean matches = false; }; diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index 04c0d4a6d63d..2f9840cac83d 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -323,7 +323,7 @@ dictionary ScrollToOptions : ScrollOptions { partial interface Window { //[Throws, NewObject, NeedsCallerType] MediaQueryList matchMedia(DOMString query); - [Throws, NewObject, NeedsCallerType] MediaQueryList? matchMedia(DOMString query); + [Throws, NewObject, NeedsCallerType] MediaQueryList? matchMedia(UTF8String query); // Per spec, screen is SameObject, but we don't actually guarantee that given // nsGlobalWindow::Cleanup. :( //[SameObject, Replaceable, Throws] readonly attribute Screen screen; diff --git a/editor/libeditor/CSSEditUtils.cpp b/editor/libeditor/CSSEditUtils.cpp index 4d771d8fe7ab..20bd8f998068 100644 --- a/editor/libeditor/CSSEditUtils.cpp +++ b/editor/libeditor/CSSEditUtils.cpp @@ -434,7 +434,7 @@ nsresult CSSEditUtils::SetCSSPropertyPixelsWithoutTransaction( s.AppendLiteral("px"); ErrorResult error; - cssDecl->SetProperty(propertyNameString, s, EmptyString(), error); + cssDecl->SetProperty(propertyNameString, s, EmptyCString(), error); if (error.Failed()) { NS_WARNING("nsICSSDeclaration::SetProperty() failed"); return error.StealNSResult(); @@ -515,9 +515,13 @@ nsresult CSSEditUtils::GetComputedCSSInlinePropertyBase(nsIContent& aContent, // // FIXME(bug 1606994): nsAtomCString copies, we should just keep around the // property id. + // + // FIXME: Maybe we can avoid copying aValue too, though it's no worse than + // what we used to do. + nsAutoCString value; MOZ_ALWAYS_SUCCEEDS( - computedDOMStyle->GetPropertyValue(nsAtomCString(&aCSSProperty), aValue)); - + computedDOMStyle->GetPropertyValue(nsAtomCString(&aCSSProperty), value)); + CopyUTF8toUTF16(value, aValue); return NS_OK; } @@ -537,12 +541,14 @@ nsresult CSSEditUtils::GetSpecifiedCSSInlinePropertyBase(nsIContent& aContent, return NS_OK; } + // FIXME: Same comments as above. nsCSSPropertyID prop = nsCSSProps::LookupProperty(nsAtomCString(&aCSSProperty)); MOZ_ASSERT(prop != eCSSProperty_UNKNOWN); - decl->GetPropertyValueByID(prop, aValue); - + nsAutoCString value; + decl->GetPropertyValueByID(prop, value); + CopyUTF8toUTF16(value, aValue); return NS_OK; } @@ -1041,13 +1047,11 @@ bool CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal( isSet = true; } } else if (nsGkAtoms::u == aHTMLProperty) { - nsAutoString val; - val.AssignLiteral("underline"); - isSet = ChangeStyleTransaction::ValueIncludes(aValue, val); + isSet = ChangeStyleTransaction::ValueIncludes( + NS_ConvertUTF16toUTF8(aValue), "underline"_ns); } else if (nsGkAtoms::strike == aHTMLProperty) { - nsAutoString val; - val.AssignLiteral("line-through"); - isSet = ChangeStyleTransaction::ValueIncludes(aValue, val); + isSet = ChangeStyleTransaction::ValueIncludes( + NS_ConvertUTF16toUTF8(aValue), "line-through"_ns); } else if ((nsGkAtoms::font == aHTMLProperty && aAttribute == nsGkAtoms::color) || aAttribute == nsGkAtoms::bgcolor) { @@ -1249,7 +1253,7 @@ bool CSSEditUtils::DoStyledElementsHaveSameStyle( } for (uint32_t i = 0; i < firstLength; i++) { - nsAutoString firstValue, otherValue; + nsAutoCString firstValue, otherValue; nsAutoCString propertyNameString; firstCSSDecl->Item(i, propertyNameString); DebugOnly rvIgnored = @@ -1266,7 +1270,7 @@ bool CSSEditUtils::DoStyledElementsHaveSameStyle( } } for (uint32_t i = 0; i < otherLength; i++) { - nsAutoString firstValue, otherValue; + nsAutoCString firstValue, otherValue; nsAutoCString propertyNameString; otherCSSDecl->Item(i, propertyNameString); DebugOnly rvIgnored = diff --git a/editor/libeditor/ChangeStyleTransaction.cpp b/editor/libeditor/ChangeStyleTransaction.cpp index e31d588a2dbc..22150668023c 100644 --- a/editor/libeditor/ChangeStyleTransaction.cpp +++ b/editor/libeditor/ChangeStyleTransaction.cpp @@ -47,14 +47,15 @@ ChangeStyleTransaction::ChangeStyleTransaction(nsStyledElement& aStyledElement, : EditTransactionBase(), mStyledElement(&aStyledElement), mProperty(&aProperty), - mValue(aValue), mUndoValue(), mRedoValue(), mRemoveProperty(aRemove), mUndoAttributeWasSet(false), - mRedoAttributeWasSet(false) {} + mRedoAttributeWasSet(false) { + CopyUTF16toUTF8(aValue, mValue); +} -#define kNullCh (char16_t('\0')) +#define kNullCh ('\0') NS_IMPL_CYCLE_COLLECTION_INHERITED(ChangeStyleTransaction, EditTransactionBase, mStyledElement) @@ -67,17 +68,16 @@ NS_IMPL_RELEASE_INHERITED(ChangeStyleTransaction, EditTransactionBase) // Answers true if aValue is in the string list of white-space separated values // aValueList. -bool ChangeStyleTransaction::ValueIncludes(const nsAString& aValueList, - const nsAString& aValue) { - nsAutoString valueList(aValueList); +bool ChangeStyleTransaction::ValueIncludes(const nsACString& aValueList, + const nsACString& aValue) { + nsAutoCString valueList(aValueList); bool result = false; // put an extra null at the end valueList.Append(kNullCh); - char16_t* value = ToNewUnicode(aValue); - char16_t* start = valueList.BeginWriting(); - char16_t* end = start; + char* start = valueList.BeginWriting(); + char* end = start; while (kNullCh != *start) { while (kNullCh != *start && nsCRT::IsAsciiSpace(*start)) { @@ -94,29 +94,28 @@ bool ChangeStyleTransaction::ValueIncludes(const nsAString& aValueList, *end = kNullCh; if (start < end) { - if (nsDependentString(value).Equals(nsDependentString(start), - nsCaseInsensitiveStringComparator)) { + if (aValue.Equals(nsDependentCString(start), + nsCaseInsensitiveCStringComparator)) { result = true; break; } } start = ++end; } - free(value); return result; } // Removes the value aRemoveValue from the string list of white-space separated // values aValueList void ChangeStyleTransaction::RemoveValueFromListOfValues( - nsAString& aValues, const nsAString& aRemoveValue) { - nsAutoString classStr(aValues); - nsAutoString outString; + nsACString& aValues, const nsACString& aRemoveValue) { + nsAutoCString classStr(aValues); + nsAutoCString outString; // put an extra null at the end classStr.Append(kNullCh); - char16_t* start = classStr.BeginWriting(); - char16_t* end = start; + char* start = classStr.BeginWriting(); + char* end = start; while (kNullCh != *start) { while (kNullCh != *start && nsCRT::IsAsciiSpace(*start)) { @@ -134,7 +133,7 @@ void ChangeStyleTransaction::RemoveValueFromListOfValues( if (start < end && !aRemoveValue.Equals(start)) { outString.Append(start); - outString.Append(char16_t(' ')); + outString.Append(' '); } start = ++end; @@ -158,7 +157,7 @@ NS_IMETHODIMP ChangeStyleTransaction::DoTransaction() { mUndoAttributeWasSet = mStyledElement->HasAttr(kNameSpaceID_None, nsGkAtoms::style); - nsAutoString values; + nsAutoCString values; nsresult rv = cssDecl->GetPropertyValue(propertyNameString, values); if (NS_FAILED(rv)) { NS_WARNING("nsICSSDeclaration::GetPropertyPriorityValue() failed"); @@ -170,10 +169,10 @@ NS_IMETHODIMP ChangeStyleTransaction::DoTransaction() { bool multiple = AcceptsMoreThanOneValue(*mProperty); if (mRemoveProperty) { - nsAutoString returnString; + nsAutoCString returnString; if (multiple) { // Let's remove only the value we have to remove and not the others - RemoveValueFromListOfValues(values, u"none"_ns); + RemoveValueFromListOfValues(values, "none"_ns); RemoveValueFromListOfValues(values, mValue); if (values.IsEmpty()) { ErrorResult error; @@ -184,10 +183,9 @@ NS_IMETHODIMP ChangeStyleTransaction::DoTransaction() { } } else { ErrorResult error; - nsAutoString priority; + nsAutoCString priority; cssDecl->GetPropertyPriority(propertyNameString, priority); - cssDecl->SetProperty(propertyNameString, NS_ConvertUTF16toUTF8(values), - priority, error); + cssDecl->SetProperty(propertyNameString, values, priority, error); if (error.Failed()) { NS_WARNING("nsICSSDeclaration::SetProperty() failed"); return error.StealNSResult(); @@ -202,7 +200,7 @@ NS_IMETHODIMP ChangeStyleTransaction::DoTransaction() { } } } else { - nsAutoString priority; + nsAutoCString priority; cssDecl->GetPropertyPriority(propertyNameString, priority); if (multiple) { // Let's add the value we have to add to the others @@ -211,8 +209,7 @@ NS_IMETHODIMP ChangeStyleTransaction::DoTransaction() { values.Assign(mValue); } ErrorResult error; - cssDecl->SetProperty(propertyNameString, NS_ConvertUTF16toUTF8(values), - priority, error); + cssDecl->SetProperty(propertyNameString, values, priority, error); if (error.Failed()) { NS_WARNING("nsICSSDeclaration::SetProperty() failed"); return error.StealNSResult(); @@ -239,7 +236,7 @@ NS_IMETHODIMP ChangeStyleTransaction::DoTransaction() { } nsresult ChangeStyleTransaction::SetStyle(bool aAttributeWasSet, - nsAString& aValue) { + nsACString& aValue) { if (NS_WARN_IF(!mStyledElement)) { return NS_ERROR_NOT_AVAILABLE; } @@ -256,7 +253,7 @@ nsresult ChangeStyleTransaction::SetStyle(bool aAttributeWasSet, ErrorResult error; if (aValue.IsEmpty()) { // An empty value means we have to remove the property - nsAutoString returnString; + nsAutoCString returnString; cssDecl->RemoveProperty(propertyNameString, returnString, error); if (error.Failed()) { NS_WARNING("nsICSSDeclaration::RemoveProperty() failed"); @@ -264,10 +261,9 @@ nsresult ChangeStyleTransaction::SetStyle(bool aAttributeWasSet, } } // Let's recreate the declaration as it was - nsAutoString priority; + nsAutoCString priority; cssDecl->GetPropertyPriority(propertyNameString, priority); - cssDecl->SetProperty(propertyNameString, NS_ConvertUTF16toUTF8(aValue), - priority, error); + cssDecl->SetProperty(propertyNameString, aValue, priority, error); NS_WARNING_ASSERTION(!error.Failed(), "nsICSSDeclaration::SetProperty() failed"); return error.StealNSResult(); @@ -302,7 +298,7 @@ bool ChangeStyleTransaction::AcceptsMoreThanOneValue(nsAtom& aCSSProperty) { // Adds the value aNewValue to the list of white-space separated values aValues void ChangeStyleTransaction::AddValueToMultivalueProperty( - nsAString& aValues, const nsAString& aNewValue) { + nsACString& aValues, const nsACString& aNewValue) { if (aValues.IsEmpty() || aValues.LowerCaseEqualsLiteral("none")) { aValues.Assign(aNewValue); } else if (!ValueIncludes(aValues, aNewValue)) { diff --git a/editor/libeditor/ChangeStyleTransaction.h b/editor/libeditor/ChangeStyleTransaction.h index 2368446ad785..d837f21c8467 100644 --- a/editor/libeditor/ChangeStyleTransaction.h +++ b/editor/libeditor/ChangeStyleTransaction.h @@ -69,8 +69,8 @@ class ChangeStyleTransaction final : public EditTransactionBase { * @param aValue [IN] the value to look for in the list * @return true if the value is in the list of values */ - static bool ValueIncludes(const nsAString& aValueList, - const nsAString& aValue); + static bool ValueIncludes(const nsACString& aValueList, + const nsACString& aValue); private: virtual ~ChangeStyleTransaction() = default; @@ -82,8 +82,8 @@ class ChangeStyleTransaction final : public EditTransactionBase { * @param aNewValue [IN] a value this code adds to aValues if it is not * already in */ - void AddValueToMultivalueProperty(nsAString& aValues, - const nsAString& aNewValue); + void AddValueToMultivalueProperty(nsACString& aValues, + const nsACString& aNewValue); /** * Returns true if the property accepts more than one value. @@ -98,8 +98,8 @@ class ChangeStyleTransaction final : public EditTransactionBase { * @param aValues [IN] a list of white-space separated values * @param aRemoveValue [IN] the value to remove from the list */ - void RemoveValueFromListOfValues(nsAString& aValues, - const nsAString& aRemoveValue); + void RemoveValueFromListOfValues(nsACString& aValues, + const nsACString& aRemoveValue); /** * If the boolean is true and if the value is not the empty string, @@ -108,7 +108,7 @@ class ChangeStyleTransaction final : public EditTransactionBase { * is false, just remove the style attribute. */ MOZ_CAN_RUN_SCRIPT nsresult SetStyle(bool aAttributeWasSet, - nsAString& aValue); + nsACString& aValue); // The element to operate upon. RefPtr mStyledElement; @@ -117,12 +117,12 @@ class ChangeStyleTransaction final : public EditTransactionBase { RefPtr mProperty; // The value to set the property to (ignored if mRemoveProperty==true). - nsString mValue; + nsCString mValue; // The value to set the property to for undo. - nsString mUndoValue; + nsCString mUndoValue; // The value to set the property to for redo. - nsString mRedoValue; + nsCString mRedoValue; // true if the operation is to remove mProperty from mElement. bool mRemoveProperty; diff --git a/editor/libeditor/HTMLAnonymousNodeEditor.cpp b/editor/libeditor/HTMLAnonymousNodeEditor.cpp index 119460e220e5..548a7e8b0a61 100644 --- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp +++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp @@ -57,7 +57,7 @@ static int32_t GetCSSFloatValue(nsComputedDOMStyle* aComputedStyle, MOZ_ASSERT(aComputedStyle); // get the computed CSSValue of the property - nsAutoString value; + nsAutoCString value; nsresult rv = aComputedStyle->GetPropertyValue(aProperty, value); if (NS_FAILED(rv)) { NS_WARNING("nsComputedDOMStyle::GetPropertyValue() failed"); diff --git a/layout/forms/nsSearchControlFrame.cpp b/layout/forms/nsSearchControlFrame.cpp index 66a8b45eac54..1bf86fef2511 100644 --- a/layout/forms/nsSearchControlFrame.cpp +++ b/layout/forms/nsSearchControlFrame.cpp @@ -110,10 +110,10 @@ void nsSearchControlFrame::UpdateClearButtonState() { nsGenericHTMLElement* element = nsGenericHTMLElement::FromNode(mClearButton); nsCOMPtr declaration = element->Style(); if (content->IsValueEmpty()) { - declaration->SetProperty("visibility"_ns, "hidden"_ns, u""_ns, + declaration->SetProperty("visibility"_ns, "hidden"_ns, ""_ns, IgnoreErrors()); } else { - nsAutoString dummy; + nsAutoCString dummy; declaration->RemoveProperty("visibility"_ns, dummy, IgnoreErrors()); } } diff --git a/layout/generic/ScrollbarActivity.cpp b/layout/generic/ScrollbarActivity.cpp index 5f8e6ae2d522..ac5ded26f8cc 100644 --- a/layout/generic/ScrollbarActivity.cpp +++ b/layout/generic/ScrollbarActivity.cpp @@ -298,7 +298,7 @@ static void SetOpacityOnElement(nsIContent* aContent, double aOpacity) { nsICSSDeclaration* decl = inlineStyleContent->Style(); nsAutoCString str; str.AppendFloat(aOpacity); - decl->SetProperty("opacity"_ns, str, u""_ns, IgnoreErrors()); + decl->SetProperty("opacity"_ns, str, EmptyCString(), IgnoreErrors()); } } @@ -327,7 +327,7 @@ static void UnsetOpacityOnElement(nsIContent* aContent) { if (RefPtr inlineStyleContent = nsStyledElement::FromNodeOrNull(aContent)) { nsICSSDeclaration* decl = inlineStyleContent->Style(); - nsAutoString dummy; + nsAutoCString dummy; decl->RemoveProperty("opacity"_ns, dummy, IgnoreErrors()); } } diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp index 82060cde0cb2..6482c484b0d4 100644 --- a/layout/generic/nsIFrame.cpp +++ b/layout/generic/nsIFrame.cpp @@ -7874,10 +7874,9 @@ void nsIFrame::ListMatchedRules(FILE* out, const char* aPrefix) const { nsTArray rawRuleList; Servo_ComputedValues_GetStyleRuleList(mComputedStyle, &rawRuleList); for (const RawServoStyleRule* rawRule : rawRuleList) { - nsString ruleText; + nsAutoCString ruleText; Servo_StyleRule_GetCssText(rawRule, &ruleText); - fprintf_stderr(out, "%s%s\n", aPrefix, - NS_ConvertUTF16toUTF8(ruleText).get()); + fprintf_stderr(out, "%s%s\n", aPrefix, ruleText.get()); } } @@ -12506,9 +12505,9 @@ void ReflowInput::DisplayInitFrameTypeExit(nsIFrame* aFrame, if (aFrame->IsFloating()) printf(" float"); { - nsAutoString result; + nsAutoCString result; aFrame->Style()->GetComputedPropertyValue(eCSSProperty_display, result); - printf(" display=%s", NS_ConvertUTF16toUTF8(result).get()); + printf(" display=%s", result.get()); } // This array must exactly match the NS_CSS_FRAME_TYPE constants. diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index 95abea8f3561..f6aed279c14e 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -300,7 +300,7 @@ uint32_t InspectorUtils::GetSelectorCount(GlobalObject& aGlobal, /* static */ void InspectorUtils::GetSelectorText(GlobalObject& aGlobal, BindingStyleRule& aRule, - uint32_t aSelectorIndex, nsString& aText, + uint32_t aSelectorIndex, nsACString& aText, ErrorResult& aRv) { aRv = aRule.GetSelectorText(aSelectorIndex, aText); } diff --git a/layout/inspector/InspectorUtils.h b/layout/inspector/InspectorUtils.h index afde2f0679dd..7f9dfb034a49 100644 --- a/layout/inspector/InspectorUtils.h +++ b/layout/inspector/InspectorUtils.h @@ -88,7 +88,7 @@ class InspectorUtils { // For all three functions below, aSelectorIndex is 0-based static void GetSelectorText(GlobalObject& aGlobal, BindingStyleRule& aRule, - uint32_t aSelectorIndex, nsString& aText, + uint32_t aSelectorIndex, nsACString& aText, ErrorResult& aRv); static uint64_t GetSpecificity(GlobalObject& aGlobal, BindingStyleRule& aRule, uint32_t aSelectorIndex, ErrorResult& aRv); diff --git a/layout/painting/ActiveLayerTracker.cpp b/layout/painting/ActiveLayerTracker.cpp index 10d680f3ae12..4000ee9191c5 100644 --- a/layout/painting/ActiveLayerTracker.cpp +++ b/layout/painting/ActiveLayerTracker.cpp @@ -337,9 +337,9 @@ void ActiveLayerTracker::NotifyAnimated(nsIFrame* aFrame, LayerActivity* layerActivity = GetLayerActivityForUpdate(aFrame); uint8_t& mutationCount = layerActivity->RestyleCountForProperty(aProperty); if (mutationCount != 0xFF) { - nsAutoString oldValue; + nsAutoCString oldValue; aDOMCSSDecl->GetPropertyValue(aProperty, oldValue); - if (NS_ConvertUTF16toUTF8(oldValue) != aNewValue) { + if (oldValue != aNewValue) { // We know this is animated, so just hack the mutation count. mutationCount = 0xFF; } diff --git a/layout/style/BindingStyleRule.h b/layout/style/BindingStyleRule.h index 86aa275d5220..9de9510f58e5 100644 --- a/layout/style/BindingStyleRule.h +++ b/layout/style/BindingStyleRule.h @@ -46,7 +46,7 @@ class BindingStyleRule : public css::Rule { virtual uint32_t GetSelectorCount() = 0; virtual nsresult GetSelectorText(uint32_t aSelectorIndex, - nsAString& aText) = 0; + nsACString& aText) = 0; virtual nsresult GetSpecificity(uint32_t aSelectorIndex, uint64_t* aSpecificity) = 0; virtual nsresult SelectorMatchesElement(dom::Element* aElement, @@ -57,8 +57,8 @@ class BindingStyleRule : public css::Rule { virtual NotNull GetDeclarationBlock() const = 0; // WebIDL API - virtual void GetSelectorText(nsAString& aSelectorText) = 0; - virtual void SetSelectorText(const nsAString& aSelectorText) = 0; + virtual void GetSelectorText(nsACString& aSelectorText) = 0; + virtual void SetSelectorText(const nsACString& aSelectorText) = 0; virtual nsICSSDeclaration* Style() = 0; virtual JSObject* WrapObject(JSContext* aCx, diff --git a/layout/style/CSSCounterStyleRule.cpp b/layout/style/CSSCounterStyleRule.cpp index 933609f8ba54..531988aa725b 100644 --- a/layout/style/CSSCounterStyleRule.cpp +++ b/layout/style/CSSCounterStyleRule.cpp @@ -31,7 +31,7 @@ uint16_t CSSCounterStyleRule::Type() const { return CSSRule_Binding::COUNTER_STYLE_RULE; } -void CSSCounterStyleRule::GetCssText(nsAString& aCssText) const { +void CSSCounterStyleRule::GetCssText(nsACString& aCssText) const { Servo_CounterStyleRule_GetCssText(mRawRule, &aCssText); } @@ -54,23 +54,22 @@ void CSSCounterStyleRule::SetName(const nsAString& aName) { } } -#define CSS_COUNTER_DESC(name_, method_) \ - void CSSCounterStyleRule::Get##method_(nsAString& aValue) { \ - aValue.Truncate(); \ - Servo_CounterStyleRule_GetDescriptorCssText( \ - mRawRule, eCSSCounterDesc_##method_, &aValue); \ - } \ - void CSSCounterStyleRule::Set##method_(const nsAString& aValue) { \ - if (IsReadOnly()) { \ - return; \ - } \ - NS_ConvertUTF16toUTF8 value(aValue); \ - if (Servo_CounterStyleRule_SetDescriptor( \ - mRawRule, eCSSCounterDesc_##method_, &value)) { \ - if (StyleSheet* sheet = GetStyleSheet()) { \ - sheet->RuleChanged(this, StyleRuleChangeKind::Generic); \ - } \ - } \ +#define CSS_COUNTER_DESC(name_, method_) \ + void CSSCounterStyleRule::Get##method_(nsACString& aValue) { \ + MOZ_ASSERT(aValue.IsEmpty()); \ + Servo_CounterStyleRule_GetDescriptorCssText( \ + mRawRule, eCSSCounterDesc_##method_, &aValue); \ + } \ + void CSSCounterStyleRule::Set##method_(const nsACString& aValue) { \ + if (IsReadOnly()) { \ + return; \ + } \ + if (Servo_CounterStyleRule_SetDescriptor( \ + mRawRule, eCSSCounterDesc_##method_, &aValue)) { \ + if (StyleSheet* sheet = GetStyleSheet()) { \ + sheet->RuleChanged(this, StyleRuleChangeKind::Generic); \ + } \ + } \ } #include "nsCSSCounterDescList.h" #undef CSS_COUNTER_DESC diff --git a/layout/style/CSSCounterStyleRule.h b/layout/style/CSSCounterStyleRule.h index 8ec991904c87..4020adf5c25a 100644 --- a/layout/style/CSSCounterStyleRule.h +++ b/layout/style/CSSCounterStyleRule.h @@ -38,12 +38,12 @@ class CSSCounterStyleRule final : public css::Rule { // WebIDL interface uint16_t Type() const override; - void GetCssText(nsAString& aCssText) const override; + void GetCssText(nsACString& aCssText) const override; void GetName(nsAString& aName); void SetName(const nsAString& aName); #define CSS_COUNTER_DESC(name_, method_) \ - void Get##method_(nsAString& aValue); \ - void Set##method_(const nsAString& aValue); + void Get##method_(nsACString& aValue); \ + void Set##method_(const nsACString& aValue); #include "nsCSSCounterDescList.h" #undef CSS_COUNTER_DESC diff --git a/layout/style/CSSFontFaceRule.cpp b/layout/style/CSSFontFaceRule.cpp index 095dd35fad8e..e83665876af5 100644 --- a/layout/style/CSSFontFaceRule.cpp +++ b/layout/style/CSSFontFaceRule.cpp @@ -36,17 +36,17 @@ NS_IMPL_RELEASE_USING_AGGREGATOR(CSSFontFaceRuleDecl, ContainingRule()) // helper for string GetPropertyValue and RemovePropertyValue void CSSFontFaceRuleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID, - nsAString& aResult) const { + nsACString& aResult) const { MOZ_ASSERT(aResult.IsEmpty()); Servo_FontFaceRule_GetDescriptorCssText(mRawRule, aFontDescID, &aResult); } -void CSSFontFaceRuleDecl::GetCssText(nsAString& aCssText) { - aCssText.Truncate(); +void CSSFontFaceRuleDecl::GetCssText(nsACString& aCssText) { + MOZ_ASSERT(aCssText.IsEmpty()); Servo_FontFaceRule_GetDeclCssText(mRawRule, &aCssText); } -void CSSFontFaceRuleDecl::SetCssText(const nsAString& aCssText, +void CSSFontFaceRuleDecl::SetCssText(const nsACString& aCssText, nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { if (ContainingRule()->IsReadOnly()) { @@ -59,7 +59,7 @@ void CSSFontFaceRuleDecl::SetCssText(const nsAString& aCssText, NS_IMETHODIMP CSSFontFaceRuleDecl::GetPropertyValue(const nsACString& aPropName, - nsAString& aResult) { + nsACString& aResult) { aResult.Truncate(); nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(aPropName); if (descID != eCSSFontDesc_UNKNOWN) { @@ -69,7 +69,8 @@ CSSFontFaceRuleDecl::GetPropertyValue(const nsACString& aPropName, } void CSSFontFaceRuleDecl::RemoveProperty(const nsACString& aPropName, - nsAString& aResult, ErrorResult& aRv) { + nsACString& aResult, + ErrorResult& aRv) { nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(aPropName); NS_ASSERTION(descID >= eCSSFontDesc_UNKNOWN && descID < eCSSFontDesc_COUNT, "LookupFontDesc returned value out of range"); @@ -86,14 +87,14 @@ void CSSFontFaceRuleDecl::RemoveProperty(const nsACString& aPropName, } void CSSFontFaceRuleDecl::GetPropertyPriority(const nsACString& aPropName, - nsAString& aResult) { + nsACString& aResult) { // font descriptors do not have priorities at present aResult.Truncate(); } void CSSFontFaceRuleDecl::SetProperty(const nsACString& aPropName, const nsACString& aValue, - const nsAString& aPriority, + const nsACString& aPriority, nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { // FIXME(heycam): If we are changing unicode-range, then a FontFace object @@ -192,7 +193,7 @@ uint16_t CSSFontFaceRule::Type() const { return CSSRule_Binding::FONT_FACE_RULE; } -void CSSFontFaceRule::GetCssText(nsAString& aCssText) const { +void CSSFontFaceRule::GetCssText(nsACString& aCssText) const { aCssText.Truncate(); Servo_FontFaceRule_GetCssText(Raw(), &aCssText); } diff --git a/layout/style/CSSFontFaceRule.h b/layout/style/CSSFontFaceRule.h index 167c40bda28f..d5f9030d6916 100644 --- a/layout/style/CSSFontFaceRule.h +++ b/layout/style/CSSFontFaceRule.h @@ -25,7 +25,7 @@ class CSSFontFaceRuleDecl final : public nsICSSDeclaration { void IndexedGetter(uint32_t aIndex, bool& aFound, nsACString& aPropName) final; - void GetPropertyValue(nsCSSFontDesc aFontDescID, nsAString& aResult) const; + void GetPropertyValue(nsCSSFontDesc aFontDescID, nsACString& aResult) const; JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) final; @@ -66,7 +66,7 @@ class CSSFontFaceRule final : public css::Rule { // WebIDL interface uint16_t Type() const final; - void GetCssText(nsAString& aCssText) const final; + void GetCssText(nsACString& aCssText) const final; nsICSSDeclaration* Style(); // Methods of mozilla::css::Rule diff --git a/layout/style/CSSFontFeatureValuesRule.cpp b/layout/style/CSSFontFeatureValuesRule.cpp index 920f001a7ae9..5af4c3d444cd 100644 --- a/layout/style/CSSFontFeatureValuesRule.cpp +++ b/layout/style/CSSFontFeatureValuesRule.cpp @@ -30,21 +30,21 @@ void CSSFontFeatureValuesRule::List(FILE* out, int32_t aIndent) const { /* CSSRule implementation */ -void CSSFontFeatureValuesRule::GetCssText(nsAString& aCssText) const { +void CSSFontFeatureValuesRule::GetCssText(nsACString& aCssText) const { Servo_FontFeatureValuesRule_GetCssText(mRawRule, &aCssText); } /* CSSFontFeatureValuesRule implementation */ -void CSSFontFeatureValuesRule::GetFontFamily(nsAString& aFamilyListStr) { +void CSSFontFeatureValuesRule::GetFontFamily(nsACString& aFamilyListStr) { Servo_FontFeatureValuesRule_GetFontFamily(mRawRule, &aFamilyListStr); } -void CSSFontFeatureValuesRule::GetValueText(nsAString& aValueText) { +void CSSFontFeatureValuesRule::GetValueText(nsACString& aValueText) { Servo_FontFeatureValuesRule_GetValueText(mRawRule, &aValueText); } -void CSSFontFeatureValuesRule::SetFontFamily(const nsAString& aFontFamily, +void CSSFontFeatureValuesRule::SetFontFamily(const nsACString& aFontFamily, ErrorResult& aRv) { if (IsReadOnly()) { return; @@ -53,7 +53,7 @@ void CSSFontFeatureValuesRule::SetFontFamily(const nsAString& aFontFamily, aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); } -void CSSFontFeatureValuesRule::SetValueText(const nsAString& aValueText, +void CSSFontFeatureValuesRule::SetValueText(const nsACString& aValueText, ErrorResult& aRv) { if (IsReadOnly()) { return; diff --git a/layout/style/CSSFontFeatureValuesRule.h b/layout/style/CSSFontFeatureValuesRule.h index 4622cd1e315b..7cfe295466a8 100644 --- a/layout/style/CSSFontFeatureValuesRule.h +++ b/layout/style/CSSFontFeatureValuesRule.h @@ -32,11 +32,11 @@ class CSSFontFeatureValuesRule final : public css::Rule { return CSSRule_Binding::FONT_FEATURE_VALUES_RULE; } - void GetCssText(nsAString& aCssText) const override; - void GetFontFamily(nsAString& aFamily); - void SetFontFamily(const nsAString& aFamily, mozilla::ErrorResult& aRv); - void GetValueText(nsAString& aValueText); - void SetValueText(const nsAString& aValueText, mozilla::ErrorResult& aRv); + void GetCssText(nsACString& aCssText) const override; + void GetFontFamily(nsACString& aFamily); + void SetFontFamily(const nsACString& aFamily, mozilla::ErrorResult& aRv); + void GetValueText(nsACString& aValueText); + void SetValueText(const nsACString& aValueText, mozilla::ErrorResult& aRv); size_t SizeOfIncludingThis( mozilla::MallocSizeOf aMallocSizeOf) const override; diff --git a/layout/style/CSSImportRule.cpp b/layout/style/CSSImportRule.cpp index 28bc7f19e56d..4e7c438942b6 100644 --- a/layout/style/CSSImportRule.cpp +++ b/layout/style/CSSImportRule.cpp @@ -88,7 +88,7 @@ void CSSImportRule::GetHref(nsAString& aHref) const { } /* virtual */ -void CSSImportRule::GetCssText(nsAString& aCssText) const { +void CSSImportRule::GetCssText(nsACString& aCssText) const { Servo_ImportRule_GetCssText(mRawRule, &aCssText); } diff --git a/layout/style/CSSImportRule.h b/layout/style/CSSImportRule.h index d57dd8b5915e..8732b81af389 100644 --- a/layout/style/CSSImportRule.h +++ b/layout/style/CSSImportRule.h @@ -33,7 +33,7 @@ class CSSImportRule final : public css::Rule { // WebIDL interface uint16_t Type() const final { return CSSRule_Binding::IMPORT_RULE; } - void GetCssText(nsAString& aCssText) const override; + void GetCssText(nsACString& aCssText) const override; void GetHref(nsAString& aHref) const; dom::MediaList* GetMedia() const; StyleSheet* GetStyleSheet() const { return mChildSheet; } diff --git a/layout/style/CSSKeyframeRule.cpp b/layout/style/CSSKeyframeRule.cpp index 8fca273f45d2..50634584e135 100644 --- a/layout/style/CSSKeyframeRule.cpp +++ b/layout/style/CSSKeyframeRule.cpp @@ -151,16 +151,16 @@ void CSSKeyframeRule::UpdateRule(Func aCallback) { } } -void CSSKeyframeRule::GetKeyText(nsAString& aKeyText) { +void CSSKeyframeRule::GetKeyText(nsACString& aKeyText) { Servo_Keyframe_GetKeyText(mRaw, &aKeyText); } -void CSSKeyframeRule::SetKeyText(const nsAString& aKeyText) { - NS_ConvertUTF16toUTF8 keyText(aKeyText); - UpdateRule([this, &keyText]() { Servo_Keyframe_SetKeyText(mRaw, &keyText); }); +void CSSKeyframeRule::SetKeyText(const nsACString& aKeyText) { + UpdateRule( + [this, &aKeyText]() { Servo_Keyframe_SetKeyText(mRaw, &aKeyText); }); } -void CSSKeyframeRule::GetCssText(nsAString& aCssText) const { +void CSSKeyframeRule::GetCssText(nsACString& aCssText) const { Servo_Keyframe_GetCssText(mRaw, &aCssText); } diff --git a/layout/style/CSSKeyframeRule.h b/layout/style/CSSKeyframeRule.h index bd5ba21988d6..2149576d8d4f 100644 --- a/layout/style/CSSKeyframeRule.h +++ b/layout/style/CSSKeyframeRule.h @@ -35,9 +35,9 @@ class CSSKeyframeRule final : public css::Rule { // WebIDL interface uint16_t Type() const final { return CSSRule_Binding::KEYFRAME_RULE; } - void GetCssText(nsAString& aCssText) const final; - void GetKeyText(nsAString& aKey); - void SetKeyText(const nsAString& aKey); + void GetCssText(nsACString& aCssText) const final; + void GetKeyText(nsACString& aKey); + void SetKeyText(const nsACString& aKey); nsICSSDeclaration* Style(); size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; diff --git a/layout/style/CSSKeyframesRule.cpp b/layout/style/CSSKeyframesRule.cpp index 4e6214a11638..5a73700d41d7 100644 --- a/layout/style/CSSKeyframesRule.cpp +++ b/layout/style/CSSKeyframesRule.cpp @@ -281,7 +281,7 @@ void CSSKeyframesRule::DeleteRule(const nsAString& aKey) { } /* virtual */ -void CSSKeyframesRule::GetCssText(nsAString& aCssText) const { +void CSSKeyframesRule::GetCssText(nsACString& aCssText) const { Servo_KeyframesRule_GetCssText(mRawRule, &aCssText); } diff --git a/layout/style/CSSKeyframesRule.h b/layout/style/CSSKeyframesRule.h index 6d28b7a084e7..95829455545d 100644 --- a/layout/style/CSSKeyframesRule.h +++ b/layout/style/CSSKeyframesRule.h @@ -35,7 +35,7 @@ class CSSKeyframesRule final : public css::Rule { uint16_t Type() const final { return CSSRule_Binding::KEYFRAMES_RULE; } const RawServoKeyframesRule* Raw() const { return mRawRule.get(); } - void GetCssText(nsAString& aCssText) const final; + void GetCssText(nsACString& aCssText) const final; void GetName(nsAString& aName) const; void SetName(const nsAString& aName); CSSRuleList* CssRules(); diff --git a/layout/style/CSSMediaRule.cpp b/layout/style/CSSMediaRule.cpp index c31b0f288126..8389663923ea 100644 --- a/layout/style/CSSMediaRule.cpp +++ b/layout/style/CSSMediaRule.cpp @@ -68,11 +68,11 @@ void CSSMediaRule::List(FILE* out, int32_t aIndent) const { } #endif -void CSSMediaRule::GetConditionText(nsAString& aConditionText) { +void CSSMediaRule::GetConditionText(nsACString& aConditionText) { Media()->GetMediaText(aConditionText); } -void CSSMediaRule::SetConditionText(const nsAString& aConditionText, +void CSSMediaRule::SetConditionText(const nsACString& aConditionText, ErrorResult& aRv) { if (IsReadOnly()) { return; @@ -81,7 +81,7 @@ void CSSMediaRule::SetConditionText(const nsAString& aConditionText, } /* virtual */ -void CSSMediaRule::GetCssText(nsAString& aCssText) const { +void CSSMediaRule::GetCssText(nsACString& aCssText) const { Servo_MediaRule_GetCssText(mRawRule, &aCssText); } diff --git a/layout/style/CSSMediaRule.h b/layout/style/CSSMediaRule.h index bae8c9e81897..4b21239ac1dd 100644 --- a/layout/style/CSSMediaRule.h +++ b/layout/style/CSSMediaRule.h @@ -32,9 +32,9 @@ class CSSMediaRule final : public css::ConditionRule { // WebIDL interface uint16_t Type() const override { return CSSRule_Binding::MEDIA_RULE; } // WebIDL interface - void GetCssText(nsAString& aCssText) const final; - void GetConditionText(nsAString& aConditionText) final; - void SetConditionText(const nsAString& aConditionText, + void GetCssText(nsACString& aCssText) const final; + void GetConditionText(nsACString& aConditionText) final; + void SetConditionText(const nsACString& aConditionText, ErrorResult& aRv) final; dom::MediaList* Media(); diff --git a/layout/style/CSSMozDocumentRule.cpp b/layout/style/CSSMozDocumentRule.cpp index c506b7a06b8d..191118d3518a 100644 --- a/layout/style/CSSMozDocumentRule.cpp +++ b/layout/style/CSSMozDocumentRule.cpp @@ -99,11 +99,11 @@ void CSSMozDocumentRule::List(FILE* out, int32_t aIndent) const { } #endif -void CSSMozDocumentRule::GetConditionText(nsAString& aConditionText) { +void CSSMozDocumentRule::GetConditionText(nsACString& aConditionText) { Servo_MozDocumentRule_GetConditionText(mRawRule, &aConditionText); } -void CSSMozDocumentRule::SetConditionText(const nsAString& aConditionText, +void CSSMozDocumentRule::SetConditionText(const nsACString& aConditionText, ErrorResult& aRv) { if (IsReadOnly()) { return; @@ -113,7 +113,7 @@ void CSSMozDocumentRule::SetConditionText(const nsAString& aConditionText, } /* virtual */ -void CSSMozDocumentRule::GetCssText(nsAString& aCssText) const { +void CSSMozDocumentRule::GetCssText(nsACString& aCssText) const { Servo_MozDocumentRule_GetCssText(mRawRule, &aCssText); } diff --git a/layout/style/CSSMozDocumentRule.h b/layout/style/CSSMozDocumentRule.h index 278c859954ca..9ae28567dbd3 100644 --- a/layout/style/CSSMozDocumentRule.h +++ b/layout/style/CSSMozDocumentRule.h @@ -34,9 +34,9 @@ class CSSMozDocumentRule final : public css::ConditionRule { // WebIDL interface uint16_t Type() const final { return CSSRule_Binding::DOCUMENT_RULE; } - void GetCssText(nsAString& aCssText) const final; - void GetConditionText(nsAString& aConditionText) final; - void SetConditionText(const nsAString& aConditionText, + void GetCssText(nsACString& aCssText) const final; + void GetConditionText(nsACString& aConditionText) final; + void SetConditionText(const nsACString& aConditionText, ErrorResult& aRv) final; size_t SizeOfIncludingThis(MallocSizeOf) const override; diff --git a/layout/style/CSSNamespaceRule.cpp b/layout/style/CSSNamespaceRule.cpp index 4d0d545b7dd0..219ff5b7f51d 100644 --- a/layout/style/CSSNamespaceRule.cpp +++ b/layout/style/CSSNamespaceRule.cpp @@ -34,7 +34,7 @@ void CSSNamespaceRule::GetURLSpec(nsString& aURLSpec) const { atom->ToString(aURLSpec); } -void CSSNamespaceRule::GetCssText(nsAString& aCssText) const { +void CSSNamespaceRule::GetCssText(nsACString& aCssText) const { Servo_NamespaceRule_GetCssText(mRawRule, &aCssText); } diff --git a/layout/style/CSSNamespaceRule.h b/layout/style/CSSNamespaceRule.h index 08e403f349a2..ff28de8e7ea1 100644 --- a/layout/style/CSSNamespaceRule.h +++ b/layout/style/CSSNamespaceRule.h @@ -34,7 +34,7 @@ class CSSNamespaceRule final : public css::Rule { void GetURLSpec(nsString& aURLSpec) const; // WebIDL interface - void GetCssText(nsAString& aCssText) const final; + void GetCssText(nsACString& aCssText) const final; // WebIDL interfaces uint16_t Type() const final { return CSSRule_Binding::NAMESPACE_RULE; } diff --git a/layout/style/CSSPageRule.cpp b/layout/style/CSSPageRule.cpp index 673e180ec976..5bf4f0c63c8e 100644 --- a/layout/style/CSSPageRule.cpp +++ b/layout/style/CSSPageRule.cpp @@ -143,7 +143,7 @@ void CSSPageRule::List(FILE* out, int32_t aIndent) const { /* CSSRule implementation */ -void CSSPageRule::GetCssText(nsAString& aCssText) const { +void CSSPageRule::GetCssText(nsACString& aCssText) const { Servo_PageRule_GetCssText(mRawRule, &aCssText); } diff --git a/layout/style/CSSPageRule.h b/layout/style/CSSPageRule.h index d4727a491e36..95ab9fc73511 100644 --- a/layout/style/CSSPageRule.h +++ b/layout/style/CSSPageRule.h @@ -64,7 +64,7 @@ class CSSPageRule final : public css::Rule { // WebIDL interfaces uint16_t Type() const final { return CSSRule_Binding::PAGE_RULE; } - void GetCssText(nsAString& aCssText) const final; + void GetCssText(nsACString& aCssText) const final; nsICSSDeclaration* Style(); size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; diff --git a/layout/style/CSSStyleRule.cpp b/layout/style/CSSStyleRule.cpp index 6e5e1cca3823..780a2c4ad72f 100644 --- a/layout/style/CSSStyleRule.cpp +++ b/layout/style/CSSStyleRule.cpp @@ -154,7 +154,7 @@ void CSSStyleRule::List(FILE* out, int32_t aIndent) const { /* CSSRule implementation */ -void CSSStyleRule::GetCssText(nsAString& aCssText) const { +void CSSStyleRule::GetCssText(nsACString& aCssText) const { Servo_StyleRule_GetCssText(mRawRule, &aCssText); } @@ -162,11 +162,11 @@ nsICSSDeclaration* CSSStyleRule::Style() { return &mDecls; } /* CSSStyleRule implementation */ -void CSSStyleRule::GetSelectorText(nsAString& aSelectorText) { +void CSSStyleRule::GetSelectorText(nsACString& aSelectorText) { Servo_StyleRule_GetSelectorText(mRawRule, &aSelectorText); } -void CSSStyleRule::SetSelectorText(const nsAString& aSelectorText) { +void CSSStyleRule::SetSelectorText(const nsACString& aSelectorText) { if (IsReadOnly()) { return; } @@ -193,7 +193,7 @@ uint32_t CSSStyleRule::GetSelectorCount() { } nsresult CSSStyleRule::GetSelectorText(uint32_t aSelectorIndex, - nsAString& aText) { + nsACString& aText) { Servo_StyleRule_GetSelectorTextAtIndex(mRawRule, aSelectorIndex, &aText); return NS_OK; } diff --git a/layout/style/CSSStyleRule.h b/layout/style/CSSStyleRule.h index 8f22d1c56a4d..7bebe9271556 100644 --- a/layout/style/CSSStyleRule.h +++ b/layout/style/CSSStyleRule.h @@ -62,7 +62,7 @@ class CSSStyleRule final : public BindingStyleRule, public SupportsWeakPtr { bool IsCCLeaf() const final MOZ_MUST_OVERRIDE; uint32_t GetSelectorCount() override; - nsresult GetSelectorText(uint32_t aSelectorIndex, nsAString& aText) override; + nsresult GetSelectorText(uint32_t aSelectorIndex, nsACString& aText) override; nsresult GetSpecificity(uint32_t aSelectorIndex, uint64_t* aSpecificity) override; nsresult SelectorMatchesElement(dom::Element* aElement, @@ -74,9 +74,9 @@ class CSSStyleRule final : public BindingStyleRule, public SupportsWeakPtr { // WebIDL interface uint16_t Type() const final { return dom::CSSRule_Binding::STYLE_RULE; } - void GetCssText(nsAString& aCssText) const final; - void GetSelectorText(nsAString& aSelectorText) final; - void SetSelectorText(const nsAString& aSelectorText) final; + void GetCssText(nsACString& aCssText) const final; + void GetSelectorText(nsACString& aSelectorText) final; + void SetSelectorText(const nsACString& aSelectorText) final; nsICSSDeclaration* Style() final; RawServoStyleRule* Raw() const { return mRawRule; } diff --git a/layout/style/CSSSupportsRule.cpp b/layout/style/CSSSupportsRule.cpp index 21eae87455fe..e1266c3957ab 100644 --- a/layout/style/CSSSupportsRule.cpp +++ b/layout/style/CSSSupportsRule.cpp @@ -41,11 +41,11 @@ void CSSSupportsRule::List(FILE* out, int32_t aIndent) const { } #endif -void CSSSupportsRule::GetConditionText(nsAString& aConditionText) { +void CSSSupportsRule::GetConditionText(nsACString& aConditionText) { Servo_SupportsRule_GetConditionText(mRawRule, &aConditionText); } -void CSSSupportsRule::SetConditionText(const nsAString& aConditionText, +void CSSSupportsRule::SetConditionText(const nsACString& aConditionText, ErrorResult& aRv) { if (IsReadOnly()) { return; @@ -55,7 +55,7 @@ void CSSSupportsRule::SetConditionText(const nsAString& aConditionText, } /* virtual */ -void CSSSupportsRule::GetCssText(nsAString& aCssText) const { +void CSSSupportsRule::GetCssText(nsACString& aCssText) const { Servo_SupportsRule_GetCssText(mRawRule, &aCssText); } diff --git a/layout/style/CSSSupportsRule.h b/layout/style/CSSSupportsRule.h index 9fe8918db45c..e291f8079ca2 100644 --- a/layout/style/CSSSupportsRule.h +++ b/layout/style/CSSSupportsRule.h @@ -28,9 +28,9 @@ class CSSSupportsRule : public css::ConditionRule { // WebIDL interface uint16_t Type() const override { return CSSRule_Binding::SUPPORTS_RULE; } - void GetCssText(nsAString& aCssText) const final; - void GetConditionText(nsAString& aConditionText) final; - void SetConditionText(const nsAString& aConditionText, + void GetCssText(nsACString& aCssText) const final; + void GetConditionText(nsACString& aConditionText) final; + void SetConditionText(const nsACString& aConditionText, ErrorResult& aRv) final; size_t SizeOfIncludingThis(MallocSizeOf) const override; diff --git a/layout/style/ComputedStyle.h b/layout/style/ComputedStyle.h index 63f68947ead6..22024f2d92a2 100644 --- a/layout/style/ComputedStyle.h +++ b/layout/style/ComputedStyle.h @@ -65,7 +65,7 @@ class ComputedStyle { ServoComputedDataForgotten aComputedValues); // Returns the computed (not resolved) value of the given property. - void GetComputedPropertyValue(nsCSSPropertyID aId, nsAString& aOut) const { + void GetComputedPropertyValue(nsCSSPropertyID aId, nsACString& aOut) const { Servo_GetPropertyValue(this, aId, &aOut); } diff --git a/layout/style/DeclarationBlock.h b/layout/style/DeclarationBlock.h index 3f8920c740ac..57bfd6f1bcb3 100644 --- a/layout/style/DeclarationBlock.h +++ b/layout/style/DeclarationBlock.h @@ -16,6 +16,7 @@ #include "mozilla/ServoBindings.h" #include "nsCSSPropertyID.h" +#include "nsString.h" class nsHTMLCSSStyleSheet; @@ -145,14 +146,21 @@ class DeclarationBlock final { size_t SizeofIncludingThis(MallocSizeOf); + static already_AddRefed FromCssText( + const nsACString& aCssText, URLExtraData* aExtraData, + nsCompatibility aMode, css::Loader* aLoader, uint16_t aRuleType) { + RefPtr raw = + Servo_ParseStyleAttribute(&aCssText, aExtraData, aMode, aLoader, + aRuleType) + .Consume(); + return MakeAndAddRef(raw.forget()); + } + static already_AddRefed FromCssText( const nsAString& aCssText, URLExtraData* aExtraData, nsCompatibility aMode, css::Loader* aLoader, uint16_t aRuleType) { NS_ConvertUTF16toUTF8 value(aCssText); - RefPtr raw = - Servo_ParseStyleAttribute(&value, aExtraData, aMode, aLoader, aRuleType) - .Consume(); - return MakeAndAddRef(raw.forget()); + return FromCssText(value, aExtraData, aMode, aLoader, aRuleType); } RawServoDeclarationBlock* Raw() const { return mRaw; } @@ -175,7 +183,7 @@ class DeclarationBlock final { &mRaw); } - void ToString(nsAString& aResult) const { + void ToString(nsACString& aResult) const { Servo_DeclarationBlock_GetCssText(mRaw, &aResult); } @@ -186,11 +194,11 @@ class DeclarationBlock final { return Servo_DeclarationBlock_GetNthProperty(mRaw, aIndex, &aReturn); } - void GetPropertyValue(const nsACString& aProperty, nsAString& aValue) const { + void GetPropertyValue(const nsACString& aProperty, nsACString& aValue) const { Servo_DeclarationBlock_GetPropertyValue(mRaw, &aProperty, &aValue); } - void GetPropertyValueByID(nsCSSPropertyID aPropID, nsAString& aValue) const { + void GetPropertyValueByID(nsCSSPropertyID aPropID, nsACString& aValue) const { Servo_DeclarationBlock_GetPropertyValueById(mRaw, aPropID, &aValue); } diff --git a/layout/style/FontFace.cpp b/layout/style/FontFace.cpp index 557b85189369..157639e6e59e 100644 --- a/layout/style/FontFace.cpp +++ b/layout/style/FontFace.cpp @@ -155,8 +155,8 @@ already_AddRefed FontFace::CreateForRule( } already_AddRefed FontFace::Constructor( - const GlobalObject& aGlobal, const nsAString& aFamily, - const StringOrArrayBufferOrArrayBufferView& aSource, + const GlobalObject& aGlobal, const nsACString& aFamily, + const UTF8StringOrArrayBufferOrArrayBufferView& aSource, const FontFaceDescriptors& aDescriptors, ErrorResult& aRv) { nsISupports* global = aGlobal.GetAsSupports(); nsCOMPtr window = do_QueryInterface(global); @@ -176,10 +176,10 @@ already_AddRefed FontFace::Constructor( } void FontFace::InitializeSource( - const StringOrArrayBufferOrArrayBufferView& aSource) { - if (aSource.IsString()) { + const UTF8StringOrArrayBufferOrArrayBufferView& aSource) { + if (aSource.IsUTF8String()) { IgnoredErrorResult rv; - SetDescriptor(eCSSFontDesc_Src, aSource.GetAsString(), rv); + SetDescriptor(eCSSFontDesc_Src, aSource.GetAsUTF8String(), rv); if (rv.Failed()) { Reject(NS_ERROR_DOM_SYNTAX_ERR); @@ -205,98 +205,99 @@ void FontFace::InitializeSource( DoLoad(); } -void FontFace::GetFamily(nsString& aResult) { +void FontFace::GetFamily(nsACString& aResult) { GetDesc(eCSSFontDesc_Family, aResult); } -void FontFace::SetFamily(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetFamily(const nsACString& aValue, ErrorResult& aRv) { mFontFaceSet->FlushUserFontSet(); if (SetDescriptor(eCSSFontDesc_Family, aValue, aRv)) { DescriptorUpdated(); } } -void FontFace::GetStyle(nsString& aResult) { +void FontFace::GetStyle(nsACString& aResult) { GetDesc(eCSSFontDesc_Style, aResult); } -void FontFace::SetStyle(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetStyle(const nsACString& aValue, ErrorResult& aRv) { if (SetDescriptor(eCSSFontDesc_Style, aValue, aRv)) { DescriptorUpdated(); } } -void FontFace::GetWeight(nsString& aResult) { +void FontFace::GetWeight(nsACString& aResult) { GetDesc(eCSSFontDesc_Weight, aResult); } -void FontFace::SetWeight(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetWeight(const nsACString& aValue, ErrorResult& aRv) { mFontFaceSet->FlushUserFontSet(); if (SetDescriptor(eCSSFontDesc_Weight, aValue, aRv)) { DescriptorUpdated(); } } -void FontFace::GetStretch(nsString& aResult) { +void FontFace::GetStretch(nsACString& aResult) { GetDesc(eCSSFontDesc_Stretch, aResult); } -void FontFace::SetStretch(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetStretch(const nsACString& aValue, ErrorResult& aRv) { mFontFaceSet->FlushUserFontSet(); if (SetDescriptor(eCSSFontDesc_Stretch, aValue, aRv)) { DescriptorUpdated(); } } -void FontFace::GetUnicodeRange(nsString& aResult) { +void FontFace::GetUnicodeRange(nsACString& aResult) { GetDesc(eCSSFontDesc_UnicodeRange, aResult); } -void FontFace::SetUnicodeRange(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetUnicodeRange(const nsACString& aValue, ErrorResult& aRv) { mFontFaceSet->FlushUserFontSet(); if (SetDescriptor(eCSSFontDesc_UnicodeRange, aValue, aRv)) { DescriptorUpdated(); } } -void FontFace::GetVariant(nsString& aResult) { +void FontFace::GetVariant(nsACString& aResult) { // XXX Just expose the font-variant descriptor as "normal" until we // support it properly (bug 1055385). aResult.AssignLiteral("normal"); } -void FontFace::SetVariant(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetVariant(const nsACString& aValue, ErrorResult& aRv) { // XXX Ignore assignments to variant until we support font-variant // descriptors (bug 1055385). } -void FontFace::GetFeatureSettings(nsString& aResult) { +void FontFace::GetFeatureSettings(nsACString& aResult) { GetDesc(eCSSFontDesc_FontFeatureSettings, aResult); } -void FontFace::SetFeatureSettings(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetFeatureSettings(const nsACString& aValue, ErrorResult& aRv) { mFontFaceSet->FlushUserFontSet(); if (SetDescriptor(eCSSFontDesc_FontFeatureSettings, aValue, aRv)) { DescriptorUpdated(); } } -void FontFace::GetVariationSettings(nsString& aResult) { +void FontFace::GetVariationSettings(nsACString& aResult) { GetDesc(eCSSFontDesc_FontVariationSettings, aResult); } -void FontFace::SetVariationSettings(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetVariationSettings(const nsACString& aValue, + ErrorResult& aRv) { mFontFaceSet->FlushUserFontSet(); if (SetDescriptor(eCSSFontDesc_FontVariationSettings, aValue, aRv)) { DescriptorUpdated(); } } -void FontFace::GetDisplay(nsString& aResult) { +void FontFace::GetDisplay(nsACString& aResult) { GetDesc(eCSSFontDesc_Display, aResult); } -void FontFace::SetDisplay(const nsAString& aValue, ErrorResult& aRv) { +void FontFace::SetDisplay(const nsACString& aValue, ErrorResult& aRv) { if (SetDescriptor(eCSSFontDesc_Display, aValue, aRv)) { DescriptorUpdated(); } @@ -474,7 +475,7 @@ already_AddRefed FontFace::GetURLExtraData() const { // Boolean result indicates whether the value of the descriptor was actually // changed. -bool FontFace::SetDescriptor(nsCSSFontDesc aFontDesc, const nsAString& aValue, +bool FontFace::SetDescriptor(nsCSSFontDesc aFontDesc, const nsACString& aValue, ErrorResult& aRv) { // FIXME We probably don't need to distinguish between this anymore // since we have common backend now. @@ -485,11 +486,9 @@ bool FontFace::SetDescriptor(nsCSSFontDesc aFontDesc, const nsAString& aValue, // FIXME(heycam): Should not allow modification of FontFaces that are // CSS-connected and whose rule is read only. - - NS_ConvertUTF16toUTF8 value(aValue); RefPtr url = GetURLExtraData(); bool changed; - if (!Servo_FontFaceRule_SetDescriptor(GetData(), aFontDesc, &value, url, + if (!Servo_FontFaceRule_SetDescriptor(GetData(), aFontDesc, &aValue, url, &changed)) { aRv.ThrowSyntaxError("Invalid font descriptor"); return false; @@ -506,7 +505,7 @@ bool FontFace::SetDescriptor(nsCSSFontDesc aFontDesc, const nsAString& aValue, return true; } -bool FontFace::SetDescriptors(const nsAString& aFamily, +bool FontFace::SetDescriptors(const nsACString& aFamily, const FontFaceDescriptors& aDescriptors) { MOZ_ASSERT(!HasRule()); MOZ_ASSERT(!mDescriptors); @@ -514,7 +513,7 @@ bool FontFace::SetDescriptors(const nsAString& aFamily, mDescriptors = Servo_FontFaceRule_CreateEmpty().Consume(); // Helper to call SetDescriptor and return true on success, false on failure. - auto setDesc = [=](nsCSSFontDesc aDesc, const nsAString& aVal) -> bool { + auto setDesc = [=](nsCSSFontDesc aDesc, const nsACString& aVal) -> bool { IgnoredErrorResult rv; SetDescriptor(aDesc, aVal, rv); return !rv.Failed(); @@ -548,7 +547,7 @@ bool FontFace::SetDescriptors(const nsAString& aFamily, return true; } -void FontFace::GetDesc(nsCSSFontDesc aDescID, nsString& aResult) const { +void FontFace::GetDesc(nsCSSFontDesc aDescID, nsACString& aResult) const { aResult.Truncate(); Servo_FontFaceRule_GetDescriptorCssText(GetData(), aDescID, &aResult); diff --git a/layout/style/FontFace.h b/layout/style/FontFace.h index 22b1f5256b7f..ff7dc6e62295 100644 --- a/layout/style/FontFace.h +++ b/layout/style/FontFace.h @@ -28,7 +28,7 @@ class FontFaceBufferSource; struct FontFaceDescriptors; class FontFaceSet; class Promise; -class StringOrArrayBufferOrArrayBufferView; +class UTF8StringOrArrayBufferOrArrayBufferView; } // namespace dom } // namespace mozilla @@ -149,28 +149,28 @@ class FontFace final : public nsISupports, public nsWrapperCache { // Web IDL static already_AddRefed Constructor( - const GlobalObject& aGlobal, const nsAString& aFamily, - const StringOrArrayBufferOrArrayBufferView& aSource, + const GlobalObject& aGlobal, const nsACString& aFamily, + const UTF8StringOrArrayBufferOrArrayBufferView& aSource, const FontFaceDescriptors& aDescriptors, ErrorResult& aRV); - void GetFamily(nsString& aResult); - void SetFamily(const nsAString& aValue, ErrorResult& aRv); - void GetStyle(nsString& aResult); - void SetStyle(const nsAString& aValue, ErrorResult& aRv); - void GetWeight(nsString& aResult); - void SetWeight(const nsAString& aValue, ErrorResult& aRv); - void GetStretch(nsString& aResult); - void SetStretch(const nsAString& aValue, ErrorResult& aRv); - void GetUnicodeRange(nsString& aResult); - void SetUnicodeRange(const nsAString& aValue, ErrorResult& aRv); - void GetVariant(nsString& aResult); - void SetVariant(const nsAString& aValue, ErrorResult& aRv); - void GetFeatureSettings(nsString& aResult); - void SetFeatureSettings(const nsAString& aValue, ErrorResult& aRv); - void GetVariationSettings(nsString& aResult); - void SetVariationSettings(const nsAString& aValue, ErrorResult& aRv); - void GetDisplay(nsString& aResult); - void SetDisplay(const nsAString& aValue, ErrorResult& aRv); + void GetFamily(nsACString& aResult); + void SetFamily(const nsACString& aValue, ErrorResult& aRv); + void GetStyle(nsACString& aResult); + void SetStyle(const nsACString& aValue, ErrorResult& aRv); + void GetWeight(nsACString& aResult); + void SetWeight(const nsACString& aValue, ErrorResult& aRv); + void GetStretch(nsACString& aResult); + void SetStretch(const nsACString& aValue, ErrorResult& aRv); + void GetUnicodeRange(nsACString& aResult); + void SetUnicodeRange(const nsACString& aValue, ErrorResult& aRv); + void GetVariant(nsACString& aResult); + void SetVariant(const nsACString& aValue, ErrorResult& aRv); + void GetFeatureSettings(nsACString& aResult); + void SetFeatureSettings(const nsACString& aValue, ErrorResult& aRv); + void GetVariationSettings(nsACString& aResult); + void SetVariationSettings(const nsACString& aValue, ErrorResult& aRv); + void GetDisplay(nsACString& aResult); + void SetDisplay(const nsACString& aValue, ErrorResult& aRv); FontFaceLoadStatus Status(); Promise* Load(ErrorResult& aRv); @@ -180,7 +180,7 @@ class FontFace final : public nsISupports, public nsWrapperCache { FontFace(nsISupports* aParent, FontFaceSet* aFontFaceSet); ~FontFace(); - void InitializeSource(const StringOrArrayBufferOrArrayBufferView& aSource); + void InitializeSource(const UTF8StringOrArrayBufferOrArrayBufferView&); // Helper function for Load. void DoLoad(); @@ -188,7 +188,7 @@ class FontFace final : public nsISupports, public nsWrapperCache { // Helper function for the descriptor setter methods. // Returns true if the descriptor was modified, false if descriptor is // unchanged (which may not be an error: check aRv for actual failure). - bool SetDescriptor(nsCSSFontDesc aFontDesc, const nsAString& aValue, + bool SetDescriptor(nsCSSFontDesc aFontDesc, const nsACString& aValue, ErrorResult& aRv); /** @@ -196,7 +196,7 @@ class FontFace final : public nsISupports, public nsWrapperCache { * to the JS constructor. * Returns true on success, false if parsing any descriptor failed. */ - bool SetDescriptors(const nsAString& aFamily, + bool SetDescriptors(const nsACString& aFamily, const FontFaceDescriptors& aDescriptors); /** @@ -210,7 +210,7 @@ class FontFace final : public nsISupports, public nsWrapperCache { */ void SetStatus(FontFaceLoadStatus aStatus); - void GetDesc(nsCSSFontDesc aDescID, nsString& aResult) const; + void GetDesc(nsCSSFontDesc aDescID, nsACString& aResult) const; already_AddRefed GetURLExtraData() const; diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index d4785110a44b..38ca772fb7f1 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -198,7 +198,7 @@ void FontFaceSet::RemoveDOMContentLoadedListener() { } void FontFaceSet::ParseFontShorthandForMatching( - const nsAString& aFont, RefPtr& aFamilyList, + const nsACString& aFont, RefPtr& aFamilyList, FontWeight& aWeight, FontStretch& aStretch, FontSlantStyle& aStyle, ErrorResult& aRv) { auto style = StyleComputedFontStyleDescriptor::Normal(); @@ -245,7 +245,7 @@ static bool HasAnyCharacterInUnicodeRange(gfxUserFontEntry* aEntry, return false; } -void FontFaceSet::FindMatchingFontFaces(const nsAString& aFont, +void FontFaceSet::FindMatchingFontFaces(const nsACString& aFont, const nsAString& aText, nsTArray& aFontFaces, ErrorResult& aRv) { @@ -318,7 +318,7 @@ TimeStamp FontFaceSet::GetNavigationStartTimeStamp() { } already_AddRefed FontFaceSet::Load(JSContext* aCx, - const nsAString& aFont, + const nsACString& aFont, const nsAString& aText, ErrorResult& aRv) { FlushUserFontSet(); @@ -345,7 +345,7 @@ already_AddRefed FontFaceSet::Load(JSContext* aCx, return Promise::All(aCx, promises, aRv); } -bool FontFaceSet::Check(const nsAString& aFont, const nsAString& aText, +bool FontFaceSet::Check(const nsACString& aFont, const nsAString& aText, ErrorResult& aRv) { FlushUserFontSet(); @@ -1218,7 +1218,7 @@ nsresult FontFaceSet::LogMessage(gfxUserFontEntry* aUserFontEntry, // try to give the user an indication of where the rule came from RawServoFontFaceRule* rule = FindRuleForUserFontEntry(aUserFontEntry); nsString href; - nsString text; + nsAutoCString text; uint32_t line = 0; uint32_t column = 0; if (rule) { @@ -1247,8 +1247,8 @@ nsresult FontFaceSet::LogMessage(gfxUserFontEntry* aUserFontEntry, uint64_t innerWindowID = mDocument->InnerWindowID(); rv = scriptError->InitWithWindowID(NS_ConvertUTF8toUTF16(message), - href, // file - text, // src line + href, // file + NS_ConvertUTF8toUTF16(text), // src line line, column, aFlags, // flags "CSS Loader", // category (make separate?) diff --git a/layout/style/FontFaceSet.h b/layout/style/FontFaceSet.h index fb03e1260d26..1b4d6ef04487 100644 --- a/layout/style/FontFaceSet.h +++ b/layout/style/FontFaceSet.h @@ -176,9 +176,9 @@ class FontFaceSet final : public DOMEventTargetHelper, IMPL_EVENT_HANDLER(loading) IMPL_EVENT_HANDLER(loadingdone) IMPL_EVENT_HANDLER(loadingerror) - already_AddRefed Load(JSContext* aCx, const nsAString& aFont, + already_AddRefed Load(JSContext* aCx, const nsACString& aFont, const nsAString& aText, ErrorResult& aRv); - bool Check(const nsAString& aFont, const nsAString& aText, ErrorResult& aRv); + bool Check(const nsACString& aFont, const nsAString& aText, ErrorResult& aRv); dom::Promise* GetReady(ErrorResult& aRv); dom::FontFaceSetLoadStatus Status(); @@ -298,11 +298,11 @@ class FontFaceSet final : public DOMEventTargetHelper, // Helper function for HasLoadingFontFaces. void UpdateHasLoadingFontFaces(); - void ParseFontShorthandForMatching(const nsAString& aFont, + void ParseFontShorthandForMatching(const nsACString& aFont, RefPtr& aFamilyList, FontWeight& aWeight, FontStretch& aStretch, FontSlantStyle& aStyle, ErrorResult& aRv); - void FindMatchingFontFaces(const nsAString& aFont, const nsAString& aText, + void FindMatchingFontFaces(const nsACString& aFont, const nsAString& aText, nsTArray& aFontFaces, ErrorResult& aRv); void DispatchLoadingEventAndReplaceReadyPromise(); diff --git a/layout/style/GroupRule.cpp b/layout/style/GroupRule.cpp index 731149abb932..3c6a895bbb38 100644 --- a/layout/style/GroupRule.cpp +++ b/layout/style/GroupRule.cpp @@ -74,7 +74,7 @@ void GroupRule::DropSheetReference() { Rule::DropSheetReference(); } -uint32_t GroupRule::InsertRule(const nsAString& aRule, uint32_t aIndex, +uint32_t GroupRule::InsertRule(const nsACString& aRule, uint32_t aIndex, ErrorResult& aRv) { if (IsReadOnly()) { return 0; diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index 258e23def11a..73122a79e6b6 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -69,7 +69,7 @@ class GroupRule : public Rule { // WebIDL API dom::CSSRuleList* CssRules() { return mRuleList; } - uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex, + uint32_t InsertRule(const nsACString& aRule, uint32_t aIndex, ErrorResult& aRv); void DeleteRule(uint32_t aIndex, ErrorResult& aRv); @@ -83,8 +83,8 @@ class ConditionRule : public GroupRule { using GroupRule::GroupRule; public: - virtual void GetConditionText(nsAString& aConditionText) = 0; - virtual void SetConditionText(const nsAString& aConditionText, + virtual void GetConditionText(nsACString& aConditionText) = 0; + virtual void SetConditionText(const nsACString& aConditionText, ErrorResult& aRv) = 0; }; diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index cc60ae85bfdf..6db81b949f91 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1017,7 +1017,7 @@ Loader::MediaMatched Loader::PrepareSheet( if (!aMediaString.IsEmpty()) { NS_ASSERTION(!aMediaList, "must not provide both aMediaString and aMediaList"); - mediaList = MediaList::Create(aMediaString); + mediaList = MediaList::Create(NS_ConvertUTF16toUTF8(aMediaString)); } aSheet.SetMedia(do_AddRef(mediaList)); diff --git a/layout/style/MappedDeclarations.cpp b/layout/style/MappedDeclarations.cpp index 00c75bb6fa30..bd3f069b4c32 100644 --- a/layout/style/MappedDeclarations.cpp +++ b/layout/style/MappedDeclarations.cpp @@ -31,11 +31,12 @@ void MappedDeclarations::SetBackgroundImage(const nsAttrValue& aValue) { if (aValue.Type() != nsAttrValue::eURL) { return; } - // FIXME(emilio): Going through URL parsing again seems slightly wasteful. nsAutoString str; aValue.ToString(str); + nsAutoCString utf8; + CopyUTF16toUTF8(str, utf8); Servo_DeclarationBlock_SetBackgroundImage( - mDecl, &str, mDocument->DefaultStyleAttrURLData()); + mDecl, &utf8, mDocument->DefaultStyleAttrURLData()); } } // namespace mozilla diff --git a/layout/style/MappedDeclarations.h b/layout/style/MappedDeclarations.h index 1c4459d2c0f0..da5f51b687da 100644 --- a/layout/style/MappedDeclarations.h +++ b/layout/style/MappedDeclarations.h @@ -178,7 +178,7 @@ class MappedDeclarations final { } // Set font-family to a string - void SetFontFamily(const nsString& aValue) { + void SetFontFamily(const nsACString& aValue) { Servo_DeclarationBlock_SetFontFamily(mDecl, &aValue); } diff --git a/layout/style/MediaList.cpp b/layout/style/MediaList.cpp index 6caf0ed81af9..1b795f276fcd 100644 --- a/layout/style/MediaList.cpp +++ b/layout/style/MediaList.cpp @@ -72,23 +72,23 @@ already_AddRefed MediaList::Clone() { MediaList::MediaList() : mRawList(Servo_MediaList_Create().Consume()) {} -MediaList::MediaList(const nsAString& aMedia, CallerType aCallerType) +MediaList::MediaList(const nsACString& aMedia, CallerType aCallerType) : MediaList() { SetTextInternal(aMedia, aCallerType); } -void MediaList::GetText(nsAString& aMediaText) { +void MediaList::GetText(nsACString& aMediaText) { Servo_MediaList_GetText(mRawList, &aMediaText); } /* static */ -already_AddRefed MediaList::Create(const nsAString& aMedia, +already_AddRefed MediaList::Create(const nsACString& aMedia, CallerType aCallerType) { RefPtr mediaList = new MediaList(aMedia, aCallerType); return mediaList.forget(); } -void MediaList::SetText(const nsAString& aMediaText) { +void MediaList::SetText(const nsACString& aMediaText) { if (IsReadOnly()) { return; } @@ -96,28 +96,26 @@ void MediaList::SetText(const nsAString& aMediaText) { SetTextInternal(aMediaText, CallerType::NonSystem); } -void MediaList::GetMediaText(nsAString& aMediaText) { GetText(aMediaText); } +void MediaList::GetMediaText(nsACString& aMediaText) { GetText(aMediaText); } -void MediaList::SetTextInternal(const nsAString& aMediaText, +void MediaList::SetTextInternal(const nsACString& aMediaText, CallerType aCallerType) { - NS_ConvertUTF16toUTF8 mediaText(aMediaText); - Servo_MediaList_SetText(mRawList, &mediaText, aCallerType); + Servo_MediaList_SetText(mRawList, &aMediaText, aCallerType); } uint32_t MediaList::Length() { return Servo_MediaList_GetLength(mRawList); } void MediaList::IndexedGetter(uint32_t aIndex, bool& aFound, - nsAString& aReturn) { + nsACString& aReturn) { aFound = Servo_MediaList_GetMediumAt(mRawList, aIndex, &aReturn); if (!aFound) { - SetDOMStringToNull(aReturn); + aReturn.SetIsVoid(true); } } -void MediaList::Delete(const nsAString& aOldMedium, ErrorResult& aRv) { +void MediaList::Delete(const nsACString& aOldMedium, ErrorResult& aRv) { MOZ_ASSERT(!IsReadOnly()); - NS_ConvertUTF16toUTF8 oldMedium(aOldMedium); - if (Servo_MediaList_DeleteMedium(mRawList, &oldMedium)) { + if (Servo_MediaList_DeleteMedium(mRawList, &aOldMedium)) { return; } aRv.ThrowNotFoundError("Medium not in list"); @@ -130,7 +128,7 @@ bool MediaList::Matches(const Document& aDocument) const { return Servo_MediaList_Matches(mRawList, rawSet); } -void MediaList::Append(const nsAString& aNewMedium, ErrorResult& aRv) { +void MediaList::Append(const nsACString& aNewMedium, ErrorResult& aRv) { MOZ_ASSERT(!IsReadOnly()); if (aNewMedium.IsEmpty()) { // XXXbz per spec there should not be an exception here, as far as @@ -138,24 +136,23 @@ void MediaList::Append(const nsAString& aNewMedium, ErrorResult& aRv) { aRv.ThrowNotFoundError("Empty medium"); return; } - NS_ConvertUTF16toUTF8 newMedium(aNewMedium); - Servo_MediaList_AppendMedium(mRawList, &newMedium); + Servo_MediaList_AppendMedium(mRawList, &aNewMedium); } -void MediaList::SetMediaText(const nsAString& aMediaText) { +void MediaList::SetMediaText(const nsACString& aMediaText) { DoMediaChange([&](ErrorResult& aRv) { SetText(aMediaText); }, IgnoreErrors()); } -void MediaList::Item(uint32_t aIndex, nsAString& aReturn) { +void MediaList::Item(uint32_t aIndex, nsACString& aReturn) { bool dummy; IndexedGetter(aIndex, dummy, aReturn); } -void MediaList::DeleteMedium(const nsAString& aOldMedium, ErrorResult& aRv) { +void MediaList::DeleteMedium(const nsACString& aOldMedium, ErrorResult& aRv) { DoMediaChange([&](ErrorResult& aRv) { Delete(aOldMedium, aRv); }, aRv); } -void MediaList::AppendMedium(const nsAString& aNewMedium, ErrorResult& aRv) { +void MediaList::AppendMedium(const nsACString& aNewMedium, ErrorResult& aRv) { DoMediaChange([&](ErrorResult& aRv) { Append(aNewMedium, aRv); }, aRv); } diff --git a/layout/style/MediaList.h b/layout/style/MediaList.h index fd8ca84fc17c..29ce7cfdc752 100644 --- a/layout/style/MediaList.h +++ b/layout/style/MediaList.h @@ -35,27 +35,27 @@ class MediaList final : public nsISupports, public nsWrapperCache { : mRawList(aRawList) {} static already_AddRefed Create( - const nsAString& aMedia, CallerType aCallerType = CallerType::NonSystem); + const nsACString& aMedia, CallerType aCallerType = CallerType::NonSystem); already_AddRefed Clone(); JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) final; nsISupports* GetParentObject() const; - void GetText(nsAString& aMediaText); - void SetText(const nsAString& aMediaText); + void GetText(nsACString& aMediaText); + void SetText(const nsACString& aMediaText); bool Matches(const Document&) const; void SetStyleSheet(StyleSheet* aSheet); // WebIDL - void GetMediaText(nsAString& aMediaText); - void SetMediaText(const nsAString& aMediaText); + void GetMediaText(nsACString& aMediaText); + void SetMediaText(const nsACString& aMediaText); uint32_t Length(); - void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aReturn); - void Item(uint32_t aIndex, nsAString& aResult); - void DeleteMedium(const nsAString& aMedium, ErrorResult& aRv); - void AppendMedium(const nsAString& aMedium, ErrorResult& aRv); + void IndexedGetter(uint32_t aIndex, bool& aFound, nsACString& aReturn); + void Item(uint32_t aIndex, nsACString& aResult); + void DeleteMedium(const nsACString& aMedium, ErrorResult& aRv); + void AppendMedium(const nsACString& aMedium, ErrorResult& aRv); size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; @@ -64,13 +64,13 @@ class MediaList final : public nsISupports, public nsWrapperCache { } protected: - MediaList(const nsAString& aMedia, CallerType); + MediaList(const nsACString& aMedia, CallerType); MediaList(); - void SetTextInternal(const nsAString& aMediaText, CallerType); + void SetTextInternal(const nsACString& aMediaText, CallerType); - void Delete(const nsAString& aOldMedium, ErrorResult& aRv); - void Append(const nsAString& aNewMedium, ErrorResult& aRv); + void Delete(const nsACString& aOldMedium, ErrorResult& aRv); + void Append(const nsACString& aNewMedium, ErrorResult& aRv); ~MediaList() { MOZ_ASSERT(!mStyleSheet, "Backpointer should have been cleared"); diff --git a/layout/style/MediaQueryList.cpp b/layout/style/MediaQueryList.cpp index e8006afac27f..e8d5ed17cc69 100644 --- a/layout/style/MediaQueryList.cpp +++ b/layout/style/MediaQueryList.cpp @@ -20,7 +20,7 @@ namespace mozilla { namespace dom { MediaQueryList::MediaQueryList(Document* aDocument, - const nsAString& aMediaQueryList, + const nsACString& aMediaQueryList, CallerType aCallerType) : DOMEventTargetHelper(aDocument->GetInnerWindow()), mDocument(aDocument), @@ -56,7 +56,7 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_IMPL_ADDREF_INHERITED(MediaQueryList, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(MediaQueryList, DOMEventTargetHelper) -void MediaQueryList::GetMedia(nsAString& aMedia) { +void MediaQueryList::GetMedia(nsACString& aMedia) { mMediaList->GetText(aMedia); } diff --git a/layout/style/MediaQueryList.h b/layout/style/MediaQueryList.h index 22d24e88506e..9fd1b1ca194a 100644 --- a/layout/style/MediaQueryList.h +++ b/layout/style/MediaQueryList.h @@ -29,7 +29,7 @@ class MediaQueryList final : public DOMEventTargetHelper, public: // The caller who constructs is responsible for calling Evaluate // before calling any other methods. - MediaQueryList(Document* aDocument, const nsAString& aMediaQueryList, + MediaQueryList(Document* aDocument, const nsACString& aMediaQueryList, CallerType aCallerType); private: @@ -50,7 +50,7 @@ class MediaQueryList final : public DOMEventTargetHelper, JS::Handle aGivenProto) override; // WebIDL methods - void GetMedia(nsAString& aMedia); + void GetMedia(nsACString& aMedia); bool Matches(); void AddListener(EventListener* aListener, ErrorResult& aRv); void RemoveListener(EventListener* aListener, ErrorResult& aRv); diff --git a/layout/style/Rule.cpp b/layout/style/Rule.cpp index a1111439fa36..bb34b7d14d3e 100644 --- a/layout/style/Rule.cpp +++ b/layout/style/Rule.cpp @@ -86,7 +86,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END /* virtual */ void Rule::DropSheetReference() { mSheet = nullptr; } -void Rule::SetCssText(const nsAString& aCssText) { +void Rule::SetCssText(const nsACString& aCssText) { // We used to throw for some rule types, but not all. Specifically, we did // not throw for StyleRule. Let's just always not throw. } diff --git a/layout/style/Rule.h b/layout/style/Rule.h index fe4055b8772c..2cd6a02f39b6 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -95,8 +95,8 @@ class Rule : public nsISupports, public nsWrapperCache { // WebIDL interface virtual uint16_t Type() const = 0; - virtual void GetCssText(nsAString& aCssText) const = 0; - void SetCssText(const nsAString& aCssText); + virtual void GetCssText(nsACString& aCssText) const = 0; + void SetCssText(const nsACString& aCssText); Rule* GetParentRule() const; StyleSheet* GetParentStyleSheet() const { return GetStyleSheet(); } nsINode* GetParentObject() const { diff --git a/layout/style/ServoBindings.h b/layout/style/ServoBindings.h index a1e801a8307b..4043ed4e8794 100644 --- a/layout/style/ServoBindings.h +++ b/layout/style/ServoBindings.h @@ -36,7 +36,7 @@ extern "C" { #define BASIC_RULE_FUNCS_WITHOUT_GETTER(type_) \ void Servo_##type_##_Debug(const RawServo##type_*, nsACString* result); \ - void Servo_##type_##_GetCssText(const RawServo##type_*, nsAString* result); + void Servo_##type_##_GetCssText(const RawServo##type_*, nsACString* result); #define BASIC_RULE_FUNCS(type_) \ StyleStrong Servo_CssRules_Get##type_##RuleAt( \ @@ -87,7 +87,7 @@ BASIC_SERDE_FUNCS(StylePositionOrAuto) void Servo_CounterStyleRule_GetDescriptorCssText( const RawServoCounterStyleRule* rule, nsCSSCounterDesc desc, - nsAString* result); + nsACString* result); bool Servo_CounterStyleRule_SetDescriptor(const RawServoCounterStyleRule* rule, nsCSSCounterDesc desc, diff --git a/layout/style/ServoCSSParser.cpp b/layout/style/ServoCSSParser.cpp index 06554c5b621c..913879ed2070 100644 --- a/layout/style/ServoCSSParser.cpp +++ b/layout/style/ServoCSSParser.cpp @@ -33,18 +33,17 @@ bool ServoCSSParser::ComputeColor(ServoStyleSet* aStyleSet, /* static */ already_AddRefed ServoCSSParser::ParseProperty( - nsCSSPropertyID aProperty, const nsAString& aValue, + nsCSSPropertyID aProperty, const nsACString& aValue, const ParsingEnvironment& aParsingEnvironment, ParsingMode aParsingMode) { - NS_ConvertUTF16toUTF8 value(aValue); return Servo_ParseProperty( - aProperty, &value, aParsingEnvironment.mUrlExtraData, aParsingMode, - aParsingEnvironment.mCompatMode, aParsingEnvironment.mLoader, - aParsingEnvironment.mRuleType) + aProperty, &aValue, aParsingEnvironment.mUrlExtraData, + aParsingMode, aParsingEnvironment.mCompatMode, + aParsingEnvironment.mLoader, aParsingEnvironment.mRuleType) .Consume(); } /* static */ -bool ServoCSSParser::ParseEasing(const nsAString& aValue, +bool ServoCSSParser::ParseEasing(const nsACString& aValue, nsTimingFunction& aResult) { return Servo_ParseEasing(&aValue, &aResult); } @@ -59,7 +58,7 @@ bool ServoCSSParser::ParseTransformIntoMatrix(const nsACString& aValue, /* static */ bool ServoCSSParser::ParseFontShorthandForMatching( - const nsAString& aValue, URLExtraData* aUrl, RefPtr& aList, + const nsACString& aValue, URLExtraData* aUrl, RefPtr& aList, StyleComputedFontStyleDescriptor& aStyle, float& aStretch, float& aWeight) { return Servo_ParseFontShorthandForMatching(&aValue, aUrl, &aList, &aStyle, &aStretch, &aWeight); diff --git a/layout/style/ServoCSSParser.h b/layout/style/ServoCSSParser.h index c2e881ae26b5..a7387a134f7a 100644 --- a/layout/style/ServoCSSParser.h +++ b/layout/style/ServoCSSParser.h @@ -83,7 +83,7 @@ class ServoCSSParser { * in Servo. */ static already_AddRefed ParseProperty( - nsCSSPropertyID aProperty, const nsAString& aValue, + nsCSSPropertyID aProperty, const nsACString& aValue, const ParsingEnvironment& aParsingEnvironment, ParsingMode aParsingMode = ParsingMode::Default); @@ -94,7 +94,7 @@ class ServoCSSParser { * @param aResult The output timing function. (output) * @return Whether the value was successfully parsed. */ - static bool ParseEasing(const nsAString& aValue, nsTimingFunction& aResult); + static bool ParseEasing(const nsACString& aValue, nsTimingFunction& aResult); /** * Parse a specified transform list into a gfx matrix. @@ -122,7 +122,7 @@ class ServoCSSParser { * @return Whether the value was successfully parsed. */ static bool ParseFontShorthandForMatching( - const nsAString& aValue, URLExtraData* aUrl, + const nsACString& aValue, URLExtraData* aUrl, RefPtr& aList, StyleComputedFontStyleDescriptor& aStyle, float& aStretch, float& aWeight); diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index 3a7513ad8d35..131e954bfdac 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -155,7 +155,8 @@ void ServoCSSRuleList::DropParentRuleReference() { [](css::Rule* rule) { rule->DropParentRuleReference(); }); } -nsresult ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex) { +nsresult ServoCSSRuleList::InsertRule(const nsACString& aRule, + uint32_t aIndex) { MOZ_ASSERT(mStyleSheet, "Caller must ensure that " "the list is not unlinked from stylesheet"); @@ -164,7 +165,6 @@ nsresult ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex) { return NS_OK; } - NS_ConvertUTF16toUTF8 rule(aRule); bool nested = !!mParentRule; css::Loader* loader = nullptr; auto allowImportRules = mStyleSheet->SelfOrAncestorIsConstructed() @@ -181,7 +181,7 @@ nsresult ServoCSSRuleList::InsertRule(const nsAString& aRule, uint32_t aIndex) { } uint16_t type; nsresult rv = Servo_CssRules_InsertRule(mRawRules, mStyleSheet->RawContents(), - &rule, aIndex, nested, loader, + &aRule, aIndex, nested, loader, allowImportRules, mStyleSheet, &type); if (NS_FAILED(rv)) { return rv; diff --git a/layout/style/ServoCSSRuleList.h b/layout/style/ServoCSSRuleList.h index d4972ace442d..79dbb3344003 100644 --- a/layout/style/ServoCSSRuleList.h +++ b/layout/style/ServoCSSRuleList.h @@ -46,7 +46,7 @@ class ServoCSSRuleList final : public dom::CSSRuleList { uint32_t Length() final { return mRules.Length(); } css::Rule* GetRule(uint32_t aIndex); - nsresult InsertRule(const nsAString& aRule, uint32_t aIndex); + nsresult InsertRule(const nsACString& aRule, uint32_t aIndex); nsresult DeleteRule(uint32_t aIndex); uint16_t GetDOMCSSRuleType(uint32_t aIndex) const; diff --git a/layout/style/StyleAnimationValue.cpp b/layout/style/StyleAnimationValue.cpp index e293f0354e58..c5983a068123 100644 --- a/layout/style/StyleAnimationValue.cpp +++ b/layout/style/StyleAnimationValue.cpp @@ -148,7 +148,7 @@ Size AnimationValue::GetScaleValue(const nsIFrame* aFrame) const { void AnimationValue::SerializeSpecifiedValue(nsCSSPropertyID aProperty, const RawServoStyleSet* aRawSet, - nsAString& aString) const { + nsACString& aString) const { MOZ_ASSERT(mServo); Servo_AnimationValue_Serialize(mServo, aProperty, aRawSet, &aString); } @@ -180,7 +180,7 @@ double AnimationValue::ComputeDistance(nsCSSPropertyID aProperty, /* static */ AnimationValue AnimationValue::FromString(nsCSSPropertyID aProperty, - const nsAString& aValue, + const nsACString& aValue, Element* aElement) { MOZ_ASSERT(aElement); diff --git a/layout/style/StyleAnimationValue.h b/layout/style/StyleAnimationValue.h index f9a70b90262f..330ab86a0bbc 100644 --- a/layout/style/StyleAnimationValue.h +++ b/layout/style/StyleAnimationValue.h @@ -88,7 +88,7 @@ struct AnimationValue { // Uncompute this AnimationValue and then serialize it. void SerializeSpecifiedValue(nsCSSPropertyID aProperty, const RawServoStyleSet* aRawSet, - nsAString& aString) const; + nsACString& aString) const; // Check if |*this| and |aToValue| can be interpolated. bool IsInterpolableWith(nsCSSPropertyID aProperty, @@ -102,7 +102,7 @@ struct AnimationValue { // should use this carefully. Now, it is only used by // nsDOMWindowUtils::ComputeAnimationDistance. static AnimationValue FromString(nsCSSPropertyID aProperty, - const nsAString& aValue, + const nsACString& aValue, dom::Element* aElement); // Create an already_AddRefed from a @@ -119,7 +119,7 @@ struct AnimationValue { inline std::ostream& operator<<(std::ostream& aOut, const AnimationValue& aValue) { MOZ_ASSERT(aValue.mServo); - nsString s; + nsAutoCString s; Servo_AnimationValue_Dump(aValue.mServo, &s); return aOut << s; } diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index 3b0ac2cd3d77..b5338dea0c88 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -133,8 +133,8 @@ already_AddRefed StyleSheet::Constructor( sheet->mConstructorDocument = constructorDocument; // 2. Set the sheet's media according to aOptions. - if (aOptions.mMedia.IsString()) { - sheet->SetMedia(MediaList::Create(aOptions.mMedia.GetAsString())); + if (aOptions.mMedia.IsUTF8String()) { + sheet->SetMedia(MediaList::Create(aOptions.mMedia.GetAsUTF8String())); } else { sheet->SetMedia(aOptions.mMedia.GetAsMediaList()->Clone()); } @@ -582,7 +582,7 @@ css::Rule* StyleSheet::GetDOMOwnerRule() const { return mOwnerRule; } // https://drafts.csswg.org/cssom/#dom-cssstylesheet-insertrule // https://wicg.github.io/construct-stylesheets/#dom-cssstylesheet-insertrule -uint32_t StyleSheet::InsertRule(const nsAString& aRule, uint32_t aIndex, +uint32_t StyleSheet::InsertRule(const nsACString& aRule, uint32_t aIndex, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) { if (IsReadOnly() || !AreRulesAvailable(aSubjectPrincipal, aRv)) { @@ -616,14 +616,15 @@ void StyleSheet::DeleteRule(uint32_t aIndex, nsIPrincipal& aSubjectPrincipal, return DeleteRuleInternal(aIndex, aRv); } -int32_t StyleSheet::AddRule(const nsAString& aSelector, const nsAString& aBlock, +int32_t StyleSheet::AddRule(const nsACString& aSelector, + const nsACString& aBlock, const Optional& aIndex, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) { if (IsReadOnly() || !AreRulesAvailable(aSubjectPrincipal, aRv)) { return -1; } - nsAutoString rule; + nsAutoCString rule; rule.Append(aSelector); rule.AppendLiteral(" { "); if (!aBlock.IsEmpty()) { @@ -832,7 +833,7 @@ StyleSheet::StyleSheetLoaded(StyleSheet* aSheet, bool aWasDeferred, #undef NOTIFY -nsresult StyleSheet::InsertRuleIntoGroup(const nsAString& aRule, +nsresult StyleSheet::InsertRuleIntoGroup(const nsACString& aRule, css::GroupRule* aGroup, uint32_t aIndex) { NS_ASSERTION(IsComplete(), "No inserting into an incomplete sheet!"); @@ -1032,12 +1033,12 @@ void StyleSheet::List(FILE* aOut, int32_t aIndent) { } if (mMedia) { - nsString buffer; + nsAutoCString buffer; mMedia->GetText(buffer); if (!buffer.IsEmpty()) { line.AppendLiteral(", "); - AppendUTF16toUTF8(buffer, line); + line.Append(buffer); } } @@ -1053,14 +1054,12 @@ void StyleSheet::List(FILE* aOut, int32_t aIndent) { ServoCSSRuleList* ruleList = GetCssRulesInternal(); for (uint32_t i = 0, len = ruleList->Length(); i < len; ++i) { - nsString cssText; css::Rule* rule = ruleList->GetRule(i); + + nsAutoCString cssText; rule->GetCssText(cssText); - - NS_ConvertUTF16toUTF8 s(cssText); - s.ReplaceSubstring("\n"_ns, newlineIndent); - - fprintf_stderr(aOut, "%s\n", s.get()); + cssText.ReplaceSubstring("\n"_ns, newlineIndent); + fprintf_stderr(aOut, "%s\n", cssText.get()); } if (ruleList->Length() != 0) { @@ -1085,7 +1084,7 @@ void StyleSheet::DropMedia() { dom::MediaList* StyleSheet::Media() { if (!mMedia) { - mMedia = dom::MediaList::Create(nsString()); + mMedia = dom::MediaList::Create(EmptyCString()); mMedia->SetStyleSheet(this); } @@ -1376,8 +1375,8 @@ ServoCSSRuleList* StyleSheet::GetCssRulesInternal() { return mRuleList; } -uint32_t StyleSheet::InsertRuleInternal(const nsAString& aRule, uint32_t aIndex, - ErrorResult& aRv) { +uint32_t StyleSheet::InsertRuleInternal(const nsACString& aRule, + uint32_t aIndex, ErrorResult& aRv) { MOZ_ASSERT(!IsReadOnly()); MOZ_ASSERT(!ModificationDisallowed()); @@ -1421,7 +1420,7 @@ void StyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv) { } } -nsresult StyleSheet::InsertRuleIntoGroupInternal(const nsAString& aRule, +nsresult StyleSheet::InsertRuleIntoGroupInternal(const nsACString& aRule, css::GroupRule* aGroup, uint32_t aIndex) { MOZ_ASSERT(!IsReadOnly()); diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h index 0eb0eb7ac423..fcd7460af1ce 100644 --- a/layout/style/StyleSheet.h +++ b/layout/style/StyleSheet.h @@ -343,11 +343,11 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache { // version. css::Rule* GetDOMOwnerRule() const; dom::CSSRuleList* GetCssRules(nsIPrincipal& aSubjectPrincipal, ErrorResult&); - uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex, + uint32_t InsertRule(const nsACString& aRule, uint32_t aIndex, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); void DeleteRule(uint32_t aIndex, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); - int32_t AddRule(const nsAString& aSelector, const nsAString& aBlock, + int32_t AddRule(const nsACString& aSelector, const nsACString& aBlock, const dom::Optional& aIndex, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); already_AddRefed Replace(const nsACString& aText, ErrorResult&); @@ -418,7 +418,7 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache { void DropStyleSet(ServoStyleSet* aStyleSet); nsresult DeleteRuleFromGroup(css::GroupRule* aGroup, uint32_t aIndex); - nsresult InsertRuleIntoGroup(const nsAString& aRule, css::GroupRule* aGroup, + nsresult InsertRuleIntoGroup(const nsACString& aRule, css::GroupRule* aGroup, uint32_t aIndex); // Find the ID of the owner inner window. @@ -487,10 +487,10 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache { protected: // Internal methods which do not have security check and completeness check. - uint32_t InsertRuleInternal(const nsAString& aRule, uint32_t aIndex, + uint32_t InsertRuleInternal(const nsACString& aRule, uint32_t aIndex, ErrorResult&); void DeleteRuleInternal(uint32_t aIndex, ErrorResult&); - nsresult InsertRuleIntoGroupInternal(const nsAString& aRule, + nsresult InsertRuleIntoGroupInternal(const nsACString& aRule, css::GroupRule* aGroup, uint32_t aIndex); // Common tail routine for the synchronous and asynchronous parsing paths. diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 7d03935cec16..1d2110fc8771 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -357,8 +357,7 @@ NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE( nsComputedDOMStyle, ClearComputedStyle()) nsresult nsComputedDOMStyle::GetPropertyValue(const nsCSSPropertyID aPropID, - nsAString& aValue) { - MOZ_ASSERT(aPropID != eCSSPropertyExtra_variable); + nsACString& aValue) { return GetPropertyValue(aPropID, EmptyCString(), aValue); } @@ -371,11 +370,11 @@ void nsComputedDOMStyle::SetPropertyValue(const nsCSSPropertyID aPropID, PromiseFlatCString(nsCSSProps::GetStringValue(aPropID)).get())); } -void nsComputedDOMStyle::GetCssText(nsAString& aCssText) { +void nsComputedDOMStyle::GetCssText(nsACString& aCssText) { aCssText.Truncate(); } -void nsComputedDOMStyle::SetCssText(const nsAString& aCssText, +void nsComputedDOMStyle::SetCssText(const nsACString& aCssText, nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { aRv.ThrowNoModificationAllowedError("Can't set cssText on computed style"); @@ -401,14 +400,14 @@ css::Rule* nsComputedDOMStyle::GetParentRule() { return nullptr; } NS_IMETHODIMP nsComputedDOMStyle::GetPropertyValue(const nsACString& aPropertyName, - nsAString& aReturn) { + nsACString& aReturn) { nsCSSPropertyID prop = nsCSSProps::LookupProperty(aPropertyName); return GetPropertyValue(prop, aPropertyName, aReturn); } nsresult nsComputedDOMStyle::GetPropertyValue( nsCSSPropertyID aPropID, const nsACString& aMaybeCustomPropertyName, - nsAString& aReturn) { + nsACString& aReturn) { MOZ_ASSERT(aReturn.IsEmpty()); const ComputedStyleMap::Entry* entry = nullptr; @@ -451,9 +450,9 @@ nsresult nsComputedDOMStyle::GetPropertyValue( if (!nsCSSProps::PropHasFlags(aPropID, CSSPropFlags::SerializedByServo)) { if (RefPtr value = (this->*entry->mGetter)()) { ErrorResult rv; - nsString text; + nsAutoString text; value->GetCssText(text, rv); - aReturn.Assign(text); + CopyUTF16toUTF8(text, aReturn); return rv.StealNSResult(); } return NS_OK; @@ -1108,7 +1107,7 @@ void nsComputedDOMStyle::ClearCurrentStyleSources() { } void nsComputedDOMStyle::RemoveProperty(const nsACString& aPropertyName, - nsAString& aReturn, ErrorResult& aRv) { + nsACString& aReturn, ErrorResult& aRv) { // Note: not using nsPrintfCString here in case aPropertyName contains // nulls. aRv.ThrowNoModificationAllowedError("Can't remove property '"_ns + @@ -1117,13 +1116,13 @@ void nsComputedDOMStyle::RemoveProperty(const nsACString& aPropertyName, } void nsComputedDOMStyle::GetPropertyPriority(const nsACString& aPropertyName, - nsAString& aReturn) { + nsACString& aReturn) { aReturn.Truncate(); } void nsComputedDOMStyle::SetProperty(const nsACString& aPropertyName, const nsACString& aValue, - const nsAString& aPriority, + const nsACString& aPriority, nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { // Note: not using nsPrintfCString here in case aPropertyName contains @@ -1317,7 +1316,7 @@ already_AddRefed nsComputedDOMStyle::DoGetOsxFontSmoothing() { return nullptr; } - nsAutoString result; + nsAutoCString result; mComputedStyle->GetComputedPropertyValue(eCSSProperty__moz_osx_font_smoothing, result); RefPtr val = new nsROCSSPrimitiveValue; @@ -1382,7 +1381,7 @@ void nsComputedDOMStyle::SetValueToURLValue(const StyleComputedUrl* aURL, enum class Brackets { No, Yes }; -static void AppendGridLineNames(nsAString& aResult, +static void AppendGridLineNames(nsACString& aResult, Span aLineNames, Brackets aBrackets) { if (aLineNames.IsEmpty()) { @@ -1396,8 +1395,12 @@ static void AppendGridLineNames(nsAString& aResult, aResult.Append('['); } for (uint32_t i = 0;;) { + // TODO: Maybe use servo to do this and avoid the silly utf16->utf8 dance? + nsAutoString name; nsStyleUtil::AppendEscapedCSSIdent( - nsDependentAtomString(aLineNames[i].AsAtom()), aResult); + nsDependentAtomString(aLineNames[i].AsAtom()), name); + AppendUTF16toUTF8(name, aResult); + if (++i == numLines) { break; } @@ -1415,7 +1418,7 @@ static void AppendGridLineNames(nsDOMCSSValueList* aValueList, return; } RefPtr val = new nsROCSSPrimitiveValue; - nsAutoString lineNamesString; + nsAutoCString lineNamesString; AppendGridLineNames(lineNamesString, aLineNames, Brackets::Yes); val->SetString(lineNamesString); aValueList->AppendCSSValue(val.forget()); @@ -1428,7 +1431,7 @@ static void AppendGridLineNames(nsDOMCSSValueList* aValueList, return; } RefPtr val = new nsROCSSPrimitiveValue; - nsAutoString lineNamesString; + nsAutoCString lineNamesString; lineNamesString.Assign('['); if (!aLineNames1.IsEmpty()) { AppendGridLineNames(lineNamesString, aLineNames1, Brackets::No); @@ -1710,7 +1713,7 @@ already_AddRefed nsComputedDOMStyle::DoGetGridTemplateColumns() { if (!gridFrame) { // The element doesn't have a box - return the computed value. // https://drafts.csswg.org/css-grid/#resolved-track-list - nsAutoString string; + nsAutoCString string; mComputedStyle->GetComputedPropertyValue(eCSSProperty_grid_template_columns, string); RefPtr value = new nsROCSSPrimitiveValue; @@ -1730,7 +1733,7 @@ already_AddRefed nsComputedDOMStyle::DoGetGridTemplateRows() { if (!gridFrame) { // The element doesn't have a box - return the computed value. // https://drafts.csswg.org/css-grid/#resolved-track-list - nsAutoString string; + nsAutoCString string; mComputedStyle->GetComputedPropertyValue(eCSSProperty_grid_template_rows, string); RefPtr value = new nsROCSSPrimitiveValue; @@ -1835,7 +1838,7 @@ already_AddRefed nsComputedDOMStyle::DoGetLineHeight() { already_AddRefed nsComputedDOMStyle::DoGetTextDecoration() { auto getPropertyValue = [&](nsCSSPropertyID aID) { RefPtr value = new nsROCSSPrimitiveValue; - nsAutoString string; + nsAutoCString string; mComputedStyle->GetComputedPropertyValue(aID, string); value->SetString(string); return value.forget(); @@ -2294,7 +2297,7 @@ void nsComputedDOMStyle::SetValueToLengthPercentage( return aValue->SetPercent(result); } - nsAutoString result; + nsAutoCString result; Servo_LengthPercentage_ToCss(&aLength, &result); aValue->SetString(result); } diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index 22d909f8f43c..904945a625ae 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -73,7 +73,7 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration, NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER nsresult GetPropertyValue(const nsCSSPropertyID aPropID, - nsAString& aValue) override; + nsACString& aValue) override; void SetPropertyValue(const nsCSSPropertyID aPropID, const nsACString& aValue, nsIPrincipal* aSubjectPrincipal, mozilla::ErrorResult& aRv) override; @@ -139,7 +139,7 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration, private: nsresult GetPropertyValue(const nsCSSPropertyID aPropID, const nsACString& aMaybeCustomPropertyNme, - nsAString& aValue); + nsACString& aValue); virtual ~nsComputedDOMStyle(); diff --git a/layout/style/nsDOMCSSDeclaration.cpp b/layout/style/nsDOMCSSDeclaration.cpp index ff5469f5914e..526f02db7655 100644 --- a/layout/style/nsDOMCSSDeclaration.cpp +++ b/layout/style/nsDOMCSSDeclaration.cpp @@ -34,7 +34,7 @@ JSObject* nsDOMCSSDeclaration::WrapObject(JSContext* aCx, NS_IMPL_QUERY_INTERFACE(nsDOMCSSDeclaration, nsICSSDeclaration) nsresult nsDOMCSSDeclaration::GetPropertyValue(const nsCSSPropertyID aPropID, - nsAString& aValue) { + nsACString& aValue) { MOZ_ASSERT(aPropID != eCSSProperty_UNKNOWN, "Should never pass eCSSProperty_UNKNOWN around"); MOZ_ASSERT(aValue.IsEmpty()); @@ -90,7 +90,7 @@ void nsDOMCSSDeclaration::SetPropertyValue(const nsCSSPropertyID aPropID, aRv = ParsePropertyValue(aPropID, aValue, false, aSubjectPrincipal); } -void nsDOMCSSDeclaration::GetCssText(nsAString& aCssText) { +void nsDOMCSSDeclaration::GetCssText(nsACString& aCssText) { MOZ_ASSERT(aCssText.IsEmpty()); if (auto* decl = GetOrCreateCSSDeclaration(eOperation_Read, nullptr)) { @@ -98,7 +98,7 @@ void nsDOMCSSDeclaration::GetCssText(nsAString& aCssText) { } } -void nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText, +void nsDOMCSSDeclaration::SetCssText(const nsACString& aCssText, nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { if (IsReadOnly()) { @@ -163,7 +163,7 @@ void nsDOMCSSDeclaration::IndexedGetter(uint32_t aIndex, bool& aFound, NS_IMETHODIMP nsDOMCSSDeclaration::GetPropertyValue(const nsACString& aPropertyName, - nsAString& aReturn) { + nsACString& aReturn) { MOZ_ASSERT(aReturn.IsEmpty()); if (auto* decl = GetOrCreateCSSDeclaration(eOperation_Read, nullptr)) { decl->GetPropertyValue(aPropertyName, aReturn); @@ -172,7 +172,7 @@ nsDOMCSSDeclaration::GetPropertyValue(const nsACString& aPropertyName, } void nsDOMCSSDeclaration::GetPropertyPriority(const nsACString& aPropertyName, - nsAString& aPriority) { + nsACString& aPriority) { MOZ_ASSERT(aPriority.IsEmpty()); DeclarationBlock* decl = GetOrCreateCSSDeclaration(eOperation_Read, nullptr); if (decl && decl->GetPropertyIsImportant(aPropertyName)) { @@ -182,7 +182,7 @@ void nsDOMCSSDeclaration::GetPropertyPriority(const nsACString& aPropertyName, void nsDOMCSSDeclaration::SetProperty(const nsACString& aPropertyName, const nsACString& aValue, - const nsAString& aPriority, + const nsACString& aPriority, nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { if (IsReadOnly()) { @@ -221,7 +221,8 @@ void nsDOMCSSDeclaration::SetProperty(const nsACString& aPropertyName, } void nsDOMCSSDeclaration::RemoveProperty(const nsACString& aPropertyName, - nsAString& aReturn, ErrorResult& aRv) { + nsACString& aReturn, + ErrorResult& aRv) { if (IsReadOnly()) { return; } diff --git a/layout/style/nsDOMCSSDeclaration.h b/layout/style/nsDOMCSSDeclaration.h index d53469ee0212..2aeb1d19a583 100644 --- a/layout/style/nsDOMCSSDeclaration.h +++ b/layout/style/nsDOMCSSDeclaration.h @@ -66,7 +66,7 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration { * which obeys all the same restrictions. */ virtual nsresult GetPropertyValue(const nsCSSPropertyID aPropID, - nsAString& aValue); + nsACString& aValue); /** * Method analogous to CSSStyleDeclaration::SetProperty. This @@ -80,33 +80,30 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration { // Require subclasses to implement |GetParentRule|. // NS_DECL_NSIDOMCSSSTYLEDECLARATION - void GetCssText(nsAString& aCssText) override; - void SetCssText(const nsAString& aCssText, nsIPrincipal* aSubjectPrincipal, + void GetCssText(nsACString& aCssText) override; + void SetCssText(const nsACString& aCssText, nsIPrincipal* aSubjectPrincipal, mozilla::ErrorResult& aRv) override; NS_IMETHOD GetPropertyValue(const nsACString& propertyName, - nsAString& _retval) override; - void RemoveProperty(const nsACString& propertyName, nsAString& _retval, + nsACString& _retval) override; + void RemoveProperty(const nsACString& propertyName, nsACString& _retval, mozilla::ErrorResult& aRv) override; void GetPropertyPriority(const nsACString& propertyName, - nsAString& aPriority) override; + nsACString& aPriority) override; void SetProperty(const nsACString& propertyName, const nsACString& value, - const nsAString& priority, nsIPrincipal* aSubjectPrincipal, + const nsACString& priority, nsIPrincipal* aSubjectPrincipal, mozilla::ErrorResult& aRv) override; uint32_t Length() override; // WebIDL interface for CSS2Properties #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_ -#define CSS_PROP(id_, method_) \ - void Get##method_(nsAString& aValue, mozilla::ErrorResult& rv) { \ - rv = GetPropertyValue(eCSSProperty_##id_, aValue); \ - } \ - \ - void Set##method_(const nsAString& aValue, nsIPrincipal* aSubjectPrincipal, \ - mozilla::ErrorResult& aRv) { \ - /* FIXME: Should switch to UTF8String in the IDL, either by switching the \ - * serialization code to it too, or by something like bug 862800. */ \ - NS_ConvertUTF16toUTF8 v(aValue); \ - SetPropertyValue(eCSSProperty_##id_, v, aSubjectPrincipal, aRv); \ +#define CSS_PROP(id_, method_) \ + void Get##method_(nsACString& aValue, mozilla::ErrorResult& rv) { \ + rv = GetPropertyValue(eCSSProperty_##id_, aValue); \ + } \ + \ + void Set##method_(const nsACString& aValue, nsIPrincipal* aSubjectPrincipal, \ + mozilla::ErrorResult& aRv) { \ + SetPropertyValue(eCSSProperty_##id_, aValue, aSubjectPrincipal, aRv); \ } #define CSS_PROP_LIST_EXCLUDE_INTERNAL diff --git a/layout/style/nsICSSDeclaration.h b/layout/style/nsICSSDeclaration.h index 8ec2d275d59e..fd86fe8135bb 100644 --- a/layout/style/nsICSSDeclaration.h +++ b/layout/style/nsICSSDeclaration.h @@ -55,17 +55,18 @@ class nsICSSDeclaration : public nsISupports, public nsWrapperCache { mozilla::dom::DocGroup* GetDocGroup(); NS_IMETHOD GetPropertyValue(const nsACString& aPropName, - nsAString& aValue) = 0; + nsACString& aValue) = 0; virtual void RemoveProperty(const nsACString& aPropertyName, - nsAString& aReturn, + nsACString& aReturn, mozilla::ErrorResult& aRv) = 0; virtual void SetProperty(const nsACString& aPropertyName, - const nsACString& aValue, const nsAString& aPriority, + const nsACString& aValue, + const nsACString& aPriority, nsIPrincipal* aSubjectPrincipal, mozilla::ErrorResult& aRv) = 0; // For C++ callers. void SetProperty(const nsACString& aPropertyName, const nsACString& aValue, - const nsAString& aPriority, mozilla::ErrorResult& aRv) { + const nsACString& aPriority, mozilla::ErrorResult& aRv) { SetProperty(aPropertyName, aValue, aPriority, nullptr, aRv); } @@ -84,22 +85,22 @@ class nsICSSDeclaration : public nsISupports, public nsWrapperCache { } // WebIDL interface for CSSStyleDeclaration - virtual void SetCssText(const nsAString& aString, + virtual void SetCssText(const nsACString& aString, nsIPrincipal* aSubjectPrincipal, mozilla::ErrorResult& rv) = 0; - virtual void GetCssText(nsAString& aString) = 0; + virtual void GetCssText(nsACString& aString) = 0; virtual uint32_t Length() = 0; // The actual implementation of the Item method and the WebIDL indexed getter virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsACString& aPropName) = 0; - void GetPropertyValue(const nsACString& aPropName, nsString& aValue, + void GetPropertyValue(const nsACString& aPropName, nsACString& aValue, mozilla::ErrorResult& rv) { rv = GetPropertyValue(aPropName, aValue); } virtual void GetPropertyPriority(const nsACString& aPropName, - nsAString& aPriority) = 0; + nsACString& aPriority) = 0; virtual mozilla::css::Rule* GetParentRule() = 0; protected: @@ -109,18 +110,19 @@ class nsICSSDeclaration : public nsISupports, public nsWrapperCache { NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSDeclaration, NS_ICSSDECLARATION_IID) #define NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER \ - void GetCssText(nsAString& aCssText) override; \ - void SetCssText(const nsAString& aCssText, nsIPrincipal* aSubjectPrincipal, \ + void GetCssText(nsACString& aCssText) override; \ + void SetCssText(const nsACString& aCssText, nsIPrincipal* aSubjectPrincipal, \ mozilla::ErrorResult& aRv) override; \ NS_IMETHOD GetPropertyValue(const nsACString& propertyName, \ - nsAString& _retval) override; \ - void RemoveProperty(const nsACString& propertyName, nsAString& _retval, \ + nsACString& _retval) override; \ + void RemoveProperty(const nsACString& propertyName, nsACString& _retval, \ mozilla::ErrorResult& aRv) override; \ void GetPropertyPriority(const nsACString& propertyName, \ - nsAString& aPriority) override; \ + nsACString& aPriority) override; \ void SetProperty(const nsACString& propertyName, const nsACString& value, \ - const nsAString& priority, nsIPrincipal* aSubjectPrincipal, \ - mozilla::ErrorResult& aRv) override; \ + const nsACString& priority, \ + nsIPrincipal* aSubjectPrincipal, mozilla::ErrorResult& aRv) \ + override; \ uint32_t Length() override; \ mozilla::css::Rule* GetParentRule() override; diff --git a/layout/style/test/gtest/StyloParsingBench.cpp b/layout/style/test/gtest/StyloParsingBench.cpp index fb066a2c7aac..2d2fb2a3c3bc 100644 --- a/layout/style/test/gtest/StyloParsingBench.cpp +++ b/layout/style/test/gtest/StyloParsingBench.cpp @@ -88,8 +88,7 @@ static void ServoGetPropertyValueById() { eCompatibility_FullStandards, nullptr, STYLE_RULE, {}); for (int i = 0; i < GETPROPERTY_REPETITIONS; i++) { - DOMString value_; - nsAString& value = value_; + nsAutoCString value; Servo_DeclarationBlock_GetPropertyValueById(block, eCSSProperty_width, &value); ASSERT_TRUE(value.EqualsLiteral("10px")); diff --git a/layout/xul/nsResizerFrame.cpp b/layout/xul/nsResizerFrame.cpp index b7962108ae42..3e5f5e100051 100644 --- a/layout/xul/nsResizerFrame.cpp +++ b/layout/xul/nsResizerFrame.cpp @@ -406,26 +406,8 @@ void nsResizerFrame::ResizeContent(nsIContent* aContent, const Direction& aDirection, const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo) { - // for XUL elements, just set the width and height attributes. For - // other elements, set style.width and style.height - if (aContent->IsXULElement()) { - if (aOriginalSizeInfo) { - aContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::width, - aOriginalSizeInfo->width); - aContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::height, - aOriginalSizeInfo->height); - } - // only set the property if the element could have changed in that direction - if (aDirection.mHorizontal) { - aContent->AsElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::width, - aSizeInfo.width, true); - } - if (aDirection.mVertical) { - aContent->AsElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::height, - aSizeInfo.height, true); - } - } else if (RefPtr inlineStyleContent = - nsStyledElement::FromNode(aContent)) { + if (RefPtr inlineStyleContent = + nsStyledElement::FromNode(aContent)) { nsICSSDeclaration* decl = inlineStyleContent->Style(); if (aOriginalSizeInfo) { @@ -436,18 +418,18 @@ void nsResizerFrame::ResizeContent(nsIContent* aContent, // only set the property if the element could have changed in that // direction if (aDirection.mHorizontal) { - NS_ConvertUTF16toUTF8 widthstr(aSizeInfo.width); + nsAutoCString widthstr(aSizeInfo.width); if (!widthstr.IsEmpty() && !Substring(widthstr, widthstr.Length() - 2, 2).EqualsLiteral("px")) widthstr.AppendLiteral("px"); - decl->SetProperty("width"_ns, widthstr, u""_ns, IgnoreErrors()); + decl->SetProperty("width"_ns, widthstr, ""_ns, IgnoreErrors()); } if (aDirection.mVertical) { - NS_ConvertUTF16toUTF8 heightstr(aSizeInfo.height); + nsAutoCString heightstr(aSizeInfo.height); if (!heightstr.IsEmpty() && !Substring(heightstr, heightstr.Length() - 2, 2).EqualsLiteral("px")) heightstr.AppendLiteral("px"); - decl->SetProperty("height"_ns, heightstr, u""_ns, IgnoreErrors()); + decl->SetProperty("height"_ns, heightstr, ""_ns, IgnoreErrors()); } } } diff --git a/layout/xul/nsResizerFrame.h b/layout/xul/nsResizerFrame.h index ffb749c05059..52115746f784 100644 --- a/layout/xul/nsResizerFrame.h +++ b/layout/xul/nsResizerFrame.h @@ -64,7 +64,7 @@ class nsResizerFrame final : public nsTitleBarFrame { int8_t aResizerDirection); struct SizeInfo { - nsString width, height; + nsCString width, height; }; static void SizeInfoDtorFunc(void* aObject, nsAtom* aPropertyName, void* aPropertyValue, void* aData); diff --git a/servo/components/style/properties/declaration_block.rs b/servo/components/style/properties/declaration_block.rs index bd0a87f0b0a1..9170f6e650d6 100644 --- a/servo/components/style/properties/declaration_block.rs +++ b/servo/components/style/properties/declaration_block.rs @@ -14,7 +14,7 @@ use crate::parser::ParserContext; use crate::properties::animated_properties::{AnimationValue, AnimationValueMap}; use crate::selector_parser::SelectorImpl; use crate::shared_lock::Locked; -use crate::str::{CssString, CssStringBorrow, CssStringWriter}; +use crate::str::{CssString, CssStringWriter}; use crate::stylesheets::{CssRuleType, Origin, UrlExtraData}; use crate::values::computed::Context; use cssparser::{parse_important, CowRcStr, DeclarationListParser, ParserInput}; @@ -1093,7 +1093,11 @@ impl PropertyDeclarationBlock { } AppendableValue::Css { - css: CssStringBorrow::from(&v), + // Safety: serialization only generates valid utf-8. + #[cfg(feature = "gecko")] + css: unsafe { v.as_str_unchecked() }, + #[cfg(feature = "servo")] + css: &v, with_variables: false, } }, @@ -1179,7 +1183,7 @@ where /// or when storing a serialized shorthand value before appending directly. Css { /// The raw CSS string. - css: CssStringBorrow<'a>, + css: &'a str, /// Whether the original serialization contained variables or not. with_variables: bool, }, @@ -1207,7 +1211,7 @@ where I: Iterator, { match appendable_value { - AppendableValue::Css { css, .. } => css.append_to(dest), + AppendableValue::Css { css, .. } => dest.write_str(css), AppendableValue::Declaration(decl) => decl.to_css(dest), AppendableValue::DeclarationsForShorthand(shorthand, decls) => { shorthand.longhands_to_css(decls, &mut CssWriter::new(dest)) diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index a4316a501ada..505068b85565 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -46,7 +46,7 @@ use crate::values::computed::NonNegativeLength; use crate::values::serialize_atom_name; use crate::rule_tree::StrongRuleNode; use crate::Zero; -use crate::str::{CssString, CssStringBorrow, CssStringWriter}; +use crate::str::{CssString, CssStringWriter}; use std::cell::Cell; pub use self::declaration_block::*; @@ -1529,10 +1529,7 @@ impl ShorthandId { // https://drafts.csswg.org/css-variables/#variables-in-shorthands if let Some(css) = first_declaration.with_variables_from_shorthand(self) { if declarations2.all(|d| d.with_variables_from_shorthand(self) == Some(css)) { - return Some(AppendableValue::Css { - css: CssStringBorrow::from(css), - with_variables: true, - }); + return Some(AppendableValue::Css { css, with_variables: true }); } return None; } @@ -1541,7 +1538,7 @@ impl ShorthandId { if let Some(keyword) = first_declaration.get_css_wide_keyword() { if declarations2.all(|d| d.get_css_wide_keyword() == Some(keyword)) { return Some(AppendableValue::Css { - css: CssStringBorrow::from(keyword.to_str()), + css: keyword.to_str(), with_variables: false, }); } diff --git a/servo/components/style/str.rs b/servo/components/style/str.rs index 01f70c1f9637..9badcdf413c7 100644 --- a/servo/components/style/str.rs +++ b/servo/components/style/str.rs @@ -9,7 +9,6 @@ use num_traits::ToPrimitive; use std::borrow::Cow; use std::convert::AsRef; -use std::fmt::{self, Write}; use std::iter::{Filter, Peekable}; use std::str::Split; @@ -171,98 +170,12 @@ pub fn string_as_ascii_lowercase<'a>(input: &'a str) -> Cow<'a, str> { /// To avoid accidentally instantiating multiple monomorphizations of large /// serialization routines, we define explicit concrete types and require -/// them in those routines. This primarily avoids accidental mixing of UTF8 -/// with UTF16 serializations in Gecko. +/// them in those routines. This avoids accidental mixing of String and +/// nsACString arguments in Gecko, which would cause code size to blow up. #[cfg(feature = "gecko")] -pub type CssStringWriter = ::nsstring::nsAString; +pub type CssStringWriter = ::nsstring::nsACString; /// String type that coerces to CssStringWriter, used when serialization code /// needs to allocate a temporary string. #[cfg(feature = "gecko")] -pub type CssString = ::nsstring::nsString; - -/// Certain serialization code needs to interact with borrowed strings, which -/// are sometimes native UTF8 Rust strings, and other times serialized UTF16 -/// strings. This enum multiplexes the two cases. -#[cfg(feature = "gecko")] -pub enum CssStringBorrow<'a> { - /// A borrow of a UTF16 CssString. - UTF16(&'a ::nsstring::nsString), - /// A borrow of a regular Rust UTF8 string. - UTF8(&'a str), -} - -#[cfg(feature = "gecko")] -impl<'a> CssStringBorrow<'a> { - /// Writes the borrowed string to the provided writer. - pub fn append_to(&self, dest: &mut CssStringWriter) -> fmt::Result { - match *self { - CssStringBorrow::UTF16(s) => { - dest.append(s); - Ok(()) - }, - CssStringBorrow::UTF8(s) => dest.write_str(s), - } - } - - /// Returns true of the borrowed string is empty. - pub fn is_empty(&self) -> bool { - match *self { - CssStringBorrow::UTF16(s) => s.is_empty(), - CssStringBorrow::UTF8(s) => s.is_empty(), - } - } -} - -#[cfg(feature = "gecko")] -impl<'a> From<&'a str> for CssStringBorrow<'a> { - fn from(s: &'a str) -> Self { - CssStringBorrow::UTF8(s) - } -} - -#[cfg(feature = "gecko")] -impl<'a> From<&'a ::nsstring::nsString> for CssStringBorrow<'a> { - fn from(s: &'a ::nsstring::nsString) -> Self { - CssStringBorrow::UTF16(s) - } -} - -/// String. The comments for the Gecko types explain the need for this abstraction. -#[cfg(feature = "servo")] -pub type CssStringWriter = String; - -/// String. The comments for the Gecko types explain the need for this abstraction. -#[cfg(feature = "servo")] -pub type CssString = String; - -/// Borrowed string. The comments for the Gecko types explain the need for this abstraction. -#[cfg(feature = "servo")] -pub struct CssStringBorrow<'a>(&'a str); - -#[cfg(feature = "servo")] -impl<'a> CssStringBorrow<'a> { - /// Appends the borrowed string to the given string. - pub fn append_to(&self, dest: &mut CssStringWriter) -> fmt::Result { - dest.write_str(self.0) - } - - /// Returns true if the borrowed string is empty. - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } -} - -#[cfg(feature = "servo")] -impl<'a> From<&'a str> for CssStringBorrow<'a> { - fn from(s: &'a str) -> Self { - CssStringBorrow(s) - } -} - -#[cfg(feature = "servo")] -impl<'a> From<&'a String> for CssStringBorrow<'a> { - fn from(s: &'a String) -> Self { - CssStringBorrow(&*s) - } -} +pub type CssString = ::nsstring::nsCString; diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index a10e7466b72c..545bad849b9d 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -712,7 +712,7 @@ pub extern "C" fn Servo_AnimationValue_Serialize( value: &RawServoAnimationValue, property: nsCSSPropertyID, raw_data: &RawServoStyleSet, - buffer: &mut nsAString, + buffer: &mut nsACString, ) { let uncomputed_value = AnimationValue::as_arc(&value).uncompute(); let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); @@ -731,7 +731,7 @@ pub extern "C" fn Servo_AnimationValue_Serialize( #[no_mangle] pub extern "C" fn Servo_AnimationValue_Dump( value: &RawServoAnimationValue, - result: &mut nsAString, + result: &mut nsACString, ) { let value = AnimationValue::as_arc(&value); write!(result, "{:?}", value).unwrap(); @@ -2160,7 +2160,7 @@ macro_rules! impl_basic_rule_funcs_without_getter { } #[no_mangle] - pub extern "C" fn $to_css(rule: &$raw_type, result: &mut nsAString) { + pub extern "C" fn $to_css(rule: &$raw_type, result: &mut nsACString) { let global_style_data = &*GLOBAL_STYLE_DATA; let guard = global_style_data.shared_lock.read(); let rule = Locked::<$rule_type>::as_arc(&rule); @@ -2353,7 +2353,7 @@ pub extern "C" fn Servo_StyleRule_SetStyle( #[no_mangle] pub extern "C" fn Servo_StyleRule_GetSelectorText( rule: &RawServoStyleRule, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &StyleRule| { rule.selectors.to_css(result).unwrap(); @@ -2364,7 +2364,7 @@ pub extern "C" fn Servo_StyleRule_GetSelectorText( pub extern "C" fn Servo_StyleRule_GetSelectorTextAtIndex( rule: &RawServoStyleRule, index: u32, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &StyleRule| { let index = index as usize; @@ -2453,9 +2453,9 @@ pub extern "C" fn Servo_StyleRule_SelectorMatchesElement( pub extern "C" fn Servo_StyleRule_SetSelectorText( sheet: &RawServoStyleSheetContents, rule: &RawServoStyleRule, - text: &nsAString, + text: &nsACString, ) -> bool { - let value_str = text.to_string(); + let value_str = unsafe { text.as_str_unchecked() }; write_locked_arc(rule, |rule: &mut StyleRule| { use style::selector_parser::SelectorParser; @@ -2591,15 +2591,17 @@ pub extern "C" fn Servo_ImportRule_GetSheet(rule: &RawServoImportRule) -> *const } #[no_mangle] -pub extern "C" fn Servo_ImportRule_SetSheet(rule: &RawServoImportRule, sheet: *mut DomStyleSheet) { +pub unsafe extern "C" fn Servo_ImportRule_SetSheet( + rule: &RawServoImportRule, + sheet: *mut DomStyleSheet, +) { write_locked_arc(rule, |rule: &mut ImportRule| { - let sheet = unsafe { GeckoStyleSheet::new(sheet) }; - rule.stylesheet = ImportSheet::new(sheet); + rule.stylesheet = ImportSheet::new(GeckoStyleSheet::new(sheet)); }) } #[no_mangle] -pub extern "C" fn Servo_Keyframe_GetKeyText(keyframe: &RawServoKeyframe, result: &mut nsAString) { +pub extern "C" fn Servo_Keyframe_GetKeyText(keyframe: &RawServoKeyframe, result: &mut nsACString) { read_locked_arc(keyframe, |keyframe: &Keyframe| { keyframe .selector @@ -2769,7 +2771,7 @@ pub extern "C" fn Servo_PageRule_SetStyle( #[no_mangle] pub extern "C" fn Servo_SupportsRule_GetConditionText( rule: &RawServoSupportsRule, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &SupportsRule| { rule.condition.to_css(&mut CssWriter::new(result)).unwrap(); @@ -2779,7 +2781,7 @@ pub extern "C" fn Servo_SupportsRule_GetConditionText( #[no_mangle] pub extern "C" fn Servo_MozDocumentRule_GetConditionText( rule: &RawServoMozDocumentRule, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &DocumentRule| { rule.condition.to_css(&mut CssWriter::new(result)).unwrap(); @@ -2789,7 +2791,7 @@ pub extern "C" fn Servo_MozDocumentRule_GetConditionText( #[no_mangle] pub extern "C" fn Servo_FontFeatureValuesRule_GetFontFamily( rule: &RawServoFontFeatureValuesRule, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &FontFeatureValuesRule| { rule.font_family_to_css(&mut CssWriter::new(result)) @@ -2800,7 +2802,7 @@ pub extern "C" fn Servo_FontFeatureValuesRule_GetFontFamily( #[no_mangle] pub extern "C" fn Servo_FontFeatureValuesRule_GetValueText( rule: &RawServoFontFeatureValuesRule, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &FontFeatureValuesRule| { rule.value_to_css(&mut CssWriter::new(result)).unwrap(); @@ -2914,7 +2916,7 @@ pub unsafe extern "C" fn Servo_FontFaceRule_IndexGetter( #[no_mangle] pub unsafe extern "C" fn Servo_FontFaceRule_GetDeclCssText( rule: &RawServoFontFaceRule, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &FontFaceRule| { rule.decl_to_css(result).unwrap(); @@ -3098,7 +3100,7 @@ pub unsafe extern "C" fn Servo_FontFaceRule_GetFeatureSettings( pub unsafe extern "C" fn Servo_FontFaceRule_GetDescriptorCssText( rule: &RawServoFontFaceRule, desc: nsCSSFontDesc, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(rule, |rule: &FontFaceRule| { let mut writer = CssWriter::new(result); @@ -3508,7 +3510,7 @@ macro_rules! counter_style_descriptors { pub unsafe extern "C" fn Servo_CounterStyleRule_GetDescriptorCssText( rule: &RawServoCounterStyleRule, desc: nsCSSCounterDesc, - result: &mut nsAString, + result: &mut nsACString, ) { let mut writer = CssWriter::new(result); read_locked_arc(rule, |rule: &CounterStyleRule| { @@ -3975,7 +3977,7 @@ fn dump_properties_and_rules(cv: &ComputedValues, properties: &LonghandIdSet) { println_stderr!(" [DeclarationBlock: {:?}]", d); } if let Some(r) = rn.style_source().and_then(|s| s.as_rule()) { - let mut s = nsString::new(); + let mut s = nsCString::new(); r.read_with(&guard).to_css(&guard, &mut s).unwrap(); println_stderr!(" {}", s); } @@ -4123,7 +4125,7 @@ pub unsafe extern "C" fn Servo_ParseProperty( } #[no_mangle] -pub extern "C" fn Servo_ParseEasing(easing: &nsAString, output: &mut nsTimingFunction) -> bool { +pub extern "C" fn Servo_ParseEasing(easing: &nsACString, output: &mut nsTimingFunction) -> bool { use style::properties::longhands::transition_timing_function; let context = ParserContext::new( @@ -4151,7 +4153,7 @@ pub extern "C" fn Servo_ParseEasing(easing: &nsAString, output: &mut nsTimingFun } #[no_mangle] -pub extern "C" fn Servo_SerializeEasing(easing: &nsTimingFunction, output: &mut nsAString) { +pub extern "C" fn Servo_SerializeEasing(easing: &nsTimingFunction, output: &mut nsACString) { easing.mTiming.to_css(&mut CssWriter::new(output)).unwrap(); } @@ -4291,7 +4293,7 @@ pub extern "C" fn Servo_DeclarationBlock_Equals( #[no_mangle] pub extern "C" fn Servo_DeclarationBlock_GetCssText( declarations: &RawServoDeclarationBlock, - result: &mut nsAString, + result: &mut nsACString, ) { read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| { decls.to_css(result).unwrap() @@ -4302,7 +4304,7 @@ pub extern "C" fn Servo_DeclarationBlock_GetCssText( pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue( declarations: &RawServoDeclarationBlock, property_id: nsCSSPropertyID, - buffer: &mut nsAString, + buffer: &mut nsACString, computed_values: Option<&ComputedValues>, custom_properties: Option<&RawServoDeclarationBlock>, raw_data: &RawServoStyleSet, @@ -4330,7 +4332,7 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue( #[no_mangle] pub unsafe extern "C" fn Servo_SerializeFontValueForCanvas( declarations: &RawServoDeclarationBlock, - buffer: &mut nsAString, + buffer: &mut nsACString, ) { use style::properties::shorthands::font; read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| { @@ -4383,7 +4385,7 @@ macro_rules! get_property_id_from_property { unsafe fn get_property_value( declarations: &RawServoDeclarationBlock, property_id: PropertyId, - value: &mut nsAString, + value: &mut nsACString, ) { // This callsite is hot enough that the lock acquisition shows up in profiles. // Using an unchecked read here improves our performance by ~10% on the @@ -4397,7 +4399,7 @@ unsafe fn get_property_value( pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyValue( declarations: &RawServoDeclarationBlock, property: &nsACString, - value: &mut nsAString, + value: &mut nsACString, ) { get_property_value( declarations, @@ -4410,7 +4412,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyValue( pub unsafe extern "C" fn Servo_DeclarationBlock_GetPropertyValueById( declarations: &RawServoDeclarationBlock, property: nsCSSPropertyID, - value: &mut nsAString, + value: &mut nsACString, ) { get_property_value( declarations, @@ -4661,7 +4663,7 @@ pub extern "C" fn Servo_DeclarationBlock_HasCSSWideKeyword( } #[no_mangle] -pub extern "C" fn Servo_MediaList_GetText(list: &RawServoMediaList, result: &mut nsAString) { +pub extern "C" fn Servo_MediaList_GetText(list: &RawServoMediaList, result: &mut nsACString) { read_locked_arc(list, |list: &MediaList| { list.to_css(&mut CssWriter::new(result)).unwrap(); }) @@ -4714,7 +4716,7 @@ pub extern "C" fn Servo_MediaList_GetLength(list: &RawServoMediaList) -> u32 { pub extern "C" fn Servo_MediaList_GetMediumAt( list: &RawServoMediaList, index: u32, - result: &mut nsAString, + result: &mut nsACString, ) -> bool { read_locked_arc(list, |list: &MediaList| { let media_query = match list.media_queries.get(index as usize) { @@ -5228,14 +5230,14 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue( } #[no_mangle] -pub extern "C" fn Servo_DeclarationBlock_SetFontFamily( +pub unsafe extern "C" fn Servo_DeclarationBlock_SetFontFamily( declarations: &RawServoDeclarationBlock, - value: &nsAString, + value: &nsACString, ) { use style::properties::longhands::font_family::SpecifiedValue as FontFamily; use style::properties::PropertyDeclaration; - let string = value.to_string(); + let string = value.as_str_unchecked(); let mut input = ParserInput::new(&string); let mut parser = Parser::new(&mut input); let result = FontFamily::parse_specified(&mut parser); @@ -5250,9 +5252,9 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily( } #[no_mangle] -pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage( +pub unsafe extern "C" fn Servo_DeclarationBlock_SetBackgroundImage( declarations: &RawServoDeclarationBlock, - value: &nsAString, + value: &nsACString, raw_extra_data: *mut URLExtraData, ) { use style::properties::longhands::background_image::SpecifiedValue as BackgroundImage; @@ -5261,8 +5263,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage( use style::values::generics::image::Image; use style::values::specified::url::SpecifiedImageUrl; - let url_data = unsafe { UrlExtraData::from_ptr_ref(&raw_extra_data) }; - let string = value.to_string(); + let url_data = UrlExtraData::from_ptr_ref(&raw_extra_data); + let string = value.as_str_unchecked(); let context = ParserContext::new( Origin::Author, url_data, @@ -6289,7 +6291,7 @@ pub extern "C" fn Servo_StyleSet_HasDocumentStateDependency( pub unsafe extern "C" fn Servo_GetPropertyValue( style: &ComputedValues, prop: nsCSSPropertyID, - value: &mut nsAString, + value: &mut nsACString, ) { if let Ok(longhand) = LonghandId::from_nscsspropertyid(prop) { style @@ -6325,7 +6327,7 @@ pub unsafe extern "C" fn Servo_GetPropertyValue( pub unsafe extern "C" fn Servo_GetCustomPropertyValue( computed_values: &ComputedValues, name: &nsACString, - value: &mut nsAString, + value: &mut nsACString, ) -> bool { let custom_properties = match computed_values.custom_properties() { Some(p) => p, @@ -6597,10 +6599,10 @@ pub unsafe extern "C" fn Servo_ComputeColor( #[no_mangle] pub unsafe extern "C" fn Servo_IntersectionObserverRootMargin_Parse( - value: &nsAString, + value: &nsACString, result: *mut IntersectionObserverRootMargin, ) -> bool { - let value = value.to_string(); + let value = value.as_str_unchecked(); let result = result.as_mut().unwrap(); let mut input = ParserInput::new(&value); @@ -6630,7 +6632,7 @@ pub unsafe extern "C" fn Servo_IntersectionObserverRootMargin_Parse( #[no_mangle] pub extern "C" fn Servo_IntersectionObserverRootMargin_ToString( root_margin: &IntersectionObserverRootMargin, - result: &mut nsAString, + result: &mut nsACString, ) { let mut writer = CssWriter::new(result); root_margin.to_css(&mut writer).unwrap(); @@ -6674,7 +6676,7 @@ pub extern "C" fn Servo_ParseTransformIntoMatrix( #[no_mangle] pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching( - value: &nsAString, + value: &nsACString, data: *mut URLExtraData, family: &mut structs::RefPtr, style: &mut ComputedFontStyleDescriptor, @@ -6689,7 +6691,7 @@ pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching( FontFamily, FontStretch, FontStyle, FontWeight, SpecifiedFontStyle, }; - let string = value.to_string(); + let string = value.as_str_unchecked(); let mut input = ParserInput::new(&string); let mut parser = Parser::new(&mut input); let url_data = UrlExtraData::from_ptr_ref(&data); @@ -6983,7 +6985,7 @@ pub unsafe extern "C" fn Servo_LoadData_GetLazy( #[no_mangle] pub extern "C" fn Servo_LengthPercentage_ToCss( lp: &computed::LengthPercentage, - result: &mut nsAString, + result: &mut nsACString, ) { lp.to_css(&mut CssWriter::new(result)).unwrap(); }