mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Respect calc for percentages.
This commit is contained in:
parent
465e6f14fe
commit
310be02ba8
28 changed files with 308 additions and 176 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue