LibWeb: Preserve unit when serializing angle values

Previously, when serializing an angle value, we would always convert it
to degrees. We now canonicalize the angle value only when serializing
its computed value.
This commit is contained in:
Tim Ledbetter 2025-03-19 17:04:15 +00:00 committed by Sam Atkins
parent d0be5a0cdf
commit 5bfbb7abe6
Notes: github-actions[bot] 2025-03-20 17:00:27 +00:00
3 changed files with 20 additions and 19 deletions

View file

@ -29,7 +29,7 @@ Angle Angle::percentage_of(Percentage const& percentage) const
String Angle::to_string() const
{
return MUST(String::formatted("{}deg", to_degrees()));
return MUST(String::formatted("{}{}", raw_value(), unit_name()));
}
double Angle::to_degrees() const

View file

@ -19,8 +19,10 @@ AngleStyleValue::AngleStyleValue(Angle angle)
AngleStyleValue::~AngleStyleValue() = default;
String AngleStyleValue::to_string(SerializationMode) const
String AngleStyleValue::to_string(SerializationMode serialization_mode) const
{
if (serialization_mode == SerializationMode::ResolvedValue)
return MUST(String::formatted("{}deg", m_angle.to_degrees()));
return m_angle.to_string();
}

View file

@ -2,22 +2,21 @@ Harness status: OK
Found 17 tests
2 Pass
15 Fail
17 Pass
Pass e.style['rotate'] = "none" should set the property value
Pass e.style['rotate'] = "0deg" should set the property value
Fail e.style['rotate'] = "100 200 300 400grad" should set the property value
Fail e.style['rotate'] = "400grad 100 200 300" should set the property value
Fail e.style['rotate'] = "0 0 0 400grad" should set the property value
Fail e.style['rotate'] = "x 400grad" should set the property value
Fail e.style['rotate'] = "400grad x" should set the property value
Fail e.style['rotate'] = "0.5 0 0 400grad" should set the property value
Fail e.style['rotate'] = "1 0 0 400grad" should set the property value
Fail e.style['rotate'] = "y 400grad" should set the property value
Fail e.style['rotate'] = "400grad y" should set the property value
Fail e.style['rotate'] = "0 0.5 0 400grad" should set the property value
Fail e.style['rotate'] = "0 1 0 400grad" should set the property value
Fail e.style['rotate'] = "400grad" should set the property value
Fail e.style['rotate'] = "400grad z" should set the property value
Fail e.style['rotate'] = "0 0 0.5 400grad" should set the property value
Fail e.style['rotate'] = "0 0 1 400grad" should set the property value
Pass e.style['rotate'] = "100 200 300 400grad" should set the property value
Pass e.style['rotate'] = "400grad 100 200 300" should set the property value
Pass e.style['rotate'] = "0 0 0 400grad" should set the property value
Pass e.style['rotate'] = "x 400grad" should set the property value
Pass e.style['rotate'] = "400grad x" should set the property value
Pass e.style['rotate'] = "0.5 0 0 400grad" should set the property value
Pass e.style['rotate'] = "1 0 0 400grad" should set the property value
Pass e.style['rotate'] = "y 400grad" should set the property value
Pass e.style['rotate'] = "400grad y" should set the property value
Pass e.style['rotate'] = "0 0.5 0 400grad" should set the property value
Pass e.style['rotate'] = "0 1 0 400grad" should set the property value
Pass e.style['rotate'] = "400grad" should set the property value
Pass e.style['rotate'] = "400grad z" should set the property value
Pass e.style['rotate'] = "0 0 0.5 400grad" should set the property value
Pass e.style['rotate'] = "0 0 1 400grad" should set the property value