The main issue here is that we transition the zoomed value, which is generally wrong because the animated value gets injected back into the cascade (and thus zoomed again). We happen to cancel the transition in [1], which is kinda nice because otherwise we would've just transitioned to a completely wrong value (and maybe indefinitely, since values would keep getting bigger and bigger...). We need to do something similar to to_resolved_value, and unzoom lengths in to_animated_value, that is, interpolate "unzoomed" values. The extra test to test_transitions_per_property caught some existing issues with calc() and zoom which are fixed too for the test to pass. Same for the ToResolvedValue for Au, that is needed for properties like column-rule-width to return the correct resolved values. Main thing I left unfixed is bug 1909280, but that deserves a more subtle test and a bit more thought because only matrix components need to be zoomed. While at it, I simplified the animation setup a little bit, removing the special animation_value_type="ComputedValue", which means that we need to add a few ToAnimatedValue calls. Now the only values are "none", "discrete", and "normal", and given it's not a value type anymore I called it just "animation_type". This got a bit bigger than I would've liked, but also it fixes more bugs that what I was originally expecting, so... :) [1]: https://searchfox.org/mozilla-central/rev/5756c5a3dea4f2896cdb3c8bb15d0ced5e2bf690/layout/style/nsTransitionManager.cpp#168-171 Differential Revision: https://phabricator.services.mozilla.com/D217308
88 lines
2.2 KiB
Rust
88 lines
2.2 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
//! Generic types for CSS values related to <ratio>.
|
|
//! https://drafts.csswg.org/css-values/#ratios
|
|
|
|
use std::fmt::{self, Write};
|
|
use style_traits::{CssWriter, ToCss};
|
|
use crate::{One, Zero};
|
|
|
|
/// A generic value for the `<ratio>` value.
|
|
#[derive(
|
|
Clone,
|
|
Copy,
|
|
Debug,
|
|
MallocSizeOf,
|
|
PartialEq,
|
|
SpecifiedValueInfo,
|
|
ToAnimatedValue,
|
|
ToComputedValue,
|
|
ToResolvedValue,
|
|
ToShmem,
|
|
)]
|
|
#[repr(C)]
|
|
pub struct Ratio<N>(pub N, pub N);
|
|
|
|
impl<N> ToCss for Ratio<N>
|
|
where
|
|
N: ToCss,
|
|
{
|
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
where
|
|
W: Write,
|
|
{
|
|
self.0.to_css(dest)?;
|
|
// Even though 1 could be omitted, we don't per
|
|
// https://drafts.csswg.org/css-values-4/#ratio-value:
|
|
//
|
|
// The second <number> is optional, defaulting to 1. However,
|
|
// <ratio> is always serialized with both components.
|
|
//
|
|
// And for compat reasons, see bug 1669742.
|
|
//
|
|
// We serialize with spaces for consistency with all other
|
|
// slash-delimited things, see
|
|
// https://github.com/w3c/csswg-drafts/issues/4282
|
|
dest.write_str(" / ")?;
|
|
self.1.to_css(dest)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl<N> Ratio<N>
|
|
where
|
|
N: Zero + One,
|
|
{
|
|
/// Returns true if this is a degenerate ratio.
|
|
/// https://drafts.csswg.org/css-values/#degenerate-ratio
|
|
#[inline]
|
|
pub fn is_degenerate(&self) -> bool {
|
|
self.0.is_zero() || self.1.is_zero()
|
|
}
|
|
|
|
/// Returns the used value. A ratio of 0/0 behaves as the ratio 1/0.
|
|
/// https://drafts.csswg.org/css-values-4/#ratios
|
|
pub fn used_value(self) -> Self {
|
|
if self.0.is_zero() && self.1.is_zero() {
|
|
Self(One::one(), Zero::zero())
|
|
} else {
|
|
self
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<N> Zero for Ratio<N>
|
|
where
|
|
N: Zero + One,
|
|
{
|
|
fn zero() -> Self {
|
|
Self(Zero::zero(), One::one())
|
|
}
|
|
|
|
fn is_zero(&self) -> bool {
|
|
self.0.is_zero()
|
|
}
|
|
}
|