Skip to content

Commit 614353a

Browse files
committed
LibWeb: Preserve auto in computed caret colors
Keep caret-color computed and used values separate so inherited auto values resolve against each element's own currentColor.
1 parent 56a32ba commit 614353a

5 files changed

Lines changed: 18 additions & 8 deletions

File tree

Libraries/LibWeb/CSS/CSSStyleProperties.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ static void ensure_pseudo_element_style_for_cssom(DOM::AbstractElement abstract_
585585
abstract_element.element().set_computed_style(*pseudo_element, nullptr);
586586
}
587587

588+
static RefPtr<StyleValue const> resolve_color_style_value(StyleValue const&, Color, Layout::NodeWithStyle const* = nullptr);
589+
588590
Optional<StyleProperty> CSSStyleProperties::get_direct_property(PropertyNameAndID const& property_name_and_id) const
589591
{
590592
auto const property_id = property_name_and_id.id();
@@ -703,6 +705,8 @@ Optional<StyleProperty> CSSStyleProperties::get_direct_property(PropertyNameAndI
703705
return style_value.release_nonnull();
704706
}
705707
auto computed_value = computed_values->computed_style_value(computed_property_id).release_nonnull();
708+
if (computed_property_id == PropertyID::CaretColor)
709+
return resolve_color_style_value(*computed_value, computed_values->caret_color()).release_nonnull();
706710
return computed_value;
707711
};
708712

@@ -743,7 +747,7 @@ Optional<StyleProperty> CSSStyleProperties::get_direct_property(PropertyNameAndI
743747
return {};
744748
}
745749

746-
static RefPtr<StyleValue const> resolve_color_style_value(StyleValue const& style_value, Color computed_color, Layout::NodeWithStyle const* layout_node = nullptr)
750+
static RefPtr<StyleValue const> resolve_color_style_value(StyleValue const& style_value, Color computed_color, Layout::NodeWithStyle const* layout_node)
747751
{
748752
if (layout_node && style_value.is_color_function()) {
749753
auto const& color_function = as<ColorFunctionStyleValue>(style_value);

Libraries/LibWeb/CSS/ComputedProperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ RefPtr<StyleValue const> ComputedValues::computed_style_value(PropertyID propert
441441
return m_noninherited.border_top_color_style_value;
442442
return color_style_value(border_top().color);
443443
case PropertyID::CaretColor:
444-
return color_style_value(caret_color());
444+
return color_or_auto_style_value(caret_color_value());
445445
case PropertyID::CaptionSide:
446446
return KeywordStyleValue::create(to_keyword(caption_side()));
447447
case PropertyID::ClipRule:

Libraries/LibWeb/CSS/ComputedValues.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,12 @@ NonnullRefPtr<ComputedValues const> ComputedValues::create(ComputedProperties co
904904
computed_values.set_container_type(computed_style.container_type());
905905
computed_values.set_will_change(computed_style.will_change());
906906

907-
computed_values.set_caret_color(computed_style.caret_color(color_resolution_context));
907+
auto const& caret_color_value = computed_style.property(CSS::PropertyID::CaretColor);
908+
CSS::ColorOrAuto caret_color;
909+
caret_color.used_value = computed_style.caret_color(color_resolution_context);
910+
if (caret_color_value.to_keyword() != CSS::Keyword::Auto)
911+
caret_color.computed_value = caret_color.used_value;
912+
computed_values.set_caret_color(move(caret_color));
908913
computed_values.set_color_interpolation(computed_style.color_interpolation());
909914
computed_values.set_color_interpolation_filters(computed_style.color_interpolation_filters());
910915
computed_values.set_resize(computed_style.resize());

Libraries/LibWeb/CSS/ComputedValues.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,8 @@ class WEB_API ComputedValues final : public RefCounted<ComputedValues> {
884884
CSSPixels border_spacing_horizontal() const { return m_inherited.border_spacing_horizontal; }
885885
CSSPixels border_spacing_vertical() const { return m_inherited.border_spacing_vertical; }
886886
CaptionSide caption_side() const { return m_inherited.caption_side; }
887-
Color caret_color() const { return m_inherited.caret_color; }
887+
ColorOrAuto const& caret_color_value() const { return m_inherited.caret_color; }
888+
Color caret_color() const { return m_inherited.caret_color.used_value; }
888889
Clear clear() const { return m_noninherited.clear; }
889890
Clip clip() const { return m_noninherited.clip; }
890891
ColorInterpolation color_interpolation() const { return m_inherited.color_interpolation; }
@@ -1202,7 +1203,7 @@ class WEB_API ComputedValues final : public RefCounted<ComputedValues> {
12021203
void inherit_from(ComputedValues const& other) { m_inherited = other.m_inherited; }
12031204

12041205
struct InheritedValues {
1205-
Color caret_color { InitialValues::caret_color() };
1206+
ColorOrAuto caret_color;
12061207
CSSPixels font_size { InitialValues::font_size() };
12071208
RefPtr<Gfx::FontCascadeList const> font_list {};
12081209
Vector<ComputedFontFamily> font_families { GenericFontFamily::Serif };
@@ -1532,7 +1533,7 @@ class ComputedValues::Mutator final {
15321533
void set_animation_timelines(Vector<AnimationTimelineData> value) { m_values.m_noninherited.animation_timelines = move(value); }
15331534
void set_animation_timing_functions(Vector<EasingFunction> value) { m_values.m_noninherited.animation_timing_functions = move(value); }
15341535
void set_animation_timing_function_style_values(StyleValueVector value) { m_values.m_noninherited.animation_timing_function_style_values = move(value); }
1535-
void set_caret_color(Color caret_color) { m_values.m_inherited.caret_color = caret_color; }
1536+
void set_caret_color(ColorOrAuto caret_color) { m_values.m_inherited.caret_color = move(caret_color); }
15361537
void set_font_list(NonnullRefPtr<Gfx::FontCascadeList const> font_list) { m_values.m_inherited.font_list = move(font_list); }
15371538
void set_font_families(Vector<ComputedFontFamily> value) { m_values.m_inherited.font_families = move(value); }
15381539
void set_font_size(CSSPixels font_size) { m_values.m_inherited.font_size = font_size; }

Tests/LibWeb/Text/expected/wpt-import/css/css-ui/caret-color-021.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ Harness status: OK
22

33
Found 1 tests
44

5-
1 Fail
6-
Fail Default caret-color is not interpolable
5+
1 Pass
6+
Pass Default caret-color is not interpolable

0 commit comments

Comments
 (0)