diff --git a/Userland/Libraries/LibWeb/CSS/Identifiers.json b/Userland/Libraries/LibWeb/CSS/Identifiers.json index a4b4628b62..518003d6b9 100644 --- a/Userland/Libraries/LibWeb/CSS/Identifiers.json +++ b/Userland/Libraries/LibWeb/CSS/Identifiers.json @@ -85,6 +85,7 @@ "collapse", "column", "column-reverse", + "condensed", "contain", "content", "content-box", @@ -111,6 +112,9 @@ "enabled", "end", "ew-resize", + "expanded", + "extra-condensed", + "extra-expanded", "fantasy", "fast", "fine", @@ -235,6 +239,8 @@ "se-resize", "self-end", "self-start", + "semi-condensed", + "semi-expanded", "separate", "serif", "slow", @@ -282,6 +288,8 @@ "ui-rounded", "ui-sans-serif", "ui-serif", + "ultra-condensed", + "ultra-expanded", "underline", "unsafe", "upper-alpha", diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index bc6ac2cec3..d0e9b82dee 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -5123,13 +5123,13 @@ static bool is_generic_font_family(ValueID identifier) RefPtr Parser::parse_font_value(Vector const& component_values) { + RefPtr font_stretch; RefPtr font_style; RefPtr font_weight; RefPtr font_size; RefPtr line_height; RefPtr font_families; RefPtr font_variant; - // FIXME: Implement font-stretch. // FIXME: Handle system fonts. (caption, icon, menu, message-box, small-caption, status-bar) @@ -5189,6 +5189,12 @@ RefPtr Parser::parse_font_value(Vector const& compon font_families = maybe_font_families.release_nonnull(); break; } + if (property_accepts_value(PropertyID::FontStretch, *value)) { + if (font_stretch) + return nullptr; + font_stretch = value.release_nonnull(); + continue; + } return nullptr; } @@ -5202,6 +5208,8 @@ RefPtr Parser::parse_font_value(Vector const& compon if (!font_size || !font_families) return nullptr; + if (!font_stretch) + font_stretch = property_initial_value(PropertyID::FontStretch); if (!font_style) font_style = property_initial_value(PropertyID::FontStyle); if (!font_weight) @@ -5209,7 +5217,7 @@ RefPtr Parser::parse_font_value(Vector const& compon if (!line_height) line_height = property_initial_value(PropertyID::LineHeight); - return FontStyleValue::create(font_style.release_nonnull(), font_weight.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull()); + return FontStyleValue::create(font_stretch.release_nonnull(), font_style.release_nonnull(), font_weight.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull()); } RefPtr Parser::parse_font_family_value(Vector const& component_values, size_t start_index) diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index fe6f69713b..6fca39a5d1 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -692,6 +692,24 @@ "unitless-length" ] }, + "font-stretch": { + "inherited": true, + "initial": "normal", + "valid-types": [ + "percentage [0,∞]" + ], + "valid-identifiers": [ + "normal", + "ultra-condensed", + "extra-condensed", + "condensed", + "semi-condensed", + "semi-expanded", + "expanded", + "extra-expanded", + "ultra-expanded" + ] + }, "font-style": { "inherited": true, "initial": "normal", diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 1b55d9089a..2b27a63059 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -476,19 +476,21 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope auto const& font_shorthand = value.as_font(); style.set_property(CSS::PropertyID::FontSize, font_shorthand.font_size()); style.set_property(CSS::PropertyID::FontFamily, font_shorthand.font_families()); + style.set_property(CSS::PropertyID::FontStretch, font_shorthand.font_stretch()); style.set_property(CSS::PropertyID::FontStyle, font_shorthand.font_style()); style.set_property(CSS::PropertyID::FontWeight, font_shorthand.font_weight()); style.set_property(CSS::PropertyID::LineHeight, font_shorthand.line_height()); - // FIXME: Implement font-stretch and font-variant + // FIXME: Implement font-variant return; } + style.set_property(CSS::PropertyID::FontStretch, value); style.set_property(CSS::PropertyID::FontSize, value); style.set_property(CSS::PropertyID::FontFamily, value); style.set_property(CSS::PropertyID::FontStyle, value); style.set_property(CSS::PropertyID::FontWeight, value); style.set_property(CSS::PropertyID::LineHeight, value); - // FIXME: Implement font-stretch and font-variant + // FIXME: Implement font-variant return; } @@ -986,6 +988,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele // FIXME: This should be more sophisticated. compute_defaulted_property_value(style, element, CSS::PropertyID::FontFamily, pseudo_element); compute_defaulted_property_value(style, element, CSS::PropertyID::FontSize, pseudo_element); + compute_defaulted_property_value(style, element, CSS::PropertyID::FontStretch, pseudo_element); compute_defaulted_property_value(style, element, CSS::PropertyID::FontStyle, pseudo_element); compute_defaulted_property_value(style, element, CSS::PropertyID::FontWeight, pseudo_element); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index ece839c8a3..71086ac8f8 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -1006,9 +1006,10 @@ private: class FontStyleValue final : public StyleValue { public: - static NonnullRefPtr create(NonnullRefPtr font_style, NonnullRefPtr font_weight, NonnullRefPtr font_size, NonnullRefPtr line_height, NonnullRefPtr font_families) { return adopt_ref(*new FontStyleValue(font_style, font_weight, font_size, line_height, font_families)); } + static NonnullRefPtr create(NonnullRefPtr font_stretch, NonnullRefPtr font_style, NonnullRefPtr font_weight, NonnullRefPtr font_size, NonnullRefPtr line_height, NonnullRefPtr font_families) { return adopt_ref(*new FontStyleValue(font_stretch, font_style, font_weight, font_size, line_height, font_families)); } virtual ~FontStyleValue() override = default; + NonnullRefPtr font_stretch() const { return m_font_stretch; } NonnullRefPtr font_style() const { return m_font_style; } NonnullRefPtr font_weight() const { return m_font_weight; } NonnullRefPtr font_size() const { return m_font_size; } @@ -1019,8 +1020,9 @@ public: virtual bool equals(StyleValue const& other) const override; private: - FontStyleValue(NonnullRefPtr font_style, NonnullRefPtr font_weight, NonnullRefPtr font_size, NonnullRefPtr line_height, NonnullRefPtr font_families) + FontStyleValue(NonnullRefPtr font_stretch, NonnullRefPtr font_style, NonnullRefPtr font_weight, NonnullRefPtr font_size, NonnullRefPtr line_height, NonnullRefPtr font_families) : StyleValue(Type::Font) + , m_font_stretch(font_stretch) , m_font_style(font_style) , m_font_weight(font_weight) , m_font_size(font_size) @@ -1029,12 +1031,13 @@ private: { } + NonnullRefPtr m_font_stretch; NonnullRefPtr m_font_style; NonnullRefPtr m_font_weight; NonnullRefPtr m_font_size; NonnullRefPtr m_line_height; NonnullRefPtr m_font_families; - // FIXME: Implement font-stretch and font-variant. + // FIXME: Implement font-variant. }; class FrequencyStyleValue : public StyleValue {