1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:25:07 +00:00
serenity/Libraries/LibHTML/CSS/StyleProperties.h
Andreas Kling 92b6a7a18f LibHTML: Add StyleProperties::line_height()
We currently hard-code the line height to 140% of the font glyph height
and this patch doesn't fix the hard-coding, but at least moves it out
of LayoutText and into StyleProperties where it can be re-used until
the day we go and do a proper implementation of CSS line-height. :^)
2019-10-12 13:42:58 +02:00

43 lines
1.2 KiB
C++

#pragma once
#include <AK/HashMap.h>
#include <AK/NonnullRefPtr.h>
#include <LibDraw/Font.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((CSS::PropertyID)it.key, *it.value);
}
void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value);
Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const;
Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
const Font& font() const
{
if (!m_font)
load_font();
return *m_font;
}
int line_height() const;
private:
HashMap<unsigned, NonnullRefPtr<StyleValue>> m_property_values;
void load_font() const;
mutable RefPtr<Font> m_font;
};