Angle.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 Angle {
  11. public:
  12. enum class Type {
  13. Calculated,
  14. Deg,
  15. Grad,
  16. Rad,
  17. Turn,
  18. };
  19. static Optional<Type> unit_from_name(StringView);
  20. Angle(int value, Type type);
  21. Angle(float value, Type type);
  22. static Angle make_calculated(NonnullRefPtr<CalculatedStyleValue>);
  23. static Angle make_degrees(float);
  24. Angle percentage_of(Percentage const&) const;
  25. bool is_calculated() const { return m_type == Type::Calculated; }
  26. String to_string() const;
  27. float to_degrees() const;
  28. bool operator==(Angle const& other) const
  29. {
  30. if (is_calculated())
  31. return m_calculated_style == other.m_calculated_style;
  32. return m_type == other.m_type && m_value == other.m_value;
  33. }
  34. bool operator!=(Angle const& other) const
  35. {
  36. return !(*this == other);
  37. }
  38. private:
  39. StringView unit_name() const;
  40. Type m_type;
  41. float m_value { 0 };
  42. RefPtr<CalculatedStyleValue> m_calculated_style;
  43. };
  44. }