Time.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefPtr.h>
  8. #include <LibWeb/Forward.h>
  9. namespace Web::CSS {
  10. class Time {
  11. public:
  12. enum class Type {
  13. Calculated,
  14. S,
  15. Ms,
  16. };
  17. static Optional<Type> unit_from_name(StringView);
  18. Time(int value, Type type);
  19. Time(float value, Type type);
  20. static Time make_calculated(NonnullRefPtr<CalculatedStyleValue>);
  21. static Time make_seconds(float);
  22. Time percentage_of(Percentage const&) const;
  23. bool is_calculated() const { return m_type == Type::Calculated; }
  24. String to_string() const;
  25. float to_seconds() const;
  26. bool operator==(Time const& other) const
  27. {
  28. if (is_calculated())
  29. return m_calculated_style == other.m_calculated_style;
  30. return m_type == other.m_type && m_value == other.m_value;
  31. }
  32. bool operator!=(Time const& other) const
  33. {
  34. return !(*this == other);
  35. }
  36. private:
  37. StringView unit_name() const;
  38. Type m_type;
  39. float m_value { 0 };
  40. RefPtr<CalculatedStyleValue> m_calculated_style;
  41. };
  42. }