mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +00:00
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:
parent
eec4365542
commit
443f9e5afb
Notes:
github-actions[bot]
2025-05-17 06:54:42 +00:00
Author: https://github.com/AtkinsSJ
Commit: 443f9e5afb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4783
Reviewed-by: https://github.com/tcl3 ✅
20 changed files with 70 additions and 58 deletions
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -198,10 +198,14 @@ CSSPixels Length::to_px_slow_case(Layout::Node const& layout_node) const
|
|||
return viewport_relative_length_to_px(viewport_rect);
|
||||
}
|
||||
|
||||
String Length::to_string() const
|
||||
String Length::to_string(SerializationMode serialization_mode) const
|
||||
{
|
||||
if (is_auto())
|
||||
return "auto"_string;
|
||||
// FIXME: Manually skip this for px so we avoid rounding errors in absolute_length_to_px.
|
||||
// Maybe provide alternative functions that don't produce CSSPixels?
|
||||
if (serialization_mode == SerializationMode::ResolvedValue && is_absolute() && m_type != Type::Px)
|
||||
return MUST(String::formatted("{:.5}px", absolute_length_to_px()));
|
||||
return MUST(String::formatted("{:.5}{}", m_value, unit_name()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue