mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb: Implement new StyleValueList
StyleValueList is a list of StyleValues of the same type, for use in properties like `margin` which accept a variable number of arguments. I had originally hoped to simply swap the old ValueListStyleValue from being a list of ComponentValues to one of StyleValues, but I can see now that I will need to have both for a little while, so renamed the old is_value_list() to is_component_value_list() temporarily.
This commit is contained in:
parent
81527f5eba
commit
21c9825caf
3 changed files with 50 additions and 19 deletions
|
@ -542,7 +542,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (!parts.is_empty() && parts.size() <= 3) {
|
||||
RefPtr<StyleValue> color_value;
|
||||
|
@ -614,7 +614,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 2) {
|
||||
auto diagonal1 = Parser::parse_css_value(context, property_id, parts[0]);
|
||||
|
@ -691,7 +691,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
if (parts.size() == 1) {
|
||||
|
@ -746,7 +746,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::BorderStyle) {
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 4) {
|
||||
auto top = Parser::parse_css_value(context, property_id, parts[0]);
|
||||
|
@ -799,7 +799,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::BorderWidth) {
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 4) {
|
||||
auto top_border_width = Parser::parse_css_value(context, property_id, parts[0]);
|
||||
|
@ -851,7 +851,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::BorderColor) {
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 4) {
|
||||
auto top = Parser::parse_css_value(context, property_id, parts[0]);
|
||||
|
@ -918,7 +918,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
RefPtr<StyleValue> background_color_value;
|
||||
|
@ -1026,7 +1026,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
// FIXME: Handle multiple backgrounds.
|
||||
if (!parts.is_empty()) {
|
||||
|
@ -1059,7 +1059,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
assign_background_repeat_from_single_value(value);
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
NonnullRefPtrVector<StyleValue> repeat_values;
|
||||
for (auto& part : parts) {
|
||||
|
@ -1100,7 +1100,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 2) {
|
||||
auto vertical = Parser::parse_css_value(context, property_id, parts[0]);
|
||||
|
@ -1151,7 +1151,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 2) {
|
||||
auto vertical = Parser::parse_css_value(context, property_id, parts[0]);
|
||||
|
@ -1194,7 +1194,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::ListStyle) {
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
if (!parts.is_empty() && parts.size() <= 3) {
|
||||
|
@ -1251,7 +1251,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::Font) {
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
RefPtr<StyleValue> font_style_value;
|
||||
|
@ -1352,7 +1352,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::FontFamily) {
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
// FIXME: Handle multiple font-families separated by commas, for fallback purposes.
|
||||
for (auto& part : parts) {
|
||||
|
@ -1380,7 +1380,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 1) {
|
||||
auto value = Parser::parse_css_value(context, property_id, parts[0]);
|
||||
|
@ -1434,7 +1434,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::FlexFlow) {
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.is_empty() || parts.size() > 2)
|
||||
return;
|
||||
|
@ -1471,7 +1471,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
if (value.is_component_value_list()) {
|
||||
dbgln("Values list for CSS property '{}' went unhandled. List: '{}'", string_from_property_id(property_id), value.to_string());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ void ImageStyleValue::resource_did_load()
|
|||
}
|
||||
|
||||
ValueListStyleValue::ValueListStyleValue(Vector<StyleComponentValueRule>&& values)
|
||||
: StyleValue(Type::ValueList)
|
||||
: StyleValue(Type::ComponentValueList)
|
||||
, m_values(move(values))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -227,6 +227,7 @@ public:
|
|||
CustomProperty,
|
||||
Numeric,
|
||||
ValueList,
|
||||
ComponentValueList,
|
||||
Calculated,
|
||||
BoxShadow,
|
||||
};
|
||||
|
@ -243,8 +244,9 @@ public:
|
|||
bool is_custom_property() const { return type() == Type::CustomProperty; }
|
||||
bool is_numeric() const { return type() == Type::Numeric; }
|
||||
bool is_value_list() const { return type() == Type::ValueList; }
|
||||
bool is_box_shadow() const { return type() == Type::BoxShadow; }
|
||||
bool is_component_value_list() const { return type() == Type::ComponentValueList; }
|
||||
bool is_calculated() const { return type() == Type::Calculated; }
|
||||
bool is_box_shadow() const { return type() == Type::BoxShadow; }
|
||||
|
||||
bool is_builtin() const { return is_inherit() || is_initial(); }
|
||||
|
||||
|
@ -621,6 +623,35 @@ private:
|
|||
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||
};
|
||||
|
||||
class StyleValueList final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<StyleValueList> create(NonnullRefPtrVector<StyleValue>&& values) { return adopt_ref(*new StyleValueList(move(values))); }
|
||||
|
||||
NonnullRefPtrVector<StyleValue> const& values() const { return m_values; }
|
||||
|
||||
virtual String to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.appendff("List[{}](", m_values.size());
|
||||
for (size_t i = 0; i < m_values.size(); ++i) {
|
||||
if (i)
|
||||
builder.append(',');
|
||||
builder.append(m_values[i].to_string());
|
||||
}
|
||||
builder.append(')');
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
private:
|
||||
StyleValueList(NonnullRefPtrVector<StyleValue>&& values)
|
||||
: StyleValue(Type::ValueList)
|
||||
, m_values(move(values))
|
||||
{
|
||||
}
|
||||
|
||||
NonnullRefPtrVector<StyleValue> m_values;
|
||||
};
|
||||
|
||||
class ValueListStyleValue final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<ValueListStyleValue> create(Vector<StyleComponentValueRule>&& values) { return adopt_ref(*new ValueListStyleValue(move(values))); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue