commit ecb9929061eed786b0d4622d85b31773e6fd5169
parent 62867aa4c6a6b5858166a3e9ca05c80e7bcfdcb1
Author: Jan Varga <jan.varga@gmail.com>
Date: Tue, 25 Nov 2025 15:22:54 +0000
Bug 1990419 - Add ToCssTextWithProperty() for temporary use in StylePropertyMap::Set; r=emilio,firefox-style-system-reviewers
This patch adds a ToCssTextWithProperty() method to CSSStyleValue subclasses.
For now, it is used by StylePropertyMap::Set, which still relies on
CSSOM-style string serialization when assigning values.
In the future, this method may be replaced or removed once
StylePropertyMap::Set is updated to use a proper FromTyped mechanism for
building internal representations directly from Typed OM values.
Differential Revision: https://phabricator.services.mozilla.com/D270134
Diffstat:
5 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/layout/style/typedom/CSSKeywordValue.cpp b/layout/style/typedom/CSSKeywordValue.cpp
@@ -57,6 +57,11 @@ void CSSKeywordValue::SetValue(const nsACString& aArg, ErrorResult& aRv) {
// end of CSSKeywordValue Web IDL implementation
+void CSSKeywordValue::ToCssTextWithProperty(const CSSPropertyId& aPropertyId,
+ nsACString& aDest) const {
+ aDest.Append(mValue);
+}
+
CSSKeywordValue& CSSStyleValue::GetAsCSSKeywordValue() {
MOZ_DIAGNOSTIC_ASSERT(mValueType == ValueType::Keyword);
diff --git a/layout/style/typedom/CSSKeywordValue.h b/layout/style/typedom/CSSKeywordValue.h
@@ -19,6 +19,7 @@ class nsISupports;
namespace mozilla {
+struct CSSPropertyId;
class ErrorResult;
namespace dom {
@@ -45,6 +46,9 @@ class CSSKeywordValue final : public CSSStyleValue {
// end of CSSKeywordValue Web IDL declarations
+ void ToCssTextWithProperty(const CSSPropertyId& aPropertyId,
+ nsACString& aDest) const;
+
private:
virtual ~CSSKeywordValue() = default;
diff --git a/layout/style/typedom/CSSUnsupportedValue.cpp b/layout/style/typedom/CSSUnsupportedValue.cpp
@@ -18,8 +18,19 @@ CSSUnsupportedValue::CSSUnsupportedValue(nsCOMPtr<nsISupports> aParent,
mPropertyId(aPropertyId),
mDeclarations(std::move(aDeclarations)) {}
-void CSSUnsupportedValue::GetValue(nsACString& aRetVal) const {
- mDeclarations->GetPropertyValueById(mPropertyId, aRetVal);
+void CSSUnsupportedValue::ToCssTextWithProperty(
+ const CSSPropertyId& aPropertyId, nsACString& aDest) const {
+ MOZ_ASSERT(aPropertyId == mPropertyId);
+
+ if (aDest.IsEmpty()) {
+ mDeclarations->GetPropertyValueById(mPropertyId, aDest);
+ return;
+ }
+
+ nsAutoCString value;
+ mDeclarations->GetPropertyValueById(mPropertyId, value);
+
+ aDest.Append(value);
}
CSSUnsupportedValue& CSSStyleValue::GetAsCSSUnsupportedValue() {
diff --git a/layout/style/typedom/CSSUnsupportedValue.h b/layout/style/typedom/CSSUnsupportedValue.h
@@ -35,7 +35,8 @@ class CSSUnsupportedValue final : public CSSStyleValue {
const CSSPropertyId& GetPropertyId() const { return mPropertyId; }
- void GetValue(nsACString& aRetVal) const;
+ void ToCssTextWithProperty(const CSSPropertyId& aPropertyId,
+ nsACString& aDest) const;
private:
virtual ~CSSUnsupportedValue() = default;
diff --git a/layout/style/typedom/StylePropertyMap.cpp b/layout/style/typedom/StylePropertyMap.cpp
@@ -73,17 +73,17 @@ void StylePropertyMap::Set(
return;
}
- nsAutoCString value;
+ nsAutoCString cssText;
if (styleValue.IsCSSUnsupportedValue()) {
CSSUnsupportedValue& unsupportedValue =
styleValue.GetAsCSSUnsupportedValue();
- unsupportedValue.GetValue(value);
+ unsupportedValue.ToCssTextWithProperty(propertyId, cssText);
} else if (styleValue.IsCSSKeywordValue()) {
CSSKeywordValue& keywordValue = styleValue.GetAsCSSKeywordValue();
- keywordValue.GetValue(value);
+ keywordValue.ToCssTextWithProperty(propertyId, cssText);
} else {
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
return;
@@ -99,7 +99,7 @@ void StylePropertyMap::Set(
nsCOMPtr<nsDOMCSSDeclaration> declaration = styledElement->Style();
- declaration->SetProperty(aProperty, value, ""_ns, aRv);
+ declaration->SetProperty(aProperty, cssText, ""_ns, aRv);
}
void StylePropertyMap::Append(