LibWeb: Serialize grid-template shorthand correctly

This commit is contained in:
Tim Ledbetter 2025-09-27 18:31:19 +01:00 committed by Alexander Kalenik
parent cb6ca85564
commit bf1564388d
5 changed files with 106 additions and 89 deletions

View File

@ -648,27 +648,45 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
auto construct_rows_string = [&]() {
StringBuilder builder;
size_t idx = 0;
for (auto const& row : rows.grid_track_size_list().track_list()) {
if (areas.grid_template_area().size() > idx) {
builder.append("\""sv);
for (size_t y = 0; y < areas.grid_template_area()[idx].size(); ++y) {
builder.append(areas.grid_template_area()[idx][y]);
if (y != areas.grid_template_area()[idx].size() - 1)
builder.append(" "sv);
}
builder.append("\" "sv);
for (size_t i = 0; i < rows.grid_track_size_list().list().size(); ++i) {
auto track_size_or_line_names = rows.grid_track_size_list().list()[i];
if (auto* line_names = track_size_or_line_names.get_pointer<GridLineNames>()) {
if (i != 0)
builder.append(' ');
builder.append(line_names->to_string());
}
if (areas.grid_template_area().size() > i) {
if (!builder.is_empty())
builder.append(' ');
builder.append("\""sv);
for (size_t y = 0; y < areas.grid_template_area()[i].size(); ++y) {
if (y != 0)
builder.append(' ');
builder.append(areas.grid_template_area()[i][y]);
}
builder.append("\""sv);
}
if (auto* track_size = track_size_or_line_names.get_pointer<ExplicitGridTrack>()) {
auto track_size_serialization = track_size->to_string(mode);
if (track_size_serialization != "auto"sv) {
if (!builder.is_empty())
builder.append(' ');
builder.append(track_size_serialization);
}
}
builder.append(row.to_string(mode));
if (idx < rows.grid_track_size_list().track_list().size() - 1)
builder.append(' ');
idx++;
}
return MUST(builder.to_string());
};
if (columns.grid_track_size_list().track_list().size() == 0)
return MUST(String::formatted("{}", construct_rows_string()));
if (areas.grid_template_area().is_empty())
return MUST(String::formatted("{} / {}", rows.grid_track_size_list().to_string(mode), columns.grid_track_size_list().to_string(mode)));
auto rows_serialization = construct_rows_string();
if (rows_serialization.is_empty())
return String {};
if (columns.grid_track_size_list().is_empty())
return MUST(String::formatted("{}", rows_serialization));
return MUST(String::formatted("{} / {}", construct_rows_string(), columns.grid_track_size_list().to_string(mode)));
}
case PropertyID::GridColumn: {

View File

@ -2,8 +2,8 @@ Harness status: OK
Found 141 tests
100 Pass
41 Fail
101 Pass
40 Fail
Fail e.style.cssText = grid: auto-flow auto / 100px 100px should set grid
Fail e.style.cssText = grid: auto-flow auto / 100px 100px should set grid-template-areas
Pass e.style.cssText = grid: auto-flow auto / 100px 100px; grid-template-areas: "one two" "three four" should set grid
@ -41,7 +41,7 @@ Fail e.style.cssText = grid: auto-flow / 10px; grid-template-columns: repeat(aut
Pass e.style.cssText = grid: auto-flow / 10px; grid-template-columns: repeat(auto-fit, 20px) should set grid-template-columns
Pass e.style.cssText = grid: auto-flow 1px / 2px; grid-auto-flow: inherit should set grid
Pass e.style.cssText = grid: 1px / 2px; grid-auto-flow: row should set grid
Fail e.style.cssText = grid: none / 2px; grid-auto-flow: row should set grid
Pass e.style.cssText = grid: none / 2px; grid-auto-flow: row should set grid
Pass e.style.cssText = grid: 1px / 2px; grid-auto-columns: auto should set grid
Pass e.style.cssText = grid: 1px / 2px; grid-auto-rows: auto should set grid
Fail e.style.cssText = grid: 1px / auto-flow 2px; grid-auto-rows: auto should set grid

View File

@ -2,46 +2,46 @@ Harness status: OK
Found 49 tests
8 Pass
41 Fail
38 Pass
11 Fail
Pass e.style['grid'] = "none" should set the property value
Pass e.style['grid'] = "none / none" should set the property value
Pass e.style['grid'] = "auto / auto" should set the property value
Fail e.style['grid'] = "none / [a] 0px" should set the property value
Fail e.style['grid'] = "none / [] 0px" should set the property value
Fail e.style['grid'] = "[a] 10px / auto" should set the property value
Fail e.style['grid'] = "[a] 10px / none" should set the property value
Pass e.style['grid'] = "none / [a] 0px" should set the property value
Pass e.style['grid'] = "none / [] 0px" should set the property value
Pass e.style['grid'] = "[a] 10px / auto" should set the property value
Pass e.style['grid'] = "[a] 10px / none" should set the property value
Pass e.style['grid'] = "[] 10px [] / [] auto []" should set the property value
Fail e.style['grid'] = "[a] \"a\" 10px" should set the property value
Fail e.style['grid'] = "[a] \"a\" 10px []" should set the property value
Pass e.style['grid'] = "[a] \"a\" 10px" should set the property value
Pass e.style['grid'] = "[a] \"a\" 10px []" should set the property value
Pass e.style['grid'] = "\"a\" 10px" should set the property value
Pass e.style['grid'] = "[] \"a\" 10px" should set the property value
Fail e.style['grid'] = "[a] \"a\" 10px [a]" should set the property value
Fail e.style['grid'] = "\"a\"" should set the property value
Fail e.style['grid'] = "\"a\" auto" should set the property value
Fail e.style['grid'] = "\"a a a\"" should set the property value
Fail e.style['grid'] = "\"a\" / 10px" should set the property value
Fail e.style['grid'] = "\"a\" / 20%" should set the property value
Fail e.style['grid'] = "\"a\" / 5fr" should set the property value
Fail e.style['grid'] = "[a] \"a\"" should set the property value
Fail e.style['grid'] = "[a] \"a\" [a]" should set the property value
Fail e.style['grid'] = "[] \"a\"" should set the property value
Fail e.style['grid'] = "\"a\" [] [] \"b\"" should set the property value
Fail e.style['grid'] = "\"a\" [] \"b\"" should set the property value
Fail e.style['grid'] = "\"a\" [a] [b] \"b\"" should set the property value
Fail e.style['grid'] = "\"a\" [a] \"b\"" should set the property value
Fail e.style['grid'] = "\"a\" / 0" should set the property value
Pass e.style['grid'] = "[a] \"a\" 10px [a]" should set the property value
Pass e.style['grid'] = "\"a\"" should set the property value
Pass e.style['grid'] = "\"a\" auto" should set the property value
Pass e.style['grid'] = "\"a a a\"" should set the property value
Pass e.style['grid'] = "\"a\" / 10px" should set the property value
Pass e.style['grid'] = "\"a\" / 20%" should set the property value
Pass e.style['grid'] = "\"a\" / 5fr" should set the property value
Pass e.style['grid'] = "[a] \"a\"" should set the property value
Pass e.style['grid'] = "[a] \"a\" [a]" should set the property value
Pass e.style['grid'] = "[] \"a\"" should set the property value
Pass e.style['grid'] = "\"a\" [] [] \"b\"" should set the property value
Pass e.style['grid'] = "\"a\" [] \"b\"" should set the property value
Pass e.style['grid'] = "\"a\" [a] [b] \"b\"" should set the property value
Pass e.style['grid'] = "\"a\" [a] \"b\"" should set the property value
Pass e.style['grid'] = "\"a\" / 0" should set the property value
Pass e.style['grid'] = "\"a\" 10px / 10px" should set the property value
Fail e.style['grid'] = "\"a\" [a] \"b\" 10px" should set the property value
Fail e.style['grid'] = "\"a\" [a] \"b\" 10px [a]" should set the property value
Fail e.style['grid'] = "\"a\" [a] [a] \"b\" 10px" should set the property value
Fail e.style['grid'] = "\"a\" [a] [] \"b\" 10px" should set the property value
Fail e.style['grid'] = "\"a\" 10px [a] \"b\" [a]" should set the property value
Fail e.style['grid'] = "\"a\" [a] \"b\" [a]" should set the property value
Pass e.style['grid'] = "\"a\" [a] \"b\" 10px" should set the property value
Pass e.style['grid'] = "\"a\" [a] \"b\" 10px [a]" should set the property value
Pass e.style['grid'] = "\"a\" [a] [a] \"b\" 10px" should set the property value
Pass e.style['grid'] = "\"a\" [a] [] \"b\" 10px" should set the property value
Pass e.style['grid'] = "\"a\" 10px [a] \"b\" [a]" should set the property value
Pass e.style['grid'] = "\"a\" [a] \"b\" [a]" should set the property value
Fail e.style['grid'] = "[a] \"a\" [a] \"b\" [a]" should set the property value
Fail e.style['grid'] = "\"a\" \"a\" [a] \"b\" [a]" should set the property value
Fail e.style['grid'] = "\"a\" [a] \"b\" [a] / 0" should set the property value
Fail e.style['grid'] = "\"a\" \"a\" [a] [a] \"b\" / auto" should set the property value
Pass e.style['grid'] = "\"a\" \"a\" [a] \"b\" [a]" should set the property value
Pass e.style['grid'] = "\"a\" [a] \"b\" [a] / 0" should set the property value
Pass e.style['grid'] = "\"a\" \"a\" [a] [a] \"b\" / auto" should set the property value
Fail e.style['grid'] = "100px / auto-flow dense 100px" should set the property value
Fail e.style['grid'] = "auto-flow dense 1fr / 100px" should set the property value
Fail e.style['grid'] = "100px / dense auto-flow 100px" should set the property value

View File

@ -2,11 +2,10 @@ Harness status: OK
Found 6 tests
3 Pass
3 Fail
Fail grid-template: none / 1px and "grid-template-areas: "a";" should be valid.
6 Pass
Pass grid-template: none / 1px and "grid-template-areas: "a";" should be valid.
Pass grid-template: none / none and "grid-template-areas: "a";" should be valid.
Pass grid-template: none / none and "grid-template-areas: "a" "b" "c" "d" "e";" should be valid.
Fail grid-template: auto / 1px and "grid-template-areas: "a a a";" should be valid.
Fail grid-template: auto / auto and "grid-template-areas: "a a a";" should be valid.
Pass grid-template: auto / 1px and "grid-template-areas: "a a a";" should be valid.
Pass grid-template: auto / auto and "grid-template-areas: "a a a";" should be valid.
Pass grid-template: 10px 20px 30px / 40px 50px 60px 70px and "grid-template-areas: "a . b ." "c d . e" "f g h .";" should be valid.

View File

@ -2,45 +2,45 @@ Harness status: OK
Found 40 tests
8 Pass
32 Fail
39 Pass
1 Fail
Pass e.style['grid-template'] = "none" should set the property value
Pass e.style['grid-template'] = "none / none" should set the property value
Pass e.style['grid-template'] = "auto / auto" should set the property value
Fail e.style['grid-template'] = "none / [a] 0px" should set the property value
Fail e.style['grid-template'] = "none / [] 0px" should set the property value
Fail e.style['grid-template'] = "[a] 10px / auto" should set the property value
Fail e.style['grid-template'] = "[a] 10px / none" should set the property value
Pass e.style['grid-template'] = "none / [a] 0px" should set the property value
Pass e.style['grid-template'] = "none / [] 0px" should set the property value
Pass e.style['grid-template'] = "[a] 10px / auto" should set the property value
Pass e.style['grid-template'] = "[a] 10px / none" should set the property value
Pass e.style['grid-template'] = "[] 10px [] / [] auto []" should set the property value
Fail e.style['grid-template'] = "[a] \"a\" 10px" should set the property value
Fail e.style['grid-template'] = "[a] \"a\" 10px []" should set the property value
Pass e.style['grid-template'] = "[a] \"a\" 10px" should set the property value
Pass e.style['grid-template'] = "[a] \"a\" 10px []" should set the property value
Pass e.style['grid-template'] = "\"a\" 10px" should set the property value
Pass e.style['grid-template'] = "[] \"a\" 10px" should set the property value
Fail e.style['grid-template'] = "[a] \"a\" 10px [a]" should set the property value
Fail e.style['grid-template'] = "\"a\"" should set the property value
Fail e.style['grid-template'] = "\"a\" auto" should set the property value
Fail e.style['grid-template'] = "\"a a a\"" should set the property value
Fail e.style['grid-template'] = "\"a\" / 10px" should set the property value
Fail e.style['grid-template'] = "\"a\" / 20%" should set the property value
Fail e.style['grid-template'] = "\"a\" / 5fr" should set the property value
Fail e.style['grid-template'] = "[a] \"a\"" should set the property value
Fail e.style['grid-template'] = "[a] \"a\" [a]" should set the property value
Fail e.style['grid-template'] = "[] \"a\"" should set the property value
Fail e.style['grid-template'] = "\"a\" [] [] \"b\"" should set the property value
Fail e.style['grid-template'] = "\"a\" [] \"b\"" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] [b] \"b\"" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] \"b\"" should set the property value
Fail e.style['grid-template'] = "\"a\" / 0" should set the property value
Pass e.style['grid-template'] = "[a] \"a\" 10px [a]" should set the property value
Pass e.style['grid-template'] = "\"a\"" should set the property value
Pass e.style['grid-template'] = "\"a\" auto" should set the property value
Pass e.style['grid-template'] = "\"a a a\"" should set the property value
Pass e.style['grid-template'] = "\"a\" / 10px" should set the property value
Pass e.style['grid-template'] = "\"a\" / 20%" should set the property value
Pass e.style['grid-template'] = "\"a\" / 5fr" should set the property value
Pass e.style['grid-template'] = "[a] \"a\"" should set the property value
Pass e.style['grid-template'] = "[a] \"a\" [a]" should set the property value
Pass e.style['grid-template'] = "[] \"a\"" should set the property value
Pass e.style['grid-template'] = "\"a\" [] [] \"b\"" should set the property value
Pass e.style['grid-template'] = "\"a\" [] \"b\"" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] [b] \"b\"" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] \"b\"" should set the property value
Pass e.style['grid-template'] = "\"a\" / 0" should set the property value
Pass e.style['grid-template'] = "\"a\" 10px / 10px" should set the property value
Pass e.style['grid-template'] = "\"a\" calc(100% - 10px) / calc(10px)" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] \"b\" 10px" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] \"b\" 10px [a]" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] [a] \"b\" 10px" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] [] \"b\" 10px" should set the property value
Fail e.style['grid-template'] = "\"a\" 10px [a] \"b\" [a]" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] \"b\" [a]" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] \"b\" 10px" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] \"b\" 10px [a]" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] [a] \"b\" 10px" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] [] \"b\" 10px" should set the property value
Pass e.style['grid-template'] = "\"a\" 10px [a] \"b\" [a]" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] \"b\" [a]" should set the property value
Fail e.style['grid-template'] = "[a] \"a\" [a] \"b\" [a]" should set the property value
Fail e.style['grid-template'] = "\"a\" \"a\" [a] \"b\" [a]" should set the property value
Fail e.style['grid-template'] = "\"a\" [a] \"b\" [a] / 0" should set the property value
Fail e.style['grid-template'] = "\"a\" \"a\" [a] [a] \"b\" / auto" should set the property value
Fail e.style['grid-template'] = "\"a\" auto [a] \"b\" auto [b] / 10px" should set the property value
Pass e.style['grid-template'] = "\"a\" \"a\" [a] \"b\" [a]" should set the property value
Pass e.style['grid-template'] = "\"a\" [a] \"b\" [a] / 0" should set the property value
Pass e.style['grid-template'] = "\"a\" \"a\" [a] [a] \"b\" / auto" should set the property value
Pass e.style['grid-template'] = "\"a\" auto [a] \"b\" auto [b] / 10px" should set the property value