style: Remove the paper size variant of GenericPageSize and add an implied default to the paper size and orientation variant

Differential Revision: https://phabricator.services.mozilla.com/D119915
This commit is contained in:
Emily McDonough 2023-05-22 10:09:22 +02:00 committed by Oriol Brufau
parent 45d6e64d51
commit c2a50c92fa
3 changed files with 21 additions and 20 deletions

View file

@ -36,16 +36,14 @@ impl ToComputedValue for specified::PageSize {
fn to_computed_value(&self, ctx: &Context) -> Self::ComputedValue { fn to_computed_value(&self, ctx: &Context) -> Self::ComputedValue {
match &*self { match &*self {
Self::Size(s) => PageSize::Size(s.to_computed_value(ctx)), Self::Size(s) => PageSize::Size(s.to_computed_value(ctx)),
Self::PaperSizeAndOrientation(p, Orientation::Landscape) => PageSize::Size(Size2D { Self::PaperSize(p, Orientation::Landscape) => PageSize::Size(Size2D {
width: p.long_edge().to_computed_value(ctx), width: p.long_edge().to_computed_value(ctx),
height: p.short_edge().to_computed_value(ctx), height: p.short_edge().to_computed_value(ctx),
}), }),
Self::PaperSizeAndOrientation(p, Orientation::Portrait) | Self::PaperSize(p) => { Self::PaperSize(p, Orientation::Portrait) => PageSize::Size(Size2D {
PageSize::Size(Size2D { width: p.short_edge().to_computed_value(ctx),
width: p.short_edge().to_computed_value(ctx), height: p.long_edge().to_computed_value(ctx),
height: p.long_edge().to_computed_value(ctx), }),
})
},
Self::Orientation(o) => PageSize::Orientation(*o), Self::Orientation(o) => PageSize::Orientation(*o),
Self::Auto => PageSize::Auto, Self::Auto => PageSize::Auto,
} }

View file

@ -94,22 +94,25 @@ pub enum Orientation {
Landscape, Landscape,
} }
#[inline]
fn is_portrait(orientation: &Orientation) -> bool {
*orientation == Orientation::Portrait
}
/// Page size property /// Page size property
/// ///
/// https://drafts.csswg.org/css-page-3/#page-size-prop /// https://drafts.csswg.org/css-page-3/#page-size-prop
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
#[repr(C, u8)] #[repr(C, u8)]
pub enum GenericPageSize<S> { pub enum GenericPageSize<S> {
/// Page dimensions.
Size(S),
/// Paper size with no orientation.
PaperSize(PaperSize),
/// An orientation with no size.
Orientation(Orientation),
/// Paper size by name, with an orientation.
PaperSizeAndOrientation(PaperSize, Orientation),
/// `auto` value. /// `auto` value.
Auto, Auto,
/// Page dimensions.
Size(S),
/// An orientation with no size.
Orientation(Orientation),
/// Paper size by name
PaperSize(PaperSize, #[css(skip_if = "is_portrait")] Orientation),
} }
pub use self::GenericPageSize as PageSize; pub use self::GenericPageSize as PageSize;

View file

@ -23,15 +23,15 @@ impl Parse for PageSize {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
// Try to parse as <page-size> [ <orientation> ] // Try to parse as <page-size> [ <orientation> ]
if let Ok(paper_size) = input.try_parse(PaperSize::parse) { if let Ok(paper_size) = input.try_parse(PaperSize::parse) {
if let Ok(orientation) = input.try_parse(Orientation::parse) { let orientation = input
return Ok(PageSize::PaperSizeAndOrientation(paper_size, orientation)); .try_parse(Orientation::parse)
} .unwrap_or(Orientation::Portrait);
return Ok(PageSize::PaperSize(paper_size)); return Ok(PageSize::PaperSize(paper_size, orientation));
} }
// Try to parse as <orientation> [ <page-size> ] // Try to parse as <orientation> [ <page-size> ]
if let Ok(orientation) = input.try_parse(Orientation::parse) { if let Ok(orientation) = input.try_parse(Orientation::parse) {
if let Ok(paper_size) = input.try_parse(PaperSize::parse) { if let Ok(paper_size) = input.try_parse(PaperSize::parse) {
return Ok(PageSize::PaperSizeAndOrientation(paper_size, orientation)); return Ok(PageSize::PaperSize(paper_size, orientation));
} }
return Ok(PageSize::Orientation(orientation)); return Ok(PageSize::Orientation(orientation));
} }