/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> |
4 | | * Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org> |
5 | | * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> |
6 | | * |
7 | | * SPDX-License-Identifier: BSD-2-Clause |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <LibWeb/CSS/StyleValues/CSSUnitValue.h> |
13 | | |
14 | | namespace Web::CSS { |
15 | | |
16 | | class NumberStyleValue final : public CSSUnitValue { |
17 | | public: |
18 | | static ValueComparingNonnullRefPtr<NumberStyleValue> create(double value) |
19 | 0 | { |
20 | 0 | return adopt_ref(*new (nothrow) NumberStyleValue(value)); |
21 | 0 | } |
22 | | |
23 | 0 | double number() const { return m_value; } |
24 | 0 | virtual double value() const override { return m_value; } |
25 | 0 | virtual StringView unit() const override { return "number"sv; } |
26 | | |
27 | | virtual String to_string() const override; |
28 | | |
29 | | bool equals(CSSStyleValue const& other) const override |
30 | 0 | { |
31 | 0 | if (type() != other.type()) |
32 | 0 | return false; |
33 | 0 | auto const& other_number = other.as_number(); |
34 | 0 | return m_value == other_number.m_value; |
35 | 0 | } |
36 | | |
37 | | private: |
38 | | explicit NumberStyleValue(double value) |
39 | 0 | : CSSUnitValue(Type::Number) |
40 | 0 | , m_value(value) |
41 | 0 | { |
42 | 0 | } |
43 | | |
44 | | double m_value { 0 }; |
45 | | }; |
46 | | |
47 | | } |