Forráskód Böngészése

LibWeb: Add letter-spacing css property to Node

Kostya Farber 9 hónapja
szülő
commit
537cbf55c3

+ 4 - 0
Userland/Libraries/LibWeb/CSS/ComputedValues.h

@@ -106,6 +106,7 @@ public:
     static CSS::Cursor cursor() { return CSS::Cursor::Auto; }
     static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
     static CSS::LengthOrCalculated word_spacing() { return CSS::Length::make_px(0); }
+    static LengthOrCalculated letter_spacing() { return CSS::Length::make_px(0); }
     static Variant<LengthOrCalculated, NumberOrCalculated> tab_size() { return NumberOrCalculated(8.0f); }
     static CSS::TextAlign text_align() { return CSS::TextAlign::Start; }
     static CSS::TextJustify text_justify() { return CSS::TextJustify::Auto; }
@@ -389,6 +390,7 @@ public:
     CSS::Positioning position() const { return m_noninherited.position; }
     CSS::WhiteSpace white_space() const { return m_inherited.white_space; }
     CSS::LengthOrCalculated word_spacing() const { return m_inherited.word_spacing; }
+    LengthOrCalculated letter_spacing() const { return m_inherited.letter_spacing; }
     CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; }
     CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; }
     FlexBasis const& flex_basis() const { return m_noninherited.flex_basis; }
@@ -550,6 +552,7 @@ protected:
         CSS::LengthPercentage text_indent { InitialValues::text_indent() };
         CSS::WhiteSpace white_space { InitialValues::white_space() };
         CSS::LengthOrCalculated word_spacing { InitialValues::word_spacing() };
+        LengthOrCalculated letter_spacing { InitialValues::letter_spacing() };
         CSS::ListStyleType list_style_type { InitialValues::list_style_type() };
         CSS::ListStylePosition list_style_position { InitialValues::list_style_position() };
         CSS::Visibility visibility { InitialValues::visibility() };
@@ -725,6 +728,7 @@ public:
     void set_position(CSS::Positioning position) { m_noninherited.position = position; }
     void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
     void set_word_spacing(CSS::LengthOrCalculated value) { m_inherited.word_spacing = value; }
+    void set_letter_spacing(CSS::LengthOrCalculated value) { m_inherited.letter_spacing = value; }
     void set_width(CSS::Size const& width) { m_noninherited.width = width; }
     void set_min_width(CSS::Size const& width) { m_noninherited.min_width = width; }
     void set_max_width(CSS::Size const& width) { m_noninherited.max_width = width; }

+ 17 - 1
Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

@@ -687,7 +687,7 @@ Variant<LengthOrCalculated, NumberOrCalculated> StyleProperties::tab_size() cons
 {
     auto value = property(CSS::PropertyID::TabSize);
     if (value->is_math()) {
-        auto& math_value = value->as_math();
+        auto const& math_value = value->as_math();
         if (math_value.resolves_to_length()) {
             return LengthOrCalculated { math_value };
         }
@@ -724,6 +724,22 @@ Optional<CSS::WhiteSpace> StyleProperties::white_space() const
     return keyword_to_white_space(value->to_keyword());
 }
 
+Optional<LengthOrCalculated> StyleProperties::letter_spacing() const
+{
+    auto value = property(CSS::PropertyID::LetterSpacing);
+    if (value->is_math()) {
+        auto const& math_value = value->as_math();
+        if (math_value.resolves_to_length()) {
+            return LengthOrCalculated { math_value };
+        }
+    }
+
+    if (value->is_length())
+        return LengthOrCalculated { value->as_length().length() };
+
+    return {};
+}
+
 Optional<CSS::LineStyle> StyleProperties::line_style(CSS::PropertyID property_id) const
 {
     auto value = property(property_id);

+ 1 - 0
Userland/Libraries/LibWeb/CSS/StyleProperties.h

@@ -116,6 +116,7 @@ public:
     Variant<LengthOrCalculated, NumberOrCalculated> tab_size() const;
     Optional<CSS::WhiteSpace> white_space() const;
     Optional<CSS::LengthOrCalculated> word_spacing() const;
+    Optional<LengthOrCalculated> letter_spacing() const;
     Optional<CSS::LineStyle> line_style(CSS::PropertyID) const;
     Optional<CSS::OutlineStyle> outline_style() const;
     Vector<CSS::TextDecorationLine> text_decoration_line() const;

+ 4 - 0
Userland/Libraries/LibWeb/Layout/Node.cpp

@@ -602,6 +602,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
     if (word_spacing.has_value())
         computed_values.set_word_spacing(word_spacing.value());
 
+    auto letter_spacing = computed_style.letter_spacing();
+    if (letter_spacing.has_value())
+        computed_values.set_letter_spacing(letter_spacing.value());
+
     auto float_ = computed_style.float_();
     if (float_.has_value())
         computed_values.set_float(float_.value());