/* 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/. */
//! Animation implementation for various grid-related types.
// Note: we can implement Animate on their generic types directly, but in this case we need to // make sure two trait bounds, L: Clone and I: PartialEq, are satisfied on almost all the // grid-related types and their other trait implementations because Animate needs them. So in // order to avoid adding these two trait bounds (or maybe more..) everywhere, we implement // Animate for the computed types, instead of the generic types.
fn discrete<T: Clone>(from: &T, to: &T, procedure: Procedure) -> Result<T, ()> { iflet Procedure::Interpolate { progress } = procedure {
Ok(if progress < 0.5 {
from.clone()
} else {
to.clone()
})
} else { // The discrete animation is not additive, so per spec [1] we should use the |from|, which // is the underlying value. However this mismatches our animation mechanism (see // composite_endpoint() in servo/ports/geckolib/glues.rs), which uses the effect value // (i.e. |to| value here) [2]. So in order to match the behavior of other properties and // other browsers, we use |to| value for addition and accumulation, i.e. Vresult = Vb. // // [1] https://drafts.csswg.org/css-values-4/#not-additive // [2] https://github.com/w3c/csswg-drafts/issues/9070
Ok(to.clone())
}
}
impl Animate for generics::TrackRepeat<LengthPercentage, Integer> { fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> { // If the keyword, auto-fit/fill, is the same it can result in different // number of tracks. For both auto-fit/fill, the number of columns isn't // known until you do layout since it depends on the container size, item // placement and other factors, so we cannot do the correct interpolation // by computed values. Therefore, return Err(()) if it's keywords. If it // is Number, we support animation only if the count is the same and the // length of track_sizes is the same. // https://github.com/w3c/csswg-drafts/issues/3503 match (&self.count, &other.count) {
(&generics::RepeatCount::Number(from), &generics::RepeatCount::Number(to)) if from == to =>
{
()
},
(_, _) => return Err(()),
}
let count = self.count; let track_sizes = super::lists::by_computed_value::animate(
&self.track_sizes,
&other.track_sizes,
procedure,
)?;
// The length of |line_names| is always 0 or N+1, where N is the length // of |track_sizes|. Besides, <line-names> is always discrete. let line_names = discrete(&self.line_names, &other.line_names, procedure)?;
impl Animate for TrackList { // Based on https://github.com/w3c/csswg-drafts/issues/3201: // 1. Check interpolation type per track, so we need to handle discrete animations // in TrackSize, so any Err(()) returned from TrackSize doesn't make all TrackSize // fallback to discrete animation. // 2. line-names is always discrete. fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> { ifself.values.len() != other.values.len() { return Err(());
}
// For now, repeat(auto-fill/auto-fit, ...) is not animatable. // TrackRepeat will return Err(()) if we use keywords. Therefore, we can // early return here to avoid traversing |values| in <auto-track-list>. // This may be updated in the future. // https://github.com/w3c/csswg-drafts/issues/3503 ifself.has_auto_repeat() || other.has_auto_repeat() { return Err(());
}
let values = super::lists::by_computed_value::animate(&self.values, &other.values, procedure)?;
// The length of |line_names| is always 0 or N+1, where N is the length // of |track_sizes|. Besides, <line-names> is always discrete. let line_names = discrete(&self.line_names, &other.line_names, procedure)?;
impl ComputeSquaredDistance for GridTemplateComponent { #[inline] fn compute_squared_distance(&self, _other: &Self) -> Result<SquaredDistance, ()> { // TODO: Bug 1518585, we should implement ComputeSquaredDistance.
Err(())
}
}
impl ToAnimatedZero for GridTemplateComponent { #[inline] fn to_animated_zero(&self) -> Result<Self, ()> { // It's not clear to get a zero grid track list based on the current definition // of spec, so we return Err(()) directly.
Err(())
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet am 2026-06-27)
¤
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.