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
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,6 +1,6 @@
/*
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -10,6 +10,7 @@
#include <AK/String.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Rect.h>
#include <LibWeb/CSS/SerializationMode.h>
#include <LibWeb/Forward.h>
#include <LibWeb/PixelUnits.h>
@ -17,7 +18,7 @@ namespace Web::CSS {
class Length {
public:
enum class Type {
enum class Type : u8 {
// Font-relative
Em,
Rem,
@ -218,7 +219,7 @@ public:
}
}
String to_string() const;
String to_string(SerializationMode = SerializationMode::Normal) const;
bool operator==(Length const& other) const
{