diff --git a/servo/components/style/values/computed/page.rs b/servo/components/style/values/computed/page.rs index 524f6ba468e1..27b16d0af15a 100644 --- a/servo/components/style/values/computed/page.rs +++ b/servo/components/style/values/computed/page.rs @@ -36,16 +36,14 @@ impl ToComputedValue for specified::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 { + Self::PaperSize(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::PaperSize(p, Orientation::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, } diff --git a/servo/components/style/values/generics/page.rs b/servo/components/style/values/generics/page.rs index 6f5617104910..1de1a8e912c1 100644 --- a/servo/components/style/values/generics/page.rs +++ b/servo/components/style/values/generics/page.rs @@ -94,22 +94,25 @@ pub enum Orientation { Landscape, } +#[inline] +fn is_portrait(orientation: &Orientation) -> bool { + *orientation == Orientation::Portrait +} + /// Page size property /// /// https://drafts.csswg.org/css-page-3/#page-size-prop #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] #[repr(C, u8)] pub enum GenericPageSize { - /// 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, + /// 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; diff --git a/servo/components/style/values/specified/page.rs b/servo/components/style/values/specified/page.rs index 81684e114a34..4d96b5326899 100644 --- a/servo/components/style/values/specified/page.rs +++ b/servo/components/style/values/specified/page.rs @@ -23,15 +23,15 @@ impl Parse for PageSize { ) -> Result> { // Try to parse as [ ] if let Ok(paper_size) = input.try_parse(PaperSize::parse) { - if let Ok(orientation) = input.try_parse(Orientation::parse) { - return Ok(PageSize::PaperSizeAndOrientation(paper_size, orientation)); - } - return Ok(PageSize::PaperSize(paper_size)); + let orientation = input + .try_parse(Orientation::parse) + .unwrap_or(Orientation::Portrait); + return Ok(PageSize::PaperSize(paper_size, orientation)); } // Try to parse as [ ] if let Ok(orientation) = input.try_parse(Orientation::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)); }