Selaa lähdekoodia

LibWeb: Compute `text-decoration-color` values

Previosly, we used only the text color as a line decoration color.

The FIXME comment has been directly copy-pasted from the border color
note a few lines below.
Karol Kosek 3 vuotta sitten
vanhempi
commit
f9d66bef5d

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

@@ -112,6 +112,7 @@ public:
     CSS::TextAlign text_align() const { return m_inherited.text_align; }
     CSS::TextAlign text_align() const { return m_inherited.text_align; }
     CSS::TextDecorationLine text_decoration_line() const { return m_noninherited.text_decoration_line; }
     CSS::TextDecorationLine text_decoration_line() const { return m_noninherited.text_decoration_line; }
     CSS::TextDecorationStyle text_decoration_style() const { return m_noninherited.text_decoration_style; }
     CSS::TextDecorationStyle text_decoration_style() const { return m_noninherited.text_decoration_style; }
+    Color text_decoration_color() const { return m_noninherited.text_decoration_color; }
     CSS::TextTransform text_transform() const { return m_inherited.text_transform; }
     CSS::TextTransform text_transform() const { return m_inherited.text_transform; }
     CSS::Position position() const { return m_noninherited.position; }
     CSS::Position position() const { return m_noninherited.position; }
     CSS::WhiteSpace white_space() const { return m_inherited.white_space; }
     CSS::WhiteSpace white_space() const { return m_inherited.white_space; }
@@ -198,6 +199,7 @@ protected:
         Optional<int> z_index;
         Optional<int> z_index;
         CSS::TextDecorationLine text_decoration_line { InitialValues::text_decoration_line() };
         CSS::TextDecorationLine text_decoration_line { InitialValues::text_decoration_line() };
         CSS::TextDecorationStyle text_decoration_style { InitialValues::text_decoration_style() };
         CSS::TextDecorationStyle text_decoration_style { InitialValues::text_decoration_style() };
+        Color text_decoration_color { InitialValues::color() };
         CSS::Position position { InitialValues::position() };
         CSS::Position position { InitialValues::position() };
         Optional<CSS::LengthPercentage> width;
         Optional<CSS::LengthPercentage> width;
         Optional<CSS::LengthPercentage> min_width;
         Optional<CSS::LengthPercentage> min_width;
@@ -256,6 +258,7 @@ public:
     void set_text_align(CSS::TextAlign text_align) { m_inherited.text_align = text_align; }
     void set_text_align(CSS::TextAlign text_align) { m_inherited.text_align = text_align; }
     void set_text_decoration_line(CSS::TextDecorationLine value) { m_noninherited.text_decoration_line = value; }
     void set_text_decoration_line(CSS::TextDecorationLine value) { m_noninherited.text_decoration_line = value; }
     void set_text_decoration_style(CSS::TextDecorationStyle value) { m_noninherited.text_decoration_style = value; }
     void set_text_decoration_style(CSS::TextDecorationStyle value) { m_noninherited.text_decoration_style = value; }
+    void set_text_decoration_color(Color value) { m_noninherited.text_decoration_color = value; }
     void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
     void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
     void set_position(CSS::Position position) { m_noninherited.position = position; }
     void set_position(CSS::Position position) { m_noninherited.position = position; }
     void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
     void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }

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

@@ -426,6 +426,11 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
 
 
     computed_values.set_color(specified_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
     computed_values.set_color(specified_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
 
 
+    // FIXME: The default text decoration color value is `currentcolor`, but since we can't resolve that easily,
+    //        we just manually grab the value from `color`. This makes it dependent on `color` being
+    //        specified first, so it's far from ideal.
+    computed_values.set_text_decoration_color(specified_style.color_or_fallback(CSS::PropertyID::TextDecorationColor, *this, computed_values.color()));
+
     computed_values.set_z_index(specified_style.z_index());
     computed_values.set_z_index(specified_style.z_index());
     computed_values.set_opacity(specified_style.opacity());
     computed_values.set_opacity(specified_style.opacity());
     if (computed_values.opacity() == 0)
     if (computed_values.opacity() == 0)

+ 4 - 2
Userland/Libraries/LibWeb/Layout/TextNode.cpp

@@ -68,17 +68,19 @@ void TextNode::paint_text_decoration(Gfx::Painter& painter, LineBoxFragment cons
         return;
         return;
     }
     }
 
 
+    auto line_color = computed_values().text_decoration_color();
+
     switch (computed_values().text_decoration_style()) {
     switch (computed_values().text_decoration_style()) {
         // FIXME: Implement the other styles
         // FIXME: Implement the other styles
     case CSS::TextDecorationStyle::Solid:
     case CSS::TextDecorationStyle::Solid:
     case CSS::TextDecorationStyle::Double:
     case CSS::TextDecorationStyle::Double:
     case CSS::TextDecorationStyle::Dashed:
     case CSS::TextDecorationStyle::Dashed:
     case CSS::TextDecorationStyle::Dotted:
     case CSS::TextDecorationStyle::Dotted:
-        painter.draw_line(line_start_point, line_end_point, computed_values().color());
+        painter.draw_line(line_start_point, line_end_point, line_color);
         break;
         break;
     case CSS::TextDecorationStyle::Wavy:
     case CSS::TextDecorationStyle::Wavy:
         // FIXME: There is a thing called text-decoration-thickness which also affects the amplitude here.
         // FIXME: There is a thing called text-decoration-thickness which also affects the amplitude here.
-        painter.draw_triangle_wave(line_start_point, line_end_point, computed_values().color(), 2);
+        painter.draw_triangle_wave(line_start_point, line_end_point, line_color, 2);
         break;
         break;
     }
     }
 }
 }