mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-05 07:39:16 +00:00
LibWeb/CSS: Use serialize_a_number() for Length serialization
This changes the maximum number of decimal places from 5 to 6, but 5 was previously a guess, and not specified behaviour: > For all of the decimal changes (except color) I couldn't really find a > spec that mandates any required precision, so I just copied what > Firefox seems to do, which is limit the output to 5 decimal places. > https://github.com/SerenityOS/serenity/pull/23449
This commit is contained in:
parent
1a7f6c8f87
commit
dffebee901
Notes:
github-actions[bot]
2025-08-18 15:54:28 +00:00
Author: https://github.com/AtkinsSJ
Commit: dffebee901
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5898
5 changed files with 47 additions and 34 deletions
|
@ -225,11 +225,24 @@ String Length::to_string(SerializationMode serialization_mode) const
|
|||
{
|
||||
if (is_auto())
|
||||
return "auto"_string;
|
||||
|
||||
// https://drafts.csswg.org/cssom/#serialize-a-css-value
|
||||
// -> <length>
|
||||
// The <number> component serialized as per <number> followed by the unit in its canonical form as defined in its
|
||||
// respective specification.
|
||||
|
||||
// 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()));
|
||||
if (serialization_mode == SerializationMode::ResolvedValue && is_absolute() && m_type != Type::Px) {
|
||||
StringBuilder builder;
|
||||
serialize_a_number(builder, absolute_length_to_px().to_double());
|
||||
builder.append("px"sv);
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
StringBuilder builder;
|
||||
serialize_a_number(builder, m_value);
|
||||
builder.append(unit_name());
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
StringView Length::unit_name() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue