use crate::values::computed::length::NonNegativeLength;
use crate::values::computed::{Context, ToComputedValue};
use crate::values::generics;
use crate::values::generics::size::Size2D;
use crate::values::specified::page as specified;
pub use generics::page::GenericPageSize;
pub use generics::page::PageOrientation;
pub use generics::page::PageSizeOrientation;
pub use generics::page::PaperSize;
pub use specified::PageName;
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)]
#[repr(C, u8)]
pub enum PageSize {
Size(Size2D<NonNegativeLength>),
Orientation(PageSizeOrientation),
Auto,
}
impl ToComputedValue for specified::PageSize {
type ComputedValue = PageSize;
fn to_computed_value(&self, ctx: &Context) -> Self::ComputedValue {
match &*self {
Self::Size(s) => PageSize::Size(s.to_computed_value(ctx)),
Self::PaperSize(p, PageSizeOrientation::Landscape) => PageSize::Size(Size2D {
width: p.long_edge().to_computed_value(ctx),
height: p.short_edge().to_computed_value(ctx),
}),
Self::PaperSize(p, PageSizeOrientation::Portrait) => PageSize::Size(Size2D {
width: p.short_edge().to_computed_value(ctx),
height: p.long_edge().to_computed_value(ctx),
}),
Self::Orientation(o) => PageSize::Orientation(*o),
Self::Auto => PageSize::Auto,
}
}
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
match *computed {
PageSize::Size(s) => Self::Size(ToComputedValue::from_computed_value(&s)),
PageSize::Orientation(o) => Self::Orientation(o),
PageSize::Auto => Self::Auto,
}
}
}
impl PageSize {
#[inline]
pub fn auto() -> Self {
PageSize::Auto
}
#[inline]
pub fn is_auto(&self) -> bool {
matches!(*self, PageSize::Auto)
}
}