diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs index a7056f23ca9..f3afabf15fc 100644 --- a/components/layout_2020/flow/construct.rs +++ b/components/layout_2020/flow/construct.rs @@ -210,7 +210,6 @@ where self.handle_block_level_element(style.clone(), inside, contents, box_slot) } }, - DisplayOutside::None => panic!(":("), }, } } @@ -352,7 +351,6 @@ where inline_box.last_fragment = true; Arc::new(InlineLevelBox::InlineBox(inline_box)) }, - DisplayInside::None | DisplayInside::Contents => panic!(":("), }, }; self.current_inline_level_boxes().push(box_.clone()); diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs index 59b822976ca..133654f32b7 100644 --- a/components/layout_2020/flow/inline.rs +++ b/components/layout_2020/flow/inline.rs @@ -122,7 +122,6 @@ impl InlineFormattingContext { inline: match outside { DisplayOutside::Inline => ifc.inline_position, DisplayOutside::Block => Length::zero(), - DisplayOutside::None => unreachable!(":("), }, block: ifc.line_boxes.next_line_block_position, }, diff --git a/components/layout_2020/lib.rs b/components/layout_2020/lib.rs index 5c046feecd7..052cb4b0540 100644 --- a/components/layout_2020/lib.rs +++ b/components/layout_2020/lib.rs @@ -38,11 +38,10 @@ use crate::flow::{BlockFormattingContext, FlowChildren}; use crate::geom::flow_relative::Vec2; use crate::positioned::AbsolutelyPositionedFragment; use crate::replaced::ReplacedContent; -use crate::style_ext::{ComputedValuesExt, Direction, Position, WritingMode}; +use crate::style_ext::{ComputedValuesExt, Direction, DisplayInside, Position, WritingMode}; use servo_arc::Arc; use std::convert::TryInto; use style::context::SharedStyleContext; -use style::values::specified::box_::DisplayInside; /// https://drafts.csswg.org/css-display/#independent-formatting-context #[derive(Debug)] @@ -74,7 +73,6 @@ impl IndependentFormattingContext { non_replaced, )) }, - DisplayInside::None | DisplayInside::Contents => panic!(":("), }, Err(replaced) => IndependentFormattingContext::Replaced(replaced), } diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index bb0b0411dec..e6d4537f47c 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -4,14 +4,12 @@ use crate::geom::{flow_relative, physical}; use style::properties::ComputedValues; -use style::values::computed::{ - Display as PackedDisplay, Length, LengthPercentage, LengthPercentageOrAuto, Size, -}; +use style::values::computed::{Length, LengthPercentage, LengthPercentageOrAuto, Size}; +use style::values::specified::box_ as stylo; pub use style::computed_values::direction::T as Direction; pub use style::computed_values::position::T as Position; pub use style::computed_values::writing_mode::T as WritingMode; -pub use style::values::specified::box_::{DisplayInside, DisplayOutside}; #[derive(Clone, Copy, Eq, PartialEq)] pub(crate) enum Display { @@ -31,6 +29,18 @@ pub(crate) enum DisplayGeneratingBox { // https://drafts.csswg.org/css-display-3/#layout-specific-display } +#[derive(Clone, Copy, Eq, PartialEq)] +pub(crate) enum DisplayOutside { + Block, + Inline, +} + +#[derive(Clone, Copy, Eq, PartialEq)] +pub(crate) enum DisplayInside { + Flow, + FlowRoot, +} + pub(crate) trait ComputedValuesExt { fn writing_mode(&self) -> (WritingMode, Direction); fn box_offsets(&self) -> flow_relative::Sides; @@ -105,18 +115,27 @@ impl ComputedValuesExt for ComputedValues { } } -impl From for Display { - fn from(packed_display: PackedDisplay) -> Self { - if packed_display == PackedDisplay::None { - return Self::None; - } - if packed_display == PackedDisplay::Contents { - return Self::Contents; - } - Self::GeneratingBox(DisplayGeneratingBox::OutsideInside { - outside: packed_display.outside(), - inside: packed_display.inside(), - // list_item: packed_display.is_list_item(), +impl From for Display { + fn from(packed: stylo::Display) -> Self { + let inside = match packed.inside() { + stylo::DisplayInside::Flow => DisplayInside::Flow, + stylo::DisplayInside::FlowRoot => DisplayInside::FlowRoot, + + // These should not be values of DisplayInside, but oh well + stylo::DisplayInside::None => return Display::None, + stylo::DisplayInside::Contents => return Display::Contents, + }; + let outside = match packed.outside() { + stylo::DisplayOutside::Block => DisplayOutside::Block, + stylo::DisplayOutside::Inline => DisplayOutside::Inline, + + // This should not be a value of DisplayInside, but oh well + stylo::DisplayOutside::None => return Display::None, + }; + Display::GeneratingBox(DisplayGeneratingBox::OutsideInside { + outside, + inside, + // list_item: packed.is_list_item(), }) } }