style: Respect calc for percentages.

This commit is contained in:
Emilio Cobos Álvarez 2017-07-14 13:18:29 +02:00
parent 465e6f14fe
commit 310be02ba8
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
28 changed files with 308 additions and 176 deletions

View file

@ -12,11 +12,52 @@ use style_traits::values::specified::AllowedLengthType;
use super::{Number, ToComputedValue, Context};
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified};
use values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength};
use values::specified::length::{Percentage, ViewportPercentageLength};
use values::specified::length::ViewportPercentageLength;
pub use super::image::Image;
pub use values::specified::{Angle, BorderStyle, Time, UrlOrNone};
/// A computed `<percentage>` value.
///
/// FIXME(emilio): why is this in length.rs?
#[derive(Clone, Copy, Debug, Default, PartialEq, HasViewportPercentage)]
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
pub struct Percentage(pub CSSFloat);
impl Percentage {
/// 0%
#[inline]
pub fn zero() -> Self {
Percentage(0.)
}
/// 100%
#[inline]
pub fn hundred() -> Self {
Percentage(1.)
}
}
impl ToCss for Percentage {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}%", self.0 * 100.)
}
}
impl ToComputedValue for specified::Percentage {
type ComputedValue = Percentage;
#[inline]
fn to_computed_value(&self, _: &Context) -> Percentage {
Percentage(self.get())
}
#[inline]
fn from_computed_value(computed: &Percentage) -> Self {
specified::Percentage::new(computed.0)
}
}
impl ToComputedValue for specified::NoCalcLength {
type ComputedValue = Au;