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
|
|
@ -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