mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Add parsing for linear easing function and gate it behind pref
Differential Revision: https://phabricator.services.mozilla.com/D146839
This commit is contained in:
parent
b31be826c4
commit
949fd0e172
1 changed files with 38 additions and 1 deletions
|
@ -7,7 +7,9 @@ use crate::parser::{Parse, ParserContext};
|
|||
use crate::values::computed::easing::ComputedLinearStop;
|
||||
use crate::values::computed::easing::TimingFunction as ComputedTimingFunction;
|
||||
use crate::values::computed::Percentage as ComputedPercentage;
|
||||
use crate::values::generics::easing::TimingFunction as GenericTimingFunction;
|
||||
use crate::values::generics::easing::{
|
||||
LinearStop as GenericLinearStop, TimingFunction as GenericTimingFunction,
|
||||
};
|
||||
use crate::values::generics::easing::{StepPosition, TimingKeyword};
|
||||
use crate::values::specified::{Integer, Number, Percentage};
|
||||
use cssparser::Parser;
|
||||
|
@ -18,6 +20,16 @@ use style_traits::{ParseError, StyleParseErrorKind};
|
|||
/// A specified timing function.
|
||||
pub type TimingFunction = GenericTimingFunction<Integer, Number, Percentage>;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn linear_timing_function_enabled() -> bool {
|
||||
static_prefs::pref!("layout.css.linear-easing-function.enabled")
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
fn linear_timing_function_enabled() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
impl Parse for TimingFunction {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -75,6 +87,31 @@ impl Parse for TimingFunction {
|
|||
}
|
||||
Ok(GenericTimingFunction::Steps(steps, position))
|
||||
},
|
||||
"linear" => {
|
||||
if !linear_timing_function_enabled() {
|
||||
return Err(i.new_custom_error(StyleParseErrorKind::ExperimentalProperty));
|
||||
}
|
||||
if i.is_exhausted() {
|
||||
return Ok(GenericTimingFunction::LinearFunction(crate::OwnedSlice::default()))
|
||||
}
|
||||
let entries = i.parse_comma_separated(|i| {
|
||||
let mut input_start = i.try_parse(|i| Percentage::parse(context, i)).ok();
|
||||
let mut input_end = i.try_parse(|i| Percentage::parse(context, i)).ok();
|
||||
|
||||
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();
|
||||
}
|
||||
Ok(GenericLinearStop {
|
||||
output,
|
||||
input_start: input_start.into(),
|
||||
input_end: input_end.into()
|
||||
})
|
||||
})?;
|
||||
Ok(GenericTimingFunction::LinearFunction(crate::OwnedSlice::from(entries)))
|
||||
},
|
||||
_ => Err(()),
|
||||
})
|
||||
.map_err(|()| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue