2020: define DisplayInside and DisplayOutside enums separately from Stylo

This commit is contained in:
Simon Sapin 2019-10-23 17:59:06 +02:00
parent 8f89f59329
commit 22f5e07765
4 changed files with 36 additions and 22 deletions

View file

@ -210,7 +210,6 @@ where
self.handle_block_level_element(style.clone(), inside, contents, box_slot) self.handle_block_level_element(style.clone(), inside, contents, box_slot)
} }
}, },
DisplayOutside::None => panic!(":("),
}, },
} }
} }
@ -352,7 +351,6 @@ where
inline_box.last_fragment = true; inline_box.last_fragment = true;
Arc::new(InlineLevelBox::InlineBox(inline_box)) Arc::new(InlineLevelBox::InlineBox(inline_box))
}, },
DisplayInside::None | DisplayInside::Contents => panic!(":("),
}, },
}; };
self.current_inline_level_boxes().push(box_.clone()); self.current_inline_level_boxes().push(box_.clone());

View file

@ -122,7 +122,6 @@ impl InlineFormattingContext {
inline: match outside { inline: match outside {
DisplayOutside::Inline => ifc.inline_position, DisplayOutside::Inline => ifc.inline_position,
DisplayOutside::Block => Length::zero(), DisplayOutside::Block => Length::zero(),
DisplayOutside::None => unreachable!(":("),
}, },
block: ifc.line_boxes.next_line_block_position, block: ifc.line_boxes.next_line_block_position,
}, },

View file

@ -38,11 +38,10 @@ use crate::flow::{BlockFormattingContext, FlowChildren};
use crate::geom::flow_relative::Vec2; use crate::geom::flow_relative::Vec2;
use crate::positioned::AbsolutelyPositionedFragment; use crate::positioned::AbsolutelyPositionedFragment;
use crate::replaced::ReplacedContent; 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 servo_arc::Arc;
use std::convert::TryInto; use std::convert::TryInto;
use style::context::SharedStyleContext; use style::context::SharedStyleContext;
use style::values::specified::box_::DisplayInside;
/// https://drafts.csswg.org/css-display/#independent-formatting-context /// https://drafts.csswg.org/css-display/#independent-formatting-context
#[derive(Debug)] #[derive(Debug)]
@ -74,7 +73,6 @@ impl IndependentFormattingContext {
non_replaced, non_replaced,
)) ))
}, },
DisplayInside::None | DisplayInside::Contents => panic!(":("),
}, },
Err(replaced) => IndependentFormattingContext::Replaced(replaced), Err(replaced) => IndependentFormattingContext::Replaced(replaced),
} }

View file

@ -4,14 +4,12 @@
use crate::geom::{flow_relative, physical}; use crate::geom::{flow_relative, physical};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::{ use style::values::computed::{Length, LengthPercentage, LengthPercentageOrAuto, Size};
Display as PackedDisplay, 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::direction::T as Direction;
pub use style::computed_values::position::T as Position; pub use style::computed_values::position::T as Position;
pub use style::computed_values::writing_mode::T as WritingMode; pub use style::computed_values::writing_mode::T as WritingMode;
pub use style::values::specified::box_::{DisplayInside, DisplayOutside};
#[derive(Clone, Copy, Eq, PartialEq)] #[derive(Clone, Copy, Eq, PartialEq)]
pub(crate) enum Display { pub(crate) enum Display {
@ -31,6 +29,18 @@ pub(crate) enum DisplayGeneratingBox {
// https://drafts.csswg.org/css-display-3/#layout-specific-display // 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 { pub(crate) trait ComputedValuesExt {
fn writing_mode(&self) -> (WritingMode, Direction); fn writing_mode(&self) -> (WritingMode, Direction);
fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto>; fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto>;
@ -105,18 +115,27 @@ impl ComputedValuesExt for ComputedValues {
} }
} }
impl From<PackedDisplay> for Display { impl From<stylo::Display> for Display {
fn from(packed_display: PackedDisplay) -> Self { fn from(packed: stylo::Display) -> Self {
if packed_display == PackedDisplay::None { let inside = match packed.inside() {
return Self::None; stylo::DisplayInside::Flow => DisplayInside::Flow,
} stylo::DisplayInside::FlowRoot => DisplayInside::FlowRoot,
if packed_display == PackedDisplay::Contents {
return Self::Contents; // These should not be values of DisplayInside, but oh well
} stylo::DisplayInside::None => return Display::None,
Self::GeneratingBox(DisplayGeneratingBox::OutsideInside { stylo::DisplayInside::Contents => return Display::Contents,
outside: packed_display.outside(), };
inside: packed_display.inside(), let outside = match packed.outside() {
// list_item: packed_display.is_list_item(), 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(),
}) })
} }
} }