2023-03-24 17:16:07 +00:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-24 17:16:07 +00:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
2025-07-10 12:17:27 +01:00
|
|
|
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
2023-03-24 17:16:07 +00:00
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-08-08 10:55:30 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
2023-03-24 17:16:07 +00:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2025-08-08 10:55:30 +01:00
|
|
|
class NumberStyleValue final : public StyleValue {
|
2023-03-24 17:16:07 +00:00
|
|
|
public:
|
2025-04-15 15:18:27 -06:00
|
|
|
static ValueComparingNonnullRefPtr<NumberStyleValue const> create(double value)
|
2023-03-24 17:16:07 +00:00
|
|
|
{
|
2023-08-19 14:00:10 +01:00
|
|
|
return adopt_ref(*new (nothrow) NumberStyleValue(value));
|
2023-03-24 17:16:07 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 17:27:18 +01:00
|
|
|
double number() const { return m_value; }
|
2023-03-24 17:16:07 +00:00
|
|
|
|
2024-12-07 00:59:49 +01:00
|
|
|
virtual String to_string(SerializationMode) const override;
|
2025-07-10 12:17:27 +01:00
|
|
|
virtual Vector<Parser::ComponentValue> tokenize() const override;
|
2025-09-25 13:00:43 +01:00
|
|
|
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
|
2023-03-24 17:16:07 +00:00
|
|
|
|
2025-08-08 10:11:51 +01:00
|
|
|
bool equals(StyleValue const& other) const override
|
2024-08-14 16:25:48 +01:00
|
|
|
{
|
|
|
|
if (type() != other.type())
|
|
|
|
return false;
|
|
|
|
auto const& other_number = other.as_number();
|
|
|
|
return m_value == other_number.m_value;
|
|
|
|
}
|
2023-03-24 17:16:07 +00:00
|
|
|
|
|
|
|
private:
|
2023-06-01 17:27:18 +01:00
|
|
|
explicit NumberStyleValue(double value)
|
2025-08-08 10:55:30 +01:00
|
|
|
: StyleValue(Type::Number)
|
2023-06-01 17:10:28 +01:00
|
|
|
, m_value(value)
|
2023-03-24 17:16:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-06-01 17:27:18 +01:00
|
|
|
double m_value { 0 };
|
2023-03-24 17:16:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|