mirror of
https://github.com/servo/servo.git
synced 2025-07-12 18:03:49 +01:00
This patch: * Makes LengthPercentageOrAuto generic, and removes a bunch of code fo LengthPercentageOrNone, which was used only for servo and now can use the normal MaxLength (with a cfg() guard for the ExtremumLength variant). * Shrinks MaxLength / MozLength's repr(C) reperesentation by reducing enum nesting. The shrinking is in preparation for using them from C++ too, though that'd be a different bug. * Moves NonNegative usage to the proper places so that stuff for them can be derived. I did this on top of bug 1523071 to prove both that it could be possible and that stuff wasn't too messy. It got a bit messy, but just because of a bug I had fixed in bindgen long time ago already, so this updates bindgen's patch version to grab a fix instead of ugly workarounds :) Differential Revision: https://phabricator.services.mozilla.com/D17762
38 lines
1.4 KiB
Rust
38 lines
1.4 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/. */
|
|
|
|
//! Animation implementation for various length-related types.
|
|
|
|
use super::{Animate, Procedure};
|
|
use crate::values::computed::length::LengthPercentage;
|
|
use crate::values::computed::Percentage;
|
|
|
|
/// <https://drafts.csswg.org/css-transitions/#animtype-lpcalc>
|
|
impl Animate for LengthPercentage {
|
|
#[inline]
|
|
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
|
let animate_percentage_half = |this: Option<Percentage>, other: Option<Percentage>| {
|
|
if this.is_none() && other.is_none() {
|
|
return Ok(None);
|
|
}
|
|
let this = this.unwrap_or_default();
|
|
let other = other.unwrap_or_default();
|
|
Ok(Some(this.animate(&other, procedure)?))
|
|
};
|
|
|
|
let length = self
|
|
.unclamped_length()
|
|
.animate(&other.unclamped_length(), procedure)?;
|
|
let percentage =
|
|
animate_percentage_half(self.specified_percentage(), other.specified_percentage())?;
|
|
let is_calc =
|
|
self.was_calc || other.was_calc || self.has_percentage != other.has_percentage;
|
|
Ok(Self::with_clamping_mode(
|
|
length,
|
|
percentage,
|
|
self.clamping_mode,
|
|
is_calc,
|
|
))
|
|
}
|
|
}
|