mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-21 07:29:53 +00:00
This excludes `step-end` and `step-start` which are expected to be converted to the equivalent function at parse time. We are expected to serialize these as the explicit keywords - previously we would parse as `EasingStyleValue` and serialize equivalent functions as the keywords. This caused issues as we would incorrectly serialize even explicit functions as the keyword. This also allows us to move the magic easing functions to `EasingFunction` rather than `EasingStyleValue` which is a bit tidier
97 lines
2.8 KiB
C++
97 lines
2.8 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
|
* 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
|
|
|
|
#include <LibWeb/CSS/CalculatedOr.h>
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
|
#include <LibWeb/Export.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
class EasingStyleValue final : public StyleValueWithDefaultOperators<EasingStyleValue> {
|
|
public:
|
|
struct Linear {
|
|
struct Stop {
|
|
ValueComparingNonnullRefPtr<StyleValue const> output;
|
|
ValueComparingRefPtr<StyleValue const> input;
|
|
|
|
bool operator==(Stop const&) const = default;
|
|
};
|
|
|
|
Vector<Stop> stops;
|
|
|
|
bool operator==(Linear const&) const = default;
|
|
|
|
String to_string(SerializationMode) const;
|
|
};
|
|
|
|
struct CubicBezier {
|
|
ValueComparingNonnullRefPtr<StyleValue const> x1;
|
|
ValueComparingNonnullRefPtr<StyleValue const> y1;
|
|
ValueComparingNonnullRefPtr<StyleValue const> x2;
|
|
ValueComparingNonnullRefPtr<StyleValue const> y2;
|
|
|
|
struct CachedSample {
|
|
double x;
|
|
double y;
|
|
double t;
|
|
};
|
|
|
|
mutable Vector<CachedSample> m_cached_x_samples {};
|
|
|
|
bool operator==(CubicBezier const& other) const
|
|
{
|
|
return x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2;
|
|
}
|
|
|
|
String to_string(SerializationMode) const;
|
|
};
|
|
|
|
struct Steps {
|
|
ValueComparingNonnullRefPtr<StyleValue const> number_of_intervals;
|
|
StepPosition position;
|
|
|
|
bool operator==(Steps const&) const = default;
|
|
|
|
String to_string(SerializationMode) const;
|
|
};
|
|
|
|
struct WEB_API Function : public Variant<Linear, CubicBezier, Steps> {
|
|
using Variant::Variant;
|
|
|
|
String to_string(SerializationMode) const;
|
|
};
|
|
|
|
static ValueComparingNonnullRefPtr<EasingStyleValue const> create(Function const& function)
|
|
{
|
|
return adopt_ref(*new (nothrow) EasingStyleValue(function));
|
|
}
|
|
virtual ~EasingStyleValue() override = default;
|
|
|
|
Function const& function() const { return m_function; }
|
|
|
|
virtual String to_string(SerializationMode mode) const override { return m_function.to_string(mode); }
|
|
|
|
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
|
|
|
|
bool properties_equal(EasingStyleValue const& other) const { return m_function == other.m_function; }
|
|
|
|
private:
|
|
EasingStyleValue(Function const& function)
|
|
: StyleValueWithDefaultOperators(Type::Easing)
|
|
, m_function(function)
|
|
{
|
|
}
|
|
|
|
Function m_function;
|
|
};
|
|
|
|
}
|