summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2023-01-13 23:44:44 +0000
committerAndreas Kling <kling@serenityos.org>2023-01-14 12:37:00 +0100
commit0c688fa1173e1ff4a2a92068bdbfdfe559a7ac67 (patch)
tree6f7cda36303e4f8192b297badeb9d19e83d0eab9 /Userland/Libraries/LibWeb
parent93c1fb0b76a9f8d99b1a8807e08442577cb62b64 (diff)
downloadserenity-0c688fa1173e1ff4a2a92068bdbfdfe559a7ac67.zip
LibWeb: Remove some unnecessary .release_value()s in StyleValue
And instead propagate these errors. Also while here add my copyright (I've touched these files a lot)
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp34
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h3
2 files changed, 22 insertions, 15 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index 2f8071cdfe..92f832eca2 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -2,6 +2,7 @@
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
+ * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -1934,14 +1935,14 @@ CSSPixelPoint PositionValue::resolved(Layout::Node const& node, CSSPixelRect con
return CSSPixelPoint { rect.x() + x, rect.y() + y };
}
-void PositionValue::serialize(StringBuilder& builder) const
+ErrorOr<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)
builder.append(x_relative_to == HorizontalEdge::Left ? "left "sv : "right "sv);
- horizontal_position.visit(
- [&](HorizontalPreset preset) {
+ TRY(horizontal_position.visit(
+ [&](HorizontalPreset preset) -> ErrorOr<void> {
builder.append([&] {
switch (preset) {
case HorizontalPreset::Left:
@@ -1954,15 +1955,17 @@ void PositionValue::serialize(StringBuilder& builder) const
VERIFY_NOT_REACHED();
}
}());
+ return {};
},
- [&](LengthPercentage length_percentage) {
- builder.append(length_percentage.to_string().release_value_but_fixme_should_propagate_errors());
- });
+ [&](LengthPercentage length_percentage) -> ErrorOr<void> {
+ builder.appendff(TRY(length_percentage.to_string()));
+ return {};
+ }));
builder.append(' ');
if (has_relative_edges)
builder.append(y_relative_to == VerticalEdge::Top ? "top "sv : "bottom "sv);
- vertical_position.visit(
- [&](VerticalPreset preset) {
+ TRY(vertical_position.visit(
+ [&](VerticalPreset preset) -> ErrorOr<void> {
builder.append([&] {
switch (preset) {
case VerticalPreset::Top:
@@ -1975,10 +1978,13 @@ void PositionValue::serialize(StringBuilder& builder) const
VERIFY_NOT_REACHED();
}
}());
+ return {};
},
- [&](LengthPercentage length_percentage) {
- builder.append(length_percentage.to_string().release_value_but_fixme_should_propagate_errors());
- });
+ [&](LengthPercentage length_percentage) -> ErrorOr<void> {
+ builder.append(TRY(length_percentage.to_string()));
+ return {};
+ }));
+ return {};
}
bool PositionValue::operator==(PositionValue const& other) const
@@ -2027,7 +2033,7 @@ ErrorOr<String> RadialGradientStyleValue::to_string() const
if (m_position != PositionValue::center()) {
builder.appendff(" at "sv);
- m_position.serialize(builder);
+ TRY(m_position.serialize(builder));
}
builder.append(", "sv);
@@ -2213,7 +2219,7 @@ ErrorOr<String> ConicGradientStyleValue::to_string() const
if (has_from_angle)
builder.append(' ');
builder.appendff("at "sv);
- m_position.serialize(builder);
+ TRY(m_position.serialize(builder));
}
if (has_from_angle || has_at_position)
builder.append(", "sv);
@@ -2464,7 +2470,7 @@ ErrorOr<String> UnresolvedStyleValue::to_string() const
{
StringBuilder builder;
for (auto& value : m_values)
- builder.append(String::from_deprecated_string(value.to_deprecated_string()).release_value());
+ builder.append(value.to_deprecated_string());
return builder.to_string();
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index b24b78c4dc..33d3502738 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -2,6 +2,7 @@
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -132,7 +133,7 @@ struct PositionValue {
VerticalEdge y_relative_to { VerticalEdge::Top };
CSSPixelPoint resolved(Layout::Node const& node, CSSPixelRect const& rect) const;
- void serialize(StringBuilder&) const;
+ ErrorOr<void> serialize(StringBuilder&) const;
bool operator==(PositionValue const&) const;
};