LibWeb/CSS: Make dimension types serialize in resolved form

Some dimensions would always serialize in a canonical unit, others never
did, and others we manually would do so in their StyleValue. This
commit moves all of that into the dimension types, which means for
example that Length can apply its special rounding.

Our local serialization test now produces the same output as other
browsers. :^)
This commit is contained in:
Sam Atkins 2025-05-16 20:02:16 +01:00 committed by Tim Ledbetter
parent eec4365542
commit 443f9e5afb
Notes: github-actions[bot] 2025-05-17 06:54:42 +00:00
20 changed files with 70 additions and 58 deletions

View file

@ -1,11 +1,11 @@
/*
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2024, Glenn Skrzypczak <glenn.skrzypczak@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Resolution.h"
#include <LibWeb/CSS/Resolution.h>
namespace Web::CSS {
@ -20,9 +20,11 @@ Resolution Resolution::make_dots_per_pixel(double value)
return { value, Type::Dppx };
}
String Resolution::to_string() const
String Resolution::to_string(SerializationMode serialization_mode) const
{
return MUST(String::formatted("{}dppx", to_dots_per_pixel()));
if (serialization_mode == SerializationMode::ResolvedValue)
return MUST(String::formatted("{}dppx", to_dots_per_pixel()));
return MUST(String::formatted("{}{}", raw_value(), unit_name()));
}
double Resolution::to_dots_per_pixel() const