use crate::parser::ParserContext;
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToShmem,
Serialize,
Deserialize,
)]
#[value_info(ty = "TIMING_FUNCTION")]
#[repr(u8, C)]
pub enum TimingFunction<Integer, Number, LinearStops> {
Keyword(TimingKeyword),
#[allow(missing_docs)]
#[css(comma, function)]
CubicBezier {
x1: Number,
y1: Number,
x2: Number,
y2: Number,
},
#[css(comma, function)]
#[value_info(other_values = "step-start,step-end")]
Steps(Integer, #[css(skip_if = "is_end")] StepPosition),
#[css(function = "linear")]
LinearFunction(LinearStops),
}
#[allow(missing_docs)]
#[derive(
Clone,
Copy,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
Serialize,
Deserialize,
)]
#[repr(u8)]
pub enum TimingKeyword {
Linear,
Ease,
EaseIn,
EaseOut,
EaseInOut,
}
#[allow(missing_docs)]
#[derive(PartialEq)]
#[repr(u8)]
pub enum BeforeFlag {
Unset,
Set,
}
#[cfg(feature = "gecko")]
fn step_position_jump_enabled(_context: &ParserContext) -> bool {
true
}
#[cfg(feature = "servo")]
fn step_position_jump_enabled(_context: &ParserContext) -> bool {
false
}
#[allow(missing_docs)]
#[derive(
Clone,
Copy,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
Serialize,
Deserialize,
)]
#[repr(u8)]
pub enum StepPosition {
#[parse(condition = "step_position_jump_enabled")]
JumpStart,
#[parse(condition = "step_position_jump_enabled")]
JumpEnd,
#[parse(condition = "step_position_jump_enabled")]
JumpNone,
#[parse(condition = "step_position_jump_enabled")]
JumpBoth,
Start,
End,
}
#[inline]
fn is_end(position: &StepPosition) -> bool {
*position == StepPosition::JumpEnd || *position == StepPosition::End
}
impl<Integer, Number, LinearStops> TimingFunction<Integer, Number, LinearStops> {
#[inline]
pub fn ease() -> Self {
TimingFunction::Keyword(TimingKeyword::Ease)
}
#[inline]
pub fn is_ease(&self) -> bool {
matches!(*self, TimingFunction::Keyword(TimingKeyword::Ease))
}
}