diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 191e387f9a..324eba8c55 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -16,6 +16,7 @@ class InitialValues { public: static float font_size() { return 10; } static int font_weight() { return 400; } + static CSS::FontVariant font_variant() { return CSS::FontVariant::Normal; } static CSS::Float float_() { return CSS::Float::None; } static CSS::Clear clear() { return CSS::Clear::None; } static CSS::Cursor cursor() { return CSS::Cursor::Auto; } @@ -178,6 +179,7 @@ public: float font_size() const { return m_inherited.font_size; } int font_weight() const { return m_inherited.font_weight; } + CSS::FontVariant font_variant() const { return m_inherited.font_variant; } ComputedValues clone_inherited_values() const { @@ -190,6 +192,7 @@ protected: struct { float font_size { InitialValues::font_size() }; int font_weight { InitialValues::font_weight() }; + CSS::FontVariant font_variant { InitialValues::font_variant() }; Color color { InitialValues::color() }; CSS::Cursor cursor { InitialValues::cursor() }; CSS::ImageRendering image_rendering { InitialValues::image_rendering() }; @@ -261,6 +264,7 @@ class MutableComputedValues final : public ComputedValues { public: void set_font_size(float font_size) { m_inherited.font_size = font_size; } void set_font_weight(int font_weight) { m_inherited.font_weight = font_weight; } + void set_font_variant(CSS::FontVariant font_variant) { m_inherited.font_variant = font_variant; } void set_color(const Color& color) { m_inherited.color = color; } void set_content(ContentData const& content) { m_noninherited.content = content; } void set_cursor(CSS::Cursor cursor) { m_inherited.cursor = cursor; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 39d75c8473..89ac11ea7c 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -3590,7 +3590,8 @@ RefPtr Parser::parse_font_value(Vector cons RefPtr font_size; RefPtr line_height; RefPtr font_families; - // FIXME: Implement font-stretch and font-variant. + RefPtr font_variant; + // FIXME: Implement font-stretch. // FIXME: Handle system fonts. (caption, icon, menu, message-box, small-caption, status-bar) @@ -3620,6 +3621,12 @@ RefPtr Parser::parse_font_value(Vector cons font_weight = value.release_nonnull(); continue; } + if (property_accepts_value(PropertyID::FontVariant, *value)) { + if (font_variant) + return nullptr; + font_variant = value.release_nonnull(); + continue; + } if (property_accepts_value(PropertyID::FontSize, *value)) { if (font_size) return nullptr; diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 1e9d4e1f44..3e48827c31 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -999,4 +999,20 @@ Variant StyleProperties::vertical_ali VERIFY_NOT_REACHED(); } +Optional StyleProperties::font_variant() const +{ + auto value = property(CSS::PropertyID::FontVariant); + if (!value.has_value()) + return {}; + + switch (value.value()->to_identifier()) { + case CSS::ValueID::Normal: + return CSS::FontVariant::Normal; + case CSS::ValueID::SmallCaps: + return CSS::FontVariant::SmallCaps; + default: + return {}; + } +} + } diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 2e58608544..a1daa29b50 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -75,6 +75,7 @@ public: CSS::BoxSizing box_sizing() const; Optional pointer_events() const; Variant vertical_align() const; + Optional font_variant() const; Vector transformations() const; CSS::TransformOrigin transform_origin() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 46f649b078..623964614a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -146,6 +146,11 @@ enum class Float { Right, }; +enum class FontVariant { + Normal, + SmallCaps, +}; + enum class ImageRendering { Auto, CrispEdges, diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index efcba78b36..2dcb2db966 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -363,6 +363,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) computed_values.set_font_size(specified_style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(*this)); computed_values.set_font_weight(specified_style.property(CSS::PropertyID::FontWeight).value()->to_integer()); + if (auto maybe_font_variant = specified_style.font_variant(); maybe_font_variant.has_value()) + computed_values.set_font_variant(maybe_font_variant.release_value()); + // FIXME: BorderXRadius properties are now BorderRadiusStyleValues, so make use of that. auto border_bottom_left_radius = specified_style.property(CSS::PropertyID::BorderBottomLeftRadius); if (border_bottom_left_radius.has_value() && border_bottom_left_radius.value()->is_border_radius())