diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 123f3d98b1..8a07fea503 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1393,7 +1393,7 @@ CSSPixels StyleComputer::parent_or_root_element_line_height(DOM::Element const* return computed_values->line_height(viewport_rect(), parent_font_metrics, root_font_metrics); } -void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const* element, Optional pseudo_element) const +ErrorOr StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const* element, Optional pseudo_element) const { auto parent_or_root_line_height = parent_or_root_element_line_height(element, pseudo_element); @@ -1411,9 +1411,8 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const // because most percentages are relative to containing block metrics. auto& line_height_value_slot = style.m_property_values[to_underlying(CSS::PropertyID::LineHeight)]; if (line_height_value_slot && line_height_value_slot->is_percentage()) { - line_height_value_slot = LengthStyleValue::create( - Length::make_px(font_size * line_height_value_slot->as_percentage().percentage().as_fraction())) - .release_value_but_fixme_should_propagate_errors(); + line_height_value_slot = TRY(LengthStyleValue::create( + Length::make_px(font_size * line_height_value_slot->as_percentage().percentage().as_fraction()))); } auto line_height = style.line_height(viewport_rect(), font_metrics, root_font_metrics); @@ -1421,14 +1420,15 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const // NOTE: line-height might be using lh which should be resolved against the parent line height (like we did here already) if (line_height_value_slot && line_height_value_slot->is_length()) - line_height_value_slot = LengthStyleValue::create(Length::make_px(line_height)).release_value_but_fixme_should_propagate_errors(); + line_height_value_slot = TRY(LengthStyleValue::create(Length::make_px(line_height))); for (size_t i = 0; i < style.m_property_values.size(); ++i) { auto& value_slot = style.m_property_values[i]; if (!value_slot) continue; - value_slot = value_slot->absolutized(viewport_rect(), font_metrics, root_font_metrics); + value_slot = TRY(value_slot->absolutized(viewport_rect(), font_metrics, root_font_metrics)); } + return {}; } enum class BoxTypeTransformation { @@ -1528,7 +1528,7 @@ NonnullRefPtr StyleComputer::create_document_style() const auto style = StyleProperties::create(); compute_font(style, nullptr, {}); compute_defaulted_values(style, nullptr, {}); - absolutize_values(style, nullptr, {}); + absolutize_values(style, nullptr, {}).release_value_but_fixme_should_propagate_errors(); style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().width())).release_value_but_fixme_should_propagate_errors()); style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().height())).release_value_but_fixme_should_propagate_errors()); style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::Block)).release_value_but_fixme_should_propagate_errors()); @@ -1562,7 +1562,7 @@ ErrorOr> StyleComputer::compute_style_impl(DOM::Element& compute_font(style, &element, pseudo_element); // 3. Absolutize values, turning font/viewport relative lengths into absolute lengths - absolutize_values(style, &element, pseudo_element); + TRY(absolutize_values(style, &element, pseudo_element)); // 4. Default the values, applying inheritance and 'initial' as needed compute_defaulted_values(style, &element, pseudo_element); diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h index 8625af30a5..64e97ce00f 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h @@ -89,7 +89,7 @@ private: ErrorOr compute_cascaded_values(StyleProperties&, DOM::Element&, Optional, bool& did_match_any_pseudo_element_rules, ComputeStyleMode) const; void compute_font(StyleProperties&, DOM::Element const*, Optional) const; void compute_defaulted_values(StyleProperties&, DOM::Element const*, Optional) const; - void absolutize_values(StyleProperties&, DOM::Element const*, Optional) const; + ErrorOr absolutize_values(StyleProperties&, DOM::Element const*, Optional) const; void transform_box_type_if_needed(StyleProperties&, DOM::Element const&, Optional) const; void compute_defaulted_property_value(StyleProperties&, DOM::Element const*, CSS::PropertyID, Optional) const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 095071e4c7..9a2aaca5bf 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -352,7 +352,7 @@ StyleValueList const& StyleValue::as_value_list() const return static_cast(*this); } -ValueComparingNonnullRefPtr StyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const +ErrorOr> StyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const { return *this; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index ebce86421f..00074060c4 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -295,7 +295,7 @@ public: virtual bool has_number() const { return false; } virtual bool has_integer() const { return false; } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const; + virtual ErrorOr> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const; virtual Color to_color(Optional) const { return {}; } ValueID to_identifier() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.cpp index 1a06acc9de..030849788b 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.cpp @@ -18,7 +18,7 @@ ErrorOr BorderRadiusStyleValue::to_string() const return String::formatted("{} / {}", TRY(m_properties.horizontal_radius.to_string()), TRY(m_properties.vertical_radius.to_string())); } -ValueComparingNonnullRefPtr BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const +ErrorOr> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const { if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage()) return *this; @@ -28,7 +28,7 @@ ValueComparingNonnullRefPtr BorderRadiusStyleValue::absolutize absolutized_horizontal_radius = m_properties.horizontal_radius.length().absolutized(viewport_rect, font_metrics, root_font_metrics); if (!m_properties.vertical_radius.is_percentage()) absolutized_vertical_radius = m_properties.vertical_radius.length().absolutized(viewport_rect, font_metrics, root_font_metrics); - return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius).release_value_but_fixme_should_propagate_errors(); + return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius); } } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h index 2287390ed5..1d28b4002e 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h @@ -38,7 +38,7 @@ private: { } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override; + virtual ErrorOr> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override; struct Properties { bool is_elliptical; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp index 0442a4913f..e750edeba5 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.cpp @@ -27,10 +27,10 @@ ErrorOr> LengthStyleValue::create( return adopt_nonnull_ref_or_enomem(new (nothrow) LengthStyleValue(length)); } -ValueComparingNonnullRefPtr LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const +ErrorOr> LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const { if (auto length = m_length.absolutize(viewport_rect, font_metrics, root_font_metrics); length.has_value()) - return LengthStyleValue::create(length.release_value()).release_value_but_fixme_should_propagate_errors(); + return LengthStyleValue::create(length.release_value()); return *this; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h index 8fa8e3d54f..e305af7c12 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/LengthStyleValue.h @@ -23,7 +23,7 @@ public: virtual bool has_length() const override { return true; } virtual ErrorOr to_string() const override { return m_length.to_string(); } virtual Length to_length() const override { return m_length; } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override; + virtual ErrorOr> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override; bool properties_equal(LengthStyleValue const& other) const { return m_length == other.m_length; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.cpp index a6ccadf9eb..a94669dd46 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.cpp @@ -20,13 +20,13 @@ ErrorOr ShadowStyleValue::to_string() const return builder.to_string(); } -ValueComparingNonnullRefPtr ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const +ErrorOr> ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const { auto absolutized_offset_x = m_properties.offset_x.absolutized(viewport_rect, font_metrics, root_font_metrics); auto absolutized_offset_y = m_properties.offset_y.absolutized(viewport_rect, font_metrics, root_font_metrics); auto absolutized_blur_radius = m_properties.blur_radius.absolutized(viewport_rect, font_metrics, root_font_metrics); auto absolutized_spread_distance = m_properties.spread_distance.absolutized(viewport_rect, font_metrics, root_font_metrics); - return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement).release_value_but_fixme_should_propagate_errors(); + return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement); } } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h index e934e82490..4932e6951b 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h @@ -46,7 +46,7 @@ private: { } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override; + virtual ErrorOr> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override; struct Properties { Color color;