use crate::html::css_parse::CssDisplay;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OuterDisplay {
BlockLevel { container: bool },
Inline { block: bool },
}
impl Default for OuterDisplay {
fn default() -> Self {
OuterDisplay::BlockLevel { container: true }
}
}
impl OuterDisplay {
pub fn from_css_display(display: CssDisplay) -> Self {
match display {
CssDisplay::Inline => OuterDisplay::Inline { block: false },
CssDisplay::InlineBlock
| CssDisplay::InlineFlex
| CssDisplay::InlineGrid
| CssDisplay::InlineTable => OuterDisplay::Inline { block: true },
CssDisplay::None | CssDisplay::Contents => {
OuterDisplay::BlockLevel { container: false }
}
_ => OuterDisplay::BlockLevel { container: true },
}
}
pub fn is_inline(self) -> bool {
matches!(self, OuterDisplay::Inline { .. })
}
pub fn is_block_level(self) -> bool {
matches!(self, OuterDisplay::BlockLevel { .. })
}
pub fn establishes_formatting_context(self) -> bool {
matches!(
self,
OuterDisplay::BlockLevel { container: true } | OuterDisplay::Inline { block: true }
)
}
}