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