2023-04-02 22:56:45 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibWeb/CSS/Enums.h>
|
|
|
|
#include <LibWeb/CSS/PercentageOr.h>
|
2025-08-08 10:11:51 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
2023-04-02 22:56:45 +01:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
|
|
class EdgeStyleValue final : public StyleValueWithDefaultOperators<EdgeStyleValue> {
|
|
|
|
public:
|
2025-04-15 15:18:27 -06:00
|
|
|
static ValueComparingNonnullRefPtr<EdgeStyleValue const> create(Optional<PositionEdge> edge, Optional<LengthPercentage> const& offset)
|
2023-04-02 22:56:45 +01:00
|
|
|
{
|
2023-08-19 14:00:10 +01:00
|
|
|
return adopt_ref(*new (nothrow) EdgeStyleValue(edge, offset));
|
2023-04-02 22:56:45 +01:00
|
|
|
}
|
|
|
|
virtual ~EdgeStyleValue() override = default;
|
|
|
|
|
2024-11-29 22:44:14 +11:00
|
|
|
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();
|
|
|
|
}
|
2023-04-02 22:56:45 +01:00
|
|
|
|
2024-12-07 00:59:49 +01:00
|
|
|
virtual String to_string(SerializationMode) const override;
|
2023-04-02 22:56:45 +01:00
|
|
|
|
2025-04-11 05:56:50 +01:00
|
|
|
ValueComparingNonnullRefPtr<EdgeStyleValue const> resolved_value(CalculationContext context) const;
|
|
|
|
|
2023-04-02 22:56:45 +01:00
|
|
|
bool properties_equal(EdgeStyleValue const& other) const { return m_properties == other.m_properties; }
|
|
|
|
|
|
|
|
private:
|
2024-11-29 22:44:14 +11:00
|
|
|
EdgeStyleValue(Optional<PositionEdge> edge, Optional<LengthPercentage> const& offset)
|
2023-04-02 22:56:45 +01:00
|
|
|
: StyleValueWithDefaultOperators(Type::Edge)
|
|
|
|
, m_properties { .edge = edge, .offset = offset }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Properties {
|
2024-11-29 22:44:14 +11:00
|
|
|
Optional<PositionEdge> edge;
|
|
|
|
Optional<LengthPercentage> offset;
|
2023-04-02 22:56:45 +01:00
|
|
|
bool operator==(Properties const&) const = default;
|
|
|
|
} m_properties;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|