Skip to content

Commit 11a9b5a

Browse files
Calme1709AtkinsSJ
authored andcommitted
LibWeb: Simplify handling of font-family
We know `parse_comma_separated_value_list` always returns a `StyleValueList`
1 parent 0595d52 commit 11a9b5a

File tree

2 files changed

+18
-41
lines changed

2 files changed

+18
-41
lines changed

Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,9 +2865,7 @@ RefPtr<StyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>& t
28652865
RefPtr<StyleValue const> Parser::parse_font_family_value(TokenStream<ComponentValue>& tokens)
28662866
{
28672867
// [ <family-name> | <generic-family> ]#
2868-
// FIXME: We currently require font-family to always be a list, even with one item.
2869-
// Maybe change that?
2870-
auto result = parse_comma_separated_value_list(tokens, [this](auto& inner_tokens) -> RefPtr<StyleValue const> {
2868+
return parse_comma_separated_value_list(tokens, [this](auto& inner_tokens) -> RefPtr<StyleValue const> {
28712869
inner_tokens.discard_whitespace();
28722870

28732871
// <generic-family>
@@ -2883,15 +2881,6 @@ RefPtr<StyleValue const> Parser::parse_font_family_value(TokenStream<ComponentVa
28832881
// <family-name>
28842882
return parse_family_name_value(inner_tokens);
28852883
});
2886-
2887-
if (!result)
2888-
return nullptr;
2889-
2890-
if (result->is_value_list())
2891-
return result.release_nonnull();
2892-
2893-
// It's a single value, so wrap it in a list - see FIXME above.
2894-
return StyleValueList::create(StyleValueVector { result.release_nonnull() }, StyleValueList::Separator::Comma);
28952884
}
28962885

28972886
RefPtr<StyleValue const> Parser::parse_font_language_override_value(TokenStream<ComponentValue>& tokens)

Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,28 +1901,18 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
19011901
};
19021902

19031903
auto font_list = Gfx::FontCascadeList::create();
1904-
if (font_family.is_value_list()) {
1905-
auto const& family_list = static_cast<StyleValueList const&>(font_family).values();
1906-
for (auto const& family : family_list) {
1907-
RefPtr<Gfx::FontCascadeList const> other_font_list;
1908-
if (family->is_keyword()) {
1909-
other_font_list = find_generic_font(family->to_keyword());
1910-
} else if (family->is_string()) {
1911-
other_font_list = find_font(family->as_string().string_value());
1912-
} else if (family->is_custom_ident()) {
1913-
other_font_list = find_font(family->as_custom_ident().custom_ident());
1914-
}
1915-
if (other_font_list)
1916-
font_list->extend(*other_font_list);
1904+
1905+
for (auto const& family : font_family.as_value_list().values()) {
1906+
RefPtr<Gfx::FontCascadeList const> other_font_list;
1907+
if (family->is_keyword()) {
1908+
other_font_list = find_generic_font(family->to_keyword());
1909+
} else if (family->is_string()) {
1910+
other_font_list = find_font(family->as_string().string_value());
1911+
} else if (family->is_custom_ident()) {
1912+
other_font_list = find_font(family->as_custom_ident().custom_ident());
19171913
}
1918-
} else if (font_family.is_keyword()) {
1919-
if (auto other_font_list = find_generic_font(font_family.to_keyword()))
1920-
font_list->extend(*other_font_list);
1921-
} else if (font_family.is_string()) {
1922-
if (auto other_font_list = find_font(font_family.as_string().string_value()))
1923-
font_list->extend(*other_font_list);
1924-
} else if (font_family.is_custom_ident()) {
1925-
if (auto other_font_list = find_font(font_family.as_custom_ident().custom_ident()))
1914+
1915+
if (other_font_list)
19261916
font_list->extend(*other_font_list);
19271917
}
19281918

@@ -2430,14 +2420,12 @@ GC::Ptr<ComputedProperties> StyleComputer::compute_style_impl(DOM::AbstractEleme
24302420

24312421
static bool is_monospace(StyleValue const& value)
24322422
{
2433-
if (value.to_keyword() == Keyword::Monospace)
2434-
return true;
2435-
if (value.is_value_list()) {
2436-
auto const& values = value.as_value_list().values();
2437-
if (values.size() == 1 && values[0]->to_keyword() == Keyword::Monospace)
2438-
return true;
2439-
}
2440-
return false;
2423+
if (!value.is_value_list())
2424+
return false;
2425+
2426+
auto const& values = value.as_value_list().values();
2427+
2428+
return values.size() == 1 && values[0]->to_keyword() == Keyword::Monospace;
24412429
}
24422430

24432431
// HACK: This function implements time-travelling inheritance for the font-size property

0 commit comments

Comments
 (0)