1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibWeb: Adapt parse_position() into parse_position_value()

Having two ways that `<position>` is represented is awkward and
unnecessary. So, let's combine the two paths together. This first step
copies and modifies the `parse_position()` code to produce a
`PositionStyleValue`.

Apart from returning a StyleValue, this also makes use of automatic enum
parsing instead of manually comparing identifier strings.
This commit is contained in:
Sam Atkins 2023-11-07 11:50:44 +00:00 committed by Sam Atkins
parent 4ad58f0204
commit 8917378aa7
4 changed files with 206 additions and 0 deletions

View file

@ -16,10 +16,12 @@ class EdgeStyleValue final : public StyleValueWithDefaultOperators<EdgeStyleValu
public:
static ValueComparingNonnullRefPtr<EdgeStyleValue> create(PositionEdge edge, LengthPercentage const& offset)
{
VERIFY(edge != PositionEdge::Center);
return adopt_ref(*new (nothrow) EdgeStyleValue(edge, offset));
}
virtual ~EdgeStyleValue() override = default;
// NOTE: `center` is converted to `left 50%` or `top 50%` in parsing, so is never returned here.
PositionEdge edge() const { return m_properties.edge; }
LengthPercentage const& offset() const { return m_properties.offset; }