style/values/computed/
page.rs1use crate::derives::*;
8use crate::values::computed::length::NonNegativeLength;
9use crate::values::computed::{Context, ToComputedValue};
10use crate::values::generics;
11use crate::values::generics::size::Size2D;
12
13use crate::values::specified::page as specified;
14pub use generics::page::GenericPageSize;
15pub use generics::page::PageOrientation;
16pub use generics::page::PageSizeOrientation;
17pub use generics::page::PaperSize;
18pub use specified::PageName;
19
20#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem, ToTyped)]
26#[repr(C, u8)]
27#[typed(todo_derive_fields)]
28pub enum PageSize {
29 Size(Size2D<NonNegativeLength>),
31 Orientation(PageSizeOrientation),
33 Auto,
35}
36
37impl ToComputedValue for specified::PageSize {
38 type ComputedValue = PageSize;
39
40 fn to_computed_value(&self, ctx: &Context) -> Self::ComputedValue {
41 match &*self {
42 Self::Size(s) => PageSize::Size(s.to_computed_value(ctx)),
43 Self::PaperSize(p, PageSizeOrientation::Landscape) => PageSize::Size(Size2D {
44 width: p.long_edge().to_computed_value(ctx),
45 height: p.short_edge().to_computed_value(ctx),
46 }),
47 Self::PaperSize(p, PageSizeOrientation::Portrait) => PageSize::Size(Size2D {
48 width: p.short_edge().to_computed_value(ctx),
49 height: p.long_edge().to_computed_value(ctx),
50 }),
51 Self::Orientation(o) => PageSize::Orientation(*o),
52 Self::Auto => PageSize::Auto,
53 }
54 }
55
56 fn from_computed_value(computed: &Self::ComputedValue) -> Self {
57 match *computed {
58 PageSize::Size(s) => Self::Size(ToComputedValue::from_computed_value(&s)),
59 PageSize::Orientation(o) => Self::Orientation(o),
60 PageSize::Auto => Self::Auto,
61 }
62 }
63}
64
65impl PageSize {
66 #[inline]
68 pub fn auto() -> Self {
69 PageSize::Auto
70 }
71
72 #[inline]
74 pub fn is_auto(&self) -> bool {
75 matches!(*self, PageSize::Auto)
76 }
77}