StyleProperties.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <AK/HashMap.h>
  3. #include <AK/NonnullRefPtr.h>
  4. #include <LibDraw/Font.h>
  5. #include <LibHTML/CSS/StyleValue.h>
  6. class Color;
  7. class StyleProperties : public RefCounted<StyleProperties> {
  8. public:
  9. static NonnullRefPtr<StyleProperties> create() { return adopt(*new StyleProperties); }
  10. template<typename Callback>
  11. inline void for_each_property(Callback callback) const
  12. {
  13. for (auto& it : m_property_values)
  14. callback(it.key, *it.value);
  15. }
  16. void set_property(const String& name, NonnullRefPtr<StyleValue> value);
  17. Optional<NonnullRefPtr<StyleValue>> property(const String& name) const;
  18. Length length_or_fallback(const StringView& property_name, const Length& fallback) const;
  19. String string_or_fallback(const StringView& property_name, const StringView& fallback) const;
  20. Color color_or_fallback(const StringView& property_name, const Document&, Color fallback) const;
  21. const Font& font() const
  22. {
  23. if (!m_font)
  24. load_font();
  25. return *m_font;
  26. }
  27. private:
  28. HashMap<String, NonnullRefPtr<StyleValue>> m_property_values;
  29. void load_font() const;
  30. mutable RefPtr<Font> m_font;
  31. };