use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::layout) enum InlineBoundaryRole {
Text,
TransparentTextBoundary,
OpaqueAtomic,
IndependentFormattingContext,
Float,
ForcedBreak,
PageScopeStart,
PageScopeEnd,
}
impl InlineBoundaryRole {
pub(in crate::layout) fn is_transparent_to_whitespace(self) -> bool {
matches!(
self,
Self::TransparentTextBoundary | Self::PageScopeStart | Self::PageScopeEnd
)
}
pub(in crate::layout) fn resets_text_context(self) -> bool {
matches!(
self,
Self::OpaqueAtomic | Self::IndependentFormattingContext | Self::Float
)
}
pub(in crate::layout) fn is_page_scope(self) -> bool {
matches!(self, Self::PageScopeStart | Self::PageScopeEnd)
}
}
pub(in crate::layout) fn inline_item_boundary_role(item: &InlineItem) -> InlineBoundaryRole {
match item {
InlineItem::Word(word) if word.text.chars().all(character_is_bidi_format_control) => {
InlineBoundaryRole::TransparentTextBoundary
}
InlineItem::Word(_) => InlineBoundaryRole::Text,
InlineItem::Atom(atom) => inline_atom_boundary_role(atom.content()),
InlineItem::StaticPositionSourceMarker(_) => InlineBoundaryRole::TransparentTextBoundary,
InlineItem::Float(_) => InlineBoundaryRole::Float,
InlineItem::Break(_) => InlineBoundaryRole::ForcedBreak,
InlineItem::PageScopeStart(_) => InlineBoundaryRole::PageScopeStart,
InlineItem::PageScopeEnd => InlineBoundaryRole::PageScopeEnd,
}
}
pub(in crate::layout) fn inline_atom_boundary_role(
content: &InlineAtomContent,
) -> InlineBoundaryRole {
match content {
InlineAtomContent::InlineEdge(InlineEdgeRole::BoxEdge(_))
| InlineAtomContent::InlineEdge(InlineEdgeRole::MetricsOnlyStrut)
| InlineAtomContent::InlineEdge(InlineEdgeRole::TextAutospace(_))
| InlineAtomContent::StaticPositionHypothetical {
boundary: StaticPositionHypotheticalBoundary::Transparent,
..
} => {
InlineBoundaryRole::TransparentTextBoundary
}
InlineAtomContent::InlineBox { .. }
| InlineAtomContent::Ruby { .. }
| InlineAtomContent::TextCombineUpright { .. }
| InlineAtomContent::InlineFragment { .. } => {
InlineBoundaryRole::IndependentFormattingContext
}
InlineAtomContent::Canvas
| InlineAtomContent::StaticPositionHypothetical {
boundary: StaticPositionHypotheticalBoundary::Atomic,
..
}
| InlineAtomContent::Iframe(_)
| InlineAtomContent::Image(_)
| InlineAtomContent::Gradient { .. }
| InlineAtomContent::Svg { .. }
| InlineAtomContent::Leader(_) => InlineBoundaryRole::OpaqueAtomic,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn static_position_source_marker_is_transparent_but_hypothetical_is_atomic() {
let source = InlineStaticPositionSourceId::Block;
assert_eq!(
inline_item_boundary_role(&InlineItem::StaticPositionSourceMarker(source)),
InlineBoundaryRole::TransparentTextBoundary,
);
assert_eq!(
inline_atom_boundary_role(&InlineAtomContent::StaticPositionHypothetical {
source,
boundary: StaticPositionHypotheticalBoundary::Atomic,
}),
InlineBoundaryRole::OpaqueAtomic,
);
assert_eq!(
inline_atom_boundary_role(&InlineAtomContent::StaticPositionHypothetical {
source,
boundary: StaticPositionHypotheticalBoundary::Transparent,
}),
InlineBoundaryRole::TransparentTextBoundary,
);
}
}