CounterStyleValue.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <LibWeb/CSS/CSSStyleValue.h>
  9. namespace Web::CSS {
  10. // https://drafts.csswg.org/css-lists-3/#counter-functions
  11. class CounterStyleValue : public StyleValueWithDefaultOperators<CounterStyleValue> {
  12. public:
  13. enum class CounterFunction {
  14. Counter,
  15. Counters,
  16. };
  17. static ValueComparingNonnullRefPtr<CounterStyleValue> create_counter(FlyString counter_name, ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style)
  18. {
  19. return adopt_ref(*new (nothrow) CounterStyleValue(CounterFunction::Counter, move(counter_name), move(counter_style), {}));
  20. }
  21. static ValueComparingNonnullRefPtr<CounterStyleValue> create_counters(FlyString counter_name, FlyString join_string, ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style)
  22. {
  23. return adopt_ref(*new (nothrow) CounterStyleValue(CounterFunction::Counters, move(counter_name), move(counter_style), move(join_string)));
  24. }
  25. virtual ~CounterStyleValue() override;
  26. CounterFunction function_type() const { return m_properties.function; }
  27. auto counter_name() const { return m_properties.counter_name; }
  28. auto counter_style() const { return m_properties.counter_style; }
  29. auto join_string() const { return m_properties.join_string; }
  30. String resolve(DOM::Element&) const;
  31. virtual String to_string() const override;
  32. bool properties_equal(CounterStyleValue const& other) const;
  33. private:
  34. explicit CounterStyleValue(CounterFunction, FlyString counter_name, ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style, FlyString join_string);
  35. struct Properties {
  36. CounterFunction function;
  37. FlyString counter_name;
  38. ValueComparingNonnullRefPtr<CSSStyleValue const> counter_style;
  39. FlyString join_string;
  40. bool operator==(Properties const&) const = default;
  41. } m_properties;
  42. };
  43. }