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
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
#include <LibWeb/CSS/CSSStyleValue.h>
|
2025-06-17 09:46:51 +01:00
|
|
|
#include <LibWeb/CSS/CalculatedOr.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 {
|
2024-11-03 14:56:16 +11:00
|
|
|
static Linear identity();
|
|
|
|
|
2024-06-14 21:27:23 -07:00
|
|
|
struct Stop {
|
2024-11-03 14:56:16 +11:00
|
|
|
double output;
|
|
|
|
Optional<double> input;
|
|
|
|
|
|
|
|
// "NOTE: Serialization relies on whether or not an input progress value was originally supplied,
|
|
|
|
// so that information should be retained in the internal representation."
|
|
|
|
bool had_explicit_input;
|
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
|
|
|
|
|
|
|
double evaluate_at(double input_progress, bool before_flag) const;
|
2025-06-17 09:46:51 +01:00
|
|
|
String to_string(SerializationMode) const;
|
2024-11-03 14:56:16 +11:00
|
|
|
|
|
|
|
Linear(Vector<Stop> stops);
|
2024-06-14 21:27:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CubicBezier {
|
|
|
|
static CubicBezier ease();
|
|
|
|
static CubicBezier ease_in();
|
|
|
|
static CubicBezier ease_out();
|
|
|
|
static CubicBezier ease_in_out();
|
|
|
|
|
2025-06-17 22:51:54 +01:00
|
|
|
NumberOrCalculated x1 { 0 };
|
|
|
|
NumberOrCalculated y1 { 0 };
|
|
|
|
NumberOrCalculated x2 { 0 };
|
|
|
|
NumberOrCalculated y2 { 0 };
|
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
|
|
|
|
|
|
|
bool operator==(CubicBezier const&) const;
|
2024-11-03 10:36:44 +11:00
|
|
|
|
|
|
|
double evaluate_at(double input_progress, bool before_flag) const;
|
2025-06-17 09:46:51 +01:00
|
|
|
String to_string(SerializationMode) const;
|
2024-06-14 21:27:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Steps {
|
|
|
|
enum class Position {
|
|
|
|
JumpStart,
|
|
|
|
JumpEnd,
|
|
|
|
JumpNone,
|
|
|
|
JumpBoth,
|
|
|
|
Start,
|
|
|
|
End,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Steps step_start();
|
|
|
|
static Steps step_end();
|
|
|
|
|
2025-06-17 22:51:54 +01:00
|
|
|
IntegerOrCalculated number_of_intervals { 1 };
|
2024-06-14 21:27:23 -07:00
|
|
|
Position position { Position::End };
|
|
|
|
|
|
|
|
bool operator==(Steps const&) const = default;
|
2024-11-03 10:36:44 +11:00
|
|
|
|
|
|
|
double evaluate_at(double input_progress, bool before_flag) const;
|
2025-06-17 09:46:51 +01:00
|
|
|
String to_string(SerializationMode) const;
|
2024-06-14 21:27:23 -07:00
|
|
|
};
|
|
|
|
|
2024-06-16 12:47:35 -04:00
|
|
|
struct Function : public Variant<Linear, CubicBezier, Steps> {
|
2024-06-14 21:50:25 -07:00
|
|
|
using Variant::Variant;
|
|
|
|
|
|
|
|
double evaluate_at(double input_progress, bool before_flag) const;
|
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
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|