Skip to content

Commit 56a32ba

Browse files
committed
LibWeb: Rename AccentColor to ColorOrAuto
Generalize the computed and used color storage so it can be shared by other properties which accept either a color or auto.
1 parent e154212 commit 56a32ba

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

Libraries/LibWeb/CSS/ComputedProperties.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,15 @@ RefPtr<StyleValue const> ComputedValues::computed_style_value(PropertyID propert
279279
values.append(KeywordStyleValue::create(to_keyword(axis)));
280280
return StyleValueList::create(move(values), StyleValueList::Separator::Comma);
281281
};
282+
auto color_or_auto_style_value = [&](ColorOrAuto const& color_or_auto) -> NonnullRefPtr<StyleValue const> {
283+
return color_or_auto.computed_value.visit(
284+
[](ColorOrAuto::Auto) -> NonnullRefPtr<StyleValue const> { return KeywordStyleValue::create(Keyword::Auto); },
285+
[&](Color color) -> NonnullRefPtr<StyleValue const> { return color_style_value(color); });
286+
};
282287

283288
switch (property_id) {
284289
case PropertyID::AccentColor:
285-
return accent_color_value().computed_value.visit(
286-
[](AccentColor::Auto) -> NonnullRefPtr<StyleValue const> { return KeywordStyleValue::create(Keyword::Auto); },
287-
[&](Color color) -> NonnullRefPtr<StyleValue const> { return color_style_value(color); });
290+
return color_or_auto_style_value(accent_color_value());
288291
case PropertyID::AlignContent:
289292
return KeywordStyleValue::create(to_keyword(align_content()));
290293
case PropertyID::AlignItems:

Libraries/LibWeb/CSS/ComputedValues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ NonnullRefPtr<ComputedValues const> ComputedValues::create(ComputedProperties co
214214
color_resolution_context.current_color = color;
215215

216216
auto const& accent_color_value = computed_style.property(CSS::PropertyID::AccentColor);
217-
CSS::AccentColor accent_color;
217+
CSS::ColorOrAuto accent_color;
218218
accent_color.used_value = computed_style.accent_color(color_resolution_context);
219219
if (accent_color_value.to_keyword() != CSS::Keyword::Auto)
220220
accent_color.computed_value = accent_color.used_value;

Libraries/LibWeb/CSS/ComputedValues.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ struct TextDecorationThickness {
770770
Variant<Auto, FromFont, LengthPercentage> value;
771771
};
772772

773-
struct AccentColor {
773+
struct ColorOrAuto {
774774
struct Auto { };
775775

776776
Variant<Auto, Color> computed_value { Auto {} };
@@ -957,10 +957,10 @@ class WEB_API ComputedValues final : public RefCounted<ComputedValues> {
957957
double flex_grow() const { return m_noninherited.flex_grow; }
958958
double flex_shrink() const { return m_noninherited.flex_shrink; }
959959
i32 order() const { return m_noninherited.order; }
960-
AccentColor const& accent_color_value() const { return m_inherited.accent_color; }
960+
ColorOrAuto const& accent_color_value() const { return m_inherited.accent_color; }
961961
Optional<Color> accent_color() const
962962
{
963-
if (m_inherited.accent_color.computed_value.has<AccentColor::Auto>())
963+
if (m_inherited.accent_color.computed_value.has<ColorOrAuto::Auto>())
964964
return {};
965965
return m_inherited.accent_color.used_value;
966966
}
@@ -1228,7 +1228,7 @@ class WEB_API ComputedValues final : public RefCounted<ComputedValues> {
12281228
PreferredColorScheme color_scheme { InitialValues::color_scheme() };
12291229
Vector<Utf16FlyString> color_schemes;
12301230
bool color_scheme_only { false };
1231-
AccentColor accent_color;
1231+
ColorOrAuto accent_color;
12321232
Color webkit_text_fill_color { InitialValues::color() };
12331233
bool webkit_text_fill_color_is_current_color { true };
12341234
Vector<CursorData> cursor { InitialValues::cursor() };
@@ -1714,7 +1714,7 @@ class ComputedValues::Mutator final {
17141714
void set_flex_grow(double value) { m_values.m_noninherited.flex_grow = value; }
17151715
void set_flex_shrink(double value) { m_values.m_noninherited.flex_shrink = value; }
17161716
void set_order(i32 value) { m_values.m_noninherited.order = value; }
1717-
void set_accent_color(AccentColor value) { m_values.m_inherited.accent_color = move(value); }
1717+
void set_accent_color(ColorOrAuto value) { m_values.m_inherited.accent_color = move(value); }
17181718
void set_align_content(AlignContent value) { m_values.m_noninherited.align_content = value; }
17191719
void set_align_items(AlignItems value) { m_values.m_noninherited.align_items = value; }
17201720
void set_align_self(AlignSelf value) { m_values.m_noninherited.align_self = value; }

0 commit comments

Comments
 (0)