style/values/computed/
resolution.rs1use crate::derives::*;
10use crate::values::computed::{Context, ToComputedValue};
11use crate::values::specified;
12use crate::values::CSSFloat;
13use std::fmt::{self, Write};
14use style_traits::{CssWriter, ToCss};
15
16#[repr(C)]
18#[derive(Animate, Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
19pub struct Resolution(CSSFloat);
20
21impl Resolution {
22 #[inline]
24 pub fn dppx(&self) -> CSSFloat {
25 self.0
26 }
27
28 #[inline]
30 pub fn from_dppx(dppx: CSSFloat) -> Self {
31 Resolution(dppx)
32 }
33}
34
35impl ToComputedValue for specified::Resolution {
36 type ComputedValue = Resolution;
37
38 #[inline]
39 fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
40 Resolution(crate::values::normalize(self.dppx().max(0.0)))
41 }
42
43 #[inline]
44 fn from_computed_value(computed: &Self::ComputedValue) -> Self {
45 specified::Resolution::from_dppx(computed.dppx())
46 }
47}
48
49impl ToCss for Resolution {
50 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
51 where
52 W: fmt::Write,
53 {
54 self.dppx().to_css(dest)?;
55 dest.write_str("dppx")
56 }
57}