/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.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 | | #include <LibWeb/CSS/Time.h> |
14 | | |
15 | | namespace Web::CSS { |
16 | | |
17 | | class TimeStyleValue : public CSSUnitValue { |
18 | | public: |
19 | | static ValueComparingNonnullRefPtr<TimeStyleValue> create(Time time) |
20 | 0 | { |
21 | 0 | return adopt_ref(*new (nothrow) TimeStyleValue(move(time))); |
22 | 0 | } |
23 | | virtual ~TimeStyleValue() override = default; |
24 | | |
25 | 0 | Time const& time() const { return m_time; } |
26 | 0 | virtual double value() const override { return m_time.raw_value(); } |
27 | 0 | virtual StringView unit() const override { return m_time.unit_name(); } |
28 | | |
29 | 0 | virtual String to_string() const override { return m_time.to_string(); } |
30 | | |
31 | | bool equals(CSSStyleValue const& other) const override |
32 | 0 | { |
33 | 0 | if (type() != other.type()) |
34 | 0 | return false; |
35 | 0 | auto const& other_time = other.as_time(); |
36 | 0 | return m_time == other_time.m_time; |
37 | 0 | } |
38 | | |
39 | | private: |
40 | | explicit TimeStyleValue(Time time) |
41 | 0 | : CSSUnitValue(Type::Time) |
42 | 0 | , m_time(move(time)) |
43 | 0 | { |
44 | 0 | } |
45 | | |
46 | | Time m_time; |
47 | | }; |
48 | | |
49 | | } |