mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-23 02:55:15 +00:00
LibWeb: Store PositionStyleValue's edges as EdgeStyleValues
They can't be anything else, so this will make working with them easier.
This commit is contained in:
parent
875661a584
commit
4ad58f0204
|
@ -825,11 +825,13 @@ static ErrorOr<NonnullRefPtr<StyleValue>> interpolate_property(StyleValue const&
|
|||
case StyleValue::Type::Percentage:
|
||||
return PercentageStyleValue::create(Percentage(interpolate_raw(from.as_percentage().percentage().value(), to.as_percentage().percentage().value())));
|
||||
case StyleValue::Type::Position: {
|
||||
// https://www.w3.org/TR/css-values-4/#combine-positions
|
||||
// FIXME: Interpolation of <position> is defined as the independent interpolation of each component (x, y) normalized as an offset from the top left corner as a <length-percentage>.
|
||||
auto& from_position = from.as_position();
|
||||
auto& to_position = to.as_position();
|
||||
return PositionStyleValue::create(
|
||||
TRY(interpolate_property(from_position.edge_x(), to_position.edge_x(), delta)),
|
||||
TRY(interpolate_property(from_position.edge_y(), to_position.edge_y(), delta)));
|
||||
TRY(interpolate_property(from_position.edge_x(), to_position.edge_x(), delta))->as_edge(),
|
||||
TRY(interpolate_property(from_position.edge_y(), to_position.edge_y(), delta))->as_edge());
|
||||
}
|
||||
case StyleValue::Type::Rect: {
|
||||
auto from_rect = from.as_rect().rect();
|
||||
|
|
|
@ -12,34 +12,35 @@
|
|||
#include <LibWeb/CSS/Enums.h>
|
||||
#include <LibWeb/CSS/PercentageOr.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class PositionStyleValue final : public StyleValueWithDefaultOperators<PositionStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<PositionStyleValue> create(ValueComparingNonnullRefPtr<StyleValue> edge_x, ValueComparingNonnullRefPtr<StyleValue> edge_y)
|
||||
static ValueComparingNonnullRefPtr<PositionStyleValue> create(ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x, ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) PositionStyleValue(move(edge_x), move(edge_y)));
|
||||
}
|
||||
virtual ~PositionStyleValue() override = default;
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue> edge_x() const { return m_properties.edge_x; }
|
||||
ValueComparingNonnullRefPtr<StyleValue> edge_y() const { return m_properties.edge_y; }
|
||||
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x() const { return m_properties.edge_x; }
|
||||
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y() const { return m_properties.edge_y; }
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
||||
bool properties_equal(PositionStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
PositionStyleValue(ValueComparingNonnullRefPtr<StyleValue> edge_x, ValueComparingNonnullRefPtr<StyleValue> edge_y)
|
||||
PositionStyleValue(ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x, ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y)
|
||||
: StyleValueWithDefaultOperators(Type::Position)
|
||||
, m_properties { .edge_x = edge_x, .edge_y = edge_y }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
ValueComparingNonnullRefPtr<StyleValue> edge_x;
|
||||
ValueComparingNonnullRefPtr<StyleValue> edge_y;
|
||||
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x;
|
||||
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue