mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Make use of generics for transform-origin
This allows us to preserve keywords during serialisation.
This commit is contained in:
parent
b42aaf28df
commit
5d70580813
12 changed files with 241 additions and 221 deletions
49
components/style/values/computed/transform.rs
Normal file
49
components/style/values/computed/transform.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Computed types for CSS values that are related to transformations.
|
||||
|
||||
use properties::animated_properties::Animatable;
|
||||
use values::computed::{Length, LengthOrPercentage};
|
||||
use values::generics::transform::TransformOrigin as GenericTransformOrigin;
|
||||
|
||||
/// The computed value of a CSS `<transform-origin>`
|
||||
pub type TransformOrigin = GenericTransformOrigin<LengthOrPercentage, LengthOrPercentage, Length>;
|
||||
|
||||
impl TransformOrigin {
|
||||
/// Returns the initial computed value for `transform-origin`.
|
||||
#[inline]
|
||||
pub fn initial_value() -> Self {
|
||||
Self::new(
|
||||
LengthOrPercentage::Percentage(0.5),
|
||||
LengthOrPercentage::Percentage(0.5),
|
||||
Length::from_px(0)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Animatable for TransformOrigin {
|
||||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
Ok(Self::new(
|
||||
self.horizontal.add_weighted(&other.horizontal, self_portion, other_portion)?,
|
||||
self.vertical.add_weighted(&other.vertical, self_portion, other_portion)?,
|
||||
self.depth.add_weighted(&other.depth, self_portion, other_portion)?,
|
||||
))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
self.compute_squared_distance(other).map(f64::sqrt)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
Ok(
|
||||
self.horizontal.compute_squared_distance(&other.horizontal)? +
|
||||
self.vertical.compute_squared_distance(&other.vertical)? +
|
||||
self.depth.compute_squared_distance(&other.depth)?
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue