mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: linear(...)
easing: Parsing should split a linear stop value into two for entries with both linear-stop-length
set
This brings the behaviour inline with `linear-gradient(...)` Differential Revision: https://phabricator.services.mozilla.com/D149926
This commit is contained in:
parent
09fc10c5c2
commit
e3e2ee64de
3 changed files with 36 additions and 30 deletions
|
@ -24,8 +24,8 @@ impl ComputedLinearStop {
|
|||
) -> PiecewiseLinearFunctionBuildParameters {
|
||||
(
|
||||
x.output,
|
||||
x.input_start.into_rust().map(|x| x.0),
|
||||
x.input_end.into_rust().map(|x| x.0),
|
||||
x.input.into_rust().map(|x| x.0),
|
||||
None,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,9 @@ use crate::values::generics::Optional;
|
|||
pub struct LinearStop<Number, Percentage> {
|
||||
/// Output of the function at the given point.
|
||||
pub output: Number,
|
||||
/// Playback progress at which this output starts.
|
||||
/// Playback progress at which this output is given.
|
||||
#[css(skip_if = "Optional::is_none")]
|
||||
pub input_start: Optional<Percentage>,
|
||||
/// Playback progress at which this output ends.
|
||||
#[css(skip_if = "Optional::is_none")]
|
||||
pub input_end: Optional<Percentage>,
|
||||
pub input: Optional<Percentage>,
|
||||
}
|
||||
|
||||
/// A generic easing function.
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::values::generics::easing::{
|
|||
};
|
||||
use crate::values::generics::easing::{StepPosition, TimingKeyword};
|
||||
use crate::values::specified::{Integer, Number, Percentage};
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Delimiter, Parser, Token};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use std::iter::FromIterator;
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
|
@ -20,6 +20,8 @@ use style_traits::{ParseError, StyleParseErrorKind};
|
|||
/// A specified timing function.
|
||||
pub type TimingFunction = GenericTimingFunction<Integer, Number, Percentage>;
|
||||
|
||||
type LinearStop = GenericLinearStop<Number, Percentage>;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn linear_timing_function_enabled() -> bool {
|
||||
static_prefs::pref!("layout.css.linear-easing-function.enabled")
|
||||
|
@ -115,7 +117,9 @@ impl TimingFunction {
|
|||
if input.is_exhausted() {
|
||||
return Ok(GenericTimingFunction::LinearFunction(crate::OwnedSlice::default()))
|
||||
}
|
||||
let entries = input.parse_comma_separated(|i| {
|
||||
let mut result = vec![];
|
||||
loop {
|
||||
input.parse_until_before(Delimiter::Comma, |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();
|
||||
|
||||
|
@ -125,13 +129,23 @@ impl TimingFunction {
|
|||
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()
|
||||
})
|
||||
result.push(LinearStop { output, input: input_start.into() });
|
||||
if input_end.is_some() {
|
||||
debug_assert!(input_start.is_some(), "Input end valid but not input start?");
|
||||
result.push(LinearStop { output, input: input_end.into() });
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(GenericTimingFunction::LinearFunction(crate::OwnedSlice::from(entries)))
|
||||
|
||||
match input.next() {
|
||||
Err(_) => break,
|
||||
Ok(&Token::Comma) => continue,
|
||||
Ok(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(GenericTimingFunction::LinearFunction(crate::OwnedSlice::from(result)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,13 +171,8 @@ impl TimingFunction {
|
|||
GenericTimingFunction::LinearFunction(steps) => {
|
||||
let iter = steps.iter().map(|e| ComputedLinearStop {
|
||||
output: e.output.get(),
|
||||
input_start: e
|
||||
.input_start
|
||||
.into_rust()
|
||||
.map(|x| ComputedPercentage(x.get()))
|
||||
.into(),
|
||||
input_end: e
|
||||
.input_end
|
||||
input: e
|
||||
.input
|
||||
.into_rust()
|
||||
.map(|x| ComputedPercentage(x.get()))
|
||||
.into(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue