2023-07-06 02:29:36 +03:30
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-07-06 02:29:36 +03:30
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
|
|
|
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
|
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
|
|
|
|
* Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-06-17 09:46:51 +01:00
|
|
|
#include <LibWeb/CSS/CalculatedOr.h>
|
2025-08-08 10:11:51 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
2025-07-19 19:35:33 -07:00
|
|
|
#include <LibWeb/Export.h>
|
2023-07-06 02:29:36 +03:30
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
|
|
|
|
class EasingStyleValue final : public StyleValueWithDefaultOperators<EasingStyleValue> {
|
|
|
|
|
public:
|
2024-06-14 21:27:23 -07:00
|
|
|
struct Linear {
|
|
|
|
|
struct Stop {
|
2025-10-09 23:40:46 +13:00
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> output;
|
|
|
|
|
ValueComparingRefPtr<StyleValue const> input;
|
2024-11-03 14:56:16 +11:00
|
|
|
|
2024-06-14 21:27:23 -07:00
|
|
|
bool operator==(Stop const&) const = default;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Vector<Stop> stops;
|
|
|
|
|
|
|
|
|
|
bool operator==(Linear const&) const = default;
|
2024-11-03 10:36:44 +11:00
|
|
|
|
2025-06-17 09:46:51 +01:00
|
|
|
String to_string(SerializationMode) const;
|
2024-06-14 21:27:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CubicBezier {
|
2025-10-11 15:09:11 +13:00
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> x1;
|
|
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> y1;
|
|
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> x2;
|
|
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> y2;
|
2024-06-14 21:27:23 -07:00
|
|
|
|
2024-06-14 21:50:25 -07:00
|
|
|
struct CachedSample {
|
|
|
|
|
double x;
|
|
|
|
|
double y;
|
|
|
|
|
double t;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-24 17:05:30 +00:00
|
|
|
mutable Vector<CachedSample> m_cached_x_samples {};
|
2024-06-14 21:50:25 -07:00
|
|
|
|
2025-09-26 14:30:05 +01:00
|
|
|
bool operator==(CubicBezier const& other) const
|
|
|
|
|
{
|
|
|
|
|
return x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2;
|
|
|
|
|
}
|
2024-11-03 10:36:44 +11:00
|
|
|
|
2025-06-17 09:46:51 +01:00
|
|
|
String to_string(SerializationMode) const;
|
2024-06-14 21:27:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Steps {
|
2025-10-11 15:09:11 +13:00
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> number_of_intervals;
|
|
|
|
|
StepPosition position;
|
2024-06-14 21:27:23 -07:00
|
|
|
|
|
|
|
|
bool operator==(Steps const&) const = default;
|
2024-11-03 10:36:44 +11:00
|
|
|
|
2025-06-17 09:46:51 +01:00
|
|
|
String to_string(SerializationMode) const;
|
2024-06-14 21:27:23 -07:00
|
|
|
};
|
|
|
|
|
|
2025-07-19 19:35:33 -07:00
|
|
|
struct WEB_API Function : public Variant<Linear, CubicBezier, Steps> {
|
2024-06-14 21:50:25 -07:00
|
|
|
using Variant::Variant;
|
|
|
|
|
|
2025-06-17 09:46:51 +01:00
|
|
|
String to_string(SerializationMode) const;
|
2024-06-14 21:50:25 -07:00
|
|
|
};
|
2024-06-14 21:27:23 -07:00
|
|
|
|
2025-04-15 15:18:27 -06:00
|
|
|
static ValueComparingNonnullRefPtr<EasingStyleValue const> create(Function const& function)
|
2023-07-06 02:29:36 +03:30
|
|
|
{
|
2024-06-14 21:27:23 -07:00
|
|
|
return adopt_ref(*new (nothrow) EasingStyleValue(function));
|
2023-07-06 02:29:36 +03:30
|
|
|
}
|
|
|
|
|
virtual ~EasingStyleValue() override = default;
|
|
|
|
|
|
2024-06-14 21:27:23 -07:00
|
|
|
Function const& function() const { return m_function; }
|
2023-07-06 02:29:36 +03:30
|
|
|
|
2025-06-17 09:46:51 +01:00
|
|
|
virtual String to_string(SerializationMode mode) const override { return m_function.to_string(mode); }
|
2023-07-06 02:29:36 +03:30
|
|
|
|
2025-10-09 23:40:46 +13:00
|
|
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
|
|
|
|
|
|
2024-06-14 21:27:23 -07:00
|
|
|
bool properties_equal(EasingStyleValue const& other) const { return m_function == other.m_function; }
|
2023-07-06 02:29:36 +03:30
|
|
|
|
|
|
|
|
private:
|
2024-07-03 15:01:07 +00:00
|
|
|
EasingStyleValue(Function const& function)
|
2023-07-06 02:29:36 +03:30
|
|
|
: StyleValueWithDefaultOperators(Type::Easing)
|
2024-06-14 21:27:23 -07:00
|
|
|
, m_function(function)
|
2023-07-06 02:29:36 +03:30
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 21:27:23 -07:00
|
|
|
Function m_function;
|
2023-07-06 02:29:36 +03:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|