mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +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
Notes:
sideshowbarker
2024-07-18 00:41:35 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/763b08c23f Pull-request: https://github.com/SerenityOS/serenity/pull/21829
6 changed files with 0 additions and 373 deletions
|
@ -40,7 +40,6 @@ source_set("CSS") {
|
|||
"MediaQueryList.cpp",
|
||||
"MediaQueryListEvent.cpp",
|
||||
"PercentageOr.cpp",
|
||||
"Position.cpp",
|
||||
"PreferredColorScheme.cpp",
|
||||
"Ratio.cpp",
|
||||
"Resolution.cpp",
|
||||
|
|
|
@ -67,7 +67,6 @@ set(SOURCES
|
|||
CSS/Parser/Token.cpp
|
||||
CSS/Parser/Tokenizer.cpp
|
||||
CSS/PercentageOr.cpp
|
||||
CSS/Position.cpp
|
||||
CSS/PreferredColorScheme.cpp
|
||||
CSS/Ratio.cpp
|
||||
CSS/Resolution.cpp
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <LibWeb/CSS/Parser/Rule.h>
|
||||
#include <LibWeb/CSS/Parser/TokenStream.h>
|
||||
#include <LibWeb/CSS/Parser/Tokenizer.h>
|
||||
#include <LibWeb/CSS/Position.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/Ratio.h>
|
||||
#include <LibWeb/CSS/Selector.h>
|
||||
|
@ -183,7 +182,6 @@ private:
|
|||
Optional<GridMinMax> parse_min_max(Vector<ComponentValue> const&);
|
||||
Optional<GridRepeat> parse_repeat(Vector<ComponentValue> const&);
|
||||
Optional<ExplicitGridTrack> parse_track_sizing_function(ComponentValue const&);
|
||||
Optional<PositionValue> parse_position(TokenStream<ComponentValue>&, PositionValue initial_value = PositionValue::center());
|
||||
|
||||
Optional<AK::URL> parse_url_function(ComponentValue const&);
|
||||
RefPtr<StyleValue> parse_url_value(ComponentValue const&);
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Position.h"
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
CSSPixelPoint PositionValue::resolved(Layout::Node const& node, CSSPixelRect const& rect) const
|
||||
{
|
||||
// Note: A preset + a none default x/y_relative_to is impossible in the syntax (and makes little sense)
|
||||
CSSPixels x = horizontal_position.visit(
|
||||
[&](HorizontalPreset preset) -> CSSPixels {
|
||||
switch (preset) {
|
||||
case HorizontalPreset::Left:
|
||||
return 0;
|
||||
case HorizontalPreset::Center:
|
||||
return rect.width() / 2;
|
||||
case HorizontalPreset::Right:
|
||||
return rect.width();
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
},
|
||||
[&](LengthPercentage length_percentage) -> CSSPixels {
|
||||
return length_percentage.to_px(node, rect.width());
|
||||
});
|
||||
CSSPixels y = vertical_position.visit(
|
||||
[&](VerticalPreset preset) -> CSSPixels {
|
||||
switch (preset) {
|
||||
case VerticalPreset::Top:
|
||||
return 0;
|
||||
case VerticalPreset::Center:
|
||||
return rect.height() / 2;
|
||||
case VerticalPreset::Bottom:
|
||||
return rect.height();
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
},
|
||||
[&](LengthPercentage length_percentage) -> CSSPixels {
|
||||
return length_percentage.to_px(node, rect.height());
|
||||
});
|
||||
if (x_relative_to == HorizontalEdge::Right)
|
||||
x = rect.width() - x;
|
||||
if (y_relative_to == VerticalEdge::Bottom)
|
||||
y = rect.height() - y;
|
||||
return CSSPixelPoint { rect.x() + x, rect.y() + y };
|
||||
}
|
||||
|
||||
void PositionValue::serialize(StringBuilder& builder) const
|
||||
{
|
||||
// Note: This means our serialization with simplify any with explicit edges that are just `top left`.
|
||||
bool has_relative_edges = x_relative_to == HorizontalEdge::Right || y_relative_to == VerticalEdge::Bottom;
|
||||
if (has_relative_edges)
|
||||
builder.append(x_relative_to == HorizontalEdge::Left ? "left "sv : "right "sv);
|
||||
horizontal_position.visit(
|
||||
[&](HorizontalPreset preset) {
|
||||
builder.append([&] {
|
||||
switch (preset) {
|
||||
case HorizontalPreset::Left:
|
||||
return "left"sv;
|
||||
case HorizontalPreset::Center:
|
||||
return "center"sv;
|
||||
case HorizontalPreset::Right:
|
||||
return "right"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}());
|
||||
},
|
||||
[&](LengthPercentage length_percentage) {
|
||||
builder.append(length_percentage.to_string());
|
||||
});
|
||||
builder.append(' ');
|
||||
if (has_relative_edges)
|
||||
builder.append(y_relative_to == VerticalEdge::Top ? "top "sv : "bottom "sv);
|
||||
vertical_position.visit(
|
||||
[&](VerticalPreset preset) {
|
||||
builder.append([&] {
|
||||
switch (preset) {
|
||||
case VerticalPreset::Top:
|
||||
return "top"sv;
|
||||
case VerticalPreset::Center:
|
||||
return "center"sv;
|
||||
case VerticalPreset::Bottom:
|
||||
return "bottom"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}());
|
||||
},
|
||||
[&](LengthPercentage length_percentage) {
|
||||
builder.append(length_percentage.to_string());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/PercentageOr.h>
|
||||
#include <LibWeb/PixelUnits.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
// FIXME: Named PositionValue to avoid conflicts with enums, but this represents a <position>
|
||||
struct PositionValue {
|
||||
enum class HorizontalPreset {
|
||||
Left,
|
||||
Center,
|
||||
Right
|
||||
};
|
||||
|
||||
enum class VerticalPreset {
|
||||
Top,
|
||||
Center,
|
||||
Bottom
|
||||
};
|
||||
|
||||
enum class HorizontalEdge {
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
|
||||
enum class VerticalEdge {
|
||||
Top,
|
||||
Bottom
|
||||
};
|
||||
|
||||
static PositionValue center()
|
||||
{
|
||||
return PositionValue { HorizontalPreset::Center, VerticalPreset::Center };
|
||||
}
|
||||
|
||||
Variant<HorizontalPreset, LengthPercentage> horizontal_position { HorizontalPreset::Left };
|
||||
Variant<VerticalPreset, LengthPercentage> vertical_position { VerticalPreset::Top };
|
||||
HorizontalEdge x_relative_to { HorizontalEdge::Left };
|
||||
VerticalEdge y_relative_to { VerticalEdge::Top };
|
||||
|
||||
CSSPixelPoint resolved(Layout::Node const& node, CSSPixelRect const& rect) const;
|
||||
void serialize(StringBuilder&) const;
|
||||
bool operator==(PositionValue const&) const = default;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue