mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:27:45 +00:00
LibWeb: Implement and use FontStyleValue
After working with the code for a while, it makes more sense to put all the parsing in Parser, instead of some of it living in StyleResolver. That means our current ValueListStyleValue needs to be replaced with specific StyleValue types for the properties that are shorthands or otherwise combine several values together. Here we implement FontStyleProperty, which represents a `font` CSS property. Also adjusted the fonts.html test page so that font-weights are featured in test cases without things we do not yet support.
This commit is contained in:
parent
5e1fad2dff
commit
59501f1940
5 changed files with 247 additions and 164 deletions
|
@ -230,6 +230,7 @@ public:
|
|||
ComponentValueList,
|
||||
Calculated,
|
||||
BoxShadow,
|
||||
Font,
|
||||
};
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
@ -247,6 +248,7 @@ public:
|
|||
bool is_component_value_list() const { return type() == Type::ComponentValueList; }
|
||||
bool is_calculated() const { return type() == Type::Calculated; }
|
||||
bool is_box_shadow() const { return type() == Type::BoxShadow; }
|
||||
bool is_font() const { return type() == Type::Font; }
|
||||
|
||||
bool is_builtin() const { return is_inherit() || is_initial(); }
|
||||
|
||||
|
@ -623,6 +625,50 @@ private:
|
|||
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||
};
|
||||
|
||||
class FontStyleValue final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<FontStyleValue> create(NonnullRefPtr<StyleValue> font_style, NonnullRefPtr<StyleValue> font_weight, NonnullRefPtr<StyleValue> font_size, NonnullRefPtr<StyleValue> line_height, NonnullRefPtrVector<StyleValue>&& font_families) { return adopt_ref(*new FontStyleValue(font_style, font_weight, font_size, line_height, move(font_families))); }
|
||||
virtual ~FontStyleValue() override { }
|
||||
|
||||
NonnullRefPtr<StyleValue> font_style() const { return m_font_style; }
|
||||
NonnullRefPtr<StyleValue> font_weight() const { return m_font_weight; }
|
||||
NonnullRefPtr<StyleValue> font_size() const { return m_font_size; }
|
||||
NonnullRefPtr<StyleValue> line_height() const { return m_line_height; }
|
||||
NonnullRefPtrVector<StyleValue> const& font_families() const { return m_font_families; }
|
||||
|
||||
virtual String to_string() const override
|
||||
{
|
||||
StringBuilder string_builder;
|
||||
string_builder.appendff("Font style: {}, weight: {}, size: {}, line_height: {}, families: [",
|
||||
m_font_style->to_string(), m_font_weight->to_string(), m_font_size->to_string(), m_line_height->to_string());
|
||||
for (auto& family : m_font_families) {
|
||||
string_builder.append(family.to_string());
|
||||
string_builder.append(",");
|
||||
}
|
||||
string_builder.append("]");
|
||||
|
||||
return string_builder.to_string();
|
||||
}
|
||||
|
||||
private:
|
||||
FontStyleValue(NonnullRefPtr<StyleValue> font_style, NonnullRefPtr<StyleValue> font_weight, NonnullRefPtr<StyleValue> font_size, NonnullRefPtr<StyleValue> line_height, NonnullRefPtrVector<StyleValue>&& font_families)
|
||||
: StyleValue(Type::Font)
|
||||
, m_font_style(font_style)
|
||||
, m_font_weight(font_weight)
|
||||
, m_font_size(font_size)
|
||||
, m_line_height(line_height)
|
||||
, m_font_families(move(font_families))
|
||||
{
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue> m_font_style;
|
||||
NonnullRefPtr<StyleValue> m_font_weight;
|
||||
NonnullRefPtr<StyleValue> m_font_size;
|
||||
NonnullRefPtr<StyleValue> m_line_height;
|
||||
NonnullRefPtrVector<StyleValue> m_font_families;
|
||||
// FIXME: Implement font-stretch and font-variant.
|
||||
};
|
||||
|
||||
class StyleValueList final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<StyleValueList> create(NonnullRefPtrVector<StyleValue>&& values) { return adopt_ref(*new StyleValueList(move(values))); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue