StyleValueList.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. Separator separator() const { return m_properties.separator; }
  30. private:
  31. StyleValueList(StyleValueVector&& values, Separator separator)
  32. : StyleValueWithDefaultOperators(Type::ValueList)
  33. , m_properties { .separator = separator, .values = move(values) }
  34. {
  35. }
  36. struct Properties {
  37. Separator separator;
  38. StyleValueVector values;
  39. bool operator==(Properties const&) const;
  40. } m_properties;
  41. };
  42. }