mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:47:35 +00:00
LibWeb: Replace GridTrackSizeListShorthandStyleValue with ShorthandSV
This commit is contained in:
parent
48f3603119
commit
f5cb2e8dc2
12 changed files with 49 additions and 125 deletions
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Martin Falisse <mfalisse@outlook.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "GridTrackSizeListShorthandStyleValue.h"
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListShorthandStyleValue> GridTrackSizeListShorthandStyleValue::create(
|
||||
ValueComparingNonnullRefPtr<GridTemplateAreaStyleValue const> areas,
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> rows,
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> columns)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) GridTrackSizeListShorthandStyleValue(move(areas), move(rows), move(columns)));
|
||||
}
|
||||
|
||||
String GridTrackSizeListShorthandStyleValue::to_string() const
|
||||
{
|
||||
auto construct_rows_string = [&]() {
|
||||
StringBuilder builder;
|
||||
size_t idx = 0;
|
||||
for (auto const& row : m_properties.rows->grid_track_size_list().track_list()) {
|
||||
if (m_properties.areas->grid_template_area().size() > idx) {
|
||||
builder.append("\""sv);
|
||||
for (size_t y = 0; y < m_properties.areas->grid_template_area()[idx].size(); ++y) {
|
||||
builder.append(m_properties.areas->grid_template_area()[idx][y]);
|
||||
if (y != m_properties.areas->grid_template_area()[idx].size() - 1)
|
||||
builder.append(" "sv);
|
||||
}
|
||||
builder.append("\" "sv);
|
||||
}
|
||||
builder.append(row.to_string());
|
||||
if (idx < m_properties.rows->grid_track_size_list().track_list().size() - 1)
|
||||
builder.append(' ');
|
||||
idx++;
|
||||
}
|
||||
return MUST(builder.to_string());
|
||||
};
|
||||
|
||||
if (m_properties.columns->grid_track_size_list().track_list().size() == 0)
|
||||
return MUST(String::formatted("{}", construct_rows_string()));
|
||||
return MUST(String::formatted("{} / {}", construct_rows_string(), m_properties.columns->grid_track_size_list().to_string()));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Martin Falisse <mfalisse@outlook.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class GridTrackSizeListShorthandStyleValue final : public StyleValueWithDefaultOperators<GridTrackSizeListShorthandStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<GridTrackSizeListShorthandStyleValue> create(
|
||||
ValueComparingNonnullRefPtr<GridTemplateAreaStyleValue const> areas,
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> rows,
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> columns);
|
||||
virtual ~GridTrackSizeListShorthandStyleValue() override = default;
|
||||
|
||||
auto rows() const { return m_properties.rows; }
|
||||
auto columns() const { return m_properties.columns; }
|
||||
auto areas() const { return m_properties.areas; }
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
||||
bool properties_equal(GridTrackSizeListShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
GridTrackSizeListShorthandStyleValue(
|
||||
ValueComparingNonnullRefPtr<GridTemplateAreaStyleValue const> areas,
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> rows,
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> columns)
|
||||
: StyleValueWithDefaultOperators(Type::GridTrackSizeListShorthand)
|
||||
, m_properties { .areas = move(areas), .rows = move(rows), .columns = move(columns) }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
ValueComparingNonnullRefPtr<GridTemplateAreaStyleValue const> areas;
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> rows;
|
||||
ValueComparingNonnullRefPtr<GridTrackSizeListStyleValue const> columns;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
}
|
|
@ -8,7 +8,9 @@
|
|||
#include "ShorthandStyleValue.h"
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -110,6 +112,38 @@ String ShorthandStyleValue::to_string() const
|
|||
if (!column_end.grid_track_placement().is_auto())
|
||||
builder.appendff(" / {}", column_end.grid_track_placement().to_string());
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
// FIXME: Serialize Grid differently once we support it better!
|
||||
case PropertyID::Grid:
|
||||
case PropertyID::GridTemplate: {
|
||||
auto& areas = longhand(PropertyID::GridTemplateAreas)->as_grid_template_area();
|
||||
auto& rows = longhand(PropertyID::GridTemplateRows)->as_grid_track_size_list();
|
||||
auto& columns = longhand(PropertyID::GridTemplateColumns)->as_grid_track_size_list();
|
||||
|
||||
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);
|
||||
}
|
||||
builder.append(row.to_string());
|
||||
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()));
|
||||
return MUST(String::formatted("{} / {}", construct_rows_string(), columns.grid_track_size_list().to_string()));
|
||||
}
|
||||
default:
|
||||
StringBuilder builder;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue