mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:57:35 +00:00
LibWeb: Use property_accepts_value() for parsing flexbox properties
This commit is contained in:
parent
37e69fb286
commit
e262596ee1
1 changed files with 5 additions and 46 deletions
|
@ -2066,24 +2066,6 @@ RefPtr<StyleValue> Parser::parse_box_shadow_value(ParsingContext const& context,
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_flex_value(ParsingContext const& context, Vector<StyleComponentValueRule> const& component_values)
|
RefPtr<StyleValue> Parser::parse_flex_value(ParsingContext const& context, Vector<StyleComponentValueRule> const& component_values)
|
||||||
{
|
{
|
||||||
auto is_flex_grow_or_shrink = [](StyleValue const& value) -> bool {
|
|
||||||
if (value.is_numeric())
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto is_flex_basis = [](StyleValue const& value) -> bool {
|
|
||||||
if (value.is_length())
|
|
||||||
return true;
|
|
||||||
switch (value.to_identifier()) {
|
|
||||||
case ValueID::Auto:
|
|
||||||
case ValueID::Content:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (component_values.size() == 1) {
|
if (component_values.size() == 1) {
|
||||||
auto value = parse_css_value(context, component_values[0]);
|
auto value = parse_css_value(context, component_values[0]);
|
||||||
if (!value)
|
if (!value)
|
||||||
|
@ -2120,7 +2102,7 @@ RefPtr<StyleValue> Parser::parse_flex_value(ParsingContext const& context, Vecto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_flex_grow_or_shrink(*value)) {
|
if (property_accepts_value(PropertyID::FlexGrow, *value)) {
|
||||||
if (flex_grow)
|
if (flex_grow)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
flex_grow = value.release_nonnull();
|
flex_grow = value.release_nonnull();
|
||||||
|
@ -2128,7 +2110,7 @@ RefPtr<StyleValue> Parser::parse_flex_value(ParsingContext const& context, Vecto
|
||||||
// Flex-shrink may optionally follow directly after.
|
// Flex-shrink may optionally follow directly after.
|
||||||
if (i + 1 < component_values.size()) {
|
if (i + 1 < component_values.size()) {
|
||||||
auto second_value = parse_css_value(context, component_values[i + 1]);
|
auto second_value = parse_css_value(context, component_values[i + 1]);
|
||||||
if (second_value && is_flex_grow_or_shrink(*second_value)) {
|
if (second_value && property_accepts_value(PropertyID::FlexShrink, *second_value)) {
|
||||||
flex_shrink = second_value.release_nonnull();
|
flex_shrink = second_value.release_nonnull();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -2136,7 +2118,7 @@ RefPtr<StyleValue> Parser::parse_flex_value(ParsingContext const& context, Vecto
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_flex_basis(*value)) {
|
if (property_accepts_value(PropertyID::FlexBasis, *value)) {
|
||||||
if (flex_basis)
|
if (flex_basis)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
flex_basis = value.release_nonnull();
|
flex_basis = value.release_nonnull();
|
||||||
|
@ -2158,29 +2140,6 @@ RefPtr<StyleValue> Parser::parse_flex_value(ParsingContext const& context, Vecto
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_flex_flow_value(ParsingContext const& context, Vector<StyleComponentValueRule> const& component_values)
|
RefPtr<StyleValue> Parser::parse_flex_flow_value(ParsingContext const& context, Vector<StyleComponentValueRule> const& component_values)
|
||||||
{
|
{
|
||||||
auto is_flex_direction = [](StyleValue const& value) -> bool {
|
|
||||||
switch (value.to_identifier()) {
|
|
||||||
case ValueID::Row:
|
|
||||||
case ValueID::RowReverse:
|
|
||||||
case ValueID::Column:
|
|
||||||
case ValueID::ColumnReverse:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
auto is_flex_wrap = [](StyleValue const& value) -> bool {
|
|
||||||
switch (value.to_identifier()) {
|
|
||||||
case ValueID::Wrap:
|
|
||||||
case ValueID::Nowrap:
|
|
||||||
case ValueID::WrapReverse:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (component_values.size() > 2)
|
if (component_values.size() > 2)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -2191,13 +2150,13 @@ RefPtr<StyleValue> Parser::parse_flex_flow_value(ParsingContext const& context,
|
||||||
auto value = parse_css_value(context, part);
|
auto value = parse_css_value(context, part);
|
||||||
if (!value)
|
if (!value)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (is_flex_direction(*value)) {
|
if (property_accepts_value(PropertyID::FlexDirection, *value)) {
|
||||||
if (flex_direction)
|
if (flex_direction)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
flex_direction = value.release_nonnull();
|
flex_direction = value.release_nonnull();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_flex_wrap(*value)) {
|
if (property_accepts_value(PropertyID::FlexWrap, *value)) {
|
||||||
if (flex_wrap)
|
if (flex_wrap)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
flex_wrap = value.release_nonnull();
|
flex_wrap = value.release_nonnull();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue