mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
style: C++ ComputedTimingFunction
uses Rust's timing function calculation
This was made economical by having Rust's computed `easing::TimingFunction` use a fully resolved function for `linear(...)` easing, as per draft resolution from https://github.com/w3c/csswg-drafts/issues/7415 Differential Revision: https://phabricator.services.mozilla.com/D151295
This commit is contained in:
parent
bb0f857dfa
commit
af058e6332
5 changed files with 134 additions and 85 deletions
|
@ -3,25 +3,64 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! A piecewise linear function, following CSS linear easing
|
||||
use crate::values::computed::Percentage;
|
||||
use core::slice::Iter;
|
||||
/// draft as in https://github.com/w3c/csswg-drafts/pull/6533.
|
||||
use euclid::approxeq::ApproxEq;
|
||||
use itertools::Itertools;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
use crate::values::CSSFloat;
|
||||
|
||||
type ValueType = CSSFloat;
|
||||
/// a single entry in a piecewise linear function.
|
||||
#[derive(Clone, Copy)]
|
||||
#[allow(missing_docs)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToResolvedValue,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[repr(C)]
|
||||
struct PiecewiseLinearFunctionEntry {
|
||||
x: ValueType,
|
||||
y: ValueType,
|
||||
pub struct PiecewiseLinearFunctionEntry {
|
||||
pub x: ValueType,
|
||||
pub y: ValueType,
|
||||
}
|
||||
|
||||
impl ToCss for PiecewiseLinearFunctionEntry {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
self.y.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
Percentage(self.x).to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
/// Representation of a piecewise linear function, a series of linear functions.
|
||||
#[derive(Default)]
|
||||
#[derive(
|
||||
Default,
|
||||
Clone,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToResolvedValue,
|
||||
ToCss,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[repr(C)]
|
||||
#[css(comma)]
|
||||
pub struct PiecewiseLinearFunction {
|
||||
#[css(iterable)]
|
||||
entries: crate::OwnedSlice<PiecewiseLinearFunctionEntry>,
|
||||
}
|
||||
|
||||
|
@ -102,6 +141,11 @@ impl PiecewiseLinearFunction {
|
|||
}
|
||||
builder.build()
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub fn iter(&self) -> Iter<PiecewiseLinearFunctionEntry> {
|
||||
self.entries.iter()
|
||||
}
|
||||
}
|
||||
|
||||
/// Entry of a piecewise linear function while building, where the calculation of x value can be deferred.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue