#![allow(unused_assignments)] #![allow(unused_variables)] //! Module that handles the construction on `AnonDom`, a `Dom` that holds //! "anonymous" nodes (that group two following "inline" texts into one "anonymous" block). use std::collections::BTreeMap; use crate::{ RectContent, style::{Style, Overflow, Display, PositionType}, }; use azul_core::{ id_tree::{NodeDataContainer, NodeHierarchy, NodeId, NodeDepths, Node}, traits::GetTextLayout, }; pub(crate) type OriginalNodeId = NodeId; pub(crate) type AnonNodeId = NodeId; /// Same as the original DOM, but with anonymous nodes added to the original nodes. /// /// Each box must contain only block children, or only inline children. When an DOM element /// contains a mix of block and inline children, the layout engine inserts anonymous boxes to /// separate the two types. (These boxes are "anonymous" because they aren't associated with /// nodes in the DOM tree.) #[derive(Debug, Clone)] pub(crate) struct AnonDom { pub(crate) anon_node_hierarchy: NodeHierarchy, pub(crate) anon_node_data: NodeDataContainer, pub(crate) original_node_id_mapping: BTreeMap, pub(crate) reverse_node_id_mapping: BTreeMap, } #[derive(Debug, Copy, Clone)] pub(crate) enum AnonNode { /// Node that doesn't have a correspondent in the DOM tree, /// but still behaves like display: block. Is always a parent of one or /// more display:inline items AnonStyle, /// Non-inline DOM node (block / flex, etc.) BlockNode(Style), /// Inline node or text. Note that the style.display may still be "block", /// on text nodes the "display" property is ignored, since texts are always /// laid out as inline items. InlineNode(Style), } impl AnonNode { pub(crate) fn get_style(&self) -> &Style { use self::AnonNode::*; use crate::style::DEFAULT_STYLE; match &self { AnonStyle => &DEFAULT_STYLE, BlockNode(s) | InlineNode(s) => s, } } pub(crate) fn get_position_type(&self) -> PositionType { use self::AnonNode::*; match self { AnonStyle => PositionType::Static, BlockNode(s) | InlineNode(s) => s.position_type, } } pub(crate) fn get_display(&self) -> Display { use self::AnonNode::*; match self { AnonStyle => Display::Block, BlockNode(s) | InlineNode(s) => s.display, } } pub(crate) fn get_overflow_x(&self) -> Overflow { use self::AnonNode::*; match self { AnonStyle => Overflow::Auto, BlockNode(s) | InlineNode(s) => s.overflow, } } #[allow(dead_code)] pub(crate) fn is_inline(&self) -> bool { use self::AnonNode::*; match self { AnonStyle | BlockNode(_) => false, InlineNode(_) => true, } } } impl AnonDom { pub(crate) fn new( node_hierarchy: &NodeHierarchy, node_styles: &NodeDataContainer