Use generics for the line-height property

This commit is contained in:
Anthony Ramine 2017-05-31 12:48:06 +02:00
parent cf71a0cd96
commit 5c6987a50d
12 changed files with 234 additions and 213 deletions

View file

@ -0,0 +1,51 @@
/* 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 text properties.
use app_units::Au;
use properties::animated_properties::Animatable;
use values::CSSFloat;
use values::generics::text::LineHeight as GenericLineHeight;
/// A computed value for the `line-height` property.
pub type LineHeight = GenericLineHeight<CSSFloat, Au>;
impl Animatable for LineHeight {
#[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
match (*self, *other) {
(GenericLineHeight::Length(ref this), GenericLineHeight::Length(ref other)) => {
this.add_weighted(other, self_portion, other_portion).map(GenericLineHeight::Length)
},
(GenericLineHeight::Number(ref this), GenericLineHeight::Number(ref other)) => {
this.add_weighted(other, self_portion, other_portion).map(GenericLineHeight::Number)
},
(GenericLineHeight::Normal, GenericLineHeight::Normal) => {
Ok(GenericLineHeight::Normal)
},
#[cfg(feature = "gecko")]
(GenericLineHeight::MozBlockHeight, GenericLineHeight::MozBlockHeight) => {
Ok(GenericLineHeight::MozBlockHeight)
},
_ => Err(()),
}
}
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (*self, *other) {
(GenericLineHeight::Length(ref this), GenericLineHeight::Length(ref other)) => {
this.compute_distance(other)
},
(GenericLineHeight::Number(ref this), GenericLineHeight::Number(ref other)) => {
this.compute_distance(other)
},
(GenericLineHeight::Normal, GenericLineHeight::Normal) => Ok(0.),
#[cfg(feature = "gecko")]
(GenericLineHeight::MozBlockHeight, GenericLineHeight::MozBlockHeight) => Ok(0.),
_ => Err(()),
}
}
}