Skip to content

Truly independent web browser

LibWeb: Break block boxes across the columns of a multicol container

Aliaksandr Kalenik00581d1a2f59
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index cec93244733..614a4f03162 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -13,34 +13,41 @@ const MAXIMUM_BALANCING_ROUNDS: usize = 16;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum FragmentationStep {
LayOut,
- Skip,
Stop,
}
struct FragmentationState {
- resume_child: Option<Node>,
+ container_block_offset_in_root: CssPixels,
+ resume: Option<fragmentation::BlockResume>,
+ is_resumed: bool,
+ fragmentainer_had_content_before_container: bool,
has_in_flow_content: bool,
+ fragmentainer_had_content_before_child: bool,
truncate_next_block_start_margin: bool,
previous_in_flow_child_forces_break_after: bool,
}
impl FragmentationState {
- fn new(fragmentainer: &fragmentation::FragmentainerContext) -> Self {
- let (resume_child, after_forced_break) = match fragmentainer.incoming.as_deref() {
- Some(fragmentation::BlockBreakToken {
- resume:
- fragmentation::BlockResume::BeforeChild {
- child,
- after_forced_break,
- },
+ fn new(
+ incoming: Option<&fragmentation::BlockBreakToken>,
+ container_block_offset_in_root: CssPixels,
+ fragmentainer_had_content_before_container: bool,
+ ) -> Self {
+ let truncate_next_block_start_margin = matches!(
+ incoming.map(|token| &token.resume),
+ Some(fragmentation::BlockResume::BeforeChild {
+ after_forced_break: false,
..
- }) => (Some(*child), *after_forced_break),
- None => (None, false),
- };
+ })
+ );
Self {
- resume_child,
+ container_block_offset_in_root,
+ resume: incoming.map(|token| token.resume.clone()),
+ is_resumed: incoming.is_some(),
+ fragmentainer_had_content_before_container,
has_in_flow_content: false,
- truncate_next_block_start_margin: resume_child.is_some() && !after_forced_break,
+ fragmentainer_had_content_before_child: false,
+ truncate_next_block_start_margin,
previous_in_flow_child_forces_break_after: false,
}
}
@@ -227,8 +234,13 @@ pub(crate) struct BlockFormattingContext<'pass> {
automatic_line_clamp_max_lines: Cell<Option<usize>>,
automatic_line_clamp_block_size_exceeded: Cell<bool>,
laying_out_invisible_line_clamp_content: Cell<bool>,
+ children_laid_out_in_fragmentainer: RefCell<HashMap<Node, (Node, Node)>>,
multicol_automatic_content_block_size: Cell<Option<CssPixels>>,
discard_block_start_margin_of_next_child: Cell<bool>,
+ fragmentainer_has_content: Cell<bool>,
+ pending_continuation_token: RefCell<Option<std::rc::Rc<fragmentation::BlockBreakToken>>>,
+ incoming_container_token: RefCell<Option<std::rc::Rc<fragmentation::BlockBreakToken>>>,
+ broken_child_token: RefCell<Option<std::rc::Rc<fragmentation::BlockBreakToken>>>,
}
impl<'pass> BlockFormattingContext<'pass> {
@@ -281,8 +293,13 @@ impl<'pass> BlockFormattingContext<'pass> {
automatic_line_clamp_max_lines: Cell::new(None),
automatic_line_clamp_block_size_exceeded: Cell::new(false),
laying_out_invisible_line_clamp_content: Cell::new(false),
+ children_laid_out_in_fragmentainer: RefCell::new(HashMap::default()),
multicol_automatic_content_block_size: Cell::new(None),
discard_block_start_margin_of_next_child: Cell::new(false),
+ fragmentainer_has_content: Cell::new(false),
+ pending_continuation_token: RefCell::new(None),
+ incoming_container_token: RefCell::new(None),
+ broken_child_token: RefCell::new(None),
}
}
@@ -383,6 +400,31 @@ impl<'pass> BlockFormattingContext<'pass> {
.filter(|&child| self.facts(child).is_box())
}
+ fn children_laid_out_in_fragmentainer(&self, node: Node) -> Option<(Node, Node)> {
+ self.run.fragmentainer.as_ref()?;
+ self.children_laid_out_in_fragmentainer.borrow().get(&node).copied()
+ }
+
+ fn laid_out_children(&self, node: Node) -> impl Iterator<Item = Node> + '_ {
+ let (first, last) = self
+ .children_laid_out_in_fragmentainer(node)
+ .unwrap_or_else(|| (self.run.callbacks.first_child(node), Node::INVALID));
+ self.run
+ .callbacks
+ .siblings_from(first, last)
+ .filter(|&child| self.facts(child).is_box())
+ }
+
+ fn laid_out_children_rev(&self, node: Node) -> impl Iterator<Item = Node> + '_ {
+ let (first, last) = self
+ .children_laid_out_in_fragmentainer(node)
+ .unwrap_or_else(|| (Node::INVALID, self.run.callbacks.last_child(node)));
+ self.run
+ .callbacks
+ .siblings_from_rev(last, first)
+ .filter(|&child| self.facts(child).is_box())
+ }
+
fn is_ancestor_of(&self, ancestor: Node, node: Node) -> bool {
self.run.callbacks.is_ancestor(ancestor, node, self.run.box_)
}
@@ -1424,6 +1466,9 @@ impl<'pass> BlockFormattingContext<'pass> {
}
fn margins_collapse_through(&self, node: Node) -> bool {
+ if self.run.records.used_values_if_owned(node).is_none() {
+ return true;
+ }
let facts = self.facts(node);
let style = self.style(node);
// https://drafts.csswg.org/css2/#adjoining-margins
@@ -1824,6 +1869,16 @@ impl<'pass> BlockFormattingContext<'pass> {
let containing_block_position_in_root = input
.content_box_position_in_bfc_root
.expect("block layout requires its containing block position in the BFC root");
+ let continuation = self
+ .pending_continuation_token
+ .borrow_mut()
+ .take_if(|token| token.node == node);
+ if continuation.is_some() {
+ used.margin_top.set(CssPixels::default());
+ used.border_top.set(CssPixels::default());
+ used.padding_top.set(CssPixels::default());
+ used.continues_from_previous_fragment.set(true);
+ }
if facts.is_floating() {
let block_offset = self
@@ -1912,6 +1967,7 @@ impl<'pass> BlockFormattingContext<'pass> {
let margin_top = self.margin_state.borrow().pending_margin_for_next_box();
let box_opens_top_margin_group = !has_independent_formatting_context
+ && continuation.is_none()
&& self.used(node).border_top.get() == CssPixels::default()
&& self.used(node).padding_top.get() == CssPixels::default()
&& !self.margin_state.borrow().has_open_top_margin_group();
@@ -2015,6 +2071,15 @@ impl<'pass> BlockFormattingContext<'pass> {
}
}
+ if let Some(continuation) = &continuation
+ && self.used(node).has_definite_block_size()
+ {
+ let used = self.used(node);
+ used.set_content_block_size(
+ (used.content_block_size.get() - continuation.consumed_block_size).max(CssPixels::default()),
+ );
+ }
+
// Before we insert the children of a list item we need to know the location of the marker.
// If we do not do this then left-floating elements inside the list item will push the marker to the right,
// in some cases even causing it to overlap with the non-floating content of the list.
@@ -2121,6 +2186,7 @@ impl<'pass> BlockFormattingContext<'pass> {
if facts.children_are_inline() {
self.layout_inline_children(run, node, inside_layout_input, space_available_for_children);
} else {
+ self.incoming_container_token.replace(continuation.clone());
self.layout_block_level_children(run, node, inside_layout_input, space_available_for_children);
}
if box_opens_top_margin_group {
@@ -2186,8 +2252,66 @@ impl<'pass> BlockFormattingContext<'pass> {
);
}
+ if let Some(fragmentainer) = self.run.fragmentainer.as_deref() {
+ let content_block_start_in_root = pending_position.map(|position| {
+ containing_block_position_in_root.y
+ + self.block_offset_adjustment_from_pending_ancestor_block_start_margins(node)
+ + position.y
+ });
+ let broken_token = self
+ .broken_child_token
+ .borrow()
+ .as_ref()
+ .filter(|token| token.node == node)
+ .cloned()
+ .or_else(|| {
+ let block_size = fragmentainer.block_size?;
+ let content_block_start_in_root = content_block_start_in_root?;
+ let breaks_inside = !has_independent_formatting_context
+ && facts.is_block_container()
+ && (!facts.children_are_inline() || !self.has_lines(node))
+ && content_block_start_in_root < block_size
+ && content_block_start_in_root + self.used(node).content_block_size.get() > block_size;
+ breaks_inside.then(|| {
+ std::rc::Rc::new(fragmentation::BlockBreakToken {
+ node,
+ consumed_block_size: CssPixels::default(),
+ resume: fragmentation::BlockResume::AfterChildren,
+ })
+ })
+ });
+ if let Some(token) = broken_token {
+ let used = self.used(node);
+ if let (Some(block_size), Some(content_block_start_in_root)) =
+ (fragmentainer.block_size, content_block_start_in_root)
+ {
+ let content_block_size = used.content_block_size.get();
+ let remaining_block_size = (block_size - content_block_start_in_root).max(CssPixels::default());
+ fragmentainer.note_space_shortage(content_block_start_in_root + content_block_size);
+ used.set_content_block_size(if used.has_definite_block_size() {
+ content_block_size.min(remaining_block_size)
+ } else {
+ remaining_block_size
+ });
+ }
+ used.padding_bottom.set(CssPixels::default());
+ used.border_bottom.set(CssPixels::default());
+ used.margin_bottom.set(CssPixels::default());
+ used.continues_in_next_fragment.set(true);
+ let consumed_block_size = continuation
+ .as_ref()
+ .map_or(CssPixels::default(), |continuation| continuation.consumed_block_size)
+ + used.content_block_size.get();
+ self.broken_child_token
+ .replace(Some(std::rc::Rc::new(fragmentation::BlockBreakToken {
+ consumed_block_size,
+ ..(*token).clone()
+ })));
+ }
+ }
+
// Now that our children are formatted we place the ListItemBox with the left space we remembered.
- if is_list_item_box && !has_independent_formatting_context {
+ if is_list_item_box && !has_independent_formatting_context && continuation.is_none() {
let list_item_used = self.used(node);
let list_item_first_baseline = list_item_used
.has_first_baseline
@@ -2228,7 +2352,9 @@ impl<'pass> BlockFormattingContext<'pass> {
if has_independent_formatting_context || !self.margins_collapse_through(node) {
let mut margin_state = self.margin_state.borrow_mut();
- if !margin_state.box_last_in_flow_child_margin_bottom_collapsed {
+ if !margin_state.box_last_in_flow_child_margin_bottom_collapsed
+ || self.used(node).continues_in_next_fragment.get()
+ {
margin_state.reset();
}
drop(margin_state);
@@ -2267,9 +2393,9 @@ impl<'pass> BlockFormattingContext<'pass> {
let facts = self.facts(node);
let container_facts = self.facts(block_container);
self.run.purpose == formatting_context::LayoutPurpose::Commit
+ && self.run.fragmentainer.is_none()
&& self.run.layout_mode == LayoutMode::Normal
&& self.run.fragments.is_some()
- && self.run.fragmentainer.is_none()
&& !self.run.should_collect_devtools_layout_data
&& containing_line_box_fragment.is_none()
&& self.floats.borrow().is_empty()
@@ -2492,20 +2618,47 @@ impl<'pass> BlockFormattingContext<'pass> {
let saved = self
.block_offset_of_current_block_container
.replace(Some(CssPixels::default()));
- let fragmentainer = self
+ let fragmentainer = self.run.fragmentainer.clone();
+ let mut fragmentation_state = fragmentainer.as_deref().map(|fragmentainer| {
+ let incoming = if block_container == self.run.box_ {
+ fragmentainer.incoming.clone()
+ } else {
+ self.incoming_container_token.take()
+ };
+ let container_block_offset_in_root = input
+ .content_box_position_in_bfc_root
+ .map_or(CssPixels::default(), |position| position.y)
+ + self.block_offset_adjustment_from_pending_ancestor_block_start_margins(block_container);
+ FragmentationState::new(
+ incoming.as_deref(),
+ container_block_offset_in_root,
+ self.fragmentainer_has_content.get(),
+ )
+ });
+ let first_child = fragmentation_state
+ .as_ref()
+ .and_then(|state| match &state.resume {
+ Some(
+ fragmentation::BlockResume::BeforeChild { child, .. }
+ | fragmentation::BlockResume::InsideChild { child, .. },
+ ) => Some(*child),
+ _ => None,
+ })
+ .unwrap_or_else(|| self.run.callbacks.first_child(block_container));
+ let mut laid_out_children: Option<(Node, Node)> = None;
+ for child in self
.run
- .fragmentainer
- .clone()
- .filter(|_| block_container == self.run.box_);
- let mut fragmentation_state = fragmentainer.as_deref().map(FragmentationState::new);
- for child in self.children(block_container) {
+ .callbacks
+ .siblings_from(first_child, Node::INVALID)
+ .filter(|&child| self.facts(child).is_box())
+ {
if let (Some(fragmentainer), Some(state)) = (fragmentainer.as_deref(), fragmentation_state.as_mut()) {
match self.fragmentation_step_before_child(fragmentainer, state, block_container, child) {
- FragmentationStep::Skip => continue,
FragmentationStep::Stop => break,
FragmentationStep::LayOut => {}
}
}
+ laid_out_children = Some((laid_out_children.map_or(child, |(first, _)| first), child));
let invisible = self.line_clamp_reached() && !self.facts(child).is_absolutely_positioned();
let previous_bottom = bottom_of_lowest_margin_box;
if invisible {
@@ -2530,6 +2683,16 @@ impl<'pass> BlockFormattingContext<'pass> {
break;
}
}
+ if fragmentation_state.is_some() {
+ self.children_laid_out_in_fragmentainer.borrow_mut().insert(
+ block_container,
+ laid_out_children.unwrap_or((Node::INVALID, Node::INVALID)),
+ );
+ } else if self.run.fragmentainer.is_some() {
+ self.children_laid_out_in_fragmentainer
+ .borrow_mut()
+ .remove(&block_container);
+ }
self.block_offset_of_current_block_container.set(saved);
self.finish_block_level_children_layout(block_container, input, available_space, bottom_of_lowest_margin_box);
}
@@ -2541,30 +2704,45 @@ impl<'pass> BlockFormattingContext<'pass> {
block_container: Node,
child: Node,
) -> FragmentationStep {
- if let Some(resume_child) = state.resume_child {
- if resume_child != child {
- return FragmentationStep::Skip;
+ match &state.resume {
+ Some(fragmentation::BlockResume::BeforeChild {
+ child: resume_child, ..
+ }) => {
+ debug_assert_eq!(*resume_child, child);
+ state.resume = None;
}
- state.resume_child = None;
+ Some(fragmentation::BlockResume::AfterChildren) => return FragmentationStep::Stop,
+ Some(fragmentation::BlockResume::InsideChild {
+ child: resume_child,
+ token,
+ }) => {
+ debug_assert_eq!(*resume_child, child);
+ self.pending_continuation_token.replace(Some(token.clone()));
+ state.resume = None;
+ state.fragmentainer_had_content_before_child = self.fragmentainer_has_content.get();
+ return FragmentationStep::LayOut;
+ }
+ None => {}
}
let facts = self.facts(child);
if !facts.is_flow_layout_participant() || facts.is_floating() {
return FragmentationStep::LayOut;
}
if fragmentainer.early_break_before == Some(child) {
- self.break_before_child(fragmentainer, block_container, child, false);
+ self.break_before_child(fragmentainer, state, block_container, child, false);
return FragmentationStep::Stop;
}
let forced = state.previous_in_flow_child_forces_break_after
|| fragmentation::is_forced_column_break(self.style(child).break_before());
- if forced && state.has_in_flow_content {
- self.break_before_child(fragmentainer, block_container, child, true);
+ if forced && self.fragmentainer_has_content.get() {
+ self.break_before_child(fragmentainer, state, block_container, child, true);
return FragmentationStep::Stop;
}
if state.truncate_next_block_start_margin {
self.margin_state.borrow_mut().reset();
self.discard_block_start_margin_of_next_child.set(true);
}
+ state.fragmentainer_had_content_before_child = self.fragmentainer_has_content.get();
FragmentationStep::LayOut
}
@@ -2572,7 +2750,7 @@ impl<'pass> BlockFormattingContext<'pass> {
&self,
fragmentainer: &fragmentation::FragmentainerContext,
state: &mut FragmentationState,
- _block_container: Node,
+ block_container: Node,
child: Node,
) -> FragmentationStep {
self.discard_block_start_margin_of_next_child.set(false);
@@ -2581,38 +2759,109 @@ impl<'pass> BlockFormattingContext<'pass> {
return FragmentationStep::LayOut;
}
state.truncate_next_block_start_margin = false;
- let used = self.used(child);
+ let broken_child_token = self
+ .broken_child_token
+ .borrow_mut()
+ .take_if(|token| token.node == child);
+ if let Some(token) = broken_child_token {
+ self.fragmentainer_has_content.set(true);
+ self.stop_fragmentainer(
+ fragmentainer,
+ block_container,
+ fragmentation::BlockResume::InsideChild { child, token },
+ );
+ return FragmentationStep::Stop;
+ }
+ let Some(used) = self.run.records.used_values_if_owned(child) else {
+ return FragmentationStep::LayOut;
+ };
let collapsed = used.uses_collapsing_borders_model.get();
- let border_box_block_end =
- used.content_offset.get().y + used.content_block_size.get() + used.border_box_bottom(collapsed);
- fragmentainer.note_unbreakable_block_size(used.border_box_block_size(collapsed));
- if fragmentainer.exceeds(border_box_block_end) {
- fragmentainer.note_space_shortage(border_box_block_end);
- if state.has_in_flow_content {
+ let content_block_end =
+ state.container_block_offset_in_root + used.content_offset.get().y + used.content_block_size.get();
+ let border_box_block_size = used.border_box_block_size(collapsed);
+ let is_breakable = self.child_is_breakable(child);
+ if !is_breakable {
+ fragmentainer.note_unbreakable_block_size(border_box_block_size);
+ }
+ let block_end = if is_breakable {
+ content_block_end
+ } else {
+ content_block_end + used.border_box_bottom(collapsed)
+ };
+ if fragmentainer.exceeds(block_end) {
+ fragmentainer.note_space_shortage(block_end);
+ if state.fragmentainer_had_content_before_child {
fragmentainer.outcome_mut().needs_early_break_before = Some(child);
return FragmentationStep::Stop;
}
}
state.has_in_flow_content = true;
+ self.fragmentainer_has_content.set(true);
state.previous_in_flow_child_forces_break_after =
fragmentation::is_forced_column_break(self.style(child).break_after());
FragmentationStep::LayOut
}
+ fn child_is_breakable(&self, child: Node) -> bool {
+ let facts = self.facts(child);
+ facts.is_block_container()
+ && formatting_context::formatting_context_type_created_by_box(facts).is_none()
+ && (!facts.children_are_inline() || !self.has_lines(child))
+ && !facts.is_fieldset_box()
+ && !facts.is_table_wrapper()
+ }
+
+ fn has_lines(&self, node: Node) -> bool {
+ self.run
+ .records
+ .used_values_if_owned(node)
+ .and_then(|used| used.line_data_ref())
+ .is_some_and(|data| data.last_line().is_some())
+ }
+
fn break_before_child(
&self,
fragmentainer: &fragmentation::FragmentainerContext,
+ state: &FragmentationState,
block_container: Node,
child: Node,
after_forced_break: bool,
) {
- fragmentainer.outcome_mut().outgoing = Some(std::rc::Rc::new(fragmentation::BlockBreakToken {
- node: block_container,
- resume: fragmentation::BlockResume::BeforeChild {
+ if block_container != self.run.box_
+ && !state.is_resumed
+ && !state.has_in_flow_content
+ && !after_forced_break
+ && state.fragmentainer_had_content_before_container
+ {
+ fragmentainer.outcome_mut().needs_early_break_before = Some(block_container);
+ return;
+ }
+ self.stop_fragmentainer(
+ fragmentainer,
+ block_container,
+ fragmentation::BlockResume::BeforeChild {
child,
after_forced_break,
},
- }));
+ );
+ }
+
+ fn stop_fragmentainer(
+ &self,
+ fragmentainer: &fragmentation::FragmentainerContext,
+ block_container: Node,
+ resume: fragmentation::BlockResume,
+ ) {
+ let token = std::rc::Rc::new(fragmentation::BlockBreakToken {
+ node: block_container,
+ consumed_block_size: CssPixels::default(),
+ resume,
+ });
+ if block_container == self.run.box_ {
+ fragmentainer.outcome_mut().outgoing = Some(token);
+ } else {
+ self.broken_child_token.replace(Some(token));
+ }
}
fn is_multicol_container(&self) -> bool {
@@ -2856,6 +3105,11 @@ impl<'pass> BlockFormattingContext<'pass> {
fc_run_cache_store.begin_store_journal();
}
let outputs = formatting_context::run_fragmentainer(&self.run, purpose, input, fragmentainer.clone());
+ if outputs.result.depends_on_percentage_block_size {
+ self.used(self.run.box_)
+ .has_descendant_that_depends_on_percentage_block_size
+ .set(true);
+ }
let mut outcome = fragmentainer.take_outcome();
let retries = outcome
.needs_early_break_before
@@ -3201,17 +3455,17 @@ impl<'pass> BlockFormattingContext<'pass> {
if collapsed_margin != CssPixels::default() {
let flow_children_bottom_up = if root_facts.is_table_wrapper() {
table_wrapper_flow_children(self.run.callbacks, self.run.box_)
+ .into_iter()
+ .rev()
+ .collect()
} else {
- self.children(self.run.box_).collect()
+ self.laid_out_children_rev(self.run.box_).collect::<Vec<_>>()
};
- for child in flow_children_bottom_up.into_iter().rev() {
+ for child in flow_children_bottom_up {
let facts = self.facts(child);
if facts.is_absolutely_positioned() || facts.is_floating() {
continue;
}
- if self.run.records.used_values_if_owned(child).is_none() {
- continue;
- }
if self.margins_collapse_through(child) {
continue;
}
@@ -3709,12 +3963,7 @@ impl<'pass> BlockFormattingContext<'pass> {
// 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin does not collapse with the element's bottom margin
// 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
if !facts.children_are_inline() {
- for child in self
- .run
- .callbacks
- .children_rev(node)
- .filter(|&child| self.facts(child).is_box())
- {
+ for child in self.laid_out_children_rev(node) {
let child_facts = self.facts(child);
if child_facts.is_absolutely_positioned() || child_facts.is_floating() {
continue;
@@ -3722,7 +3971,9 @@ impl<'pass> BlockFormattingContext<'pass> {
if child_facts.is_list_item_marker_box() {
continue;
}
- let child_used = self.used(child);
+ let Some(child_used) = self.run.records.used_values_if_owned(child) else {
+ continue;
+ };
// https://drafts.csswg.org/css-overflow-4/#line-clamp-containers
// If a block container contains a clamp point, within itself or in any of its descendants, its
// automatic block size will not take into account any invisible boxes, nor any clipped float.
@@ -3849,7 +4100,7 @@ impl<'pass> BlockFormattingContext<'pass> {
}
} else {
drop(floats);
- for child in self.children(node) {
+ for child in self.laid_out_children(node) {
if !self.facts(child).is_flow_layout_participant() {
continue;
}
@@ -3971,6 +4222,8 @@ impl<'pass> BlockFormattingContext<'pass> {
self.run.records,
self.run.callbacks,
self.run.box_,
+ self.children_laid_out_in_fragmentainer(self.run.box_),
+ self.run.fragmentainer.is_none(),
(!line_clamp_reached)
.then_some(self.lowest_floating_descendant_bottom_margin_edge.get())
.flatten(),
@@ -4070,13 +4323,15 @@ pub(crate) fn automatic_block_size_for_bfc_root(
records: &RunRecords,
callbacks: LayoutPass<'_>,
root: Node,
+ laid_out_children: Option<(Node, Node)>,
+ honors_size_containment: bool,
lowest_floating_descendant_bottom_margin_edge: Option<CssPixels>,
trailing_collapsed_margin: Option<(Node, CssPixels)>,
) -> CssPixels {
let facts = NodeFacts::new(&callbacks, root);
// https://drafts.csswg.org/css-contain-2/#containment-size
// A size-contained box is sized as if it had no contents.
- if facts.node_has_size_containment() {
+ if honors_size_containment && facts.node_has_size_containment() {
return CssPixels::default();
}
let mut bottom = None;
@@ -4103,11 +4358,8 @@ pub(crate) fn automatic_block_size_for_bfc_root(
// the table box, so the wrapper considers its flow children instead of tree children.
table_wrapper_flow_children(callbacks, root)
} else {
- let mut children = Vec::new();
- for child in callbacks.children(root) {
- children.push(child);
- }
- children
+ let (first, last) = laid_out_children.unwrap_or_else(|| (callbacks.first_child(root), Node::INVALID));
+ callbacks.siblings_from(first, last).collect()
};
for child in flow_children {
let child_facts = NodeFacts::new(&callbacks, child);
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 6f421697d74..20d63cc58d1 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1966,7 +1966,8 @@ fn execute_formatting_context_run(
// Every formatting context reports its content sizes through ChildLayoutResult, so overriding here covers them all
// rather than one context's root-height path.
let containment_facts = NodeFacts::new(&run.callbacks, run.box_);
- if containment_facts.node_has_size_containment() {
+ let lays_out_own_content = run.fragmentainer.is_none();
+ if lays_out_own_content && containment_facts.node_has_size_containment() {
let style = containment_facts.style();
// https://drafts.csswg.org/css-contain-2/#containment-size
// Giving an element size containment makes its principal box a size containment box and has the following
@@ -1983,7 +1984,7 @@ fn execute_formatting_context_run(
} else {
CssPixels::default()
};
- } else if containment_facts.node_has_inline_size_containment() {
+ } else if lays_out_own_content && containment_facts.node_has_inline_size_containment() {
// https://drafts.csswg.org/css-contain-2/#containment-inline-size
// "This means the inline-axis intrinsic sizes of the principal box are determined as if the element had
// no content."
diff --git a/Libraries/LibWeb/Rust/src/layout/fragmentation.rs b/Libraries/LibWeb/Rust/src/layout/fragmentation.rs
index f6efe3df54b..e32b3b24aa5 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragmentation.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragmentation.rs
@@ -99,14 +99,27 @@ pub(crate) struct MulticolLayoutData {
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum BlockResume {
BeforeChild { child: Node, after_forced_break: bool },
+ InsideChild { child: Node, token: Rc<BlockBreakToken> },
+ AfterChildren,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct BlockBreakToken {
pub(crate) node: Node,
+ pub(crate) consumed_block_size: CssPixels,
pub(crate) resume: BlockResume,
}
+impl BlockBreakToken {
+ pub(crate) fn ends_at_forced_break(&self) -> bool {
+ match &self.resume {
+ BlockResume::BeforeChild { after_forced_break, .. } => *after_forced_break,
+ BlockResume::InsideChild { token, .. } => token.ends_at_forced_break(),
+ BlockResume::AfterChildren => false,
+ }
+ }
+}
+
#[derive(Clone, Debug, Default)]
pub(crate) struct FragmentainerOutcome {
pub(crate) outgoing: Option<Rc<BlockBreakToken>>,
@@ -117,9 +130,7 @@ pub(crate) struct FragmentainerOutcome {
impl FragmentainerOutcome {
pub(crate) fn ended_at_forced_break(&self) -> bool {
- self.outgoing.as_ref().is_some_and(|token| match token.resume {
- BlockResume::BeforeChild { after_forced_break, .. } => after_forced_break,
- })
+ self.outgoing.as_ref().is_some_and(|token| token.ends_at_forced_break())
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
index 3b714425157..3bf1341cd05 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
@@ -203,6 +203,18 @@ impl<'arena> LayoutPass<'arena> {
})
}
+ pub(crate) fn siblings_from(self, first: Node, last: Node) -> impl Iterator<Item = Node> + 'arena {
+ std::iter::successors(link(first), move |&child| {
+ (child != last).then(|| link(self.next_sibling(child))).flatten()
+ })
+ }
+
+ pub(crate) fn siblings_from_rev(self, last: Node, first: Node) -> impl Iterator<Item = Node> + 'arena {
+ std::iter::successors(link(last), move |&child| {
+ (child != first).then(|| link(self.previous_sibling(child))).flatten()
+ })
+ }
+
/// The children of `node`, last first.
pub(crate) fn children_rev(self, node: Node) -> impl Iterator<Item = Node> + 'arena {
std::iter::successors(link(self.last_child(node)), move |&child| {
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 2ddbd86a51b..aa76bb438b9 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -1058,6 +1058,8 @@ impl<'pass> SizingContext<'pass> {
|| facts.is_table_wrapper()
{
Some(used.content_block_size.get())
+ } else if facts.lays_out_in_columns() {
+ None
} else {
constraints.quirks_mode_percentage_basis_block_size
};
diff --git a/Tests/LibWeb/Layout/expected/multicol-break-block.txt b/Tests/LibWeb/Layout/expected/multicol-break-block.txt
new file mode 100644
index 00000000000..a10c3a90009
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/multicol-break-block.txt
@@ -0,0 +1,24 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 100 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 100 0+0+0] children: not-inline
+ BlockContainer <div.multicol> at [0,0] [0+0+0 220 0+0+580] [0+0+0 100 0+0+0] [BFC] children: not-inline
+ BlockContainer <(anonymous)> at [0,0] [0+0+0 100 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <div.outer> at [5,5] [0+5+0 90 0+5+0] [0+5+0 95 0+0+0] fragment at [125,0] [90 85] children: not-inline
+ BlockContainer <(anonymous)> at [5,5] [0+0+0 90 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [5,5] [0+0+0 90 0+0+0] [0+0+0 30 0+0+0] children: not-inline
+ BlockContainer <div> at [5,35] [0+0+0 90 0+0+0] [0+0+0 30 0+0+0] children: not-inline
+ BlockContainer <div> at [5,65] [0+0+0 90 0+0+0] [0+0+0 30 0+0+0] children: not-inline
+ BlockContainer <div> at [5,95] [0+0+0 90 0+0+0] [0+0+0 5 0+0+0] fragment at [125,0] [90 25] children: not-inline
+ BlockContainer <div> at [125,25] [0+0+0 90 0+0+0] [0+0+0 30 0+0+0] children: not-inline
+ BlockContainer <div> at [125,55] [0+0+0 90 0+0+0] [0+0+0 30 0+0+0] children: not-inline
+ BlockContainer <(anonymous)> at [125,85] [0+0+0 90 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [120,90] [0+0+0 100 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [0,100] [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x100] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/multicol-break-block.html b/Tests/LibWeb/Layout/input/multicol-break-block.html
new file mode 100644
index 00000000000..d366de4745a
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/multicol-break-block.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<style>
+body { margin: 0; }
+.multicol { columns: 2; column-gap: 20px; column-fill: auto; height: 100px; width: 220px; }
+.outer { border: 5px solid blue; }
+.outer > div { height: 30px; }
+</style>
+<div class="multicol">
+ <div class="outer">
+ <div></div><div></div><div></div><div></div><div></div><div></div>
+ </div>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/multicol-break-background-clip-ref.html b/Tests/LibWeb/Ref/expected/multicol-break-background-clip-ref.html
new file mode 100644
index 00000000000..a9c105fc742
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/multicol-break-background-clip-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<style>
+ body { margin: 0; }
+ div { position: absolute; }
+</style>
+<div style="left: 0; top: 0; width: 180px; height: 90px; border: 10px solid blue; border-bottom: 0"></div>
+<div style="left: 20px; top: 20px; width: 160px; height: 80px; background: green"></div>
+<div style="left: 200px; top: 0; width: 180px; height: 80px; border: 10px solid blue; border-top: 0"></div>
+<div style="left: 220px; top: 0; width: 160px; height: 70px; background: green"></div>
diff --git a/Tests/LibWeb/Ref/expected/multicol-break-background-slice-ref.html b/Tests/LibWeb/Ref/expected/multicol-break-background-slice-ref.html
new file mode 100644
index 00000000000..967586718fc
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/multicol-break-background-slice-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<style>
+ body {
+ margin: 0;
+ }
+ div {
+ position: absolute;
+ top: 0;
+ width: 100px;
+ height: 100px;
+ }
+</style>
+<div style="left: 0; background: green"></div>
+<div style="left: 100px; background: blue"></div>
diff --git a/Tests/LibWeb/Ref/expected/multicol-break-bordered-block-ref.html b/Tests/LibWeb/Ref/expected/multicol-break-bordered-block-ref.html
new file mode 100644
index 00000000000..02be3d0eab3
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/multicol-break-bordered-block-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<style>
+body { margin: 0; }
+.container { position: relative; height: 100px; width: 220px; }
+.fragment { position: absolute; top: 0; width: 90px; border: 5px solid blue; background: yellow; }
+.child { position: absolute; width: 90px; height: 30px; background: green; }
+</style>
+<div class="container">
+ <div class="fragment" style="left: 0; height: 95px; border-bottom: none"></div>
+ <div class="child" style="left: 5px; top: 5px"></div>
+ <div class="child" style="left: 5px; top: 35px"></div>
+ <div class="child" style="left: 5px; top: 65px"></div>
+ <div class="fragment" style="left: 120px; height: 90px; border-top: none"></div>
+ <div class="child" style="left: 125px; top: 0"></div>
+ <div class="child" style="left: 125px; top: 30px"></div>
+ <div class="child" style="left: 125px; top: 60px"></div>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/multicol-break-clip-path-and-mask-ref.html b/Tests/LibWeb/Ref/expected/multicol-break-clip-path-and-mask-ref.html
new file mode 100644
index 00000000000..f2da44a814e
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/multicol-break-clip-path-and-mask-ref.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<style>
+ body { margin: 0; }
+ .row { position: relative; height: 100px; margin-bottom: 10px; }
+ .row > div { position: absolute; top: 0; width: 200px; }
+</style>
+<div class="row"><div style="left: 0; height: 100px; background: green"></div><div style="left: 220px; height: 80px; background: green"></div></div>
+<div class="row"><div style="left: 0; height: 100px; background: blue"></div><div style="left: 220px; height: 80px; background: blue"></div></div>
diff --git a/Tests/LibWeb/Ref/expected/multicol-break-fixed-height-blocks-ref.html b/Tests/LibWeb/Ref/expected/multicol-break-fixed-height-blocks-ref.html
new file mode 100644
index 00000000000..05f11c8c961
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/multicol-break-fixed-height-blocks-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<style>
+body { margin: 0; }
+.container { position: relative; height: 100px; width: 320px; background: lightgray; }
+.container > div { position: absolute; width: 100px; }
+</style>
+<div class="container">
+ <div style="background: red; left: 0; top: 0; height: 40px"></div>
+ <div style="background: orange; left: 0; top: 40px; height: 40px"></div>
+ <div style="background: yellow; left: 0; top: 80px; height: 20px"></div>
+ <div style="background: yellow; left: 110px; top: 0; height: 20px"></div>
+ <div style="background: green; left: 110px; top: 20px; height: 40px"></div>
+ <div style="background: blue; left: 110px; top: 60px; height: 40px"></div>
+ <div style="background: blue; left: 220px; top: 0; height: 20px"></div>
+ <div style="background: purple; left: 220px; top: 20px; height: 40px"></div>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/multicol-broken-rounded-image-background-ref.html b/Tests/LibWeb/Ref/expected/multicol-broken-rounded-image-background-ref.html
new file mode 100644
index 00000000000..883c5d9df8a
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/multicol-broken-rounded-image-background-ref.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<style>
+ body { margin: 0; }
+ .multicol { columns: 2; column-gap: 20px; column-fill: auto; height: 200px; width: 420px; }
+ .box { height: 292px; border-radius: 50%; border: 4px solid black; background: green; }
+</style>
+<div class="multicol"><div class="box"></div></div>
diff --git a/Tests/LibWeb/Ref/input/multicol-break-background-clip.html b/Tests/LibWeb/Ref/input/multicol-break-background-clip.html
new file mode 100644
index 00000000000..2298741f12b
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/multicol-break-background-clip.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/multicol-break-background-clip-ref.html">
+<style>
+ body { margin: 0; }
+</style>
+<div style="columns: 2; column-gap: 0; column-fill: auto; width: 400px; height: 100px">
+ <div style="height: 150px; border: 10px solid blue; padding: 10px; background: green; background-clip: content-box"></div>
+</div>
diff --git a/Tests/LibWeb/Ref/input/multicol-break-background-slice.html b/Tests/LibWeb/Ref/input/multicol-break-background-slice.html
new file mode 100644
index 00000000000..255549d885b
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/multicol-break-background-slice.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/multicol-break-background-slice-ref.html">
+<style>
+ body {
+ margin: 0;
+ }
+ .multicol {
+ columns: 2;
+ column-gap: 0;
+ column-fill: auto;
+ width: 200px;
+ height: 100px;
+ }
+ .sliced {
+ background: linear-gradient(green 50%, blue 50%);
+ }
+ .sliced > div {
+ height: 100px;
+ }
+</style>
+<div class="multicol"><div class="sliced"><div></div><div></div></div></div>
diff --git a/Tests/LibWeb/Ref/input/multicol-break-bordered-block.html b/Tests/LibWeb/Ref/input/multicol-break-bordered-block.html
new file mode 100644
index 00000000000..792ab6c638c
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/multicol-break-bordered-block.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/multicol-break-bordered-block-ref.html">
+<style>
+body { margin: 0; }
+.multicol { columns: 2; column-gap: 20px; column-fill: auto; height: 100px; width: 220px; }
+.outer { border: 5px solid blue; background: yellow; }
+.outer > div { height: 30px; background: green; overflow: hidden; }
+</style>
+<div class="multicol">
+ <div class="outer">
+ <div></div><div></div><div></div><div></div><div></div><div></div>
+ </div>
+</div>
diff --git a/Tests/LibWeb/Ref/input/multicol-break-clip-path-and-mask.html b/Tests/LibWeb/Ref/input/multicol-break-clip-path-and-mask.html
new file mode 100644
index 00000000000..f2c2132306d
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/multicol-break-clip-path-and-mask.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/multicol-break-clip-path-and-mask-ref.html">
+<style>
+ body { margin: 0; }
+ .multicol { columns: 2; column-gap: 20px; width: 420px; column-fill: auto; height: 100px; margin-bottom: 10px; }
+</style>
+<div class="multicol"><div style="clip-path: inset(0); height: 180px; background: green"></div></div>
+<div class="multicol"><div style="mask-image: linear-gradient(black, black); height: 180px; background: blue"></div></div>
diff --git a/Tests/LibWeb/Ref/input/multicol-break-fixed-height-blocks.html b/Tests/LibWeb/Ref/input/multicol-break-fixed-height-blocks.html
new file mode 100644
index 00000000000..a07f23c7e33
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/multicol-break-fixed-height-blocks.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/multicol-break-fixed-height-blocks-ref.html">
+<style>
+body { margin: 0; }
+.multicol { columns: 3; column-gap: 10px; column-fill: auto; height: 100px; width: 320px; background: lightgray; }
+.multicol > div { height: 40px; }
+</style>
+<div class="multicol">
+ <div style="background: red"></div>
+ <div style="background: orange"></div>
+ <div style="background: yellow"></div>
+ <div style="background: green"></div>
+ <div style="background: blue; height: 60px"></div>
+ <div style="background: purple"></div>
+</div>
diff --git a/Tests/LibWeb/Ref/input/multicol-broken-rounded-image-background.html b/Tests/LibWeb/Ref/input/multicol-broken-rounded-image-background.html
new file mode 100644
index 00000000000..e7822978149
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/multicol-broken-rounded-image-background.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/multicol-broken-rounded-image-background-ref.html">
+<meta name="fuzzy" content="maxDifference=0-64;totalPixels=0-200" />
+<style>
+ body { margin: 0; }
+ .multicol { columns: 2; column-gap: 20px; column-fill: auto; height: 200px; width: 420px; }
+ .box { height: 292px; border-radius: 50%; border: 4px solid black; background: linear-gradient(green, green); }
+</style>
+<div class="multicol"><div class="box"></div></div>
diff --git a/Tests/LibWeb/Text/expected/multicol-broken-box-wheel-targets.txt b/Tests/LibWeb/Text/expected/multicol-broken-box-wheel-targets.txt
new file mode 100644
index 00000000000..d0d1d05763d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/multicol-broken-box-wheel-targets.txt
@@ -0,0 +1,12 @@
+blocking regions: 2
+CompositorWheelHitTestTarget@s0/e0 target_scroll_node_index=s0 rect=[0,0 800x600]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,0 800x239]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,0 800x226]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,0 420x200]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s2 rect=[0,0 200x60]
+CompositorWheelHitTestTarget@s2/c0/e0 target_scroll_node_index=s2 rect=[0,0 200x500]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,60 200x140]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[220,0 200x160]
+CompositorBlockingWheelEventRegion@s1/e0 rect=[0,60 200x140]
+CompositorBlockingWheelEventRegion@s1/e0 rect=[220,0 200x160]
+CompositorWheelHitTestTarget@s1/e0 target_scroll_node_index=s0 rect=[0,213 800x13]
diff --git a/Tests/LibWeb/Text/expected/multicol-broken-definite-height.txt b/Tests/LibWeb/Text/expected/multicol-broken-definite-height.txt
new file mode 100644
index 00000000000..215456c9f68
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/multicol-broken-definite-height.txt
@@ -0,0 +1,3 @@
+short: 0,0 200x50 200,0 200x0
+tall: 0,0 100x85 100,0 100x75
+after: 100,75 100x10
diff --git a/Tests/LibWeb/Text/expected/multicol-broken-empty-editable-hit-testing.txt b/Tests/LibWeb/Text/expected/multicol-broken-empty-editable-hit-testing.txt
new file mode 100644
index 00000000000..d4b6178697c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/multicol-broken-empty-editable-hit-testing.txt
@@ -0,0 +1,4 @@
+over text before the editable: before, caret in before
+over the editable in column 1: editable, caret in editable
+over the editable in column 2: editable, caret in editable
+over text after the editable: editable, caret in editable
diff --git a/Tests/LibWeb/Text/expected/multicol-fieldset-content-box.txt b/Tests/LibWeb/Text/expected/multicol-fieldset-content-box.txt
new file mode 100644
index 00000000000..12a1f700739
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/multicol-fieldset-content-box.txt
@@ -0,0 +1,5 @@
+clearfix: 420x40, blocks 0,0 200x40 | 220,0 200x40
+direct-table: 420x43, blocks 0,0 420x43 | 220,3 200x40
+legend-fill: 420x100, blocks 0,20 200x40 | 0,60 200x40 | 220,20 200x40 | 220,60 200x40
+legend-balanced: 420x60, blocks 0,20 200x40 | 220,20 200x40 | 440,20 200x40 | 660,20 200x40
+legend-percentage: 420x100, blocks 0,20 420x40
diff --git a/Tests/LibWeb/Text/expected/multicol-later-fragment-move.txt b/Tests/LibWeb/Text/expected/multicol-later-fragment-move.txt
new file mode 100644
index 00000000000..d35d60581b7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/multicol-later-fragment-move.txt
@@ -0,0 +1,2 @@
+clipped: 200,0 50x50, hit true
+transformed: 225,112.5 25x25, hit true
diff --git a/Tests/LibWeb/Text/expected/multicol-quirks-percentage-height.txt b/Tests/LibWeb/Text/expected/multicol-quirks-percentage-height.txt
new file mode 100644
index 00000000000..355ef791cce
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/multicol-quirks-percentage-height.txt
@@ -0,0 +1,3 @@
+at 400px: auto-height=0 auto-height-child=0 percentage-height=400 percentage-height-child=100
+at 200px: auto-height=0 auto-height-child=0 percentage-height=200 percentage-height-child=50
+back at 400px: auto-height=0 auto-height-child=0 percentage-height=400 percentage-height-child=100
diff --git a/Tests/LibWeb/Text/input/multicol-broken-box-wheel-targets.html b/Tests/LibWeb/Text/input/multicol-broken-box-wheel-targets.html
new file mode 100644
index 00000000000..25e0bb503a4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/multicol-broken-box-wheel-targets.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; }
+ #multicol { columns: 2; column-gap: 20px; column-fill: auto; height: 200px; width: 420px; }
+ #scroller { overflow: auto; height: 60px; }
+</style>
+<div id="multicol">
+ <div id="scroller"><div style="height: 500px"></div></div>
+ <div id="broken" style="height: 300px"></div>
+</div>
+<script>
+ test(() => {
+ document.getElementById("broken").addEventListener("wheel", () => {}, { passive: false });
+ internals.recordDisplayListForTesting();
+ const state = internals.recordedAsyncScrollingState();
+ println(`blocking regions: ${state.blockingWheelEventRegionCount}`);
+ for (const line of internals.dumpDisplayList().split("\n")) {
+ if (line.startsWith("CompositorWheelHitTestTarget") || line.startsWith("CompositorBlockingWheelEventRegion"))
+ println(line);
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/multicol-broken-definite-height.html b/Tests/LibWeb/Text/input/multicol-broken-definite-height.html
new file mode 100644
index 00000000000..173402ebbf1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/multicol-broken-definite-height.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; }
+</style>
+<div style="columns: 2; column-gap: 0; column-fill: auto; height: 100px; width: 400px"><div id="short" style="height: 50px"><div style="height: 200px"></div></div></div>
+<div style="columns: 2; column-gap: 0; width: 200px"><div id="tall" style="height: 160px"></div><div id="after" style="height: 10px"></div></div>
+<script>
+ test(() => {
+ for (const id of ["short", "tall", "after"]) {
+ const element = document.getElementById(id);
+ const origin = element.parentElement.getBoundingClientRect();
+ const rects = [...element.getClientRects()].map(rect => `${rect.x - origin.x},${rect.y - origin.y} ${rect.width}x${rect.height}`);
+ println(`${id}: ${rects.join(" ")}`);
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/multicol-broken-empty-editable-hit-testing.html b/Tests/LibWeb/Text/input/multicol-broken-empty-editable-hit-testing.html
new file mode 100644
index 00000000000..1ad4f182039
--- /dev/null
+++ b/Tests/LibWeb/Text/input/multicol-broken-empty-editable-hit-testing.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ @font-face { font-family: Ahem; src: url(../../Ref/data/fonts/Ahem.ttf); }
+ body { margin: 0; font: 20px/20px Ahem; }
+ #multicol { columns: 2; column-gap: 20px; column-fill: auto; height: 200px; width: 420px; }
+ p { margin: 0; }
+</style>
+<div id="multicol"><p id="before">hello world</p><div id="editable" contenteditable style="height: 300px"></div><p id="after">after</p></div>
+<script>
+ asyncTest(async done => {
+ await document.fonts.load("20px Ahem");
+ const describe = (x, y) => {
+ const element = document.elementFromPoint(x, y);
+ const caret = document.caretPositionFromPoint(x, y);
+ const node = caret ? (caret.offsetNode.id || caret.offsetNode.parentNode.id) : "none";
+ return `${element ? element.id : "none"}, caret in ${node}`;
+ };
+ println(`over text before the editable: ${describe(30, 10)}`);
+ println(`over the editable in column 1: ${describe(30, 100)}`);
+ println(`over the editable in column 2: ${describe(300, 50)}`);
+ println(`over text after the editable: ${describe(230, 130)}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/multicol-fieldset-content-box.html b/Tests/LibWeb/Text/input/multicol-fieldset-content-box.html
new file mode 100644
index 00000000000..6f0d02aeb99
--- /dev/null
+++ b/Tests/LibWeb/Text/input/multicol-fieldset-content-box.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; }
+ fieldset { margin: 0 0 10px 0; padding: 0; border: 0; columns: 2; column-gap: 20px; width: 420px; }
+ legend { padding: 0; height: 20px; }
+ .block { height: 40px; }
+ .clearfix::before, .clearfix::after { content: " "; display: table; }
+</style>
+<fieldset class="clearfix" id="clearfix"><div class="block"></div><div class="block"></div></fieldset>
+<fieldset id="direct-table"><table><tr><td></td></tr></table><div class="block"></div><div class="block"></div></fieldset>
+<fieldset id="legend-fill" style="column-fill: auto; height: 100px"><legend>L</legend><div class="block"></div><div class="block"></div><div class="block"></div><div class="block"></div></fieldset>
+<fieldset id="legend-balanced" style="height: 60px"><legend>L</legend><div class="block"></div><div class="block"></div><div class="block"></div><div class="block"></div></fieldset>
+<fieldset id="legend-percentage" style="height: 100px; columns: auto"><legend>L</legend><div style="height: 50%"></div></fieldset>
+<script>
+ test(() => {
+ for (const fieldset of document.querySelectorAll("fieldset")) {
+ const origin = fieldset.getBoundingClientRect();
+ const blocks = Array.from(fieldset.querySelectorAll(":scope > div")).map(block => {
+ const rect = block.getBoundingClientRect();
+ return `${rect.x - origin.x},${rect.y - origin.y} ${rect.width}x${rect.height}`;
+ });
+ println(`${fieldset.id}: ${origin.width}x${origin.height}, blocks ${blocks.join(" | ")}`);
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/multicol-later-fragment-move.html b/Tests/LibWeb/Text/input/multicol-later-fragment-move.html
new file mode 100644
index 00000000000..6b6dc6cb1b1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/multicol-later-fragment-move.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; }
+ .mc { columns: 2; column-gap: 0; column-fill: auto; height: 100px; width: 200px; }
+ .square { height: 50px; width: 50px; background: green; }
+</style>
+<div class="mc" id="clipped"><div style="height: 150px"><div style="height: 100px"></div><div style="overflow: hidden"><div class="square" id="clipped-square"></div></div></div></div>
+<div class="mc" id="transformed"><div style="height: 150px"><div style="height: 100px"></div><div style="transform: scale(0.5)"><div class="square" id="transformed-square"></div></div></div></div>
+<script>
+ asyncTest(async done => {
+ const frame = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ await frame();
+ for (const id of ["clipped", "transformed"]) {
+ const container = document.getElementById(id);
+ container.style.width = "300px";
+ container.style.columnGap = "100px";
+ }
+ await frame();
+ for (const id of ["clipped", "transformed"]) {
+ const square = document.getElementById(`${id}-square`);
+ const rect = square.getBoundingClientRect();
+ const hit = document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2) === square;
+ println(`${id}: ${rect.x},${rect.y} ${rect.width}x${rect.height}, hit ${hit}`);
+ }
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/multicol-quirks-percentage-height.html b/Tests/LibWeb/Text/input/multicol-quirks-percentage-height.html
new file mode 100644
index 00000000000..454fb1dbce9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/multicol-quirks-percentage-height.html
@@ -0,0 +1,25 @@
+<!DOCTYPE quirks>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; }
+</style>
+<div id="outer" style="height: 400px; width: 400px">
+ <div id="auto-height" style="columns: 2; column-gap: 0"><div id="auto-height-child" style="height: 50%"></div></div>
+ <div id="percentage-height" style="columns: 2; column-gap: 0; height: 100%"><div id="percentage-height-child" style="height: 50%"></div></div>
+</div>
+<script>
+ test(() => {
+ const outer = document.getElementById("outer");
+ const report = label => {
+ const heights = ["auto-height", "auto-height-child", "percentage-height", "percentage-height-child"].map(
+ id => `${id}=${document.getElementById(id).offsetHeight}`
+ );
+ println(`${label}: ${heights.join(" ")}`);
+ };
+ report("at 400px");
+ outer.style.height = "200px";
+ report("at 200px");
+ outer.style.height = "400px";
+ report("back at 400px");
+ });
+</script>