MathDepthStyleValue.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "MathDepthStyleValue.h"
  7. namespace Web::CSS {
  8. ValueComparingNonnullRefPtr<MathDepthStyleValue> MathDepthStyleValue::create_auto_add()
  9. {
  10. return adopt_ref(*new (nothrow) MathDepthStyleValue(MathDepthType::AutoAdd));
  11. }
  12. ValueComparingNonnullRefPtr<MathDepthStyleValue> MathDepthStyleValue::create_add(ValueComparingNonnullRefPtr<StyleValue const> integer_value)
  13. {
  14. return adopt_ref(*new (nothrow) MathDepthStyleValue(MathDepthType::Add, move(integer_value)));
  15. }
  16. ValueComparingNonnullRefPtr<MathDepthStyleValue> MathDepthStyleValue::create_integer(ValueComparingNonnullRefPtr<StyleValue const> integer_value)
  17. {
  18. return adopt_ref(*new (nothrow) MathDepthStyleValue(MathDepthType::Integer, move(integer_value)));
  19. }
  20. MathDepthStyleValue::MathDepthStyleValue(MathDepthType type, ValueComparingRefPtr<StyleValue const> integer_value)
  21. : StyleValueWithDefaultOperators(Type::MathDepth)
  22. , m_type(type)
  23. , m_integer_value(move(integer_value))
  24. {
  25. }
  26. bool MathDepthStyleValue::properties_equal(MathDepthStyleValue const& other) const
  27. {
  28. return m_type == other.m_type
  29. && m_integer_value == other.m_integer_value;
  30. }
  31. String MathDepthStyleValue::to_string() const
  32. {
  33. switch (m_type) {
  34. case MathDepthType::AutoAdd:
  35. return "auto-add"_string;
  36. case MathDepthType::Add:
  37. return MUST(String::formatted("add({})", m_integer_value->to_string()));
  38. case MathDepthType::Integer:
  39. return m_integer_value->to_string();
  40. }
  41. VERIFY_NOT_REACHED();
  42. }
  43. }