commit 29a3a9da36e32bd3ea06c83dead5937498624da7
parent a298edf3cf170ae4ef4fd7d1b0a69c8554bca127
Author: Jan Varga <jvarga@igalia.com>
Date: Sun, 30 Nov 2025 11:19:50 +0000
Bug 1990419 - Add missing pieces to CSSUnitValue for Typed OM reification; r=firefox-style-system-reviewers,dshin
This patch extends CSSUnitValue with functionality required for reification
of <length> values in CSS Typed OM. These additions are part of the initial
infrastructure needed to expose units through the TypedValue enum and enable
relevant WPT reification tests.
Differential Revision: https://phabricator.services.mozilla.com/D270144
Diffstat:
11 files changed, 73 insertions(+), 104 deletions(-)
diff --git a/layout/style/typedom/CSSKeywordValue.cpp b/layout/style/typedom/CSSKeywordValue.cpp
@@ -26,6 +26,8 @@ JSObject* CSSKeywordValue::WrapObject(JSContext* aCx,
// start of CSSKeywordValue Web IDL implementation
+// https://drafts.css-houdini.org/css-typed-om-1/#dom-csskeywordvalue-csskeywordvalue
+//
// static
already_AddRefed<CSSKeywordValue> CSSKeywordValue::Constructor(
const GlobalObject& aGlobal, const nsACString& aValue, ErrorResult& aRv) {
@@ -43,6 +45,7 @@ already_AddRefed<CSSKeywordValue> CSSKeywordValue::Constructor(
void CSSKeywordValue::GetValue(nsCString& aRetVal) const { aRetVal = mValue; }
+// https://drafts.css-houdini.org/css-typed-om-1/#dom-csskeywordvalue-value
void CSSKeywordValue::SetValue(const nsACString& aArg, ErrorResult& aRv) {
// Step 1.
diff --git a/layout/style/typedom/CSSNumericValue.cpp b/layout/style/typedom/CSSNumericValue.cpp
@@ -16,6 +16,10 @@ namespace mozilla::dom {
CSSNumericValue::CSSNumericValue(nsCOMPtr<nsISupports> aParent)
: CSSStyleValue(std::move(aParent)) {}
+CSSNumericValue::CSSNumericValue(nsCOMPtr<nsISupports> aParent,
+ ValueType aValueType)
+ : CSSStyleValue(std::move(aParent), aValueType) {}
+
JSObject* CSSNumericValue::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return CSSNumericValue_Binding::Wrap(aCx, this, aGivenProto);
diff --git a/layout/style/typedom/CSSNumericValue.h b/layout/style/typedom/CSSNumericValue.h
@@ -34,6 +34,8 @@ class CSSNumericValue : public CSSStyleValue {
public:
explicit CSSNumericValue(nsCOMPtr<nsISupports> aParent);
+ CSSNumericValue(nsCOMPtr<nsISupports> aParent, ValueType aValueType);
+
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
diff --git a/layout/style/typedom/CSSStyleValue.cpp b/layout/style/typedom/CSSStyleValue.cpp
@@ -71,4 +71,8 @@ bool CSSStyleValue::IsCSSKeywordValue() const {
return mValueType == ValueType::KeywordValue;
}
+bool CSSStyleValue::IsCSSUnitValue() const {
+ return mValueType == ValueType::UnitValue;
+}
+
} // namespace mozilla::dom
diff --git a/layout/style/typedom/CSSStyleValue.h b/layout/style/typedom/CSSStyleValue.h
@@ -27,11 +27,17 @@ namespace dom {
class GlobalObject;
class CSSKeywordValue;
+class CSSUnitValue;
class CSSUnsupportedValue;
class CSSStyleValue : public nsISupports, public nsWrapperCache {
public:
- enum class ValueType { Uninitialized, UnsupportedValue, KeywordValue };
+ enum class ValueType {
+ Uninitialized,
+ UnsupportedValue,
+ KeywordValue,
+ UnitValue
+ };
explicit CSSStyleValue(nsCOMPtr<nsISupports> aParent);
@@ -78,6 +84,11 @@ class CSSStyleValue : public nsISupports, public nsWrapperCache {
// Defined in CSSKeywordValue.cpp
CSSKeywordValue& GetAsCSSKeywordValue();
+ bool IsCSSUnitValue() const;
+
+ // Defined in CSSUnitValue.cpp
+ CSSUnitValue& GetAsCSSUnitValue();
+
protected:
virtual ~CSSStyleValue() = default;
diff --git a/layout/style/typedom/CSSUnitValue.cpp b/layout/style/typedom/CSSUnitValue.cpp
@@ -17,6 +17,12 @@ namespace mozilla::dom {
CSSUnitValue::CSSUnitValue(nsCOMPtr<nsISupports> aParent)
: CSSNumericValue(std::move(aParent)) {}
+CSSUnitValue::CSSUnitValue(nsCOMPtr<nsISupports> aParent, double aValue,
+ const nsACString& aUnit)
+ : CSSNumericValue(std::move(aParent), ValueType::UnitValue),
+ mValue(aValue),
+ mUnit(aUnit) {}
+
JSObject* CSSUnitValue::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return CSSUnitValue_Binding::Wrap(aCx, this, aGivenProto);
@@ -24,19 +30,39 @@ JSObject* CSSUnitValue::WrapObject(JSContext* aCx,
// start of CSSUnitValue Web IDL implementation
+// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssunitvalue-cssunitvalue
+//
// static
already_AddRefed<CSSUnitValue> CSSUnitValue::Constructor(
const GlobalObject& aGlobal, double aValue, const nsACString& aUnit,
ErrorResult& aRv) {
- return MakeAndAddRef<CSSUnitValue>(aGlobal.GetAsSupports());
+ // XXX Units should be normalized to lowercase. The Typed OM spec doesn’t
+ // state this explicitly, but WPT requires lowercase normalization and it
+ // can also be deduced from the CSS Values spec. Besides fixing it here,
+ // a spec issue may be needed to clarify this.
+
+ // Step 1.
+
+ // XXX A type should be created from unit and if that fails, the failure
+ // should be propagated here
+
+ // Step 2.
+
+ return MakeAndAddRef<CSSUnitValue>(aGlobal.GetAsSupports(), aValue, aUnit);
}
-double CSSUnitValue::Value() const { return 0; }
+double CSSUnitValue::Value() const { return mValue; }
-void CSSUnitValue::SetValue(double aArg) {}
+void CSSUnitValue::SetValue(double aArg) { mValue = aArg; }
-void CSSUnitValue::GetUnit(nsCString& aRetVal) const {}
+void CSSUnitValue::GetUnit(nsCString& aRetVal) const { aRetVal = mUnit; }
// end of CSSUnitValue Web IDL implementation
+CSSUnitValue& CSSStyleValue::GetAsCSSUnitValue() {
+ MOZ_DIAGNOSTIC_ASSERT(mValueType == ValueType::UnitValue);
+
+ return *static_cast<CSSUnitValue*>(this);
+}
+
} // namespace mozilla::dom
diff --git a/layout/style/typedom/CSSUnitValue.h b/layout/style/typedom/CSSUnitValue.h
@@ -9,7 +9,7 @@
#include "js/TypeDecls.h"
#include "mozilla/dom/CSSNumericValue.h"
-#include "nsStringFwd.h"
+#include "nsString.h"
template <class T>
struct already_AddRefed;
@@ -27,13 +27,18 @@ class GlobalObject;
class CSSUnitValue final : public CSSNumericValue {
public:
+ // XXX Remove this constructor once mozilla::dom::CSS stops using it
explicit CSSUnitValue(nsCOMPtr<nsISupports> aParent);
+ CSSUnitValue(nsCOMPtr<nsISupports> aParent, double aValue,
+ const nsACString& aUnit);
+
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// start of CSSUnitValue Web IDL declarations
+ // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssunitvalue-cssunitvalue
static already_AddRefed<CSSUnitValue> Constructor(const GlobalObject& aGlobal,
double aValue,
const nsACString& aUnit,
@@ -49,6 +54,9 @@ class CSSUnitValue final : public CSSNumericValue {
private:
virtual ~CSSUnitValue() = default;
+
+ double mValue;
+ nsCString mUnit;
};
} // namespace dom
diff --git a/layout/style/typedom/StylePropertyMap.cpp b/layout/style/typedom/StylePropertyMap.cpp
@@ -35,6 +35,8 @@ JSObject* StylePropertyMap::WrapObject(JSContext* aCx,
// start of StylePropertyMap Web IDL implementation
+// https://drafts.css-houdini.org/css-typed-om/#dom-stylepropertymap-set
+//
// XXX This is not yet fully implemented and optimized!
void StylePropertyMap::Set(
const nsACString& aProperty,
@@ -76,6 +78,9 @@ void StylePropertyMap::Set(
nsAutoCString cssText;
switch (styleValue.GetValueType()) {
+ case CSSStyleValue::ValueType::UnitValue:
+ break;
+
case CSSStyleValue::ValueType::KeywordValue: {
CSSKeywordValue& keywordValue = styleValue.GetAsCSSKeywordValue();
diff --git a/layout/style/typedom/StylePropertyMapReadOnly.cpp b/layout/style/typedom/StylePropertyMapReadOnly.cpp
@@ -111,6 +111,8 @@ JSObject* StylePropertyMapReadOnly::WrapObject(
// start of StylePropertyMapReadOnly Web IDL implementation
+// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-get
+//
// XXX This is not yet fully implemented and optimized!
void StylePropertyMapReadOnly::Get(const nsACString& aProperty,
OwningUndefinedOrCSSStyleValue& aRetVal,
@@ -176,6 +178,8 @@ void StylePropertyMapReadOnly::Get(const nsACString& aProperty,
}
}
+// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-getall
+//
// XXX This is not yet fully implemented and optimized!
void StylePropertyMapReadOnly::GetAll(const nsACString& aProperty,
nsTArray<RefPtr<CSSStyleValue>>& aRetVal,
diff --git a/testing/web-platform/meta/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue-value.html.ini b/testing/web-platform/meta/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue-value.html.ini
@@ -1,4 +0,0 @@
-[cssUnitValue-value.html]
- [CSSUnitValue.value can be updated to a different value]
- expected: FAIL
-
diff --git a/testing/web-platform/meta/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue.html.ini b/testing/web-platform/meta/css/css-typed-om/stylevalue-subclasses/numeric-objects/cssUnitValue.html.ini
@@ -5,105 +5,11 @@
[Constructing CSSUnitValue with a empty string unit throws a TypeError]
expected: FAIL
- [CSSUnitValue can be constructed with number]
- expected: FAIL
-
- [CSSUnitValue can be constructed with percent]
- expected: FAIL
-
- [CSSUnitValue can be constructed with em]
- expected: FAIL
-
- [CSSUnitValue can be constructed with ex]
- expected: FAIL
-
- [CSSUnitValue can be constructed with ch]
- expected: FAIL
-
- [CSSUnitValue can be constructed with ic]
- expected: FAIL
-
- [CSSUnitValue can be constructed with rem]
- expected: FAIL
-
- [CSSUnitValue can be constructed with lh]
- expected: FAIL
-
- [CSSUnitValue can be constructed with rlh]
- expected: FAIL
-
- [CSSUnitValue can be constructed with vw]
- expected: FAIL
-
- [CSSUnitValue can be constructed with vh]
- expected: FAIL
-
- [CSSUnitValue can be constructed with vi]
- expected: FAIL
-
- [CSSUnitValue can be constructed with vb]
- expected: FAIL
-
- [CSSUnitValue can be constructed with vmin]
- expected: FAIL
-
- [CSSUnitValue can be constructed with vmax]
- expected: FAIL
-
- [CSSUnitValue can be constructed with cm]
- expected: FAIL
-
- [CSSUnitValue can be constructed with mm]
- expected: FAIL
-
[CSSUnitValue can be constructed with Q]
expected: FAIL
- [CSSUnitValue can be constructed with in]
- expected: FAIL
-
- [CSSUnitValue can be constructed with pt]
- expected: FAIL
-
- [CSSUnitValue can be constructed with pc]
- expected: FAIL
-
- [CSSUnitValue can be constructed with px]
- expected: FAIL
-
- [CSSUnitValue can be constructed with deg]
- expected: FAIL
-
- [CSSUnitValue can be constructed with grad]
- expected: FAIL
-
- [CSSUnitValue can be constructed with rad]
- expected: FAIL
-
- [CSSUnitValue can be constructed with turn]
- expected: FAIL
-
- [CSSUnitValue can be constructed with s]
- expected: FAIL
-
- [CSSUnitValue can be constructed with ms]
- expected: FAIL
-
[CSSUnitValue can be constructed with Hz]
expected: FAIL
[CSSUnitValue can be constructed with kHz]
expected: FAIL
-
- [CSSUnitValue can be constructed with dpi]
- expected: FAIL
-
- [CSSUnitValue can be constructed with dpcm]
- expected: FAIL
-
- [CSSUnitValue can be constructed with dppx]
- expected: FAIL
-
- [CSSUnitValue can be constructed with fr]
- expected: FAIL
-