StyleValueList.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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)
  19. {
  20. return adopt_ref(*new (nothrow) StyleValueList(move(values), separator));
  21. }
  22. size_t size() const { return m_properties.values.size(); }
  23. StyleValueVector const& values() const { return m_properties.values; }
  24. ValueComparingNonnullRefPtr<StyleValue const> value_at(size_t i, bool allow_loop) const
  25. {
  26. if (allow_loop)
  27. return m_properties.values[i % size()];
  28. return m_properties.values[i];
  29. }
  30. virtual String to_string() const override;
  31. bool properties_equal(StyleValueList const& other) const { return m_properties == other.m_properties; }
  32. Separator separator() const { return m_properties.separator; }
  33. private:
  34. StyleValueList(StyleValueVector&& values, Separator separator)
  35. : StyleValueWithDefaultOperators(Type::ValueList)
  36. , m_properties { .separator = separator, .values = move(values) }
  37. {
  38. }
  39. struct Properties {
  40. Separator separator;
  41. StyleValueVector values;
  42. bool operator==(Properties const&) const;
  43. } m_properties;
  44. };
  45. }