mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +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
2 changed files with 11 additions and 8 deletions
|
@ -825,11 +825,13 @@ static ErrorOr<NonnullRefPtr<StyleValue>> interpolate_property(StyleValue const&
|
||||||
case StyleValue::Type::Percentage:
|
case StyleValue::Type::Percentage:
|
||||||
return PercentageStyleValue::create(Percentage(interpolate_raw(from.as_percentage().percentage().value(), to.as_percentage().percentage().value())));
|
return PercentageStyleValue::create(Percentage(interpolate_raw(from.as_percentage().percentage().value(), to.as_percentage().percentage().value())));
|
||||||
case StyleValue::Type::Position: {
|
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& from_position = from.as_position();
|
||||||
auto& to_position = to.as_position();
|
auto& to_position = to.as_position();
|
||||||
return PositionStyleValue::create(
|
return PositionStyleValue::create(
|
||||||
TRY(interpolate_property(from_position.edge_x(), to_position.edge_x(), 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)));
|
TRY(interpolate_property(from_position.edge_y(), to_position.edge_y(), delta))->as_edge());
|
||||||
}
|
}
|
||||||
case StyleValue::Type::Rect: {
|
case StyleValue::Type::Rect: {
|
||||||
auto from_rect = from.as_rect().rect();
|
auto from_rect = from.as_rect().rect();
|
||||||
|
|
|
@ -12,34 +12,35 @@
|
||||||
#include <LibWeb/CSS/Enums.h>
|
#include <LibWeb/CSS/Enums.h>
|
||||||
#include <LibWeb/CSS/PercentageOr.h>
|
#include <LibWeb/CSS/PercentageOr.h>
|
||||||
#include <LibWeb/CSS/StyleValue.h>
|
#include <LibWeb/CSS/StyleValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
class PositionStyleValue final : public StyleValueWithDefaultOperators<PositionStyleValue> {
|
class PositionStyleValue final : public StyleValueWithDefaultOperators<PositionStyleValue> {
|
||||||
public:
|
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)));
|
return adopt_ref(*new (nothrow) PositionStyleValue(move(edge_x), move(edge_y)));
|
||||||
}
|
}
|
||||||
virtual ~PositionStyleValue() override = default;
|
virtual ~PositionStyleValue() override = default;
|
||||||
|
|
||||||
ValueComparingNonnullRefPtr<StyleValue> edge_x() const { return m_properties.edge_x; }
|
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x() const { return m_properties.edge_x; }
|
||||||
ValueComparingNonnullRefPtr<StyleValue> edge_y() const { return m_properties.edge_y; }
|
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y() const { return m_properties.edge_y; }
|
||||||
|
|
||||||
virtual String to_string() const override;
|
virtual String to_string() const override;
|
||||||
|
|
||||||
bool properties_equal(PositionStyleValue const& other) const { return m_properties == other.m_properties; }
|
bool properties_equal(PositionStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PositionStyleValue(ValueComparingNonnullRefPtr<StyleValue> edge_x, ValueComparingNonnullRefPtr<StyleValue> edge_y)
|
PositionStyleValue(ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x, ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y)
|
||||||
: StyleValueWithDefaultOperators(Type::Position)
|
: StyleValueWithDefaultOperators(Type::Position)
|
||||||
, m_properties { .edge_x = edge_x, .edge_y = edge_y }
|
, m_properties { .edge_x = edge_x, .edge_y = edge_y }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Properties {
|
struct Properties {
|
||||||
ValueComparingNonnullRefPtr<StyleValue> edge_x;
|
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x;
|
||||||
ValueComparingNonnullRefPtr<StyleValue> edge_y;
|
ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y;
|
||||||
bool operator==(Properties const&) const = default;
|
bool operator==(Properties const&) const = default;
|
||||||
} m_properties;
|
} m_properties;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue