mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibWeb: Properly serialize position/edge style values
This commit is contained in:
parent
583ca6af89
commit
84150f972f
Notes:
github-actions[bot]
2024-12-13 11:36:34 +00:00
Author: https://github.com/Gingeh
Commit: 84150f972f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2651
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/awesomekling
21 changed files with 461 additions and 288 deletions
|
@ -14,31 +14,45 @@ namespace Web::CSS {
|
|||
|
||||
class EdgeStyleValue final : public StyleValueWithDefaultOperators<EdgeStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<EdgeStyleValue> create(PositionEdge edge, LengthPercentage const& offset)
|
||||
static ValueComparingNonnullRefPtr<EdgeStyleValue> create(Optional<PositionEdge> edge, Optional<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; }
|
||||
Optional<PositionEdge> edge() const
|
||||
{
|
||||
if (m_properties.edge == PositionEdge::Center)
|
||||
return {};
|
||||
|
||||
return m_properties.edge;
|
||||
}
|
||||
|
||||
LengthPercentage offset() const
|
||||
{
|
||||
if (m_properties.edge == PositionEdge::Center)
|
||||
return Percentage(50);
|
||||
|
||||
if (!m_properties.offset.has_value())
|
||||
return Percentage(0);
|
||||
|
||||
return m_properties.offset.value();
|
||||
}
|
||||
|
||||
virtual String to_string(SerializationMode) const override;
|
||||
|
||||
bool properties_equal(EdgeStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
EdgeStyleValue(PositionEdge edge, LengthPercentage const& offset)
|
||||
EdgeStyleValue(Optional<PositionEdge> edge, Optional<LengthPercentage> const& offset)
|
||||
: StyleValueWithDefaultOperators(Type::Edge)
|
||||
, m_properties { .edge = edge, .offset = offset }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
PositionEdge edge;
|
||||
LengthPercentage offset;
|
||||
Optional<PositionEdge> edge;
|
||||
Optional<LengthPercentage> offset;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue