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