diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-05-26 17:27:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-27 16:12:25 +0200 |
commit | 4ecf0b7768a7f00b2e93058d1d551ba45187c6b9 (patch) | |
tree | 872d95e4df33847e6a0eb2134c4a645429bee21d | |
parent | 5f755d721e7151dcb7ba458452e5fec0893f36e4 (diff) | |
download | serenity-4ecf0b7768a7f00b2e93058d1d551ba45187c6b9.zip |
LibWeb: Remove StyleValue::has/to_number()
Only NumericStyleValue holds numbers.
Renamed `to_number()` to `number()` because it's just a getter now.
4 files changed, 14 insertions, 15 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 9da166f638..b888b44af0 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -15,6 +15,7 @@ #include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h> #include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h> #include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h> +#include <LibWeb/CSS/StyleValues/NumericStyleValue.h> #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h> #include <LibWeb/CSS/StyleValues/RectStyleValue.h> #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> @@ -170,7 +171,7 @@ CSSPixels StyleProperties::line_height(CSSPixelRect const& viewport_rect, Length } if (line_height->is_numeric()) - return Length(line_height->to_number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics); + return Length(line_height->as_numeric().number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics); if (line_height->is_percentage()) { // Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage @@ -200,7 +201,7 @@ CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const } if (line_height->is_numeric()) - return Length(line_height->to_number(), Length::Type::Em).to_px(layout_node); + return Length(line_height->as_numeric().number(), Length::Type::Em).to_px(layout_node); if (line_height->is_percentage()) { // Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage @@ -242,8 +243,8 @@ static float resolve_opacity_value(CSS::StyleValue const& value) { float unclamped_opacity = 1.0f; - if (value.has_number()) { - unclamped_opacity = value.to_number(); + if (value.is_numeric()) { + unclamped_opacity = value.as_numeric().number(); } else if (value.is_calculated()) { auto& calculated = value.as_calculated(); if (calculated.resolved_type() == CalculatedStyleValue::ResolvedType::Percentage) { @@ -327,17 +328,17 @@ Optional<CSS::FlexBasisData> StyleProperties::flex_basis() const float StyleProperties::flex_grow() const { auto value = property(CSS::PropertyID::FlexGrow); - if (!value->has_number()) + if (!value->is_numeric()) return 0; - return value->to_number(); + return value->as_numeric().number(); } float StyleProperties::flex_shrink() const { auto value = property(CSS::PropertyID::FlexShrink); - if (!value->has_number()) + if (!value->is_numeric()) return 1; - return value->to_number(); + return value->as_numeric().number(); } int StyleProperties::order() const @@ -395,7 +396,7 @@ Vector<CSS::Transformation> StyleProperties::transformations() const } else if (transformation_value->is_percentage()) { values.append({ transformation_value->as_percentage().percentage() }); } else if (transformation_value->is_numeric()) { - values.append({ transformation_value->to_number() }); + values.append({ transformation_value->as_numeric().number() }); } else if (transformation_value->is_angle()) { values.append({ transformation_value->as_angle().angle() }); } else { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index c9cf4ca8dd..16297dfb32 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -294,7 +294,6 @@ public: bool has_auto() const; virtual bool has_color() const { return false; } virtual bool has_length() const { return false; } - virtual bool has_number() const { return false; } virtual bool has_integer() const { return false; } virtual ErrorOr<ValueComparingNonnullRefPtr<StyleValue const>> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const; @@ -302,7 +301,6 @@ public: virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; } ValueID to_identifier() const; virtual Length to_length() const { VERIFY_NOT_REACHED(); } - virtual float to_number() const { return 0; } virtual float to_integer() const { return 0; } virtual ErrorOr<String> to_string() const = 0; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.h index 59e6b86063..c435454f80 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/NumericStyleValue.h @@ -25,11 +25,10 @@ public: return adopt_nonnull_ref_or_enomem(new (nothrow) NumericStyleValue(value)); } - virtual bool has_length() const override { return to_number() == 0; } + virtual bool has_length() const override { return number() == 0; } virtual Length to_length() const override { return Length::make_px(0); } - virtual bool has_number() const override { return true; } - virtual float to_number() const override + float number() const { return m_value.visit( [](float value) { return value; }, diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 956e56120f..a0a7922494 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -10,6 +10,7 @@ #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> #include <LibWeb/CSS/StyleValues/EdgeStyleValue.h> +#include <LibWeb/CSS/StyleValues/NumericStyleValue.h> #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h> #include <LibWeb/CSS/StyleValues/StyleValueList.h> #include <LibWeb/CSS/StyleValues/URLStyleValue.h> @@ -676,7 +677,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) // FIXME: Converting to pixels isn't really correct - values should be in "user units" // https://svgwg.org/svg2-draft/coords.html#TermUserUnits if (stroke_width->is_numeric()) - computed_values.set_stroke_width(CSS::Length::make_px(stroke_width->to_number())); + computed_values.set_stroke_width(CSS::Length::make_px(stroke_width->as_numeric().number())); else if (stroke_width->is_length()) computed_values.set_stroke_width(stroke_width->to_length()); else if (stroke_width->is_percentage()) |