/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Specified types for CSS Easing functions. usecrate::parser::{Parse, ParserContext}; usecrate::piecewise_linear::{PiecewiseLinearFunction, PiecewiseLinearFunctionBuilder}; usecrate::values::computed::easing::TimingFunction as ComputedTimingFunction; usecrate::values::computed::{Context, ToComputedValue}; usecrate::values::generics::easing::TimingFunction as GenericTimingFunction; usecrate::values::generics::easing::{StepPosition, TimingKeyword}; usecrate::values::specified::{AnimationName, Integer, Number, Percentage}; use cssparser::{Delimiter, Parser, Token}; use selectors::parser::SelectorParseErrorKind; use style_traits::{ParseError, StyleParseErrorKind};
fn parse_steps<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { let steps = Integer::parse_positive(context, input)?; let position = input
.try_parse(|i| {
i.expect_comma()?;
StepPosition::parse(context, i)
})
.unwrap_or(StepPosition::End);
// jump-none accepts a positive integer greater than 1. // FIXME(emilio): The spec asks us to avoid rejecting it at parse // time except until computed value time. // // It's not totally clear it's worth it though, and no other browser // does this. if position == StepPosition::JumpNone && steps.value() <= 1 { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(GenericTimingFunction::Steps(steps, position))
}
let output = Number::parse(context, i)?; if input_start.is_none() {
debug_assert!(input_end.is_none(), "Input end parsed without input start?");
input_start = i.try_parse(|i| Percentage::parse(context, i)).ok();
input_end = i.try_parse(|i| Percentage::parse(context, i)).ok();
}
builder.push(output.into(), input_start.map(|v| v.get()).into());
num_specified_stops += 1; if input_end.is_some() {
debug_assert!(
input_start.is_some(), "Input end valid but not input start?"
);
builder.push(output.into(), input_end.map(|v| v.get()).into());
}
Ok(())
})?;
match input.next() {
Err(_) => break,
Ok(&Token::Comma) => continue,
Ok(_) => unreachable!(),
}
} // By spec, specifying only a single stop makes the function invalid, even if that single entry may generate // two entries. if num_specified_stops < 2 { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
/// Returns true if the name matches any keyword. #[inline] pubfn match_keywords(name: &AnimationName) -> bool { iflet Some(name) = name.as_atom() { #[cfg(feature = "gecko")] return name.with_str(|n| TimingKeyword::from_ident(n).is_ok()); #[cfg(feature = "servo")] return TimingKeyword::from_ident(name).is_ok();
} false
}
}
// We need this for converting the specified TimingFunction into computed TimingFunction without // Context (for some FFIs in glue.rs). In fact, we don't really need Context to get the computed // value of TimingFunction. impl TimingFunction { /// Generate the ComputedTimingFunction without Context. pubfn to_computed_value_without_context(&self) -> ComputedTimingFunction { match &self {
GenericTimingFunction::Steps(steps, pos) => {
GenericTimingFunction::Steps(steps.value(), *pos)
},
GenericTimingFunction::CubicBezier { x1, y1, x2, y2 } => {
GenericTimingFunction::CubicBezier {
x1: x1.get(),
y1: y1.get(),
x2: x2.get(),
y2: y2.get(),
}
},
GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(*keyword),
GenericTimingFunction::LinearFunction(function) => {
GenericTimingFunction::LinearFunction(function.clone())
},
}
}
}
impl ToComputedValue for TimingFunction { type ComputedValue = ComputedTimingFunction; fn to_computed_value(&self, _: &Context) -> Self::ComputedValue { self.to_computed_value_without_context()
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.