mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 14:05:09 +00:00
LibWeb: Remove now-unused CSS::PositionValue type and associated parsing
All the users now use PositionStyleValue instead.
This commit is contained in:
parent
7bcabbb325
commit
763b08c23f
6 changed files with 0 additions and 373 deletions
|
@ -1189,220 +1189,6 @@ RefPtr<StyleValue> Parser::parse_url_value(ComponentValue const& component_value
|
|||
return URLStyleValue::create(*url);
|
||||
}
|
||||
|
||||
Optional<PositionValue> Parser::parse_position(TokenStream<ComponentValue>& tokens, PositionValue initial_value)
|
||||
{
|
||||
auto transaction = tokens.begin_transaction();
|
||||
tokens.skip_whitespace();
|
||||
if (!tokens.has_next_token())
|
||||
return {};
|
||||
|
||||
auto parse_horizontal_preset = [&](auto ident) -> Optional<PositionValue::HorizontalPreset> {
|
||||
if (ident.equals_ignoring_ascii_case("left"sv))
|
||||
return PositionValue::HorizontalPreset::Left;
|
||||
if (ident.equals_ignoring_ascii_case("center"sv))
|
||||
return PositionValue::HorizontalPreset::Center;
|
||||
if (ident.equals_ignoring_ascii_case("right"sv))
|
||||
return PositionValue::HorizontalPreset::Right;
|
||||
return {};
|
||||
};
|
||||
|
||||
auto parse_vertical_preset = [&](auto ident) -> Optional<PositionValue::VerticalPreset> {
|
||||
if (ident.equals_ignoring_ascii_case("top"sv))
|
||||
return PositionValue::VerticalPreset::Top;
|
||||
if (ident.equals_ignoring_ascii_case("center"sv))
|
||||
return PositionValue::VerticalPreset::Center;
|
||||
if (ident.equals_ignoring_ascii_case("bottom"sv))
|
||||
return PositionValue::VerticalPreset::Bottom;
|
||||
return {};
|
||||
};
|
||||
|
||||
auto parse_horizontal_edge = [&](auto ident) -> Optional<PositionValue::HorizontalEdge> {
|
||||
if (ident.equals_ignoring_ascii_case("left"sv))
|
||||
return PositionValue::HorizontalEdge::Left;
|
||||
if (ident.equals_ignoring_ascii_case("right"sv))
|
||||
return PositionValue::HorizontalEdge::Right;
|
||||
return {};
|
||||
};
|
||||
|
||||
auto parse_vertical_edge = [&](auto ident) -> Optional<PositionValue::VerticalEdge> {
|
||||
if (ident.equals_ignoring_ascii_case("top"sv))
|
||||
return PositionValue::VerticalEdge::Top;
|
||||
if (ident.equals_ignoring_ascii_case("bottom"sv))
|
||||
return PositionValue::VerticalEdge::Bottom;
|
||||
return {};
|
||||
};
|
||||
|
||||
// <position> = [
|
||||
// [ left | center | right ] || [ top | center | bottom ]
|
||||
// |
|
||||
// [ left | center | right | <length-percentage> ]
|
||||
// [ top | center | bottom | <length-percentage> ]?
|
||||
// |
|
||||
// [ [ left | right ] <length-percentage> ] &&
|
||||
// [ [ top | bottom ] <length-percentage> ]
|
||||
// ]
|
||||
|
||||
// [ left | center | right ] || [ top | center | bottom ]
|
||||
auto alternation_1 = [&]() -> Optional<PositionValue> {
|
||||
auto transaction = tokens.begin_transaction();
|
||||
PositionValue position = initial_value;
|
||||
auto& first_token = tokens.next_token();
|
||||
if (!first_token.is(Token::Type::Ident))
|
||||
return {};
|
||||
auto ident = first_token.token().ident();
|
||||
// <horizontal-position> <vertical-position>?
|
||||
auto horizontal_position = parse_horizontal_preset(ident);
|
||||
if (horizontal_position.has_value()) {
|
||||
position.horizontal_position = *horizontal_position;
|
||||
auto transaction_optional_parse = tokens.begin_transaction();
|
||||
tokens.skip_whitespace();
|
||||
if (tokens.has_next_token()) {
|
||||
auto& second_token = tokens.next_token();
|
||||
if (second_token.is(Token::Type::Ident)) {
|
||||
auto vertical_position = parse_vertical_preset(second_token.token().ident());
|
||||
if (vertical_position.has_value()) {
|
||||
transaction_optional_parse.commit();
|
||||
position.vertical_position = *vertical_position;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// <vertical-position> <horizontal-position>?
|
||||
auto vertical_position = parse_vertical_preset(ident);
|
||||
if (!vertical_position.has_value())
|
||||
return {};
|
||||
position.vertical_position = *vertical_position;
|
||||
auto transaction_optional_parse = tokens.begin_transaction();
|
||||
tokens.skip_whitespace();
|
||||
if (tokens.has_next_token()) {
|
||||
auto& second_token = tokens.next_token();
|
||||
if (second_token.is(Token::Type::Ident)) {
|
||||
auto horizontal_position = parse_horizontal_preset(second_token.token().ident());
|
||||
if (horizontal_position.has_value()) {
|
||||
transaction_optional_parse.commit();
|
||||
position.horizontal_position = *horizontal_position;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
transaction.commit();
|
||||
return position;
|
||||
};
|
||||
|
||||
// [ left | center | right | <length-percentage> ]
|
||||
// [ top | center | bottom | <length-percentage> ]?
|
||||
auto alternation_2 = [&]() -> Optional<PositionValue> {
|
||||
auto transaction = tokens.begin_transaction();
|
||||
PositionValue position = initial_value;
|
||||
auto& first_token = tokens.next_token();
|
||||
if (first_token.is(Token::Type::Ident)) {
|
||||
auto horizontal_position = parse_horizontal_preset(first_token.token().ident());
|
||||
if (!horizontal_position.has_value())
|
||||
return {};
|
||||
position.horizontal_position = *horizontal_position;
|
||||
} else {
|
||||
auto dimension = parse_dimension(first_token);
|
||||
if (!dimension.has_value() || !dimension->is_length_percentage())
|
||||
return {};
|
||||
position.horizontal_position = dimension->length_percentage();
|
||||
}
|
||||
auto transaction_optional_parse = tokens.begin_transaction();
|
||||
tokens.skip_whitespace();
|
||||
if (tokens.has_next_token()) {
|
||||
auto& second_token = tokens.next_token();
|
||||
if (second_token.is(Token::Type::Ident)) {
|
||||
auto vertical_position = parse_vertical_preset(second_token.token().ident());
|
||||
if (vertical_position.has_value()) {
|
||||
transaction_optional_parse.commit();
|
||||
position.vertical_position = *vertical_position;
|
||||
}
|
||||
} else {
|
||||
auto dimension = parse_dimension(second_token);
|
||||
if (dimension.has_value() && dimension->is_length_percentage()) {
|
||||
transaction_optional_parse.commit();
|
||||
position.vertical_position = dimension->length_percentage();
|
||||
}
|
||||
}
|
||||
}
|
||||
transaction.commit();
|
||||
return position;
|
||||
};
|
||||
|
||||
// [ [ left | right ] <length-percentage> ] &&
|
||||
// [ [ top | bottom ] <length-percentage> ]
|
||||
auto alternation_3 = [&]() -> Optional<PositionValue> {
|
||||
auto transaction = tokens.begin_transaction();
|
||||
PositionValue position {};
|
||||
|
||||
auto parse_horizontal = [&] {
|
||||
// [ left | right ] <length-percentage> ]
|
||||
auto transaction = tokens.begin_transaction();
|
||||
tokens.skip_whitespace();
|
||||
if (!tokens.has_next_token())
|
||||
return false;
|
||||
auto& first_token = tokens.next_token();
|
||||
if (!first_token.is(Token::Type::Ident))
|
||||
return false;
|
||||
auto horizontal_egde = parse_horizontal_edge(first_token.token().ident());
|
||||
if (!horizontal_egde.has_value())
|
||||
return false;
|
||||
position.x_relative_to = *horizontal_egde;
|
||||
tokens.skip_whitespace();
|
||||
if (!tokens.has_next_token())
|
||||
return false;
|
||||
auto& second_token = tokens.next_token();
|
||||
auto dimension = parse_dimension(second_token);
|
||||
if (!dimension.has_value() || !dimension->is_length_percentage())
|
||||
return false;
|
||||
position.horizontal_position = dimension->length_percentage();
|
||||
transaction.commit();
|
||||
return true;
|
||||
};
|
||||
|
||||
auto parse_vertical = [&] {
|
||||
// [ top | bottom ] <length-percentage> ]
|
||||
auto transaction = tokens.begin_transaction();
|
||||
tokens.skip_whitespace();
|
||||
if (!tokens.has_next_token())
|
||||
return false;
|
||||
auto& first_token = tokens.next_token();
|
||||
if (!first_token.is(Token::Type::Ident))
|
||||
return false;
|
||||
auto vertical_edge = parse_vertical_edge(first_token.token().ident());
|
||||
if (!vertical_edge.has_value())
|
||||
return false;
|
||||
position.y_relative_to = *vertical_edge;
|
||||
tokens.skip_whitespace();
|
||||
if (!tokens.has_next_token())
|
||||
return false;
|
||||
auto& second_token = tokens.next_token();
|
||||
auto dimension = parse_dimension(second_token);
|
||||
if (!dimension.has_value() || !dimension->is_length_percentage())
|
||||
return false;
|
||||
position.vertical_position = dimension->length_percentage();
|
||||
transaction.commit();
|
||||
return true;
|
||||
};
|
||||
|
||||
if ((parse_horizontal() && parse_vertical()) || (parse_vertical() && parse_horizontal())) {
|
||||
transaction.commit();
|
||||
return position;
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
// Note: The alternatives must be attempted in this order since `alternation_2' can match a prefix of `alternation_3'
|
||||
auto position = alternation_3();
|
||||
if (!position.has_value())
|
||||
position = alternation_2();
|
||||
if (!position.has_value())
|
||||
position = alternation_1();
|
||||
if (position.has_value())
|
||||
transaction.commit();
|
||||
return position;
|
||||
}
|
||||
|
||||
CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
|
||||
{
|
||||
if (rule->is_at_rule()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue