StyleProperties.h 976 B

1234567891011121314151617181920212223242526272829
  1. #pragma once
  2. #include <AK/HashMap.h>
  3. #include <AK/NonnullRefPtr.h>
  4. #include <LibHTML/CSS/StyleValue.h>
  5. class Color;
  6. class StyleProperties : public RefCounted<StyleProperties> {
  7. public:
  8. static NonnullRefPtr<StyleProperties> create() { return adopt(*new StyleProperties); }
  9. template<typename Callback>
  10. inline void for_each_property(Callback callback) const
  11. {
  12. for (auto& it : m_property_values)
  13. callback(it.key, *it.value);
  14. }
  15. void set_property(const String& name, NonnullRefPtr<StyleValue> value);
  16. Optional<NonnullRefPtr<StyleValue>> property(const String& name) const;
  17. Length length_or_fallback(const StringView& property_name, const Length& fallback) const;
  18. String string_or_fallback(const StringView& property_name, const StringView& fallback) const;
  19. Color color_or_fallback(const StringView& property_name, Color fallback) const;
  20. private:
  21. HashMap<String, NonnullRefPtr<StyleValue>> m_property_values;
  22. };