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

LibWeb: Remove int usage of NumberStyleValues

Use IntegerStyleValue where we should; remove the ability of
NumberStyleValue to hold integers, and add integer interpolation for
animations.
This commit is contained in:
Sam Atkins 2023-06-01 17:10:28 +01:00 committed by Andreas Kling
parent 1160d8186b
commit 8889635ba7
5 changed files with 28 additions and 40 deletions

View file

@ -15,38 +15,25 @@ namespace Web::CSS {
class NumberStyleValue : public StyleValueWithDefaultOperators<NumberStyleValue> {
public:
static ErrorOr<ValueComparingNonnullRefPtr<NumberStyleValue>> create_float(float value)
static ErrorOr<ValueComparingNonnullRefPtr<NumberStyleValue>> create(float value)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) NumberStyleValue(value));
}
static ErrorOr<ValueComparingNonnullRefPtr<NumberStyleValue>> create_integer(i64 value)
{
return adopt_nonnull_ref_or_enomem(new (nothrow) NumberStyleValue(value));
}
float number() const
{
return m_value.visit(
[](float value) { return value; },
[](i64 value) { return (float)value; });
}
bool has_integer() const { return m_value.has<i64>(); }
float integer() const { return m_value.get<i64>(); }
float number() const { return m_value; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(NumberStyleValue const& other) const { return m_value == other.m_value; }
private:
explicit NumberStyleValue(Variant<float, i64> value)
explicit NumberStyleValue(float value)
: StyleValueWithDefaultOperators(Type::Number)
, m_value(move(value))
, m_value(value)
{
}
Variant<float, i64> m_value { (i64)0 };
float m_value { 0 };
};
}