mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
LibWeb: Make serializing basic CSS types infallible
This commit is contained in:
parent
b5893ee115
commit
6bee81cfb6
38 changed files with 128 additions and 121 deletions
|
@ -26,9 +26,9 @@ Angle Angle::percentage_of(Percentage const& percentage) const
|
|||
return Angle { percentage.as_fraction() * m_value, m_type };
|
||||
}
|
||||
|
||||
ErrorOr<String> Angle::to_string() const
|
||||
String Angle::to_string() const
|
||||
{
|
||||
return String::formatted("{}deg", to_degrees());
|
||||
return MUST(String::formatted("{}deg", to_degrees()));
|
||||
}
|
||||
|
||||
double Angle::to_degrees() const
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
static Angle make_degrees(double);
|
||||
Angle percentage_of(Percentage const&) const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
|
||||
double to_degrees() const;
|
||||
double to_radians() const;
|
||||
|
@ -64,6 +64,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Angle> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Angle const& angle)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(angle.to_string()));
|
||||
return Formatter<StringView>::format(builder, angle.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
|
||||
DeprecatedString key_text() const
|
||||
{
|
||||
return m_key.to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
|
||||
return m_key.to_string().to_deprecated_string();
|
||||
}
|
||||
|
||||
void set_key_text(DeprecatedString const& key_text)
|
||||
|
|
|
@ -58,10 +58,10 @@ public:
|
|||
});
|
||||
}
|
||||
|
||||
ErrorOr<String> to_string() const
|
||||
String to_string() const
|
||||
{
|
||||
if (is_calculated())
|
||||
return m_value.template get<NonnullRefPtr<CalculatedStyleValue>>()->to_string();
|
||||
return MUST(m_value.template get<NonnullRefPtr<CalculatedStyleValue>>()->to_string());
|
||||
|
||||
return m_value.template get<T>().to_string();
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::AngleOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::AngleOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(calculated_or.to_string()));
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -127,7 +127,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::FrequencyOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::FrequencyOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(calculated_or.to_string()));
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -135,7 +135,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::LengthOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::LengthOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(calculated_or.to_string()));
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -143,7 +143,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::PercentageOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::PercentageOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(calculated_or.to_string()));
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -151,6 +151,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::TimeOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::TimeOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(calculated_or.to_string()));
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,98 +8,98 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
ErrorOr<String> Display::to_string() const
|
||||
String Display::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
switch (m_type) {
|
||||
case Type::OutsideAndInside:
|
||||
switch (m_value.outside_inside.outside) {
|
||||
case Outside::Block:
|
||||
TRY(builder.try_append("block"sv));
|
||||
builder.append("block"sv);
|
||||
break;
|
||||
case Outside::Inline:
|
||||
TRY(builder.try_append("inline"sv));
|
||||
builder.append("inline"sv);
|
||||
break;
|
||||
case Outside::RunIn:
|
||||
TRY(builder.try_append("run-in"sv));
|
||||
builder.append("run-in"sv);
|
||||
break;
|
||||
}
|
||||
TRY(builder.try_append(' '));
|
||||
builder.append(' ');
|
||||
switch (m_value.outside_inside.inside) {
|
||||
case Inside::Flow:
|
||||
TRY(builder.try_append("flow"sv));
|
||||
builder.append("flow"sv);
|
||||
break;
|
||||
case Inside::FlowRoot:
|
||||
TRY(builder.try_append("flow-root"sv));
|
||||
builder.append("flow-root"sv);
|
||||
break;
|
||||
case Inside::Table:
|
||||
TRY(builder.try_append("table"sv));
|
||||
builder.append("table"sv);
|
||||
break;
|
||||
case Inside::Flex:
|
||||
TRY(builder.try_append("flex"sv));
|
||||
builder.append("flex"sv);
|
||||
break;
|
||||
case Inside::Grid:
|
||||
TRY(builder.try_append("grid"sv));
|
||||
builder.append("grid"sv);
|
||||
break;
|
||||
case Inside::Ruby:
|
||||
TRY(builder.try_append("ruby"sv));
|
||||
builder.append("ruby"sv);
|
||||
break;
|
||||
}
|
||||
if (m_value.outside_inside.list_item == ListItem::Yes)
|
||||
TRY(builder.try_append(" list-item"sv));
|
||||
builder.append(" list-item"sv);
|
||||
break;
|
||||
case Type::Internal:
|
||||
switch (m_value.internal) {
|
||||
case Internal::TableRowGroup:
|
||||
TRY(builder.try_append("table-row-group"sv));
|
||||
builder.append("table-row-group"sv);
|
||||
break;
|
||||
case Internal::TableHeaderGroup:
|
||||
TRY(builder.try_append("table-header-group"sv));
|
||||
builder.append("table-header-group"sv);
|
||||
break;
|
||||
case Internal::TableFooterGroup:
|
||||
TRY(builder.try_append("table-footer-group"sv));
|
||||
builder.append("table-footer-group"sv);
|
||||
break;
|
||||
case Internal::TableRow:
|
||||
TRY(builder.try_append("table-row"sv));
|
||||
builder.append("table-row"sv);
|
||||
break;
|
||||
case Internal::TableCell:
|
||||
TRY(builder.try_append("table-cell"sv));
|
||||
builder.append("table-cell"sv);
|
||||
break;
|
||||
case Internal::TableColumnGroup:
|
||||
TRY(builder.try_append("table-column-group"sv));
|
||||
builder.append("table-column-group"sv);
|
||||
break;
|
||||
case Internal::TableColumn:
|
||||
TRY(builder.try_append("table-column"sv));
|
||||
builder.append("table-column"sv);
|
||||
break;
|
||||
case Internal::TableCaption:
|
||||
TRY(builder.try_append("table-caption"sv));
|
||||
builder.append("table-caption"sv);
|
||||
break;
|
||||
case Internal::RubyBase:
|
||||
TRY(builder.try_append("ruby-base"sv));
|
||||
builder.append("ruby-base"sv);
|
||||
break;
|
||||
case Internal::RubyText:
|
||||
TRY(builder.try_append("ruby-text"sv));
|
||||
builder.append("ruby-text"sv);
|
||||
break;
|
||||
case Internal::RubyBaseContainer:
|
||||
TRY(builder.try_append("ruby-base-container"sv));
|
||||
builder.append("ruby-base-container"sv);
|
||||
break;
|
||||
case Internal::RubyTextContainer:
|
||||
TRY(builder.try_append("ruby-text-container"sv));
|
||||
builder.append("ruby-text-container"sv);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Type::Box:
|
||||
switch (m_value.box) {
|
||||
case Box::Contents:
|
||||
TRY(builder.try_append("contents"sv));
|
||||
builder.append("contents"sv);
|
||||
break;
|
||||
case Box::None:
|
||||
TRY(builder.try_append("none"sv));
|
||||
builder.append("none"sv);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
};
|
||||
return builder.to_string();
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
Display() = default;
|
||||
~Display() = default;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
|
||||
bool operator==(Display const& other) const
|
||||
{
|
||||
|
|
|
@ -25,9 +25,9 @@ Frequency Frequency::percentage_of(Percentage const& percentage) const
|
|||
return Frequency { percentage.as_fraction() * m_value, m_type };
|
||||
}
|
||||
|
||||
ErrorOr<String> Frequency::to_string() const
|
||||
String Frequency::to_string() const
|
||||
{
|
||||
return String::formatted("{}hz", to_hertz());
|
||||
return MUST(String::formatted("{}hz", to_hertz()));
|
||||
}
|
||||
|
||||
double Frequency::to_hertz() const
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
static Frequency make_hertz(double);
|
||||
Frequency percentage_of(Percentage const&) const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
double to_hertz() const;
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
@ -59,6 +59,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Frequency> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Frequency const& frequency)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(frequency.to_string()));
|
||||
return Formatter<StringView>::format(builder, frequency.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -186,11 +186,11 @@ CSSPixels Length::to_px(Layout::Node const& layout_node) const
|
|||
return viewport_relative_length_to_px(viewport_rect);
|
||||
}
|
||||
|
||||
ErrorOr<String> Length::to_string() const
|
||||
String Length::to_string() const
|
||||
{
|
||||
if (is_auto())
|
||||
return "auto"_string;
|
||||
return String::formatted("{}{}", m_value, unit_name());
|
||||
return MUST(String::formatted("{}{}", m_value, unit_name()));
|
||||
}
|
||||
|
||||
char const* Length::unit_name() const
|
||||
|
|
|
@ -203,7 +203,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
|
||||
bool operator==(Length const& other) const
|
||||
{
|
||||
|
@ -230,6 +230,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Length> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Length const& length)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(length.to_string()));
|
||||
return Formatter<StringView>::format(builder, length.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -24,11 +24,11 @@ NonnullRefPtr<MediaQuery> MediaQuery::create_not_all()
|
|||
ErrorOr<String> MediaFeatureValue::to_string() const
|
||||
{
|
||||
return m_value.visit(
|
||||
[](ValueID const& ident) { return String::from_utf8(string_from_value_id(ident)); },
|
||||
[](ValueID const& ident) { return MUST(String::from_utf8(string_from_value_id(ident))); },
|
||||
[](Length const& length) { return length.to_string(); },
|
||||
[](Ratio const& ratio) { return ratio.to_string(); },
|
||||
[](Resolution const& resolution) { return resolution.to_string(); },
|
||||
[](float number) { return String::number(number); });
|
||||
[](float number) { return MUST(String::number(number)); });
|
||||
}
|
||||
|
||||
bool MediaFeatureValue::is_same_type(MediaFeatureValue const& other) const
|
||||
|
|
|
@ -70,11 +70,11 @@ public:
|
|||
return { Type::Number, m_value / other.m_value };
|
||||
}
|
||||
|
||||
ErrorOr<String> to_string() const
|
||||
String to_string() const
|
||||
{
|
||||
if (m_type == Type::IntegerWithExplicitSign)
|
||||
return String::formatted("{:+}", m_value);
|
||||
return String::number(m_value);
|
||||
return MUST(String::formatted("{:+}", m_value));
|
||||
return MUST(String::number(m_value));
|
||||
}
|
||||
|
||||
bool operator==(Number const& other) const
|
||||
|
@ -101,6 +101,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Number> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Number const& number)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(number.to_string()));
|
||||
return Formatter<StringView>::format(builder, number.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,9 +26,9 @@ public:
|
|||
double value() const { return m_value; }
|
||||
double as_fraction() const { return m_value * 0.01; }
|
||||
|
||||
ErrorOr<String> to_string() const
|
||||
String to_string() const
|
||||
{
|
||||
return String::formatted("{}%", m_value);
|
||||
return MUST(String::formatted("{}%", m_value));
|
||||
}
|
||||
|
||||
bool operator==(Percentage const& other) const { return m_value == other.m_value; }
|
||||
|
|
|
@ -112,10 +112,10 @@ public:
|
|||
});
|
||||
}
|
||||
|
||||
ErrorOr<String> to_string() const
|
||||
String to_string() const
|
||||
{
|
||||
if (is_calculated())
|
||||
return m_value.template get<NonnullRefPtr<CalculatedStyleValue>>()->to_string();
|
||||
return MUST(m_value.template get<NonnullRefPtr<CalculatedStyleValue>>()->to_string());
|
||||
if (is_percentage())
|
||||
return m_value.template get<Percentage>().to_string();
|
||||
return m_value.template get<T>().to_string();
|
||||
|
@ -218,7 +218,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Percentage> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Percentage const& percentage)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(percentage.to_string()));
|
||||
return Formatter<StringView>::format(builder, percentage.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -226,7 +226,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::AnglePercentage> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::AnglePercentage const& angle_percentage)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(angle_percentage.to_string()));
|
||||
return Formatter<StringView>::format(builder, angle_percentage.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -234,7 +234,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::FrequencyPercentage> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::FrequencyPercentage const& frequency_percentage)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(frequency_percentage.to_string()));
|
||||
return Formatter<StringView>::format(builder, frequency_percentage.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -242,7 +242,7 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::LengthPercentage> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::LengthPercentage const& length_percentage)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(length_percentage.to_string()));
|
||||
return Formatter<StringView>::format(builder, length_percentage.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -250,6 +250,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::TimePercentage> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::TimePercentage const& time_percentage)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(time_percentage.to_string()));
|
||||
return Formatter<StringView>::format(builder, time_percentage.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -56,15 +56,15 @@ CSSPixelPoint PositionValue::resolved(Layout::Node const& node, CSSPixelRect con
|
|||
return CSSPixelPoint { rect.x() + x, rect.y() + y };
|
||||
}
|
||||
|
||||
ErrorOr<void> PositionValue::serialize(StringBuilder& builder) const
|
||||
void PositionValue::serialize(StringBuilder& builder) const
|
||||
{
|
||||
// Note: This means our serialization with simplify any with explicit edges that are just `top left`.
|
||||
bool has_relative_edges = x_relative_to == HorizontalEdge::Right || y_relative_to == VerticalEdge::Bottom;
|
||||
if (has_relative_edges)
|
||||
TRY(builder.try_append(x_relative_to == HorizontalEdge::Left ? "left "sv : "right "sv));
|
||||
TRY(horizontal_position.visit(
|
||||
[&](HorizontalPreset preset) -> ErrorOr<void> {
|
||||
return builder.try_append([&] {
|
||||
builder.append(x_relative_to == HorizontalEdge::Left ? "left "sv : "right "sv);
|
||||
horizontal_position.visit(
|
||||
[&](HorizontalPreset preset) {
|
||||
builder.append([&] {
|
||||
switch (preset) {
|
||||
case HorizontalPreset::Left:
|
||||
return "left"sv;
|
||||
|
@ -77,15 +77,15 @@ ErrorOr<void> PositionValue::serialize(StringBuilder& builder) const
|
|||
}
|
||||
}());
|
||||
},
|
||||
[&](LengthPercentage length_percentage) -> ErrorOr<void> {
|
||||
return builder.try_appendff(TRY(length_percentage.to_string()));
|
||||
}));
|
||||
TRY(builder.try_append(' '));
|
||||
[&](LengthPercentage length_percentage) {
|
||||
builder.append(length_percentage.to_string());
|
||||
});
|
||||
builder.append(' ');
|
||||
if (has_relative_edges)
|
||||
TRY(builder.try_append(y_relative_to == VerticalEdge::Top ? "top "sv : "bottom "sv));
|
||||
TRY(vertical_position.visit(
|
||||
[&](VerticalPreset preset) -> ErrorOr<void> {
|
||||
return builder.try_append([&] {
|
||||
builder.append(y_relative_to == VerticalEdge::Top ? "top "sv : "bottom "sv);
|
||||
vertical_position.visit(
|
||||
[&](VerticalPreset preset) {
|
||||
builder.append([&] {
|
||||
switch (preset) {
|
||||
case VerticalPreset::Top:
|
||||
return "top"sv;
|
||||
|
@ -98,10 +98,9 @@ ErrorOr<void> PositionValue::serialize(StringBuilder& builder) const
|
|||
}
|
||||
}());
|
||||
},
|
||||
[&](LengthPercentage length_percentage) -> ErrorOr<void> {
|
||||
return builder.try_append(TRY(length_percentage.to_string()));
|
||||
}));
|
||||
return {};
|
||||
[&](LengthPercentage length_percentage) {
|
||||
builder.append(length_percentage.to_string());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ struct PositionValue {
|
|||
VerticalEdge y_relative_to { VerticalEdge::Top };
|
||||
|
||||
CSSPixelPoint resolved(Layout::Node const& node, CSSPixelRect const& rect) const;
|
||||
ErrorOr<void> serialize(StringBuilder&) const;
|
||||
void serialize(StringBuilder&) const;
|
||||
bool operator==(PositionValue const&) const = default;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -22,9 +22,9 @@ bool Ratio::is_degenerate() const
|
|||
|| !isfinite(m_second_value) || m_second_value == 0;
|
||||
}
|
||||
|
||||
ErrorOr<String> Ratio::to_string() const
|
||||
String Ratio::to_string() const
|
||||
{
|
||||
return String::formatted("{} / {}", m_first_value, m_second_value);
|
||||
return MUST(String::formatted("{} / {}", m_first_value, m_second_value));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
double value() const { return m_first_value / m_second_value; }
|
||||
bool is_degenerate() const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
|
||||
bool operator==(Ratio const& other) const
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -14,9 +14,9 @@ Resolution::Resolution(double value, Type type)
|
|||
{
|
||||
}
|
||||
|
||||
ErrorOr<String> Resolution::to_string() const
|
||||
String Resolution::to_string() const
|
||||
{
|
||||
return String::formatted("{}dppx", to_dots_per_pixel());
|
||||
return MUST(String::formatted("{}dppx", to_dots_per_pixel()));
|
||||
}
|
||||
|
||||
double Resolution::to_dots_per_pixel() const
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
Resolution(double value, Type type);
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
double to_dots_per_pixel() const;
|
||||
|
||||
bool operator==(Resolution const& other) const
|
||||
|
|
|
@ -131,7 +131,7 @@ void serialize_a_local(StringBuilder& builder, StringView path)
|
|||
void serialize_unicode_ranges(StringBuilder& builder, Vector<UnicodeRange> const& unicode_ranges)
|
||||
{
|
||||
serialize_a_comma_separated_list(builder, unicode_ranges, [](auto& builder, UnicodeRange unicode_range) -> void {
|
||||
return serialize_a_string(builder, MUST(unicode_range.to_string()));
|
||||
return serialize_a_string(builder, unicode_range.to_string());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ bool Size::contains_percentage() const
|
|||
}
|
||||
}
|
||||
|
||||
ErrorOr<String> Size::to_string() const
|
||||
String Size::to_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Auto:
|
||||
|
@ -102,7 +102,7 @@ ErrorOr<String> Size::to_string() const
|
|||
case Type::MaxContent:
|
||||
return "max-content"_string;
|
||||
case Type::FitContent:
|
||||
return String::formatted("fit-content({})", TRY(m_length_percentage.to_string()));
|
||||
return MUST(String::formatted("fit-content({})", m_length_percentage.to_string()));
|
||||
case Type::None:
|
||||
return "none"_string;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
return m_length_percentage.length();
|
||||
}
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
Size(Type type, LengthPercentage);
|
||||
|
@ -91,6 +91,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Size> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Size const& size)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(size.to_string()));
|
||||
return Formatter<StringView>::format(builder, size.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -67,12 +67,12 @@ static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto cons
|
|||
TRY(builder.try_append(", "sv));
|
||||
|
||||
if (element.transition_hint.has_value())
|
||||
TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string())));
|
||||
TRY(builder.try_appendff("{}, "sv, element.transition_hint->value.to_string()));
|
||||
|
||||
TRY(builder.try_append(TRY(element.color_stop.color->to_string())));
|
||||
for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) {
|
||||
if (position->has_value())
|
||||
TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string())));
|
||||
TRY(builder.try_appendff(" {}"sv, (*position)->to_string()));
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ BackgroundSizeStyleValue::~BackgroundSizeStyleValue() = default;
|
|||
|
||||
ErrorOr<String> BackgroundSizeStyleValue::to_string() const
|
||||
{
|
||||
return String::formatted("{} {}", TRY(m_properties.size_x.to_string()), TRY(m_properties.size_y.to_string()));
|
||||
return String::formatted("{} {}", m_properties.size_x.to_string(), m_properties.size_y.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,15 @@ namespace Web::CSS {
|
|||
|
||||
ErrorOr<String> BorderRadiusShorthandStyleValue::to_string() const
|
||||
{
|
||||
return String::formatted("{} {} {} {} / {} {} {} {}", TRY(m_properties.top_left->horizontal_radius().to_string()), TRY(m_properties.top_right->horizontal_radius().to_string()), TRY(m_properties.bottom_right->horizontal_radius().to_string()), TRY(m_properties.bottom_left->horizontal_radius().to_string()), TRY(m_properties.top_left->vertical_radius().to_string()), TRY(m_properties.top_right->vertical_radius().to_string()), TRY(m_properties.bottom_right->vertical_radius().to_string()), TRY(m_properties.bottom_left->vertical_radius().to_string()));
|
||||
return String::formatted("{} {} {} {} / {} {} {} {}",
|
||||
m_properties.top_left->horizontal_radius().to_string(),
|
||||
m_properties.top_right->horizontal_radius().to_string(),
|
||||
m_properties.bottom_right->horizontal_radius().to_string(),
|
||||
m_properties.bottom_left->horizontal_radius().to_string(),
|
||||
m_properties.top_left->vertical_radius().to_string(),
|
||||
m_properties.top_right->vertical_radius().to_string(),
|
||||
m_properties.bottom_right->vertical_radius().to_string(),
|
||||
m_properties.bottom_left->vertical_radius().to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ ErrorOr<String> BorderRadiusStyleValue::to_string() const
|
|||
{
|
||||
if (m_properties.horizontal_radius == m_properties.vertical_radius)
|
||||
return m_properties.horizontal_radius.to_string();
|
||||
return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string()));
|
||||
return String::formatted("{} / {}", m_properties.horizontal_radius.to_string(), m_properties.vertical_radius.to_string());
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
|
||||
|
|
|
@ -208,7 +208,7 @@ CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional
|
|||
|
||||
ErrorOr<void> NumericCalculationNode::dump(StringBuilder& builder, int indent) const
|
||||
{
|
||||
return builder.try_appendff("{: >{}}NUMERIC({})\n", "", indent, TRY(m_value.visit([](auto& it) { return it.to_string(); })));
|
||||
return builder.try_appendff("{: >{}}NUMERIC({})\n", "", indent, m_value.visit([](auto& it) { return it.to_string(); }));
|
||||
}
|
||||
|
||||
NonnullOwnPtr<SumCalculationNode> SumCalculationNode::create(Vector<NonnullOwnPtr<CalculationNode>> values)
|
||||
|
|
|
@ -21,12 +21,12 @@ ErrorOr<String> ConicGradientStyleValue::to_string() const
|
|||
bool has_from_angle = false;
|
||||
bool has_at_position = false;
|
||||
if ((has_from_angle = m_properties.from_angle.to_degrees() != 0))
|
||||
TRY(builder.try_appendff("from {}", TRY(m_properties.from_angle.to_string())));
|
||||
TRY(builder.try_appendff("from {}", m_properties.from_angle.to_string()));
|
||||
if ((has_at_position = m_properties.position != PositionValue::center())) {
|
||||
if (has_from_angle)
|
||||
TRY(builder.try_append(' '));
|
||||
TRY(builder.try_appendff("at "sv));
|
||||
TRY(m_properties.position.serialize(builder));
|
||||
m_properties.position.serialize(builder);
|
||||
}
|
||||
if (has_from_angle || has_at_position)
|
||||
TRY(builder.try_append(", "sv));
|
||||
|
|
|
@ -24,7 +24,7 @@ ErrorOr<String> EdgeStyleValue::to_string() const
|
|||
VERIFY_NOT_REACHED();
|
||||
};
|
||||
|
||||
return String::formatted("{} {}", to_string(m_properties.edge), TRY(m_properties.offset.to_string()));
|
||||
return String::formatted("{} {}", to_string(m_properties.edge), m_properties.offset.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,14 +65,14 @@ ErrorOr<String> FilterValueListStyleValue::to_string() const
|
|||
[&](Filter::Blur const& blur) -> ErrorOr<void> {
|
||||
TRY(builder.try_append("blur("sv));
|
||||
if (blur.radius.has_value())
|
||||
TRY(builder.try_append(TRY(blur.radius->to_string())));
|
||||
TRY(builder.try_append(blur.radius->to_string()));
|
||||
return {};
|
||||
},
|
||||
[&](Filter::DropShadow const& drop_shadow) -> ErrorOr<void> {
|
||||
TRY(builder.try_appendff("drop-shadow({} {}"sv,
|
||||
drop_shadow.offset_x, drop_shadow.offset_y));
|
||||
if (drop_shadow.radius.has_value())
|
||||
TRY(builder.try_appendff(" {}", TRY(drop_shadow.radius->to_string())));
|
||||
TRY(builder.try_appendff(" {}", drop_shadow.radius->to_string()));
|
||||
if (drop_shadow.color.has_value()) {
|
||||
TRY(builder.try_append(' '));
|
||||
serialize_a_srgb_value(builder, *drop_shadow.color);
|
||||
|
@ -84,7 +84,7 @@ ErrorOr<String> FilterValueListStyleValue::to_string() const
|
|||
if (hue_rotate.angle.has_value()) {
|
||||
TRY(hue_rotate.angle->visit(
|
||||
[&](Angle const& angle) -> ErrorOr<void> {
|
||||
return builder.try_append(TRY(angle.to_string()));
|
||||
return builder.try_append(angle.to_string());
|
||||
},
|
||||
[&](auto&) -> ErrorOr<void> {
|
||||
return builder.try_append('0');
|
||||
|
@ -115,7 +115,7 @@ ErrorOr<String> FilterValueListStyleValue::to_string() const
|
|||
}
|
||||
}()));
|
||||
if (color.amount.has_value())
|
||||
TRY(builder.try_append(TRY(color.amount->to_string())));
|
||||
TRY(builder.try_append(color.amount->to_string()));
|
||||
return {};
|
||||
}));
|
||||
TRY(builder.try_append(')'));
|
||||
|
|
|
@ -47,7 +47,7 @@ ErrorOr<String> LinearGradientStyleValue::to_string() const
|
|||
return builder.try_appendff("{}{}, "sv, m_properties.gradient_type == GradientType::Standard ? "to "sv : ""sv, side_or_corner_to_string(side_or_corner));
|
||||
},
|
||||
[&](Angle const& angle) -> ErrorOr<void> {
|
||||
return builder.try_appendff("{}, "sv, TRY(angle.to_string()));
|
||||
return builder.try_appendff("{}, "sv, angle.to_string());
|
||||
}));
|
||||
|
||||
TRY(serialize_color_stop_list(builder, m_properties.color_stop_list));
|
||||
|
|
|
@ -38,15 +38,15 @@ ErrorOr<String> RadialGradientStyleValue::to_string() const
|
|||
}());
|
||||
},
|
||||
[&](CircleSize const& circle_size) -> ErrorOr<void> {
|
||||
return builder.try_append(TRY(circle_size.radius.to_string()));
|
||||
return builder.try_append(circle_size.radius.to_string());
|
||||
},
|
||||
[&](EllipseSize const& ellipse_size) -> ErrorOr<void> {
|
||||
return builder.try_appendff("{} {}", TRY(ellipse_size.radius_a.to_string()), TRY(ellipse_size.radius_b.to_string()));
|
||||
return builder.try_appendff("{} {}", ellipse_size.radius_a.to_string(), ellipse_size.radius_b.to_string());
|
||||
}));
|
||||
|
||||
if (m_properties.position != PositionValue::center()) {
|
||||
TRY(builder.try_appendff(" at "sv));
|
||||
TRY(m_properties.position.serialize(builder));
|
||||
m_properties.position.serialize(builder);
|
||||
}
|
||||
|
||||
TRY(builder.try_append(", "sv));
|
||||
|
|
|
@ -25,9 +25,9 @@ Time Time::percentage_of(Percentage const& percentage) const
|
|||
return Time { percentage.as_fraction() * m_value, m_type };
|
||||
}
|
||||
|
||||
ErrorOr<String> Time::to_string() const
|
||||
String Time::to_string() const
|
||||
{
|
||||
return String::formatted("{}s", to_seconds());
|
||||
return MUST(String::formatted("{}s", to_seconds()));
|
||||
}
|
||||
|
||||
double Time::to_seconds() const
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
static Time make_seconds(double);
|
||||
Time percentage_of(Percentage const&) const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
double to_milliseconds() const;
|
||||
double to_seconds() const;
|
||||
|
||||
|
@ -61,6 +61,6 @@ template<>
|
|||
struct AK::Formatter<Web::CSS::Time> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Time const& time)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(time.to_string()));
|
||||
return Formatter<StringView>::format(builder, time.to_string());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,11 +29,11 @@ public:
|
|||
return m_min_code_point <= code_point && code_point <= m_max_code_point;
|
||||
}
|
||||
|
||||
ErrorOr<String> to_string() const
|
||||
String to_string() const
|
||||
{
|
||||
if (m_min_code_point == m_max_code_point)
|
||||
return String::formatted("U+{:x}", m_min_code_point);
|
||||
return String::formatted("U+{:x}-{:x}", m_min_code_point, m_max_code_point);
|
||||
return MUST(String::formatted("U+{:x}", m_min_code_point));
|
||||
return MUST(String::formatted("U+{:x}-{:x}", m_min_code_point, m_max_code_point));
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -352,7 +352,7 @@ JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Docume
|
|||
return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
|
||||
if (display.is_grid_inside())
|
||||
return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Support display: {}", MUST(display.to_string()));
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Support display: {}", display.to_string());
|
||||
return document.heap().allocate_without_realm<Layout::InlineNode>(document, element, move(style));
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Docume
|
|||
if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_contents())
|
||||
return document.heap().allocate_without_realm<Layout::BlockContainer>(document, element, move(style));
|
||||
|
||||
dbgln("FIXME: CSS display '{}' not implemented yet.", display.to_string().release_value_but_fixme_should_propagate_errors());
|
||||
dbgln("FIXME: CSS display '{}' not implemented yet.", display.to_string());
|
||||
return document.heap().allocate_without_realm<Layout::InlineNode>(document, element, move(style));
|
||||
}
|
||||
|
||||
|
|
|
@ -661,7 +661,7 @@ void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rul
|
|||
builder.append("unicode-ranges:\n"sv);
|
||||
for (auto const& unicode_range : font_face.unicode_ranges()) {
|
||||
indent(builder, indent_levels + 2);
|
||||
builder.appendff("{}\n", unicode_range.to_string().release_value_but_fixme_should_propagate_errors());
|
||||
builder.appendff("{}\n", unicode_range.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue