mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Allow reset-only longhands in coordinating value list shorthands
Required for `animation-timeline` and the various `animation-trigger-*` properties within the `animation` coordinating value list
This commit is contained in:
parent
6bb7224f4e
commit
d79aba68d2
Notes:
github-actions[bot]
2025-11-28 13:25:46 +00:00
Author: https://github.com/Calme1709
Commit: d79aba68d2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6912
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 31 additions and 16 deletions
|
|
@ -448,7 +448,7 @@ private:
|
|||
using ParseFunction = AK::Function<RefPtr<StyleValue const>(TokenStream<ComponentValue>&)>;
|
||||
RefPtr<StyleValue const> parse_comma_separated_value_list(TokenStream<ComponentValue>&, ParseFunction);
|
||||
RefPtr<StyleValue const> parse_simple_comma_separated_value_list(PropertyID, TokenStream<ComponentValue>&);
|
||||
RefPtr<StyleValue const> parse_coordinating_value_list_shorthand(TokenStream<ComponentValue>&, PropertyID shorthand_id, Vector<PropertyID> const& longhand_ids);
|
||||
RefPtr<StyleValue const> parse_coordinating_value_list_shorthand(TokenStream<ComponentValue>&, PropertyID shorthand_id, Vector<PropertyID> const& longhand_ids, Vector<PropertyID> const& reset_only_longhand_ids);
|
||||
RefPtr<StyleValue const> parse_all_as_single_keyword_value(TokenStream<ComponentValue>&, Keyword);
|
||||
|
||||
RefPtr<StyleValue const> parse_anchor_name_value(TokenStream<ComponentValue>&);
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ RefPtr<StyleValue const> Parser::parse_simple_comma_separated_value_list(Propert
|
|||
});
|
||||
}
|
||||
|
||||
RefPtr<StyleValue const> Parser::parse_coordinating_value_list_shorthand(TokenStream<ComponentValue>& tokens, PropertyID shorthand_id, Vector<PropertyID> const& longhand_ids)
|
||||
RefPtr<StyleValue const> Parser::parse_coordinating_value_list_shorthand(TokenStream<ComponentValue>& tokens, PropertyID shorthand_id, Vector<PropertyID> const& longhand_ids, Vector<PropertyID> const& reset_only_longhand_ids = {})
|
||||
{
|
||||
HashMap<PropertyID, StyleValueVector> longhand_vectors;
|
||||
|
||||
|
|
@ -144,23 +144,25 @@ RefPtr<StyleValue const> Parser::parse_coordinating_value_list_shorthand(TokenSt
|
|||
|
||||
transaction.commit();
|
||||
|
||||
Vector<PropertyID> longhand_ids_including_reset_only_longhands;
|
||||
longhand_ids_including_reset_only_longhands.extend(longhand_ids);
|
||||
longhand_ids_including_reset_only_longhands.extend(reset_only_longhand_ids);
|
||||
StyleValueVector longhand_values {};
|
||||
|
||||
// FIXME: This is for compatibility with parse_comma_separated_value_list(), which returns a single value directly
|
||||
// instead of a list if there's only one, it would be nicer if we always returned a list.
|
||||
if (longhand_vectors.get(longhand_ids[0])->size() == 1) {
|
||||
StyleValueVector longhand_values {};
|
||||
|
||||
for (auto const& longhand_id : longhand_ids)
|
||||
longhand_values.append((*longhand_vectors.get(longhand_id))[0]);
|
||||
|
||||
return ShorthandStyleValue::create(shorthand_id, longhand_ids, longhand_values);
|
||||
} else {
|
||||
for (auto const& longhand_id : longhand_ids)
|
||||
longhand_values.append(StyleValueList::create(move(*longhand_vectors.get(longhand_id)), StyleValueList::Separator::Comma));
|
||||
}
|
||||
|
||||
StyleValueVector longhand_values {};
|
||||
for (auto reset_only_longhand_id : reset_only_longhand_ids)
|
||||
longhand_values.append(property_initial_value(reset_only_longhand_id));
|
||||
|
||||
for (auto const& longhand_id : longhand_ids)
|
||||
longhand_values.append(StyleValueList::create(move(*longhand_vectors.get(longhand_id)), StyleValueList::Separator::Comma));
|
||||
|
||||
return ShorthandStyleValue::create(shorthand_id, longhand_ids, longhand_values);
|
||||
return ShorthandStyleValue::create(shorthand_id, longhand_ids_including_reset_only_longhands, longhand_values);
|
||||
}
|
||||
|
||||
RefPtr<StyleValue const> Parser::parse_css_value_for_property(PropertyID property_id, TokenStream<ComponentValue>& tokens)
|
||||
|
|
|
|||
|
|
@ -78,20 +78,28 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
|
|||
return { value.release_nonnull() };
|
||||
};
|
||||
|
||||
auto const coordinating_value_list_shorthand_to_string = [&](StringView entry_when_all_longhands_initial, Vector<PropertyID> required_longhands = {}) {
|
||||
auto const coordinating_value_list_shorthand_to_string = [&](StringView entry_when_all_longhands_initial, Vector<PropertyID> const& required_longhands = {}, Vector<PropertyID> const& reset_only_longhands = {}) {
|
||||
for (auto reset_only_longhand : reset_only_longhands) {
|
||||
if (!longhand(reset_only_longhand)->equals(property_initial_value(reset_only_longhand)))
|
||||
return ""_string;
|
||||
}
|
||||
|
||||
auto entry_count = style_value_as_value_list(longhand(m_properties.sub_properties[0])).size();
|
||||
|
||||
// If we don't have the same number of values for each longhand, we can't serialize this shorthand.
|
||||
if (any_of(m_properties.sub_properties, [&](auto longhand_id) { return style_value_as_value_list(longhand(longhand_id)).size() != entry_count; }))
|
||||
// If we don't have the same number of values for each non-reset-only longhand, we can't serialize this shorthand.
|
||||
if (any_of(m_properties.sub_properties, [&](auto longhand_id) { return !reset_only_longhands.contains_slow(longhand_id) && style_value_as_value_list(longhand(longhand_id)).size() != entry_count; }))
|
||||
return ""_string;
|
||||
|
||||
// We should serialize a longhand if:
|
||||
// We should serialize a longhand if it is not a reset-only longhand and one of the following is true:
|
||||
// - The longhand is required
|
||||
// - The value is not the initial value
|
||||
// - Another longhand value which will be included later in the serialization is valid for this longhand.
|
||||
auto should_serialize_longhand = [&](size_t entry_index, size_t longhand_index) {
|
||||
auto longhand_id = m_properties.sub_properties[longhand_index];
|
||||
|
||||
if (reset_only_longhands.contains_slow(longhand_id))
|
||||
return false;
|
||||
|
||||
if (required_longhands.contains_slow(longhand_id))
|
||||
return true;
|
||||
|
||||
|
|
@ -102,6 +110,10 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
|
|||
|
||||
for (size_t other_longhand_index = longhand_index + 1; other_longhand_index < m_properties.sub_properties.size(); other_longhand_index++) {
|
||||
auto other_longhand_id = m_properties.sub_properties[other_longhand_index];
|
||||
|
||||
if (reset_only_longhands.contains_slow(other_longhand_id))
|
||||
continue;
|
||||
|
||||
auto other_longhand_value = style_value_as_value_list(longhand(other_longhand_id))[entry_index];
|
||||
|
||||
// FIXME: This should really account for the other longhand being included in the serialization for any reason, not just because it is not the initial value.
|
||||
|
|
@ -121,7 +133,6 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
|
|||
|
||||
for (size_t longhand_index = 0; longhand_index < m_properties.sub_properties.size(); longhand_index++) {
|
||||
auto longhand_id = m_properties.sub_properties[longhand_index];
|
||||
auto longhand_value = style_value_as_value_list(longhand(longhand_id))[entry_index];
|
||||
|
||||
if (!should_serialize_longhand(entry_index, longhand_index))
|
||||
continue;
|
||||
|
|
@ -129,6 +140,8 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
|
|||
if (!builder.is_empty() && !first)
|
||||
builder.append(' ');
|
||||
|
||||
auto longhand_value = style_value_as_value_list(longhand(longhand_id))[entry_index];
|
||||
|
||||
builder.append(longhand_value->to_string(mode));
|
||||
first = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue