mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb/CSS: Don't serialize longhands which match their initial values
Shorthand subproperties that match their initial values are now excluded from serialization, by default. Properties where this behavior is not desired, like `gap`, are special-cased.
This commit is contained in:
parent
b4b8d85251
commit
3186adeaa1
Notes:
github-actions[bot]
2025-04-07 10:40:16 +00:00
Author: https://github.com/tcl3
Commit: 3186adeaa1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4259
Reviewed-by: https://github.com/AtkinsSJ ✅
6 changed files with 144 additions and 27 deletions
|
@ -279,6 +279,13 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
|
|||
return "normal"_string;
|
||||
return MUST(String::join(' ', values));
|
||||
}
|
||||
case PropertyID::Gap: {
|
||||
auto row_gap = longhand(PropertyID::RowGap);
|
||||
auto column_gap = longhand(PropertyID::ColumnGap);
|
||||
if (row_gap == column_gap)
|
||||
return row_gap->to_string(mode);
|
||||
return MUST(String::formatted("{} {}", row_gap->to_string(mode), column_gap->to_string(mode)));
|
||||
}
|
||||
case PropertyID::GridArea: {
|
||||
auto& row_start = longhand(PropertyID::GridRowStart)->as_grid_track_placement();
|
||||
auto& column_start = longhand(PropertyID::GridColumnStart)->as_grid_track_placement();
|
||||
|
@ -411,13 +418,21 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
|
|||
|
||||
StringBuilder builder;
|
||||
auto first = true;
|
||||
for (auto& value : m_properties.values) {
|
||||
for (size_t i = 0; i < m_properties.values.size(); ++i) {
|
||||
auto value = m_properties.values[i];
|
||||
auto value_string = value->to_string(mode);
|
||||
auto initial_value_string = property_initial_value(m_properties.sub_properties[i])->to_string(mode);
|
||||
if (value_string == initial_value_string)
|
||||
continue;
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
builder.append(' ');
|
||||
builder.append(value->to_string(mode));
|
||||
}
|
||||
if (builder.is_empty())
|
||||
return m_properties.values.first()->to_string(mode);
|
||||
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue