mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-26 12:17:52 +00:00
LibWeb/CSS: Define and use serialize_a_number()
No behaviour change, this just moves things.
This commit is contained in:
parent
0205480051
commit
1a7f6c8f87
Notes:
github-actions[bot]
2025-08-18 15:54:35 +00:00
Author: https://github.com/AtkinsSJ
Commit: 1a7f6c8f87
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5898
4 changed files with 28 additions and 13 deletions
|
@ -186,32 +186,49 @@ void serialize_a_srgb_value(StringBuilder& builder, Color color)
|
|||
builder.appendff("rgba({}, {}, {}, 0.{})", color.red(), color.green(), color.blue(), format_to_8bit_compatible(color.alpha()).data());
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#serialize-a-css-value
|
||||
void serialize_a_number(StringBuilder& builder, double value)
|
||||
{
|
||||
// -> <number>
|
||||
// A base-ten number using digits 0-9 (U+0030 to U+0039) in the shortest form possible, using "." to separate
|
||||
// decimals (if any), rounding the value if necessary to not produce more than 6 decimals, preceded by "-" (U+002D)
|
||||
// if it is negative.
|
||||
builder.appendff("{:.6}", value);
|
||||
}
|
||||
|
||||
String serialize_an_identifier(StringView ident)
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize_an_identifier(builder, ident);
|
||||
return MUST(builder.to_string());
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
String serialize_a_string(StringView string)
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize_a_string(builder, string);
|
||||
return MUST(builder.to_string());
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
String serialize_a_url(StringView url)
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize_a_url(builder, url);
|
||||
return MUST(builder.to_string());
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
String serialize_a_srgb_value(Color color)
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize_a_srgb_value(builder, color);
|
||||
return MUST(builder.to_string());
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
String serialize_a_number(double value)
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize_a_number(builder, value);
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#serialize-a-css-declaration
|
||||
|
@ -239,7 +256,7 @@ String serialize_a_css_declaration(StringView property, StringView value, Import
|
|||
builder.append(';');
|
||||
|
||||
// 7. Return s.
|
||||
return MUST(builder.to_string());
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-syntax/#serialization
|
||||
|
|
|
@ -23,11 +23,13 @@ void serialize_a_string(StringBuilder&, StringView string);
|
|||
void serialize_a_url(StringBuilder&, StringView url);
|
||||
void serialize_unicode_ranges(StringBuilder&, Vector<Gfx::UnicodeRange> const& unicode_ranges);
|
||||
void serialize_a_srgb_value(StringBuilder&, Color color);
|
||||
void serialize_a_number(StringBuilder&, double value);
|
||||
|
||||
String serialize_an_identifier(StringView ident);
|
||||
String serialize_a_string(StringView string);
|
||||
String serialize_a_url(StringView url);
|
||||
String serialize_a_srgb_value(Color color);
|
||||
String serialize_a_number(double value);
|
||||
|
||||
// https://www.w3.org/TR/cssom/#serialize-a-comma-separated-list
|
||||
template<typename T, typename SerializeItem>
|
||||
|
|
|
@ -9,18 +9,13 @@
|
|||
|
||||
#include "NumberStyleValue.h"
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
String NumberStyleValue::to_string(SerializationMode) const
|
||||
{
|
||||
// FIXME: This should be moved into Serialize.cpp and used by applicable dimensions as well.
|
||||
// https://drafts.csswg.org/cssom/#serialize-a-css-value
|
||||
// <number>
|
||||
// A base-ten number using digits 0-9 (U+0030 to U+0039) in the shortest form possible, using "." to separate
|
||||
// decimals (if any), rounding the value if necessary to not produce more than 6 decimals, preceded by "-" (U+002D)
|
||||
// if it is negative.
|
||||
return MUST(String::formatted("{:.6}", m_value));
|
||||
return serialize_a_number(m_value);
|
||||
}
|
||||
|
||||
Vector<Parser::ComponentValue> NumberStyleValue::tokenize() const
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "TransformationStyleValue.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
|
@ -138,7 +139,7 @@ String TransformationStyleValue::to_string(SerializationMode mode) const
|
|||
if (!raw_value.has_value())
|
||||
return value.to_string(mode);
|
||||
|
||||
return MUST(String::formatted("{:.6}", *raw_value));
|
||||
return serialize_a_number(*raw_value);
|
||||
};
|
||||
|
||||
auto x_value = resolve_to_string(m_properties.values[0]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue