TimeStyleValue.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.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. #pragma once
  10. #include <LibWeb/CSS/StyleValues/CSSUnitValue.h>
  11. #include <LibWeb/CSS/Time.h>
  12. namespace Web::CSS {
  13. class TimeStyleValue : public CSSUnitValue {
  14. public:
  15. static ValueComparingNonnullRefPtr<TimeStyleValue> create(Time time)
  16. {
  17. return adopt_ref(*new (nothrow) TimeStyleValue(move(time)));
  18. }
  19. virtual ~TimeStyleValue() override = default;
  20. Time const& time() const { return m_time; }
  21. virtual double value() const override { return m_time.raw_value(); }
  22. virtual StringView unit() const override { return m_time.unit_name(); }
  23. virtual String to_string() const override { return m_time.to_string(); }
  24. bool equals(CSSStyleValue const& other) const override
  25. {
  26. if (type() != other.type())
  27. return false;
  28. auto const& other_time = other.as_time();
  29. return m_time == other_time.m_time;
  30. }
  31. private:
  32. explicit TimeStyleValue(Time time)
  33. : CSSUnitValue(Type::Time)
  34. , m_time(move(time))
  35. {
  36. }
  37. Time m_time;
  38. };
  39. }