Skip to content

Commit

Permalink
LibWeb: Add support for -webkit-text-fill-color
Browse files Browse the repository at this point in the history
  • Loading branch information
vpzomtrrfrt authored and ADKaster committed Jul 10, 2024
1 parent b5e80db commit 449f81b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions Tests/LibWeb/Ref/reference/webkit-text-fill-color.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p style="color: lime; text-decoration: underline black;">Well, hello friends!</p>
2 changes: 2 additions & 0 deletions Tests/LibWeb/Ref/webkit-text-fill-color.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="match" href="reference/webkit-text-fill-color.html" />
<p style="text-decoration: underline; -webkit-text-fill-color: lime">Well, hello friends!</p>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-webkit-appearance: auto
-webkit-text-fill-color: rgb(0, 0, 0)
accent-color: auto
align-content: normal
align-items: normal
Expand Down Expand Up @@ -85,7 +86,7 @@ grid-row-start: auto
grid-template-areas:
grid-template-columns:
grid-template-rows:
height: 1479px
height: 1496px
image-rendering: auto
inline-size: auto
inset-block-end: auto
Expand Down
4 changes: 4 additions & 0 deletions Userland/Libraries/LibWeb/CSS/ComputedValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ class ComputedValues {
Color background_color() const { return m_noninherited.background_color; }
Vector<BackgroundLayerData> const& background_layers() const { return m_noninherited.background_layers; }

Color webkit_text_fill_color() const { return m_inherited.webkit_text_fill_color; }

CSS::ListStyleType list_style_type() const { return m_inherited.list_style_type; }
CSS::ListStylePosition list_style_position() const { return m_inherited.list_style_position; }

Expand Down Expand Up @@ -503,6 +505,7 @@ class ComputedValues {
CSS::CaptionSide caption_side { InitialValues::caption_side() };
Color color { InitialValues::color() };
Optional<Color> accent_color {};
Color webkit_text_fill_color { InitialValues::color() };
CSS::Cursor cursor { InitialValues::cursor() };
CSS::ImageRendering image_rendering { InitialValues::image_rendering() };
CSS::PointerEvents pointer_events { InitialValues::pointer_events() };
Expand Down Expand Up @@ -667,6 +670,7 @@ class MutableComputedValues final : public ComputedValues {
void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
void set_text_shadow(Vector<ShadowData>&& value) { m_inherited.text_shadow = move(value); }
void set_text_indent(CSS::LengthPercentage value) { m_inherited.text_indent = move(value); }
void set_webkit_text_fill_color(Color value) { m_inherited.webkit_text_fill_color = value; }
void set_position(CSS::Positioning position) { m_noninherited.position = position; }
void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
void set_width(CSS::Size const& width) { m_noninherited.width = width; }
Expand Down
6 changes: 6 additions & 0 deletions Userland/Libraries/LibWeb/CSS/Properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
],
"max-values": 1
},
"-webkit-text-fill-color": {
"animation-type": "by-computed-value",
"inherited": true,
"initial": "currentColor",
"valid-types": ["color"]
},
"accent-color": {
"animation-type": "by-computed-value",
"inherited": true,
Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
auto left = style_value_for_property(layout_node, PropertyID::PaddingLeft);
return style_value_for_sided_shorthand(top.release_nonnull(), right.release_nonnull(), bottom.release_nonnull(), left.release_nonnull());
}
case PropertyID::WebkitTextFillColor:
return ColorStyleValue::create(layout_node.computed_values().webkit_text_fill_color());
case PropertyID::Invalid:
return IdentifierStyleValue::create(ValueID::Invalid);
case PropertyID::Custom:
Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/Layout/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
if (auto maybe_text_decoration_thickness = computed_style.length_percentage(CSS::PropertyID::TextDecorationThickness); maybe_text_decoration_thickness.has_value())
computed_values.set_text_decoration_thickness(maybe_text_decoration_thickness.release_value());

computed_values.set_webkit_text_fill_color(computed_style.color_or_fallback(CSS::PropertyID::WebkitTextFillColor, *this, computed_values.color()));

computed_values.set_text_shadow(computed_style.text_shadow(*this));

computed_values.set_z_index(computed_style.z_index());
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/Painting/PaintableBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ void paint_text_fragment(PaintContext& context, TextPaintable const& paintable,

DevicePixelPoint baseline_start { fragment_absolute_device_rect.x(), fragment_absolute_device_rect.y() + context.rounded_device_pixels(fragment.baseline()) };
auto scale = context.device_pixels_per_css_pixel();
painter.draw_text_run(baseline_start.to_type<int>(), *glyph_run, paintable.computed_values().color(), fragment_absolute_device_rect.to_type<int>(), scale);
painter.draw_text_run(baseline_start.to_type<int>(), *glyph_run, paintable.computed_values().webkit_text_fill_color(), fragment_absolute_device_rect.to_type<int>(), scale);

auto selection_rect = context.enclosing_device_rect(fragment.selection_rect(paintable.layout_node().first_available_font())).to_type<int>();
if (!selection_rect.is_empty()) {
Expand Down

0 comments on commit 449f81b

Please sign in to comment.