mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Split TimingFunction into a separate file to match spec.
TimingFunction is defined in a separate spec (i.e. css-easing), instead of transform, so we move it into a different file. Depends on D9310 Differential Revision: https://phabricator.services.mozilla.com/D9311
This commit is contained in:
parent
3a536f463c
commit
a20b6a5166
11 changed files with 230 additions and 193 deletions
|
@ -90,64 +90,6 @@ pub struct TransformOrigin<H, V, Depth> {
|
|||
pub depth: Depth,
|
||||
}
|
||||
|
||||
/// A generic timing function.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-easing-1/#timing-functions
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
#[value_info(ty = "TIMING_FUNCTION")]
|
||||
pub enum TimingFunction<Integer, Number> {
|
||||
/// `linear | ease | ease-in | ease-out | ease-in-out`
|
||||
Keyword(TimingKeyword),
|
||||
/// `cubic-bezier(<number>, <number>, <number>, <number>)`
|
||||
#[allow(missing_docs)]
|
||||
#[css(comma, function)]
|
||||
CubicBezier {
|
||||
x1: Number,
|
||||
y1: Number,
|
||||
x2: Number,
|
||||
y2: Number,
|
||||
},
|
||||
/// `step-start | step-end | steps(<integer>, [ start | end ]?)`
|
||||
#[css(comma, function)]
|
||||
#[value_info(other_values = "step-start,step-end")]
|
||||
Steps(Integer, #[css(skip_if = "is_end")] StepPosition),
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
)]
|
||||
pub enum TimingKeyword {
|
||||
Linear,
|
||||
Ease,
|
||||
EaseIn,
|
||||
EaseOut,
|
||||
EaseInOut,
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum StepPosition {
|
||||
Start,
|
||||
End,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_end(position: &StepPosition) -> bool {
|
||||
*position == StepPosition::End
|
||||
}
|
||||
|
||||
impl<H, V, D> TransformOrigin<H, V, D> {
|
||||
/// Returns a new transform origin.
|
||||
pub fn new(horizontal: H, vertical: V, depth: D) -> Self {
|
||||
|
@ -159,29 +101,6 @@ impl<H, V, D> TransformOrigin<H, V, D> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Integer, Number> TimingFunction<Integer, Number> {
|
||||
/// `ease`
|
||||
#[inline]
|
||||
pub fn ease() -> Self {
|
||||
TimingFunction::Keyword(TimingKeyword::Ease)
|
||||
}
|
||||
}
|
||||
|
||||
impl TimingKeyword {
|
||||
/// Returns the keyword as a quadruplet of Bezier point coordinates
|
||||
/// `(x1, y1, x2, y2)`.
|
||||
#[inline]
|
||||
pub fn to_bezier(self) -> (CSSFloat, CSSFloat, CSSFloat, CSSFloat) {
|
||||
match self {
|
||||
TimingKeyword::Linear => (0., 0., 1., 1.),
|
||||
TimingKeyword::Ease => (0.25, 0.1, 0.25, 1.),
|
||||
TimingKeyword::EaseIn => (0.42, 0., 1., 1.),
|
||||
TimingKeyword::EaseOut => (0., 0., 0.58, 1.),
|
||||
TimingKeyword::EaseInOut => (0.42, 0., 0.58, 1.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
|
||||
/// A single operation in the list of a `transform` value
|
||||
pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrPercentage> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue