tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

easing.rs (3304B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 //! Generic types for CSS Easing Functions.
      6 //! https://drafts.csswg.org/css-easing/#timing-functions
      7 
      8 use crate::derives::*;
      9 use crate::parser::ParserContext;
     10 
     11 /// A generic easing function.
     12 #[derive(
     13    Clone,
     14    Debug,
     15    MallocSizeOf,
     16    PartialEq,
     17    SpecifiedValueInfo,
     18    ToCss,
     19    ToShmem,
     20    Serialize,
     21    Deserialize,
     22 )]
     23 #[value_info(ty = "TIMING_FUNCTION")]
     24 #[repr(u8, C)]
     25 pub enum TimingFunction<Integer, Number, LinearStops> {
     26    /// `linear | ease | ease-in | ease-out | ease-in-out`
     27    Keyword(TimingKeyword),
     28    /// `cubic-bezier(<number>, <number>, <number>, <number>)`
     29    #[allow(missing_docs)]
     30    #[css(comma, function)]
     31    CubicBezier {
     32        x1: Number,
     33        y1: Number,
     34        x2: Number,
     35        y2: Number,
     36    },
     37    /// `step-start | step-end | steps(<integer>, [ <step-position> ]?)`
     38    /// `<step-position> = jump-start | jump-end | jump-none | jump-both | start | end`
     39    #[css(comma, function)]
     40    #[value_info(other_values = "step-start,step-end")]
     41    Steps(Integer, #[css(skip_if = "is_end")] StepPosition),
     42    /// linear([<linear-stop>]#)
     43    /// <linear-stop> = <output> && <linear-stop-length>?
     44    /// <linear-stop-length> = <percentage>{1, 2}
     45    #[css(function = "linear")]
     46    LinearFunction(LinearStops),
     47 }
     48 
     49 #[allow(missing_docs)]
     50 #[derive(
     51    Clone,
     52    Copy,
     53    Debug,
     54    Eq,
     55    MallocSizeOf,
     56    Parse,
     57    PartialEq,
     58    SpecifiedValueInfo,
     59    ToComputedValue,
     60    ToCss,
     61    ToResolvedValue,
     62    ToShmem,
     63    Serialize,
     64    Deserialize,
     65 )]
     66 #[repr(u8)]
     67 pub enum TimingKeyword {
     68    Linear,
     69    Ease,
     70    EaseIn,
     71    EaseOut,
     72    EaseInOut,
     73 }
     74 
     75 /// Before flag, defined as per https://drafts.csswg.org/css-easing/#before-flag
     76 /// This flag is never user-specified.
     77 #[allow(missing_docs)]
     78 #[derive(PartialEq)]
     79 #[repr(u8)]
     80 pub enum BeforeFlag {
     81    Unset,
     82    Set,
     83 }
     84 
     85 #[cfg(feature = "gecko")]
     86 fn step_position_jump_enabled(_context: &ParserContext) -> bool {
     87    true
     88 }
     89 
     90 #[cfg(feature = "servo")]
     91 fn step_position_jump_enabled(_context: &ParserContext) -> bool {
     92    false
     93 }
     94 
     95 #[allow(missing_docs)]
     96 #[derive(
     97    Clone,
     98    Copy,
     99    Debug,
    100    Eq,
    101    MallocSizeOf,
    102    Parse,
    103    PartialEq,
    104    ToComputedValue,
    105    ToCss,
    106    ToResolvedValue,
    107    ToShmem,
    108    Serialize,
    109    Deserialize,
    110 )]
    111 #[repr(u8)]
    112 pub enum StepPosition {
    113    #[parse(condition = "step_position_jump_enabled")]
    114    JumpStart,
    115    #[parse(condition = "step_position_jump_enabled")]
    116    JumpEnd,
    117    #[parse(condition = "step_position_jump_enabled")]
    118    JumpNone,
    119    #[parse(condition = "step_position_jump_enabled")]
    120    JumpBoth,
    121    Start,
    122    End,
    123 }
    124 
    125 #[inline]
    126 fn is_end(position: &StepPosition) -> bool {
    127    *position == StepPosition::JumpEnd || *position == StepPosition::End
    128 }
    129 
    130 impl<Integer, Number, LinearStops> TimingFunction<Integer, Number, LinearStops> {
    131    /// `ease`
    132    #[inline]
    133    pub fn ease() -> Self {
    134        TimingFunction::Keyword(TimingKeyword::Ease)
    135    }
    136 
    137    /// Returns true if it is `ease`.
    138    #[inline]
    139    pub fn is_ease(&self) -> bool {
    140        matches!(*self, TimingFunction::Keyword(TimingKeyword::Ease))
    141    }
    142 }