style/values/computed/
time.rs1use crate::values::CSSFloat;
8use crate::Zero;
9use std::fmt::{self, Write};
10use style_traits::{CssWriter, ToCss};
11
12#[derive(Animate, Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue)]
14#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
15#[repr(C)]
16pub struct Time {
17 seconds: CSSFloat,
18}
19
20impl Time {
21 pub fn from_seconds(seconds: CSSFloat) -> Self {
23 Time { seconds }
24 }
25
26 #[inline]
28 pub fn seconds(&self) -> CSSFloat {
29 self.seconds
30 }
31}
32
33impl ToCss for Time {
34 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
35 where
36 W: Write,
37 {
38 self.seconds().to_css(dest)?;
39 dest.write_char('s')
40 }
41}
42
43impl Zero for Time {
44 fn zero() -> Self {
45 Self::from_seconds(0.0)
46 }
47
48 fn is_zero(&self) -> bool {
49 self.seconds == 0.
50 }
51}