mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Use a computed type for page-size which converts paper sizes to a Size2D
Differential Revision: https://phabricator.services.mozilla.com/D115842
This commit is contained in:
parent
4f0e0c888c
commit
c9d4f812e5
2 changed files with 100 additions and 26 deletions
|
@ -5,10 +5,71 @@
|
|||
//! Computed @page at-rule properties
|
||||
|
||||
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::Orientation;
|
||||
pub use generics::page::PaperSize;
|
||||
|
||||
/// Computed value of the @page size descriptor
|
||||
pub type PageSize = generics::page::GenericPageSize<Size2D<NonNegativeLength>>;
|
||||
///
|
||||
/// The spec says that the computed value should be the same as the specified
|
||||
/// value but with all absolute units, but it's not currently possibly observe
|
||||
/// the computed value of page-size.
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)]
|
||||
#[repr(C, u8)]
|
||||
pub enum PageSize {
|
||||
/// Specified size, paper size, or paper size and orientation.
|
||||
Size(Size2D<NonNegativeLength>),
|
||||
/// `landscape` or `portrait` value, no specified size.
|
||||
Orientation(Orientation),
|
||||
/// `auto` value
|
||||
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::PaperSizeAndOrientation(p, Orientation::Landscape) => PageSize::Size(Size2D {
|
||||
width: p.long_edge().to_computed_value(ctx),
|
||||
height: p.short_edge().to_computed_value(ctx),
|
||||
}),
|
||||
Self::PaperSizeAndOrientation(p, Orientation::Portrait) | Self::PaperSize(p) => {
|
||||
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 {
|
||||
/// `auto` value.
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
PageSize::Auto
|
||||
}
|
||||
|
||||
/// Whether this is the `auto` value.
|
||||
#[inline]
|
||||
pub fn is_auto(&self) -> bool {
|
||||
matches!(*self, PageSize::Auto)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue