Truly independent web browser
LibWeb: Continue floats and inline content across columns
sideshowbarker241e3b9e99c9
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex e7dfa761abd..44765ce71ea 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -239,15 +239,23 @@ pub(crate) struct StateBeforeFindingLineBreaks {lowest_left_margin_edge: Option<CssPixels>,lowest_right_margin_edge: Option<CssPixels>,margin_state: BlockMarginState,+ deferred_float_sides: u8,}/// A float whose contents are laid out, which is yet to be positioned and placed.pub(crate) struct FloatLaidOutAheadOfItsPosition {- node: Node,+ pub(crate) node: Node,placed_float: formatting_context::PlacedChild,pub(crate) cells: used_values::RootInputCells,laid_out_float_handed_back_by_its_run: Option<LaidOutBox>,- fragment_arrival: Option<fragment_tree::RunRootFragment>,+ pub(crate) fragment_arrival: Option<fragment_tree::RunRootFragment>,+}++/// A float's exclusion and layout, before its fragment is placed in the column that keeps it.+pub(crate) struct PositionedFloat {+ pub(crate) laid_out_float: FloatLaidOutAheadOfItsPosition,+ floating_box: FloatingBox,+ content_block_offset: CssPixels,}/// A box a block formatting context sizes, in cells the call laying the box out owns: the cells the context lays the@@ -382,6 +390,7 @@ struct FragmentationState {/// The break token of the container, once the fragmentainer stops inside it.container_stop_token: Option<std::rc::Rc<fragmentation::BlockBreakToken>>,resume: Option<fragmentation::BlockResume>,+ deferred_floats: Vec<Node>,fragmentainer_had_content_before_container: bool,fragmentainer_had_content_before_child: bool,truncate_next_block_start_margin: bool,@@ -409,6 +418,7 @@ impl FragmentationState {container_content_box_block_start_in_root,container_stop_token: None,resume: incoming.map(|token| token.resume.clone()),+ deferred_floats: incoming.map_or_else(Vec::new, |token| token.deferred_floats.clone()),fragmentainer_had_content_before_container,fragmentainer_had_content_before_child: false,truncate_next_block_start_margin,@@ -1035,6 +1045,7 @@ pub(crate) struct BlockFormattingContext<'pass> {/// box for it.outside_marker_line_box_block_size_of_root: Cell<Option<CssPixels>>,floats: RefCell<Vec<FloatingBox>>,+ deferred_float_sides: Cell<u8>,bands: RefCell<SmallVec<[FloatBand; 4]>>,lowest_left_margin_edge: Cell<Option<CssPixels>>,lowest_right_margin_edge: Cell<Option<CssPixels>>,@@ -1244,6 +1255,7 @@ impl<'pass> BlockFormattingContext<'pass> {outside_marker_line: Cell::new(None),outside_marker_line_box_block_size_of_root: Cell::new(None),floats: RefCell::new(Vec::new()),+ deferred_float_sides: Cell::new(0),bands: RefCell::new(smallvec![FloatBand::above_every_float()]),lowest_left_margin_edge: Cell::new(None),lowest_right_margin_edge: Cell::new(None),@@ -2841,6 +2853,19 @@ impl<'pass> BlockFormattingContext<'pass> {}};+ if let Some(block_size) = self+ .run+ .fragmentainer+ .and_then(|fragmentainer| fragmentainer.block_size)+ {+ let sides = self.deferred_float_sides.get();+ if (sides & 1 != 0 && matches!(style.clear(), clear::LEFT | clear::BOTH | clear::INLINE_START))+ || (sides & 2 != 0 && matches!(style.clear(), clear::RIGHT | clear::BOTH | clear::INLINE_END))+ {+ clear_to(Some(block_size));+ }+ }+// FIXME: Honor writing-mode, direction and text-orientation.if matches!(style.clear(), clear::LEFT | clear::BOTH | clear::INLINE_START) {clear_to(self.lowest_left_margin_edge.get());@@ -3943,6 +3968,7 @@ impl<'pass> BlockFormattingContext<'pass> {std::rc::Rc::new(fragmentation::BlockBreakToken {node,consumed_block_size: CssPixels::default(),+ deferred_floats: Vec::new(),resume: fragmentation::BlockResume::AfterChildren,})})@@ -5227,6 +5253,23 @@ impl<'pass> BlockFormattingContext<'pass> {}let mut lays_out_children_ahead = fragmentainer.is_none();let mut summary = ChildrenSummary::default();+ let mut deferred_floats = Vec::new();+ if let Some(state) = fragmentation_state.as_mut() {+ for child in std::mem::take(&mut state.deferred_floats) {+ let outcome = self.layout_block_level_box(+ run,+ child,+ block_container,+ child_input.clone(),+ containing_block_position_in_root,+ None,+ );+ self.fold_in_child(&mut summary, block_container.node, child, outcome.as_ref());+ if outcome.is_some_and(|outcome| !outcome.is_placed) {+ deferred_floats.push(child);+ }+ }+ }for child in self.run.pass@@ -5273,6 +5316,12 @@ impl<'pass> BlockFormattingContext<'pass> {self.laying_out_invisible_line_clamp_content.set(false);}self.fold_in_child(&mut summary, block_container.node, child, outcome.as_ref());+ if fragmentainer.is_some()+ && self.facts(child).is_floating()+ && outcome.as_ref().is_some_and(|outcome| !outcome.is_placed)+ {+ deferred_floats.push(child);+ }if let (Some(fragmentainer), Some(state)) = (fragmentainer.as_ref(), fragmentation_state.as_mut())&& self.fragmentation_step_after_child(fragmentainer,@@ -5285,6 +5334,30 @@ impl<'pass> BlockFormattingContext<'pass> {break;}}+ if let (Some(fragmentainer), Some(state)) = (fragmentainer.as_ref(), fragmentation_state.as_mut())+ && !deferred_floats.is_empty()+ {+ let at_root = block_container.node == self.run.box_;+ let mut token = if at_root {+ fragmentainer.outcome_mut().outgoing.take()+ } else {+ state.container_stop_token.take()+ }+ .unwrap_or_else(|| {+ std::rc::Rc::new(fragmentation::BlockBreakToken {+ node: block_container.node,+ consumed_block_size: CssPixels::default(),+ resume: fragmentation::BlockResume::AfterChildren,+ deferred_floats: Vec::new(),+ })+ });+ std::rc::Rc::make_mut(&mut token).deferred_floats = deferred_floats;+ if at_root {+ fragmentainer.outcome_mut().outgoing = Some(token);+ } else {+ state.container_stop_token = Some(token);+ }+ }self.block_offset_of_current_block_container.set(saved);summary.fragmentainer_stop_token = fragmentation_state.and_then(|state| state.container_stop_token);summary@@ -5594,6 +5667,9 @@ impl<'pass> BlockFormattingContext<'pass> {Some(fragmentation::LineRootFragmentation {block_size: fragmentainer.block_size,resume,+ deferred_floats: incoming+ .as_ref()+ .map_or_else(Vec::new, |token| token.deferred_floats.clone()),fragmentainer_had_content: self.fragmentainer_has_content.get(),break_before_is_avoided: self.break_before_child_is_avoided.get() == Some(line_root),})@@ -5656,9 +5732,21 @@ impl<'pass> BlockFormattingContext<'pass> {&self,line_root: Node,line_start: fragmentation::LinePosition,+ deferred_floats: Vec<Node>,) -> Option<std::rc::Rc<fragmentation::BlockBreakToken>> {let fragmentainer = self.run.fragmentainer.as_ref()?;- self.stop_fragmentainer(fragmentainer, line_root, fragmentation::BlockResume::AtLine(line_start))+ let token = std::rc::Rc::new(fragmentation::BlockBreakToken {+ node: line_root,+ consumed_block_size: CssPixels::default(),+ resume: fragmentation::BlockResume::AtLine(line_start),+ deferred_floats,+ });+ if line_root == self.run.box_ {+ fragmentainer.outcome_mut().outgoing = Some(token);+ None+ } else {+ Some(token)+ }}fn box_can_break_inside(&self, node: Node, has_unbreakable_lines: bool) -> bool {@@ -5721,6 +5809,7 @@ impl<'pass> BlockFormattingContext<'pass> {let token = std::rc::Rc::new(fragmentation::BlockBreakToken {node: block_container,consumed_block_size: CssPixels::default(),+ deferred_floats: Vec::new(),resume,});if block_container == self.run.box_ {@@ -5911,6 +6000,7 @@ impl<'pass> BlockFormattingContext<'pass> {incoming = Some(std::rc::Rc::new(fragmentation::BlockBreakToken {node: root,consumed_block_size: CssPixels::default(),+ deferred_floats: Vec::new(),resume: fragmentation::BlockResume::BeforeChild {child: next,after_forced_break: true,@@ -6774,35 +6864,81 @@ impl<'pass> BlockFormattingContext<'pass> {Option<LaidOutBox>,Option<FfiCssPixelPoint>,) {- let FloatLaidOutAheadOfItsPosition {- node,- placed_float,- cells: float_box,- laid_out_float_handed_back_by_its_run,- fragment_arrival,- } = laid_out_float;+ let node = laid_out_float.node;let Some(side) = Self::float_side(self.style(node)) else {formatting_context::leave_child_unplaced(run,- placed_float.with_fragment_facts(fragment_facts),- fragment_arrival,+ laid_out_float.placed_float.with_fragment_facts(fragment_facts),+ laid_out_float.fragment_arrival,);return (abspos_engine::InFlowBoxInsets::default(),- laid_out_float_handed_back_by_its_run,+ laid_out_float.laid_out_float_handed_back_by_its_run,None,);};let (floating_box, content_block_offset) = self.add_float_beside_lines(node,side,- &float_box,+ &laid_out_float.cells,block_container,input,containing_block_position_in_root,block_offset,line_builder.as_deref_mut(),);+ if line_builder.is_none()+ && self.run.fragmentainer.is_some()+ && self.allows_unforced_breaks()+ && self.defer_float_past_column(floating_box, true)+ {+ if let Some(fragments) = run.fragments {+ fragments.discard_unplaced_subtree(node, laid_out_float.fragment_arrival);+ }+ return (+ abspos_engine::InFlowBoxInsets::default(),+ laid_out_float.laid_out_float_handed_back_by_its_run,+ None,+ );+ }+ if let Some(line_builder) = line_builder {+ line_builder.recalculate_available_space();+ }+ self.place_positioned_float(+ run,+ PositionedFloat {+ laid_out_float,+ floating_box,+ content_block_offset,+ },+ block_container,+ fragment_facts,+ )+ }++ pub(crate) fn place_positioned_float(+ &self,+ run: &FormattingContextRun<'pass>,+ positioned: PositionedFloat,+ block_container: BlockContainer,+ fragment_facts: run_state::FragmentFactsDecidedByParent,+ ) -> (+ abspos_engine::InFlowBoxInsets,+ Option<LaidOutBox>,+ Option<FfiCssPixelPoint>,+ ) {+ let PositionedFloat {+ laid_out_float,+ floating_box,+ content_block_offset,+ } = positioned;+ let FloatLaidOutAheadOfItsPosition {+ node,+ placed_float,+ laid_out_float_handed_back_by_its_run,+ fragment_arrival,+ ..+ } = laid_out_float;let margin_box_rect = floating_box.margin_box_rect_in_root_coordinate_space;let bottom_margin_edge = margin_box_rect.bottom();@@ -6827,12 +6963,9 @@ impl<'pass> BlockFormattingContext<'pass> {.get().map_or(bottom_margin_edge, |lowest| lowest.max(bottom_margin_edge)),));- if let Some(line_builder) = line_builder {- line_builder.recalculate_available_space();- }let insets = self.compute_inset(run, node, block_container);- let inline_offset = if side == FloatSide::Left {+ let inline_offset = if floating_box.side == FloatSide::Left {floating_box.offset_from_edge} else {floating_box.percentage_basis_inline_size.unwrap_or_default() - floating_box.offset_from_edge@@ -6854,7 +6987,77 @@ impl<'pass> BlockFormattingContext<'pass> {(insets, laid_out_float_handed_back_by_its_run, Some(content_offset))}+ #[allow(clippy::too_many_arguments)]+ pub(crate) fn position_inline_float_in_column(+ &self,+ laid_out_float: FloatLaidOutAheadOfItsPosition,+ block_container: BlockContainer,+ input: LayoutInput,+ containing_block_position_in_root: FfiCssPixelPoint,+ line_builder: &mut line_builder::LineBuilder<'_, '_>,+ ) -> (PositionedFloat, bool) {+ let node = laid_out_float.node;+ let side = Self::float_side(self.style(node)).expect("an inline float has a floating side");+ let (floating_box, content_block_offset) = self.add_float_beside_lines(+ node,+ side,+ &laid_out_float.cells,+ block_container,+ input,+ containing_block_position_in_root,+ CssPixels::default(),+ Some(&mut *line_builder),+ );+ let deferred = self.defer_float_past_column(floating_box, true);+ line_builder.recalculate_available_space();+ (+ PositionedFloat {+ laid_out_float,+ floating_box,+ content_block_offset,+ },+ deferred,+ )+ }++ // https://drafts.csswg.org/css-break-3/#parallel-flows+ // The contents of a float vs. the content wrapping outside the float.+ // AD-HOC: These flows can fragment independently, but a float's contents are laid out as an unbroken box here.+ // Move the whole float when it doesn't fit, until its layout can return a continuation of its contents.+ fn defer_float_past_column(&self, floating_box: FloatingBox, records_measurement: bool) -> bool {+ let Some(fragmentainer) = self.run.fragmentainer.as_ref() else {+ return false;+ };+ let rect = floating_box.margin_box_rect_in_root_coordinate_space.translated(+ CssPixels::default(),+ self.block_offset_adjustment_from_pending_ancestor_block_start_margins(floating_box.box_),+ );+ if records_measurement {+ fragmentainer.note_unbreakable_block_size(rect.height);+ }+ let deferred = self.deferred_float_sides.get() != 0+ || (rect.y > CssPixels::default() && fragmentainer.exceeds(rect.bottom()));+ if !deferred {+ return false;+ }+ if records_measurement {+ fragmentainer.note_space_shortage(rect.bottom());+ }+ self.deferred_float_sides+ .set(self.deferred_float_sides.get() | if floating_box.side == FloatSide::Left { 1 } else { 2 });+ self.floats.borrow_mut().pop();+ self.rebuild_float_bands();+ true+ }++ pub(crate) fn retain_inline_floats(&self, first: usize, kept: &HashSet<Node>) {+ let mut floats = self.take_floating_boxes_from(first);+ floats.retain(|float| kept.contains(&float.box_));+ self.append_floating_boxes(floats);+ }+/// Adds a float laid out in `float_box` beside the lines `line_builder` builds, only to find where they break.+ #[allow(clippy::too_many_arguments)]pub(crate) fn add_float_for_finding_line_breaks(&self,node: Node,@@ -6863,11 +7066,12 @@ impl<'pass> BlockFormattingContext<'pass> {input: LayoutInput,containing_block_position_in_root: FfiCssPixelPoint,line_builder: &mut line_builder::LineBuilder<'_, '_>,+ fragments_lines: bool,) {let Some(side) = Self::float_side(self.style(node)) else {return;};- self.add_float_beside_lines(+ let (floating_box, _) = self.add_float_beside_lines(node,side,float_box,@@ -6877,6 +7081,9 @@ impl<'pass> BlockFormattingContext<'pass> {CssPixels::default(),Some(&mut *line_builder),);+ if fragments_lines {+ self.defer_float_past_column(floating_box, false);+ }line_builder.recalculate_available_space();}@@ -6884,6 +7091,7 @@ impl<'pass> BlockFormattingContext<'pass> {pub(crate) fn state_before_finding_line_breaks(&self) -> StateBeforeFindingLineBreaks {StateBeforeFindingLineBreaks {float_count: self.floating_box_count(),+ deferred_float_sides: self.deferred_float_sides.get(),bands: self.bands.borrow().clone(),lowest_left_margin_edge: self.lowest_left_margin_edge.get(),lowest_right_margin_edge: self.lowest_right_margin_edge.get(),@@ -6895,6 +7103,7 @@ impl<'pass> BlockFormattingContext<'pass> {/// state of this context.pub(crate) fn restore_state_after_finding_line_breaks(&self, state: StateBeforeFindingLineBreaks) {*self.margin_state_mut() = state.margin_state;+ self.deferred_float_sides.set(state.deferred_float_sides);if self.floating_box_count() == state.float_count {return;}diff --git a/Libraries/LibWeb/Rust/src/layout/fragmentation.rs b/Libraries/LibWeb/Rust/src/layout/fragmentation.rsindex 5f5fc46ecca..12906a08b98 100644--- a/Libraries/LibWeb/Rust/src/layout/fragmentation.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragmentation.rs@@ -191,6 +191,7 @@ pub(crate) struct BlockBreakToken {pub(crate) node: Node,pub(crate) consumed_block_size: CssPixels,pub(crate) resume: BlockResume,+ pub(crate) deferred_floats: Vec<Node>,}impl BlockResume {@@ -213,10 +214,11 @@ impl BlockBreakToken {}}-#[derive(Clone, Copy, Debug)]+#[derive(Clone, Debug)]pub(crate) struct LineRootFragmentation {pub(crate) block_size: Option<CssPixels>,pub(crate) resume: Option<LinePosition>,+ pub(crate) deferred_floats: Vec<Node>,pub(crate) fragmentainer_had_content: bool,pub(crate) break_before_is_avoided: bool,}diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex 36cbf49d075..2342d729c99 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -990,7 +990,7 @@ impl FragmentainerLineLimit {let root_block_offset = context.content_box_position_in_bfc_root().y;for line in data.line_boxes[self.checked_line_count..finished_line_count].iter()- .filter(|line| !line.is_empty())+ .filter(|line| line.counts_toward_widows_and_orphans()){let line_block_size = line.block_end - line.block_start;self.minimum_line_block_size = Some(@@ -1036,6 +1036,9 @@ pub(crate) struct InlineFormattingContext<'context> {/// The break token of the containing block, once the fragmentainer stops before one of its lines.fragmentainer_stop_token: RefCell<Option<std::rc::Rc<fragmentation::BlockBreakToken>>>,lines_are_unbreakable: Cell<bool>,+ fragments_lines: Cell<bool>,+ positioned_floats: RefCell<Vec<(usize, block_formatting_context::PositionedFloat)>>,+ deferred_float_items: RefCell<Vec<(usize, Node)>>,/// Whether margins collapse through each block-level box this context interrupted its lines for, as the layout of/// the box found.margins_collapse_through_interrupting_blocks: RefCell<HashMap<Node, bool>>,@@ -1084,6 +1087,9 @@ impl<'context> InlineFormattingContext<'context> {placed_atomic_inlines: RefCell::new(HashMap::default()),fragmentainer_stop_token: RefCell::new(None),lines_are_unbreakable: Cell::new(false),+ fragments_lines: Cell::new(false),+ positioned_floats: RefCell::new(Vec::new()),+ deferred_float_items: RefCell::new(Vec::new()),margins_collapse_through_interrupting_blocks: RefCell::new(HashMap::default()),entered_inline_boxes: RefCell::new(HashMap::default()),used_insets_of_floats: RefCell::new(HashMap::default()),@@ -1833,7 +1839,7 @@ impl<'context> InlineFormattingContext<'context> {fn balances_lines(&self,iterator: &inline_level_iterator::InlineLevelIterator,- fragmentation: Option<fragmentation::LineRootFragmentation>,+ fragmentation: Option<&fragmentation::LineRootFragmentation>,) -> bool {let style = self.style(self.containing_block);if style.text_wrap_style() != text_wrap_style::BALANCE || style.text_wrap_mode() != text_wrap_mode::WRAP {@@ -2367,54 +2373,17 @@ impl<'context> InlineFormattingContext<'context> {absolute_boxes.push(item.node);}inline_level_iterator::ItemType::FloatingElement => {- line_builder.commit_pending_margin_before_float();- self.clear_floating_boxes(item.node);- line_builder.set_unbreakable_run_inline_size_interrupted_by_float(- iterator.next_unbreakable_run_inline_size(self).unwrap_or_default(),- );- if line_builder.only_finds_line_breaks() {- if !self.floats_laid_out_ahead_of_lines.borrow().contains_key(&item.node) {- let laid_out_float = self.lay_out_float_ahead_of_its_position(item.node);- self.floats_laid_out_ahead_of_lines- .borrow_mut()- .insert(item.node, laid_out_float);- }- let cells = self- .floats_laid_out_ahead_of_lines- .borrow()- .get(&item.node)- .expect("floats among balanced lines are laid out ahead of them")- .cells;- self.parent.add_float_for_finding_line_breaks(- item.node,- &cells,- self.block_container,- self.input.clone(),- self.containing_block_position_in_bfc_root,- line_builder,- );- continue;- }let mut fragment_facts = run_state::FragmentFactsDecidedByParent::default();if state_at_clamp_point.is_some() {fragment_facts.show.hide_after_clamp_point();}- let laid_out_ahead = self.floats_laid_out_ahead_of_lines.borrow_mut().remove(&item.node);- let laid_out_float =- laid_out_ahead.unwrap_or_else(|| self.lay_out_float_ahead_of_its_position(item.node));- let (insets, _, _) = self.parent.position_laid_out_float(- self.run,- laid_out_float,- self.block_container,- self.input.clone(),- self.containing_block_position_in_bfc_root,- CssPixels::default(),- Some(&mut *line_builder),+ self.lay_out_float_on_line(+ &item,+ item_index,+ line_builder,+ iterator.next_unbreakable_run_inline_size(self).unwrap_or_default(),fragment_facts,);- self.used_insets_of_floats- .borrow_mut()- .insert(item.node, insets.used_insets.unwrap_or_default());}inline_level_iterator::ItemType::Text => {line_builder.prepare_to_append_inline_content();@@ -2530,11 +2499,89 @@ impl<'context> InlineFormattingContext<'context> {}}+ fn lay_out_float_on_line(+ &self,+ item: &inline_level_iterator::Item,+ item_index: usize,+ line_builder: &mut line_builder::LineBuilder<'_, '_>,+ next_unbreakable_run: CssPixels,+ fragment_facts: run_state::FragmentFactsDecidedByParent,+ ) {+ line_builder.commit_pending_margin_before_float();+ self.clear_floating_boxes(item.node);+ line_builder.set_unbreakable_run_inline_size_interrupted_by_float(next_unbreakable_run);+ if line_builder.only_finds_line_breaks() {+ if !self.floats_laid_out_ahead_of_lines.borrow().contains_key(&item.node) {+ let laid_out_float = self.lay_out_float_ahead_of_its_position(item.node);+ self.floats_laid_out_ahead_of_lines+ .borrow_mut()+ .insert(item.node, laid_out_float);+ }+ let cells = self+ .floats_laid_out_ahead_of_lines+ .borrow()+ .get(&item.node)+ .expect("floats among balanced lines are laid out ahead of them")+ .cells;+ self.parent.add_float_for_finding_line_breaks(+ item.node,+ &cells,+ self.block_container,+ self.input.clone(),+ self.containing_block_position_in_bfc_root,+ line_builder,+ self.fragments_lines.get(),+ );+ return;+ }+ let laid_out_ahead = self.floats_laid_out_ahead_of_lines.borrow_mut().remove(&item.node);+ let laid_out_float = laid_out_ahead.unwrap_or_else(|| self.lay_out_float_ahead_of_its_position(item.node));+ if self.fragments_lines.get() {+ let (positioned, deferred) = self.parent.position_inline_float_in_column(+ laid_out_float,+ self.block_container,+ self.input.clone(),+ self.containing_block_position_in_bfc_root,+ line_builder,+ );+ if deferred {+ self.deferred_float_items.borrow_mut().push((item_index, item.node));+ if let Some(fragments) = self.run.fragments {+ fragments.discard_unplaced_subtree(item.node, positioned.laid_out_float.fragment_arrival);+ }+ } else {+ self.positioned_floats.borrow_mut().push((item_index, positioned));+ }+ return;+ }+ let (insets, _, _) = self.parent.position_laid_out_float(+ self.run,+ laid_out_float,+ self.block_container,+ self.input.clone(),+ self.containing_block_position_in_bfc_root,+ CssPixels::default(),+ Some(&mut *line_builder),+ fragment_facts,+ );+ self.used_insets_of_floats+ .borrow_mut()+ .insert(item.node, insets.used_insets.unwrap_or_default());+ }+pub(crate) fn generate_line_boxes(&mut self, mut iterator: inline_level_iterator::InlineLevelIterator) {self.fragmented_inlines_in_pre_order = iterator.fragmented_inlines_in_pre_order(self);let fragmentation = self.parent.line_root_fragmentation(self.containing_block);- let resume = fragmentation.and_then(|fragmentation| fragmentation.resume);- let balances_lines = self.balances_lines(&iterator, fragmentation);+ let resume = fragmentation.as_ref().and_then(|fragmentation| fragmentation.resume);+ self.fragments_lines.set(+ fragmentation.is_some()+ && !self.parent.has_line_clamp()+ && iterator+ .items()+ .iter()+ .all(|item| item.type_ != inline_level_iterator::ItemType::BlockLevelBox),+ );+ let balances_lines = self.balances_lines(&iterator, fragmentation.as_ref());// NB: A reused first line box keeps the outside marker it was laid out with.let (reused_lines, reused_item_count) = if self.parent.has_line_clamp()|| resume.is_some()@@ -2593,6 +2640,28 @@ impl<'context> InlineFormattingContext<'context> {let resumes_after_forced_break = resume.is_some()&& start_item_index > 0&& iterator.items()[start_item_index - 1].type_ == inline_level_iterator::ItemType::ForcedBreak;+ let deferred_floats = fragmentation+ .as_ref()+ .map(|fragmentation| fragmentation.deferred_floats.as_slice())+ .unwrap_or_default();+ let mut float_indices = HashMap::default();+ if !deferred_floats.is_empty() {+ for (index, item) in iterator.items().iter().enumerate() {+ if item.type_ == inline_level_iterator::ItemType::FloatingElement {+ float_indices.entry(item.node).or_insert(index);+ }+ }+ }+ let resumed_floats: Vec<_> = deferred_floats+ .iter()+ .map(|&node| {+ let index = *float_indices+ .get(&node)+ .expect("a deferred float is present in the resumed inline items");+ (index, iterator.items()[index].clone())+ })+ .collect();+ let preceding_break = resumes_after_forced_break.then(|| iterator.items()[start_item_index - 1].node);iterator.skip_items(start_item_index);// NB: Trials to balance the lines move the start of the current line, so balance before the lines start.let balancing_reductions = if balances_lines {@@ -2618,9 +2687,10 @@ impl<'context> InlineFormattingContext<'context> {let mut floating_boxes_after_clamp_point = Vec::new();let floating_box_count_before_lines = self.parent.floating_box_count();let line_limit = fragmentation+ .as_ref().filter(|_| !self.parent.has_line_clamp()).and_then(|fragmentation| fragmentation.block_size)- .filter(|_| shares_items || iterator.items().iter().all(|item| item.type_.stays_on_lines()))+ .filter(|_| self.fragments_lines.get()).map(|block_size| FragmentainerLineLimit {block_size,widows: self.style(self.containing_block).widows().max(1) as usize,@@ -2628,6 +2698,22 @@ impl<'context> InlineFormattingContext<'context> {lines_past_end: 0,minimum_line_block_size: None,});+ for (index, item) in resumed_floats {+ self.lay_out_float_on_line(+ &item,+ index,+ &mut line_builder,+ CssPixels::default(),+ Default::default(),+ );+ }+ if let Some(node) = preceding_break+ && !node.is_invalid()+ && self.clear_floating_boxes(node)+ {+ line_builder.did_introduce_clearance(self.block_axis_float_clearance.get());+ self.reset_parent_margin_state();+ }let consumed_item_nodes = (self.run.fragmentainer.is_some()&& self.run.fragments.is_some()&& !iterator.entered_inline_boxes().is_empty())@@ -2774,13 +2860,11 @@ impl<'context> InlineFormattingContext<'context> {let mut lines_are_fragmented = false;let mut kept_lines_end = None;if let Some(fragmentation) = fragmentation {- let breakable = !self.parent.has_line_clamp()- && self.parent.floating_box_count() == floating_box_count_before_lines- && !self.line_data().line_boxes.iter().any(|line| line.has_block_level_box);+ let breakable = self.fragments_lines.get();let dropped_atomic_inlines = if breakable {lines_are_fragmented = true;let (dropped_atomic_inlines, next_line_start) =- self.keep_lines_of_fragmentainer(fragmentation, stopped_at_line_limit);+ self.keep_lines_of_fragmentainer(&fragmentation, stopped_at_line_limit);kept_lines_end = next_line_start;dropped_atomic_inlines} else {@@ -2815,6 +2899,45 @@ impl<'context> InlineFormattingContext<'context> {}}}+ if lines_are_fragmented {+ let stop = kept_lines_end.unwrap_or(fragmentation::LinePosition::AFTER_LAST_LINE);+ let positioned_floats = self.positioned_floats.take();+ let kept: HashSet<_> = positioned_floats+ .iter()+ .filter(|(index, _)| *index < stop.item_index)+ .map(|(_, positioned)| positioned.laid_out_float.node)+ .collect();+ self.parent.retain_inline_floats(floating_box_count_before_lines, &kept);+ for (index, positioned) in positioned_floats {+ let node = positioned.laid_out_float.node;+ if index < stop.item_index {+ let (insets, _, _) = self.parent.place_positioned_float(+ self.run,+ positioned,+ self.block_container,+ Default::default(),+ );+ self.used_insets_of_floats+ .borrow_mut()+ .insert(node, insets.used_insets.unwrap_or_default());+ } else if let Some(fragments) = self.run.fragments {+ fragments.discard_unplaced_subtree(node, positioned.laid_out_float.fragment_arrival);+ }+ }+ let deferred: Vec<_> = self+ .deferred_float_items+ .take()+ .into_iter()+ .filter(|&(index, _)| index < stop.item_index)+ .map(|(_, node)| node)+ .collect();+ if kept_lines_end.is_some() || !deferred.is_empty() {+ let stop_token = self+ .parent+ .break_line_root_before_line(self.containing_block, stop, deferred);+ self.fragmentainer_stop_token.replace(stop_token);+ }+ }if let Some(consumed_item_nodes) = consumed_item_nodes {let present_inline_boxes = lines_are_fragmented.then(|| {self.inline_boxes_present_in_lines(@@ -3089,7 +3212,7 @@ impl<'context> InlineFormattingContext<'context> {fn keep_lines_of_fragmentainer(&self,- fragmentation: fragmentation::LineRootFragmentation,+ fragmentation: &fragmentation::LineRootFragmentation,stopped_at_line_limit: bool,) -> (Vec<Node>, Option<fragmentation::LinePosition>) {let line_count = self.line_data().line_boxes.len();@@ -3102,7 +3225,7 @@ impl<'context> InlineFormattingContext<'context> {(root_block_offset + line.block_start,root_block_offset + line.block_end,- line.is_empty(),+ !line.counts_toward_widows_and_orphans(),)};if is_empty {@@ -3127,17 +3250,19 @@ impl<'context> InlineFormattingContext<'context> {.note_line_for_fragmentation(block_end - block_start, block_end, true);}if stop < line_count {- let content_line_count = self+ let content_lines: Vec<_> = self.line_data().line_boxes.iter()- .rposition(|line| !line.is_empty())- .map_or(0, |index| index + 1);+ .enumerate()+ .filter_map(|(index, line)| line.counts_toward_widows_and_orphans().then_some(index))+ .collect();+ let kept_content_lines = content_lines.partition_point(|&index| index < stop);let style = self.style(self.containing_block);// https://drafts.csswg.org/css-break-3/#widows-orphanslet orphans = style.orphans().max(1) as usize;let widows = style.widows().max(1) as usize;- if stop < orphans {+ if kept_content_lines < orphans {if is_first_fragment&& fragmentation.fragmentainer_had_content&& !fragmentation.break_before_is_avoided@@ -3146,10 +3271,10 @@ impl<'context> InlineFormattingContext<'context> {} else {self.parent.note_violated_break_avoidance();}- } else if !stopped_at_line_limit && content_line_count.saturating_sub(stop) < widows {- let stop_keeping_widows = content_line_count.saturating_sub(widows);- if stop_keeping_widows >= orphans {- stop = stop_keeping_widows;+ } else if !stopped_at_line_limit && content_lines.len().saturating_sub(kept_content_lines) < widows {+ let lines_keeping_widows = content_lines.len().saturating_sub(widows);+ if lines_keeping_widows >= orphans {+ stop = content_lines[lines_keeping_widows];} else {self.parent.note_violated_break_avoidance();}@@ -3183,12 +3308,6 @@ impl<'context> InlineFormattingContext<'context> {let next_line_start = data.line_boxes.get(stop).map(|line| line.start);data.line_boxes.truncate(stop);drop(data);- if let Some(next_line_start) = next_line_start {- let stop_token = self- .parent- .break_line_root_before_line(self.containing_block, next_line_start);- self.fragmentainer_stop_token.replace(stop_token);- }(dropped_atomic_inlines, next_line_start)}diff --git a/Libraries/LibWeb/Rust/src/layout/line_box.rs b/Libraries/LibWeb/Rust/src/layout/line_box.rsindex eea4c604031..2625cdb5890 100644--- a/Libraries/LibWeb/Rust/src/layout/line_box.rs+++ b/Libraries/LibWeb/Rust/src/layout/line_box.rs@@ -341,4 +341,9 @@ impl LineBoxData {pub(crate) fn is_empty(&self) -> bool {self.fragments.is_empty() && !self.has_break}++ pub(crate) fn counts_toward_widows_and_orphans(&self) -> bool {+ // Empty records can have a soft break when advancing below a float, without representing a line of content.+ !self.fragments.is_empty() || self.has_forced_break+ }}diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/multicol-fill-balance-036.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/multicol-fill-balance-036.htmlnew file mode 100644index 00000000000..f305175c2e9--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/multicol-fill-balance-036.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<title>Monolithic float with margins in block formatting context</title>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://issues.chromium.org/issues/41481415">+<link rel="match" href="../../../../expected/wpt-import/css/css-multicol/../reference/ref-filled-green-100px-square.xht">+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>+<div style="width:100px; height:100px; background:red;">+ <div style="columns:2; line-height:20px; orphans:1; widows:1; background:green;">+ + <div style="float:left; width:100%; contain:size; height:20px; margin:40px 0;"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Text/expected/css/multicol-inline-floats.txt b/Tests/LibWeb/Text/expected/css/multicol-inline-floats.txtnew file mode 100644index 00000000000..38e36be523c--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/multicol-inline-floats.txt@@ -0,0 +1,29 @@+a: lines with a floated icon each (inline content): 210px+b: list items, each with a floated icon: 210px+c: one float at the start only: 210px+d: list items with overflow: hidden and a floated icon: 210px+e: 3 columns of floated list items (width 100%): 294px+a item columns: 16,16,16,16,16,16,16,16,16,16,226,226,226,226,226,226,226,226,226,226,436,436,436,436,436,436,436,436,436,436,646,646,646,646,646,646,646,646,646,646+a floats: 0,0; 0,21; 0,42; 0,63; 0,84; 0,105; 0,126; 0,147; 0,168; 0,189; 210,0; 210,21; 210,42; 210,63; 210,84; 210,105; 210,126; 210,147; 210,168; 210,189; 420,0; 420,21; 420,42; 420,63; 420,84; 420,105; 420,126; 420,147; 420,168; 420,189; 630,0; 630,21; 630,42; 630,63; 630,84; 630,105; 630,126; 630,147; 630,168; 630,189+b item columns: 16,16,16,16,16,16,16,16,16,16,226,226,226,226,226,226,226,226,226,226,436,436,436,436,436,436,436,436,436,436,646,646,646,646,646,646,646,646,646,646+b floats: 0,0; 0,21; 0,42; 0,63; 0,84; 0,105; 0,126; 0,147; 0,168; 0,189; 210,0; 210,21; 210,42; 210,63; 210,84; 210,105; 210,126; 210,147; 210,168; 210,189; 420,0; 420,21; 420,42; 420,63; 420,84; 420,105; 420,126; 420,147; 420,168; 420,189; 630,0; 630,21; 630,42; 630,63; 630,84; 630,105; 630,126; 630,147; 630,168; 630,189+c item columns: 16,0,0,0,0,0,0,0,0,0,210,210,210,210,210,210,210,210,210,210,420,420,420,420,420,420,420,420,420,420,630,630,630,630,630,630,630,630,630,630+c floats: 0,0+d item columns: 16,16,16,16,16,16,16,16,16,16,226,226,226,226,226,226,226,226,226,226,436,436,436,436,436,436,436,436,436,436,646,646,646,646,646,646,646,646,646,646+d floats: 0,0; 0,21; 0,42; 0,63; 0,84; 0,105; 0,126; 0,147; 0,168; 0,189; 210,0; 210,21; 210,42; 210,63; 210,84; 210,105; 210,126; 210,147; 210,168; 210,189; 420,0; 420,21; 420,42; 420,63; 420,84; 420,105; 420,126; 420,147; 420,168; 420,189; 630,0; 630,21; 630,42; 630,63; 630,84; 630,105; 630,126; 630,147; 630,168; 630,189+e item columns: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,280,280,280,280,280,280,280,280,280,280,280,280,280,280,560,560,560,560,560,560,560,560,560,560,560,560+e floats: 0,0; 0,21; 0,42; 0,63; 0,84; 0,105; 0,126; 0,147; 0,168; 0,189; 0,210; 0,231; 0,252; 0,273; 280,0; 280,21; 280,42; 280,63; 280,84; 280,105; 280,126; 280,147; 280,168; 280,189; 280,210; 280,231; 280,252; 280,273; 560,0; 560,21; 560,42; 560,63; 560,84; 560,105; 560,126; 560,147; 560,168; 560,189; 560,210; 560,231+tall-start item columns: 16,16,16,0,120,120,120,120+tall-start floats: 0,0+deferred item columns: 0,0,0,0,136,136,136,120+deferred floats: 120,0+deferred-clear item columns: 0,0,0,120+deferred-clear floats: 120,0+deferred-order item columns: 0,0,0,0,136,136,136,120+deferred-order floats: 120,0; 204,0+nested-inline item columns: 16,16,16,16,136,136,136,136+nested-inline floats: 0,0; 0,20; 0,40; 0,60; 120,0; 120,20; 120,40; 120,60+rtl item columns: 16,16,16,16,136,136,136,136+rtl floats: 204,0; 204,20; 204,40; 204,60; 84,0; 84,20; 84,40; 84,60+only-floats item columns:+only-floats floats: 0,0; 0,30; 120,0; 120,30diff --git a/Tests/LibWeb/Text/expected/multicol-box-reuse-geometry.txt b/Tests/LibWeb/Text/expected/multicol-box-reuse-geometry.txtindex a7547f54759..9e0bb4766da 100644--- a/Tests/LibWeb/Text/expected/multicol-box-reuse-geometry.txt+++ b/Tests/LibWeb/Text/expected/multicol-box-reuse-geometry.txt@@ -10,16 +10,16 @@ avoid box with overflowing lines after an empty formatting context, lead 30: heiavoid box with overflowing lines after an empty formatting context, lead 45: height 63: 0,0 200x45 | 0,45 200x17.5 + 210,0 200x22.5 | 210,22.5 200x0 | 210,22.5 200x10 | 210,32.5 200x30avoid box with overflowing lines after an empty formatting context, lead 60: height 70: 0,0 200x60 | 0,60 200x10 + 210,0 200x30 | 210,30 200x0 | 210,30 200x10 | 210,40 200x30avoid box with overflowing lines after an empty formatting context, lead 75: height 78: 0,0 200x75 | 0,75 200x2.5 + 210,0 200x37.5 | 210,37.5 200x0 | 210,37.5 200x10 | 210,47.5 200x30-clear box with a float and a negative margin, lead 0: height 130: 0,0 30x30 | 0,0 200x0 | 0,0 200x40 | 0,-10 200x10 | 0,-10 30x90 | 0,-10 200x10 | 0,0 200x30-clear box with a float and a negative margin, lead 15: height 145: 0,0 30x30 | 0,0 200x15 | 0,15 200x40 | 0,5 200x10 | 0,5 30x90 | 0,5 200x10 | 0,15 200x30-clear box with a float and a negative margin, lead 30: height 160: 0,0 30x30 | 0,0 200x30 | 0,30 200x40 | 0,20 200x10 | 0,20 30x90 | 0,20 200x10 | 0,30 200x30-clear box with a float and a negative margin, lead 45: height 175: 0,0 30x30 | 0,0 200x45 | 0,45 200x40 | 0,35 200x10 | 0,35 30x90 | 0,35 200x10 | 0,45 200x30-clear box with a float and a negative margin, lead 60: height 190: 0,0 30x30 | 0,0 200x60 | 0,60 200x40 | 0,50 200x10 | 0,50 30x90 | 0,50 200x10 | 0,60 200x30-clear box with a float and a negative margin, lead 75: height 205: 0,0 30x30 | 0,0 200x75 | 0,75 200x40 | 0,65 200x10 | 0,65 30x90 | 0,65 200x10 | 0,75 200x30-float past the end of the box that contains it, lead 0: height 110: 0,0 200x0 | 0,0 200x30 | 0,30 200x20 | 0,30 30x80 | 0,50 200x40 | 0,90 200x20-float past the end of the box that contains it, lead 15: height 125: 0,0 200x15 | 0,15 200x30 | 0,45 200x20 | 0,45 30x80 | 0,65 200x40 | 0,105 200x20-float past the end of the box that contains it, lead 30: height 140: 0,0 200x30 | 0,30 200x30 | 0,60 200x20 | 0,60 30x80 | 0,80 200x40 | 0,120 200x20-float past the end of the box that contains it, lead 45: height 80: 0,0 200x45 | 0,45 200x30 | 210,0 200x20 | 210,0 30x80 | 210,20 200x40 | 210,60 200x20+clear box with a float and a negative margin, lead 0: height 90: 0,0 30x30 | 0,0 200x0 | 0,0 200x40 | 0,-10 200x100 + 210,0 200x0 | 210,0 30x90 | 0,-10 200x10 | 210,0 200x30+clear box with a float and a negative margin, lead 15: height 90: 0,0 30x30 | 0,0 200x15 | 0,15 200x40 | 0,5 200x85 + 210,0 200x0 | 210,0 30x90 | 0,5 200x10 | 210,0 200x30+clear box with a float and a negative margin, lead 30: height 90: 0,0 30x30 | 0,0 200x30 | 0,30 200x40 | 0,20 200x70 + 210,0 200x0 | 210,0 30x90 | 0,20 200x10 | 210,0 200x30+clear box with a float and a negative margin, lead 45: height 90: 0,0 30x30 | 0,0 200x45 | 0,45 200x40 | 0,35 200x55 + 210,0 200x0 | 210,0 30x90 | 0,35 200x10 | 210,0 200x30+clear box with a float and a negative margin, lead 60: height 100: 0,0 30x30 | 0,0 200x60 | 0,60 200x40 | 0,50 200x50 + 210,0 200x0 | 210,0 30x90 | 0,50 200x10 | 210,0 200x30+clear box with a float and a negative margin, lead 75: height 115: 0,0 30x30 | 0,0 200x75 | 0,75 200x40 | 0,65 200x50 + 210,0 200x0 | 210,0 30x90 | 0,65 200x10 | 210,0 200x30+float past the end of the box that contains it, lead 0: height 80: 0,0 200x0 | 0,0 200x30 | 0,30 200x20 + 210,0 200x0 | 210,0 30x80 | 210,0 200x40 | 210,40 200x20+float past the end of the box that contains it, lead 15: height 80: 0,0 200x15 | 0,15 200x30 | 0,45 200x20 + 210,0 200x0 | 210,0 30x80 | 210,0 200x40 | 210,40 200x20+float past the end of the box that contains it, lead 30: height 80: 0,0 200x30 | 0,30 200x30 | 0,60 200x20 + 210,0 200x0 | 210,0 30x80 | 210,0 200x40 | 210,40 200x20+float past the end of the box that contains it, lead 45: height 80: 0,0 200x45 | 0,45 200x30 | 0,75 200x5 + 210,0 200x15 | 210,0 30x80 | 210,15 200x40 | 210,55 200x20float past the end of the box that contains it, lead 60: height 85: 0,0 200x60 | 0,60 200x25 + 210,0 200x5 | 210,5 200x20 | 210,5 30x80 | 210,25 200x40 | 210,65 200x20float past the end of the box that contains it, lead 75: height 93: 0,0 200x75 | 0,75 200x17.5 + 210,0 200x12.5 | 210,12.5 200x20 | 210,12.5 30x80 | 210,32.5 200x40 | 210,72.5 200x20descendant box past the end of its fixed-height parent, lead 0: height 60: 0,0 200x0 | 0,0 200x30 | 0,30 200x20 + 210,0 200x0 | 0,30 200x30 + 210,0 200x60 | 210,0 200x40 | 210,40 200x20@@ -64,9 +64,9 @@ column-fill auto with an indefinite height, lead 30: height 160: 0,0 200x160 | 0column-fill auto with an indefinite height, lead 45: height 160: 0,0 200x160 | 0,0 95x45 | 0,45 95x90 | 105,0 95x60 | 105,0 95x60 | 105,65 95x90column-fill auto with an indefinite height, lead 60: height 160: 0,0 200x160 | 0,0 95x60 | 0,60 95x90 | 105,0 95x60 | 105,0 95x60 | 105,65 95x90column-fill auto with an indefinite height, lead 75: height 170: 0,0 200x170 | 0,0 95x75 | 0,75 95x90 | 105,0 95x60 | 105,0 95x60 | 105,65 95x90-floats beside text across columns, lead 0: height 115: 0,0 200x0 | 0,0 30x35 | 0,0 200x40 | 0,45 200x40 | 0,90 30x25 | 0,90 200x25 + 210,0 200x20 | 210,25 200x50-floats beside text across columns, lead 15: height 130: 0,0 200x15 | 0,15 30x35 | 0,15 200x40 | 0,60 200x40 | 0,105 30x25 | 0,105 200x25 + 210,0 200x20 | 210,25 200x50-floats beside text across columns, lead 30: height 145: 0,0 200x30 | 0,30 30x35 | 0,30 200x40 | 0,75 200x40 | 0,120 30x25 | 0,120 200x25 + 210,0 200x20 | 210,25 200x50+floats beside text across columns, lead 0: height 95: 0,0 200x0 | 0,0 30x35 | 0,0 200x40 | 0,45 200x40 | 210,0 30x25 | 210,0 200x40 | 210,45 200x50+floats beside text across columns, lead 15: height 103: 0,0 200x15 | 0,15 30x35 | 0,15 200x40 | 0,60 200x40 | 210,0 30x25 | 210,0 200x40 | 210,45 200x50+floats beside text across columns, lead 30: height 115: 0,0 200x30 | 0,30 30x35 | 0,30 200x40 | 0,75 200x40 | 210,0 30x25 | 210,0 200x40 | 210,45 200x50floats beside text across columns, lead 45: height 120: 0,0 200x45 | 0,45 30x35 | 0,45 200x40 | 0,90 200x30 + 210,0 200x20 | 210,25 30x25 | 210,25 200x40 | 210,70 200x50floats beside text across columns, lead 60: height 125: 0,0 200x60 | 0,60 30x35 | 0,60 200x40 | 0,105 200x20 + 210,0 200x20 | 210,25 30x25 | 210,25 200x40 | 210,70 200x50floats beside text across columns, lead 75: height 140: 0,0 200x75 | 0,75 30x35 | 0,75 200x40 | 0,120 200x20 + 210,0 200x20 | 210,25 30x25 | 210,25 200x40 | 210,70 200x50@@ -101,11 +101,11 @@ forced breaks inside and at the start of kept boxes, lead 45: height 95: 0,0 200forced breaks inside and at the start of kept boxes, lead 60: height 110: 0,0 200x110 + 210,0 200x20 | 0,0 200x20 | 210,0 200x20 | 210,20 200x60 | 210,80 200x30 | 210,80 200x15 | 210,95 200x15 | 420,0 200x30 | 420,35 200x40forced breaks inside and at the start of kept boxes, lead 75: height 125: 0,0 200x125 + 210,0 200x20 | 0,0 200x20 | 210,0 200x20 | 210,20 200x75 | 210,95 200x30 | 210,95 200x15 | 210,110 200x15 | 420,0 200x30 | 420,35 200x40boxes beside a float in the measure pass landing in a column without it, lead 0: height 70: 0,0 410x70 | 0,0 200x0 | 0,0 30x80 | 0,0 200x20 | 0,25 200x20 | 0,50 200x20 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20-boxes beside a float in the measure pass landing in a column without it, lead 15: height 70: 0,0 410x70 | 0,0 200x15 | 0,15 30x80 | 0,15 200x20 | 0,40 200x20 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20 | 420,25 200x20-boxes beside a float in the measure pass landing in a column without it, lead 30: height 70: 0,0 410x70 | 0,0 200x30 | 0,30 30x80 | 0,30 200x20 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20 | 420,25 200x20 | 420,50 200x20-boxes beside a float in the measure pass landing in a column without it, lead 45: height 70: 0,0 410x70 | 0,0 200x45 | 0,45 30x80 | 0,45 200x20 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20 | 420,25 200x20 | 420,50 200x20-boxes beside a float in the measure pass landing in a column without it, lead 60: height 70: 0,0 410x70 | 0,0 200x60 | 0,60 30x80 | 210,0 200x10 | 210,15 200x20 | 210,40 200x20 | 420,0 200x20 | 420,25 200x20 | 420,50 200x20 | 630,0 200x20-boxes beside a float in the measure pass landing in a column without it, lead 75: height 70: 0,0 410x70 | 0,0 200x70 + 210,0 200x5 | 210,5 30x80 | 210,5 200x20 | 210,30 200x20 | 420,0 200x20 | 420,25 200x20 | 420,50 200x20 | 630,0 200x20 | 630,25 200x20+boxes beside a float in the measure pass landing in a column without it, lead 15: height 70: 0,0 410x70 | 0,0 200x15 | 210,0 30x80 | 0,15 200x10 | 0,30 200x20 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20 | 420,25 200x20+boxes beside a float in the measure pass landing in a column without it, lead 30: height 70: 0,0 410x70 | 0,0 200x30 | 210,0 30x80 | 0,30 200x10 | 0,45 200x20 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20 | 420,25 200x20+boxes beside a float in the measure pass landing in a column without it, lead 45: height 70: 0,0 410x70 | 0,0 200x45 | 210,0 30x80 | 0,45 200x10 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20 | 420,25 200x20 | 420,50 200x20+boxes beside a float in the measure pass landing in a column without it, lead 60: height 70: 0,0 410x70 | 0,0 200x60 | 210,0 30x80 | 0,60 200x10 | 210,0 200x20 | 210,25 200x20 | 210,50 200x20 | 420,0 200x20 | 420,25 200x20 | 420,50 200x20+boxes beside a float in the measure pass landing in a column without it, lead 75: height 70: 0,0 410x70 | 0,0 200x70 + 210,0 200x5 | 420,0 30x80 | 210,5 200x10 | 210,20 200x20 | 210,45 200x20 | 420,0 200x20 | 420,25 200x20 | 420,50 200x20 | 630,0 200x20clearance only in the measure pass, lead 0: height 70: 0,0 410x70 | 0,0 30x90 | 0,0 200x70 | 210,0 200x5 | 210,-15 200x10 | 210,-15 30x20 | 210,-15 200x10 | 210,-5 200x20clearance only in the measure pass, lead 15: height 70: 0,0 410x70 | 0,0 30x93 | 0,0 200x70 | 210,0 200x5 | 210,-18 200x10 | 210,-18 30x20 | 210,-18 200x10 | 210,-8 200x20clearance only in the measure pass, lead 30: height 70: 0,0 410x70 | 0,0 30x96 | 0,0 200x70 | 210,0 200x5 | 210,-21 200x10 | 210,-21 30x20 | 210,-21 200x10 | 210,-11 200x20diff --git a/Tests/LibWeb/Text/input/css/multicol-inline-floats.html b/Tests/LibWeb/Text/input/css/multicol-inline-floats.htmlnew file mode 100644index 00000000000..f13aa0a5674--- /dev/null+++ b/Tests/LibWeb/Text/input/css/multicol-inline-floats.html@@ -0,0 +1,59 @@+<!doctype html>+<style>+ body { font: 13px/21px sans-serif; width: 800px; }+ .cols { column-count: 4; column-gap: 40px; margin: 0 0 10px; outline: 1px solid teal; padding: 0; list-style: none; }+ .ic { float: left; width: 10px; height: 21px; margin-right: 6px; background: orange; }+ .rad { overflow: hidden; }+</style>+<p class="cols" id="a"></p>+<ul class="cols" id="b"></ul>+<p class="cols" id="c"></p>+<ul class="cols" id="d"></ul>+<ul class="cols" id="e" style="column-count: 3"></ul>+<script src="../include.js"></script>+<script>+ const t = Array.from({ length: 40 }, (_, i) => "Town " + (i + 1));+ a.innerHTML = t.map(x => `<span class="ic"></span> <a href="#">${x}</a><br>`).join("");+ b.innerHTML = t.map(x => `<li><span class="ic"></span><a href="#">${x}</a></li>`).join("");+ c.innerHTML = `<span class="ic"></span>` + t.map(x => `<a href="#">${x}</a><br>`).join("");+ e.innerHTML = t.map(x => `<li style="float: left; width: 100%"><a href="#">${x}</a></li>`).join("");+ d.innerHTML = t.map(x => `<li class="rad"><span class="ic"></span><a href="#">${x}</a></li>`).join("");+ test(() => {+ const output = [];+ const h = e => Math.round(e.getBoundingClientRect().height);+ output.push([+ `a: lines with a floated icon each (inline content): ${h(a)}px`,+ `b: list items, each with a floated icon: ${h(b)}px`,+ `c: one float at the start only: ${h(c)}px`,+ `d: list items with overflow: hidden and a floated icon: ${h(d)}px`,+ `e: 3 columns of floated list items (width 100%): ${h(e)}px`,+ ].join("\n"));+ for (const [name, content] of [+ ["tall-start", `<span class="ic" style="height:60px;break-inside:avoid"></span>${"<a>line</a><br>".repeat(8)}`],+ ["deferred", `${"<a>line</a><br>".repeat(2)}<span class="ic" style="height:60px;break-inside:avoid"></span>${"<a>line</a><br>".repeat(6)}`],+ ["deferred-clear", `${"<a>line</a><br>".repeat(2)}<span class="ic" style="height:60px;break-inside:avoid"></span><a>beside</a><br style="clear:both"><a>after</a>`],+ ["deferred-order", `${"<a>line</a><br>".repeat(2)}<span class="ic" style="height:60px;break-inside:avoid"></span><span class="ic" style="float:right;height:10px"></span>${"<a>line</a><br>".repeat(6)}`],+ ["nested-inline", `<span>${'<span class="ic" style="height:20px"></span><a>line</a><br>'.repeat(8)}</span>`],+ ["rtl", `${'<span class="ic" style="float:right;height:20px"></span><a>line</a><br>'.repeat(8)}`],+ ["only-floats", `<span class="ic" style="width:100%;height:30px;margin:0;break-inside:avoid"></span>`.repeat(4)],+ ]) {+ const container = document.createElement("div");+ container.id = name;+ container.className = "cols";+ container.style.cssText = "width:220px;column-count:2;column-gap:20px;column-fill:auto;height:80px;line-height:20px;orphans:1;widows:1";+ if (name === "rtl") container.style.direction = "rtl";+ container.innerHTML = content;+ document.body.append(container);+ }+ for (const container of document.querySelectorAll(".cols")) {+ const bounds = container.getBoundingClientRect();+ const items = [...container.querySelectorAll("a")];+ output.push(`${container.id} item columns: ${items.map(item => Math.round(container.id === "rtl" ? bounds.right - item.getBoundingClientRect().right : item.getBoundingClientRect().x - bounds.x)).join(",")}`);+ output.push(`${container.id} floats: ${[...container.querySelectorAll(".ic, li[style]")].map(item => {+ const rect = item.getBoundingClientRect();+ return `${Math.round(rect.x - bounds.x)},${Math.round(rect.y - bounds.y)}`;+ }).join("; ")}`);+ }+ println(output.map(line => line.trimEnd()).join("\n"));+ });+</script>