
This patch makes StyleProperties heap-allocated and ref-counted so that a LayoutNode can be without one. The ref-counting also allows anonymous blocks to share style with their parent block. LayoutText never needs a StyleProperties, since text always inherits style from its parent element. This is handled by style_properties().
29 lines
976 B
C++
29 lines
976 B
C++
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <LibHTML/CSS/StyleValue.h>
|
|
|
|
class Color;
|
|
|
|
class StyleProperties : public RefCounted<StyleProperties> {
|
|
public:
|
|
static NonnullRefPtr<StyleProperties> create() { return adopt(*new StyleProperties); }
|
|
|
|
template<typename Callback>
|
|
inline void for_each_property(Callback callback) const
|
|
{
|
|
for (auto& it : m_property_values)
|
|
callback(it.key, *it.value);
|
|
}
|
|
|
|
void set_property(const String& name, NonnullRefPtr<StyleValue> value);
|
|
Optional<NonnullRefPtr<StyleValue>> property(const String& name) const;
|
|
|
|
Length length_or_fallback(const StringView& property_name, const Length& fallback) const;
|
|
String string_or_fallback(const StringView& property_name, const StringView& fallback) const;
|
|
Color color_or_fallback(const StringView& property_name, Color fallback) const;
|
|
|
|
private:
|
|
HashMap<String, NonnullRefPtr<StyleValue>> m_property_values;
|
|
};
|