1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

LibWeb: Remove StyleValue::has/to_integer()

Only NumericStyleValue holds integers.

I'm not sure our current distinction between NumericStyleValue holding
an integer or non-integer is useful given it always returns a float.
:thonk:
This commit is contained in:
Sam Atkins 2023-05-26 17:43:20 +01:00 committed by Andreas Kling
parent 4ecf0b7768
commit 5cbf6eb930
5 changed files with 9 additions and 11 deletions

View file

@ -226,10 +226,10 @@ Optional<int> StyleProperties::z_index() const
auto value = property(CSS::PropertyID::ZIndex); auto value = property(CSS::PropertyID::ZIndex);
if (value->has_auto()) if (value->has_auto())
return {}; return {};
if (value->has_integer()) { if (value->is_numeric() && value->as_numeric().has_integer()) {
// Clamp z-index to the range of a signed 32-bit integer for consistency with other engines. // Clamp z-index to the range of a signed 32-bit integer for consistency with other engines.
// NOTE: Casting between 32-bit float and 32-bit integer is finicky here, since INT32_MAX is not representable as a 32-bit float! // NOTE: Casting between 32-bit float and 32-bit integer is finicky here, since INT32_MAX is not representable as a 32-bit float!
auto integer = value->to_integer(); auto integer = value->as_numeric().integer();
if (integer >= static_cast<float>(NumericLimits<int>::max())) if (integer >= static_cast<float>(NumericLimits<int>::max()))
return NumericLimits<int>::max(); return NumericLimits<int>::max();
if (integer <= static_cast<float>(NumericLimits<int>::min())) if (integer <= static_cast<float>(NumericLimits<int>::min()))
@ -344,9 +344,9 @@ float StyleProperties::flex_shrink() const
int StyleProperties::order() const int StyleProperties::order() const
{ {
auto value = property(CSS::PropertyID::Order); auto value = property(CSS::PropertyID::Order);
if (!value->has_integer()) if (!value->is_numeric() || !value->as_numeric().has_integer())
return 0; return 0;
return value->to_integer(); return value->as_numeric().integer();
} }
Optional<CSS::ImageRendering> StyleProperties::image_rendering() const Optional<CSS::ImageRendering> StyleProperties::image_rendering() const

View file

@ -395,8 +395,8 @@ int StyleValue::to_font_weight() const
return Gfx::FontWeight::Regular; return Gfx::FontWeight::Regular;
} }
} }
if (has_integer()) { if (is_numeric() && as_numeric().has_integer()) {
return to_integer(); return as_numeric().integer();
} }
if (is_calculated()) { if (is_calculated()) {
auto maybe_weight = const_cast<CalculatedStyleValue&>(as_calculated()).resolve_integer(); auto maybe_weight = const_cast<CalculatedStyleValue&>(as_calculated()).resolve_integer();

View file

@ -294,14 +294,12 @@ public:
bool has_auto() const; bool has_auto() const;
virtual bool has_color() const { return false; } virtual bool has_color() const { return false; }
virtual bool has_length() const { return false; } virtual bool has_length() 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; virtual ErrorOr<ValueComparingNonnullRefPtr<StyleValue const>> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const;
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; } virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
ValueID to_identifier() const; ValueID to_identifier() const;
virtual Length to_length() const { VERIFY_NOT_REACHED(); } virtual Length to_length() const { VERIFY_NOT_REACHED(); }
virtual float to_integer() const { return 0; }
virtual ErrorOr<String> to_string() const = 0; virtual ErrorOr<String> to_string() const = 0;
[[nodiscard]] int to_font_weight() const; [[nodiscard]] int to_font_weight() const;

View file

@ -35,8 +35,8 @@ public:
[](i64 value) { return (float)value; }); [](i64 value) { return (float)value; });
} }
virtual bool has_integer() const override { return m_value.has<i64>(); } bool has_integer() const { return m_value.has<i64>(); }
virtual float to_integer() const override { return m_value.get<i64>(); } float integer() const { return m_value.get<i64>(); }
virtual ErrorOr<String> to_string() const override; virtual ErrorOr<String> to_string() const override;

View file

@ -295,7 +295,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
// That's why it has to be set before everything else. // That's why it has to be set before everything else.
m_font = computed_style.computed_font(); m_font = computed_style.computed_font();
computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->to_length().to_px(*this).value()); computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->to_length().to_px(*this).value());
computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight)->to_integer()); computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight)->as_numeric().integer());
m_line_height = computed_style.line_height(*this); m_line_height = computed_style.line_height(*this);
computed_values.set_vertical_align(computed_style.vertical_align()); computed_values.set_vertical_align(computed_style.vertical_align());