Skip to content

Commit c72a2f9

Browse files
kalenikaliaksandrawesomekling
authored andcommitted
LibWeb/CSS: Serialize short version if possible for "place-" properties
Output short version when both parts of place-content, place-items, place-self are the same.
1 parent da2cd73 commit c72a2f9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Userland/Libraries/LibWeb/CSS/StyleValues/PlaceContentStyleValue.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ namespace Web::CSS {
1010

1111
ErrorOr<String> PlaceContentStyleValue::to_string() const
1212
{
13-
return String::formatted("{} {}", TRY(m_properties.align_content->to_string()), TRY(m_properties.justify_content->to_string()));
13+
auto align_content = TRY(m_properties.align_content->to_string());
14+
auto justify_content = TRY(m_properties.justify_content->to_string());
15+
if (align_content == justify_content)
16+
return String::formatted("{}", align_content);
17+
return String::formatted("{} {}", align_content, justify_content);
1418
}
1519

1620
}

Userland/Libraries/LibWeb/CSS/StyleValues/PlaceItemsStyleValue.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ namespace Web::CSS {
1010

1111
ErrorOr<String> PlaceItemsStyleValue::to_string() const
1212
{
13-
return String::formatted("{} {}", TRY(m_properties.align_items->to_string()), TRY(m_properties.justify_items->to_string()));
13+
auto align_items = TRY(m_properties.align_items->to_string());
14+
auto justify_items = TRY(m_properties.justify_items->to_string());
15+
if (align_items == justify_items)
16+
return String::formatted("{}", align_items);
17+
return String::formatted("{} {}", align_items, justify_items);
1418
}
1519

1620
}

Userland/Libraries/LibWeb/CSS/StyleValues/PlaceSelfStyleValue.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ namespace Web::CSS {
1010

1111
ErrorOr<String> PlaceSelfStyleValue::to_string() const
1212
{
13-
return String::formatted("{} {}", TRY(m_properties.align_self->to_string()), TRY(m_properties.justify_self->to_string()));
13+
auto align_self = TRY(m_properties.align_self->to_string());
14+
auto justify_self = TRY(m_properties.justify_self->to_string());
15+
if (align_self == justify_self)
16+
return String::formatted("{}", align_self);
17+
return String::formatted("{} {}", align_self, justify_self);
1418
}
1519

1620
}

0 commit comments

Comments
 (0)