style: C++ ComputedTimingFunction uses Rust's timing function calculation

This was made economical by having Rust's computed `easing::TimingFunction` use
a fully resolved function for `linear(...)` easing, as per draft resolution from
https://github.com/w3c/csswg-drafts/issues/7415

Differential Revision: https://phabricator.services.mozilla.com/D151295
This commit is contained in:
David Shin 2022-07-09 17:33:59 +00:00 committed by Martin Robinson
parent bb0f857dfa
commit af058e6332
5 changed files with 134 additions and 85 deletions

View file

@ -6,31 +6,6 @@
//! https://drafts.csswg.org/css-easing/#timing-functions
use crate::parser::ParserContext;
use crate::values::generics::Optional;
/// An entry for linear easing function.
#[derive(
Clone,
Copy,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
Serialize,
Deserialize,
)]
#[repr(C)]
pub struct LinearStop<Number, Percentage> {
/// Output of the function at the given point.
pub output: Number,
/// Playback progress at which this output is given.
#[css(skip_if = "Optional::is_none")]
pub input: Optional<Percentage>,
}
/// A generic easing function.
#[derive(
@ -39,9 +14,7 @@ pub struct LinearStop<Number, Percentage> {
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
Serialize,
Deserialize,
@ -49,7 +22,7 @@ pub struct LinearStop<Number, Percentage> {
#[value_info(ty = "TIMING_FUNCTION")]
#[repr(u8, C)]
/// cbindgen:private-default-tagged-enum-constructor=false
pub enum TimingFunction<Integer, Number, Percentage> {
pub enum TimingFunction<Integer, Number, LinearStops> {
/// `linear | ease | ease-in | ease-out | ease-in-out`
Keyword(TimingKeyword),
/// `cubic-bezier(<number>, <number>, <number>, <number>)`
@ -69,8 +42,8 @@ pub enum TimingFunction<Integer, Number, Percentage> {
/// linear([<linear-stop>]#)
/// <linear-stop> = <output> && <linear-stop-length>?
/// <linear-stop-length> = <percentage>{1, 2}
#[css(comma, function = "linear")]
LinearFunction(#[css(iterable)] crate::OwnedSlice<LinearStop<Number, Percentage>>),
#[css(function = "linear")]
LinearFunction(LinearStops),
}
#[allow(missing_docs)]
@ -106,7 +79,7 @@ pub enum TimingKeyword {
#[repr(u8)]
pub enum BeforeFlag {
Unset,
Set
Set,
}
#[cfg(feature = "gecko")]
@ -154,7 +127,7 @@ fn is_end(position: &StepPosition) -> bool {
*position == StepPosition::JumpEnd || *position == StepPosition::End
}
impl<Integer, Number, Percentage> TimingFunction<Integer, Number, Percentage> {
impl<Integer, Number, LinearStops> TimingFunction<Integer, Number, LinearStops> {
/// `ease`
#[inline]
pub fn ease() -> Self {