StyleValueList.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.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/StyleValue.h>
  11. namespace Web::CSS {
  12. class StyleValueList final : public StyleValueWithDefaultOperators<StyleValueList> {
  13. public:
  14. enum class Separator {
  15. Space,
  16. Comma,
  17. };
  18. static ValueComparingNonnullRefPtr<StyleValueList> create(StyleValueVector&& values, Separator separator) { return adopt_ref(*new StyleValueList(move(values), separator)); }
  19. size_t size() const { return m_properties.values.size(); }
  20. StyleValueVector const& values() const { return m_properties.values; }
  21. ValueComparingNonnullRefPtr<StyleValue const> value_at(size_t i, bool allow_loop) const
  22. {
  23. if (allow_loop)
  24. return m_properties.values[i % size()];
  25. return m_properties.values[i];
  26. }
  27. virtual ErrorOr<String> to_string() const override;
  28. bool properties_equal(StyleValueList const& other) const { return m_properties == other.m_properties; }
  29. private:
  30. StyleValueList(StyleValueVector&& values, Separator separator)
  31. : StyleValueWithDefaultOperators(Type::ValueList)
  32. , m_properties { .separator = separator, .values = move(values) }
  33. {
  34. }
  35. struct Properties {
  36. Separator separator;
  37. StyleValueVector values;
  38. bool operator==(Properties const&) const;
  39. } m_properties;
  40. };
  41. }