Truly independent web browser
LibWeb: Honor break avoidance and break propagation in columns
Aliaksandr Kalenik6bae539bd606
diff --git a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs b/Libraries/LibWeb/Rust/src/css/computed_value_views.rsindex 5f3b87c0981..ef374db4c0d 100644--- a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_value_views.rs@@ -430,6 +430,7 @@ scalar_accessors! {column_rule_color: u32 => column_rule_color,break_before: u8 => break_before,break_after: u8 => break_after,+ break_inside: u8 => break_inside,}border_facts: {border_top_width: CssPixels => border_top.width,diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 858b05f15a8..471918e3539 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -9,6 +9,7 @@ use super::*;use smallvec::{SmallVec, smallvec};const MAXIMUM_BALANCING_ROUNDS: usize = 16;+const MAXIMUM_EARLY_BREAK_ATTEMPTS: usize = 16;#[derive(Clone, Copy, Debug, PartialEq, Eq)]enum FragmentationStep {@@ -24,7 +25,8 @@ struct ColumnLayout {}struct FragmentationState {- container_block_offset_in_root: CssPixels,+ container_content_box_block_start_in_root: CssPixels,+ allows_unforced_breaks: bool,resume: Option<fragmentation::BlockResume>,is_resumed: bool,fragmentainer_had_content_before_container: bool,@@ -32,23 +34,35 @@ struct FragmentationState {fragmentainer_had_content_before_child: bool,truncate_next_block_start_margin: bool,previous_in_flow_child_forces_break_after: bool,+ previous_in_flow_child: Option<PreviousInFlowChild>,+}++#[derive(Clone, Copy)]+struct PreviousInFlowChild {+ node: Node,+ can_break_before: bool,+ avoids_break_after: bool,}impl FragmentationState {fn new(incoming: Option<&fragmentation::BlockBreakToken>,- container_block_offset_in_root: CssPixels,+ container_content_box_block_start_in_root: CssPixels,+ allows_unforced_breaks: bool,fragmentainer_had_content_before_container: bool,+ block_start_margin_is_truncated: bool,) -> Self {- let truncate_next_block_start_margin = matches!(- incoming.map(|token| &token.resume),- Some(fragmentation::BlockResume::BeforeChild {- after_forced_break: false,- ..- })- );+ let truncate_next_block_start_margin = block_start_margin_is_truncated+ || matches!(+ incoming.map(|token| &token.resume),+ Some(fragmentation::BlockResume::BeforeChild {+ after_forced_break: false,+ ..+ })+ );Self {- container_block_offset_in_root,+ container_content_box_block_start_in_root,+ allows_unforced_breaks,resume: incoming.map(|token| token.resume.clone()),is_resumed: incoming.is_some(),fragmentainer_had_content_before_container,@@ -56,6 +70,7 @@ impl FragmentationState {fragmentainer_had_content_before_child: false,truncate_next_block_start_margin,previous_in_flow_child_forces_break_after: false,+ previous_in_flow_child: None,}}}@@ -241,15 +256,18 @@ 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>,+ unforced_break_suppression_depth: Cell<usize>,column_inline_items: OnceCell<std::rc::Rc<inline_level_iterator::InlineItemCache>>,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>,+ propagated_break_values: RefCell<HashMap<(Node, bool), u8>>,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>>>,unbreakable_line_roots: RefCell<HashSet<Node>>,+ fragmentation_suppression_depth: Cell<usize>,}impl<'pass> BlockFormattingContext<'pass> {@@ -302,15 +320,18 @@ 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),+ unforced_break_suppression_depth: Cell::new(0),column_inline_items: OnceCell::new(),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),+ propagated_break_values: RefCell::new(HashMap::default()),pending_continuation_token: RefCell::new(None),incoming_container_token: RefCell::new(None),broken_child_token: RefCell::new(None),unbreakable_line_roots: RefCell::new(HashSet::default()),+ fragmentation_suppression_depth: Cell::new(0),}}@@ -1884,7 +1905,16 @@ impl<'pass> BlockFormattingContext<'pass> {.pending_continuation_token.borrow_mut().take_if(|token| token.node == node);+ let fragments_inside = self.run.fragmentainer.is_some() && self.fragmentation_suppression_depth.get() == 0;+ let suppresses_fragmentation_inside = fragments_inside && facts.node_has_size_containment();+ let suppresses_unforced_breaks_inside = fragments_inside+ && !suppresses_fragmentation_inside+ && self.unforced_break_suppression_depth.get() == 0+ && fragmentation::avoids_column_break_inside(self.style(node).break_inside())+ && self.fragmentainer_has_content.get();+ let mut continuation_padding_top = CssPixels::default();if continuation.is_some() {+ continuation_padding_top = used.padding_top.get();used.margin_top.set(CssPixels::default());used.border_top.set(CssPixels::default());used.padding_top.set(CssPixels::default());@@ -1918,7 +1948,10 @@ impl<'pass> BlockFormattingContext<'pass> {attempt => attempt,};- if !self.discard_block_start_margin_of_next_child.replace(false) {+ let is_in_flow_candidate = self.is_first_or_last_in_flow_candidate(node);+ let discards_block_start_margin =+ is_in_flow_candidate && self.discard_block_start_margin_of_next_child.replace(false);+ if !discards_block_start_margin {self.margin_state.borrow_mut().add_margin(self.used(node).margin_top.get());@@ -2082,12 +2115,20 @@ impl<'pass> BlockFormattingContext<'pass> {}}- if let Some(continuation) = &continuation- && self.used(node).has_definite_block_size()- {+ let block_size_box_sizing = if block_size_is_definite_from_aspect_ratio && style.height().is_auto() {+ style.box_sizing_for_aspect_ratio()+ } else {+ style.box_sizing()+ };+ let continuation_inner_size_excess = if block_size_box_sizing == box_sizing::BORDER_BOX {+ continuation_padding_top+ } else {+ CssPixels::default()+ };+ if continuation.is_some() && 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()),+ (used.content_block_size.get() - continuation_inner_size_excess).max(CssPixels::default()),);}@@ -2117,6 +2158,14 @@ impl<'pass> BlockFormattingContext<'pass> {}}+ if suppresses_fragmentation_inside {+ self.fragmentation_suppression_depth+ .set(self.fragmentation_suppression_depth.get() + 1);+ }+ if suppresses_unforced_breaks_inside {+ self.unforced_break_suppression_depth+ .set(self.unforced_break_suppression_depth.get() + 1);+ }let child_layout = if has_independent_formatting_context {// Margins of elements that establish new formatting contexts do not collapse with their in-flow childrenself.margin_state.borrow_mut().reset();@@ -2187,6 +2236,14 @@ impl<'pass> BlockFormattingContext<'pass> {.borrow_mut().open_top_margin_group(node, introduced_clearance);}+ if is_in_flow_candidate {+ self.discard_block_start_margin_of_next_child.set(+ discards_block_start_margin+ && !facts.children_are_inline()+ && self.used(node).border_top.get() == CssPixels::default()+ && self.used(node).padding_top.get() == CssPixels::default(),+ );+ }let inside_layout_input = LayoutInput {content_box_position_in_bfc_root: Some(FfiCssPixelPoint {x: containing_block_position_in_root.x + content_inline_offset,@@ -2200,6 +2257,9 @@ impl<'pass> BlockFormattingContext<'pass> {} else {self.layout_block_level_children(run, node, inside_layout_input, space_available_for_children);}+ if is_in_flow_candidate {+ self.discard_block_start_margin_of_next_child.set(false);+ }if box_opens_top_margin_group {let resolved_margin_top = self.margin_state.borrow_mut().take_pending_top_margin();let final_content_block_offset = if introduced_clearance {@@ -2263,6 +2323,16 @@ impl<'pass> BlockFormattingContext<'pass> {);}+ if let Some(continuation) = &continuation {+ self.size_continuation(+ node,+ continuation.consumed_block_size,+ continuation_inner_size_excess,+ available_space_for_block_size_resolution,+ input.containing_block_constraints,+ );+ }+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@@ -2276,9 +2346,13 @@ impl<'pass> BlockFormattingContext<'pass> {.filter(|token| token.node == node).cloned().or_else(|| {+ if !self.allows_unforced_breaks() {+ return None;+ }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.node_has_size_containment()&& facts.is_block_container()&& (!facts.children_are_inline() || !self.has_lines(node))&& content_block_start_in_root < block_size@@ -2321,6 +2395,15 @@ impl<'pass> BlockFormattingContext<'pass> {}}+ if suppresses_fragmentation_inside {+ self.fragmentation_suppression_depth+ .set(self.fragmentation_suppression_depth.get() - 1);+ }+ if suppresses_unforced_breaks_inside {+ self.unforced_break_suppression_depth+ .set(self.unforced_break_suppression_depth.get() - 1);+ }+// 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 && continuation.is_none() {let list_item_used = self.used(node);@@ -2629,21 +2712,25 @@ impl<'pass> BlockFormattingContext<'pass> {let saved = self.block_offset_of_current_block_container.replace(Some(CssPixels::default()));- let fragmentainer = self.run.fragmentainer.clone();+ let fragmentainer = self+ .run+ .fragmentainer+ .clone()+ .filter(|_| self.fragmentation_suppression_depth.get() == 0);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,+ input+ .content_box_position_in_bfc_root+ .map_or(CssPixels::default(), |position| position.y),+ self.unforced_break_suppression_depth.get() == 0,self.fragmentainer_has_content.get(),+ self.discard_block_start_margin_of_next_child.get(),)});let first_child = fragmentation_state@@ -2737,17 +2824,20 @@ impl<'pass> BlockFormattingContext<'pass> {}None => {}}- let facts = self.facts(child);- if !facts.is_flow_layout_participant() || facts.is_floating() {+ if !self.is_first_or_last_in_flow_candidate(child) {return FragmentationStep::LayOut;}if fragmentainer.early_break_before == Some(child) {+ if self.break_between_is_avoided(state, child) {+ fragmentainer.outcome_mut().violates_break_avoidance = true;+ }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 && self.fragmentainer_has_content.get() {+ || (fragmentation::is_forced_column_break(self.propagated_break_before(child))+ && self.fragmentainer_has_content.get());+ if forced {self.break_before_child(fragmentainer, state, block_container, child, true);return FragmentationStep::Stop;}@@ -2766,12 +2856,12 @@ impl<'pass> BlockFormattingContext<'pass> {block_container: Node,child: Node,) -> FragmentationStep {- self.discard_block_start_margin_of_next_child.set(false);- let facts = self.facts(child);- if !facts.is_flow_layout_participant() || facts.is_floating() {+ if !self.is_first_or_last_in_flow_candidate(child) {return FragmentationStep::LayOut;}- state.truncate_next_block_start_margin = false;+ self.discard_block_start_margin_of_next_child.set(false);+ state.truncate_next_block_start_margin &=+ self.run.records.used_values_if_owned(child).is_some() && self.margins_collapse_through(child);let broken_child_token = self.broken_child_token.borrow_mut()@@ -2789,35 +2879,201 @@ impl<'pass> BlockFormattingContext<'pass> {return FragmentationStep::LayOut;};let collapsed = used.uses_collapsing_borders_model.get();- 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;+ if state.allows_unforced_breaks {+ let content_block_end = state.container_content_box_block_start_in_root+ + self.block_offset_adjustment_from_pending_ancestor_block_start_margins(block_container)+ + used.content_offset.get().y+ + used.content_block_size.get();+ let is_breakable = self.child_is_breakable(child);+ if !is_breakable {+ fragmentainer.note_unbreakable_block_size(border_box_block_size);+ }+ let block_end = 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+ && (!is_breakable || fragmentainer.exceeds(content_block_end))+ {+ let earlier_break = state+ .previous_in_flow_child+ .filter(|previous| previous.can_break_before)+ .map(|previous| previous.node)+ .filter(|_| self.break_between_is_avoided(state, child));+ if fragmentainer.request_early_break_before(earlier_break.unwrap_or(child)) {+ return FragmentationStep::Stop;+ }+ }}}state.has_in_flow_content = true;+ let break_after = self.propagated_break_after(child);+ if fragmentation::is_forced_column_break(break_after) {+ state.previous_in_flow_child_forces_break_after = true;+ }if border_box_block_size > CssPixels::default() {self.fragmentainer_has_content.set(true);+ let can_break_before =+ state.fragmentainer_had_content_before_child && !self.break_between_is_avoided(state, child);+ state.previous_in_flow_child_forces_break_after = fragmentation::is_forced_column_break(break_after);+ state.previous_in_flow_child = Some(PreviousInFlowChild {+ node: child,+ can_break_before,+ avoids_break_after: fragmentation::avoids_column_break_between(break_after),+ });}- state.previous_in_flow_child_forces_break_after =- fragmentation::is_forced_column_break(self.style(child).break_after());FragmentationStep::LayOut}+ fn break_between_is_avoided(&self, state: &FragmentationState, child: Node) -> bool {+ state.previous_in_flow_child.is_some_and(|previous| {+ previous.avoids_break_after+ || fragmentation::avoids_column_break_between(self.propagated_break_before(child))+ })+ }++ // https://drafts.csswg.org/css-break-3/#break-propagation+ fn propagated_break_before(&self, node: Node) -> u8 {+ self.propagated_break_value(+ node,+ true,+ |style| style.break_before(),+ |node| {+ self.children(node)+ .find(|&child| self.is_first_or_last_in_flow_candidate(child))+ },+ )+ }++ fn propagated_break_after(&self, node: Node) -> u8 {+ self.propagated_break_value(+ node,+ false,+ |style| style.break_after(),+ |node| {+ self.run+ .callbacks+ .children_rev(node)+ .filter(|&child| self.facts(child).is_box())+ .find(|&child| self.is_first_or_last_in_flow_candidate(child))+ },+ )+ }++ fn propagated_break_value(+ &self,+ node: Node,+ is_break_before: bool,+ value_of: impl Fn(StyleValues<'pass>) -> u8,+ child_of: impl Fn(Node) -> Option<Node>,+ ) -> u8 {+ let memoized = |node: Node| {+ self.propagated_break_values+ .borrow()+ .get(&(node, is_break_before))+ .copied()+ };+ let mut chain = SmallVec::<[(Node, u8); 8]>::new();+ let mut current = node;+ let mut propagated_from_below = loop {+ if let Some(value) = memoized(current) {+ break Some(value);+ }+ let value = value_of(self.style(current));+ chain.push((current, value));+ if fragmentation::is_forced_column_break(value) {+ break None;+ }+ let facts = self.facts(current);+ if !facts.is_block_container()+ || facts.children_are_inline()+ || formatting_context::formatting_context_type_created_by_box(facts).is_some()+ {+ break None;+ }+ let Some(child) = child_of(current) else {+ break None;+ };+ current = child;+ };+ for (node, own_value) in chain.into_iter().rev() {+ let value = match propagated_from_below {+ Some(below)+ if !fragmentation::is_forced_column_break(own_value)+ && (fragmentation::is_forced_column_break(below) || own_value == break_between::AUTO) =>+ {+ below+ }+ _ => own_value,+ };+ self.propagated_break_values+ .borrow_mut()+ .insert((node, is_break_before), value);+ propagated_from_below = Some(value);+ }+ propagated_from_below.expect("the chain holds at least the node itself")+ }++ fn is_first_or_last_in_flow_candidate(&self, child: Node) -> bool {+ let facts = self.facts(child);+ if !facts.is_flow_layout_participant() || facts.is_floating() {+ return false;+ }+ !(self.run.callbacks.can_skip_is_anonymous_text_run(child)+ && self.style(child).white_space_collapse() == white_space_collapse::COLLAPSE)+ }++ fn allows_unforced_breaks(&self) -> bool {+ self.fragmentation_suppression_depth.get() == 0 && self.unforced_break_suppression_depth.get() == 0+ }++ fn size_continuation(+ &self,+ node: Node,+ consumed_block_size: CssPixels,+ inner_size_excess: CssPixels,+ available_space: AvailableSpace,+ constraints: ContainingBlockConstraints,+ ) {+ let used = self.used(node);+ if used.has_definite_block_size() {+ used.set_content_block_size(+ (used.content_block_size.get() - consumed_block_size).max(CssPixels::default()),+ );+ return;+ }+ let style = self.style(node);+ let sizing = self.sizing();+ let has_maximum = !style.max_height().is_auto()+ && !sizing.should_treat_max_block_size_as_none(node, available_space.block_size, constraints);+ if !has_maximum && style.min_height().is_auto() {+ return;+ }+ let remaining = |size: &ComputedSize| {+ (sizing.calculate_inner_block_size(node, available_space, size, constraints)+ - inner_size_excess+ - consumed_block_size)+ .max(CssPixels::default())+ };+ let mut block_size = self.compute_automatic_block_size_for_block_level_element(+ node,+ used.available_inner_space_or_constraints_from(available_space),+ constraints,+ None,+ );+ if has_maximum {+ block_size = block_size.min(remaining(style.max_height()));+ }+ if !style.min_height().is_auto() {+ block_size = block_size.max(remaining(style.min_height()));+ }+ used.set_content_block_size(block_size);+ }+pub(crate) fn line_root_fragmentation(&self, line_root: Node) -> Option<fragmentation::LineRootFragmentation> {+ if !self.allows_unforced_breaks() {+ return None;+ }let fragmentainer = self.run.fragmentainer.as_deref()?;let incoming = if line_root == self.run.box_ {fragmentainer.incoming.clone()@@ -2871,7 +3127,7 @@ impl<'pass> BlockFormattingContext<'pass> {pub(crate) fn request_early_break_before(&self, node: Node) {if let Some(fragmentainer) = self.run.fragmentainer.as_deref() {- fragmentainer.outcome_mut().needs_early_break_before = Some(node);+ fragmentainer.request_early_break_before(node);}}@@ -2891,6 +3147,8 @@ impl<'pass> BlockFormattingContext<'pass> {|| !self.unbreakable_line_roots.borrow().contains(&child))&& !facts.is_fieldset_box()&& !facts.is_table_wrapper()+ && !facts.node_has_size_containment()+ && !fragmentation::avoids_column_break_inside(self.style(child).break_inside())}fn has_lines(&self, node: Node) -> bool {@@ -2914,8 +3172,8 @@ impl<'pass> BlockFormattingContext<'pass> {&& !state.has_in_flow_content&& !after_forced_break&& state.fragmentainer_had_content_before_container+ && fragmentainer.request_early_break_before(block_container){- fragmentainer.outcome_mut().needs_early_break_before = Some(block_container);return;}self.stop_fragmentainer(@@ -3127,6 +3385,7 @@ impl<'pass> BlockFormattingContext<'pass> {let mut incoming = None;let mut column_count = 0;let mut forced_break_count = 0;+ let mut violates_break_avoidance = false;let mut minimal_space_shortage: Option<CssPixels> = None;loop {let ColumnLayout { outcome, .. } = self.layout_column(@@ -3141,6 +3400,7 @@ impl<'pass> BlockFormattingContext<'pass> {if outcome.ended_at_forced_break() {forced_break_count += 1;}+ violates_break_avoidance |= outcome.violates_break_avoidance;if let Some(shortage) = outcome.minimal_space_shortage {minimal_space_shortage =Some(minimal_space_shortage.map_or(shortage, |minimal| minimal.min(shortage)));@@ -3150,7 +3410,7 @@ impl<'pass> BlockFormattingContext<'pass> {break;}}- if incoming.is_none() && column_count <= geometry.count {+ if incoming.is_none() && column_count <= geometry.count && !violates_break_avoidance {break;}if forced_break_count + 1 >= geometry.count {@@ -3205,6 +3465,8 @@ impl<'pass> BlockFormattingContext<'pass> {root_line_index_offset: usize,) -> ColumnLayout {let mut early_break_before = None;+ let mut tried_early_breaks = Vec::new();+ let mut allows_early_break_requests = true;let mut minimal_space_shortage_of_discarded_attempts = None;let mut tallest_unbreakable_block_size_of_discarded_attempts = CssPixels::default();let inline_items = self.column_inline_items.get_or_init(Default::default);@@ -3214,6 +3476,7 @@ impl<'pass> BlockFormattingContext<'pass> {incoming.clone(),inline_items.clone(),early_break_before,+ allows_early_break_requests,));let journals_stored_entries = self.run.fragments.is_some();let fc_run_cache_store = self.run.callbacks.arena().fc_run_cache_store();@@ -3221,18 +3484,15 @@ impl<'pass> BlockFormattingContext<'pass> {fc_run_cache_store.begin_store_journal();}let outputs = formatting_context::run_fragmentainer(&self.run, purpose, input, fragmentainer.clone());+ if journals_stored_entries {+ fc_run_cache_store.end_store_journal(fragmentainer.outcome_mut().needs_early_break_before.is_none());+ }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- .is_some_and(|node| early_break_before != Some(node));- if journals_stored_entries {- fc_run_cache_store.end_store_journal(!retries);- }outcome.minimal_space_shortage = match (outcome.minimal_space_shortage,minimal_space_shortage_of_discarded_attempts,@@ -3243,10 +3503,14 @@ impl<'pass> BlockFormattingContext<'pass> {outcome.tallest_unbreakable_block_size = outcome.tallest_unbreakable_block_size.max(tallest_unbreakable_block_size_of_discarded_attempts);- if let Some(node) = outcome.needs_early_break_before- && early_break_before != Some(node)- {- early_break_before = Some(node);+ if let Some(node) = outcome.needs_early_break_before {+ if tried_early_breaks.contains(&node) {+ allows_early_break_requests = false;+ } else {+ tried_early_breaks.push(node);+ early_break_before = Some(node);+ allows_early_break_requests = tried_early_breaks.len() < MAXIMUM_EARLY_BREAK_ATTEMPTS;+ }minimal_space_shortage_of_discarded_attempts = outcome.minimal_space_shortage;tallest_unbreakable_block_size_of_discarded_attempts = outcome.tallest_unbreakable_block_size;continue;@@ -3619,6 +3883,8 @@ impl<'pass> BlockFormattingContext<'pass> {if is_after_clamp_point {self.laying_out_invisible_line_clamp_content.set(true);}+ self.fragmentation_suppression_depth+ .set(self.fragmentation_suppression_depth.get() + 1);self.layout_block_level_box(run,node,@@ -3630,6 +3896,8 @@ impl<'pass> BlockFormattingContext<'pass> {fragment_index: 0,}),);+ self.fragmentation_suppression_depth+ .set(self.fragmentation_suppression_depth.get() - 1);if is_after_clamp_point {self.laying_out_invisible_line_clamp_content.set(false);}@@ -3856,6 +4124,14 @@ impl<'pass> BlockFormattingContext<'pass> {self.add_float_to_bands(floating_box, containing_block_rect);let bottom_margin_edge = margin_box_rect.bottom();+ if let Some(fragmentainer) = self.run.fragmentainer.as_deref()+ && self.allows_unforced_breaks()+ {+ fragmentainer.note_unbreakable_block_size(margin_box_rect.height);+ if fragmentainer.exceeds(bottom_margin_edge) {+ fragmentainer.note_space_shortage(bottom_margin_edge);+ }+ }self.lowest_floating_descendant_bottom_margin_edge.set(Some(self.lowest_floating_descendant_bottom_margin_edge.get()diff --git a/Libraries/LibWeb/Rust/src/layout/fragmentation.rs b/Libraries/LibWeb/Rust/src/layout/fragmentation.rsindex 1b5be28fa08..c64ceac3a7d 100644--- a/Libraries/LibWeb/Rust/src/layout/fragmentation.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragmentation.rs@@ -82,6 +82,14 @@ pub(crate) fn is_forced_column_break(value: u8) -> bool {value == break_between::COLUMN}+pub(crate) fn avoids_column_break_between(value: u8) -> bool {+ matches!(value, break_between::AVOID | break_between::AVOID_COLUMN)+}++pub(crate) fn avoids_column_break_inside(value: u8) -> bool {+ matches!(value, break_inside::AVOID | break_inside::AVOID_COLUMN)+}+#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) struct ColumnRow {pub(crate) block_offset: CssPixels,@@ -140,6 +148,7 @@ pub(crate) struct FragmentainerOutcome {pub(crate) needs_early_break_before: Option<Node>,pub(crate) minimal_space_shortage: Option<CssPixels>,pub(crate) tallest_unbreakable_block_size: CssPixels,+ pub(crate) violates_break_avoidance: bool,}impl FragmentainerOutcome {@@ -153,6 +162,7 @@ pub(crate) struct FragmentainerContext {pub(crate) incoming: Option<Rc<BlockBreakToken>>,pub(crate) inline_items: Rc<inline_level_iterator::InlineItemCache>,pub(crate) early_break_before: Option<Node>,+ pub(crate) allows_early_break_requests: bool,outcome: RefCell<FragmentainerOutcome>,}@@ -162,12 +172,14 @@ impl FragmentainerContext {incoming: Option<Rc<BlockBreakToken>>,inline_items: Rc<inline_level_iterator::InlineItemCache>,early_break_before: Option<Node>,+ allows_early_break_requests: bool,) -> Self {Self {block_size,incoming,inline_items,early_break_before,+ allows_early_break_requests,outcome: RefCell::new(FragmentainerOutcome::default()),}}@@ -176,6 +188,14 @@ impl FragmentainerContext {self.outcome.borrow_mut()}+ pub(crate) fn request_early_break_before(&self, node: Node) -> bool {+ if !self.allows_early_break_requests {+ return false;+ }+ self.outcome.borrow_mut().needs_early_break_before = Some(node);+ true+ }+pub(crate) fn take_outcome(&self) -> FragmentainerOutcome {self.outcome.take()}diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-000-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-000-ref.htmlnew file mode 100644index 00000000000..a7022ae575c--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-000-ref.html@@ -0,0 +1,4 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<p>There should be a yellow box with a hotpink border in the second column.</p>+<div style="float:left; margin-left:110px; border:10px solid hotpink; width:80px; height:80px; background:yellow;"></div>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-001-ref.htmlnew file mode 100644index 00000000000..30c472f9378--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-001-ref.html@@ -0,0 +1,7 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<p>There should be a yellow box that starts in the second column and ends in the+ third. The top border should be in the second column, and the bottom border+ should be in the third.</p>+<div style="float:left; margin-left:110px; border:10px solid hotpink; border-bottom:none; width:80px; height:90px; background:yellow;"></div>+<div style="float:left; margin-left:10px; border:10px solid hotpink; border-top:none; width:80px; height:10px; background:yellow;"></div>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-002-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-002-ref.htmlnew file mode 100644index 00000000000..7abcf4ed61c--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-002-ref.html@@ -0,0 +1,8 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<p>There should be a yellow box that starts in the second column and ends in the+ fourth. The top border should be in the second column, and the bottom border+ should be in the fourth.</p>+<div style="float:left; margin-left:110px; border:10px solid hotpink; border-bottom:none; width:80px; height:90px; background:yellow;"></div>+<div style="float:left; margin-left:10px; border:10px solid hotpink; border-bottom:none; border-top:none; width:80px; height:100px; background:yellow;"></div>+<div style="float:left; margin-left:10px; border:10px solid hotpink; border-top:none; width:80px; height:60px; background:yellow;"></div>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-003-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-003-ref.htmlnew file mode 100644index 00000000000..d8a576ea6fa--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-003-ref.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<style>+ .container {+ float: left;+ width: 200px;+ height: 100px;+ margin-right: 10px;+ }+ .box {+ border-radius: 15px;+ border: 20px solid hotpink;+ background: yellow;+ }+ .skip-start {+ border-top-left-radius: 0;+ border-top-right-radius: 0;+ border-top: none;+ }+ .skip-end {+ border-bottom-left-radius: 0;+ border-bottom-right-radius: 0;+ border-bottom: none;+ }+</style>+<p>There should be a yellow box that starts in the first column and ends in the+ third. The border should be rounded at the start (first column) and at the end+ (last column).</p>+<div class="container">+ <div class="box skip-end" style="height:80px;"></div>+</div>+<div class="container">+ <div class="box skip-start skip-end" style="height:100px;"></div>+</div>+<div class="container">+ <div class="box skip-start" style="height:70px;"></div>+</div>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-004-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-004-ref.htmlnew file mode 100644index 00000000000..8cbbf0ccc45--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-004-ref.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<style>+ .container {+ float: left;+ width: 200px;+ height: 100px;+ margin-right: 10px;+ }+ .box {+ border-radius: 40px;+ border: 20px solid hotpink;+ background: yellow;+ }+ .skip-start {+ border-top-left-radius: 0;+ border-top-right-radius: 0;+ border-top: none;+ }+ .skip-end {+ border-bottom-left-radius: 0;+ border-bottom-right-radius: 0;+ border-bottom: none;+ }+</style>+<p>There should be a yellow box that starts in the first column and ends in the+ third. The border should be rounded at the start (first column) and at the end+ (last column).</p>+<div class="container">+ <div class="box skip-end" style="height:80px;"></div>+</div>+<div class="container">+ <div class="box skip-start skip-end" style="height:100px;"></div>+</div>+<div class="container">+ <div class="box skip-start" style="height:70px;"></div>+</div>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-005-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-005-ref.htmlnew file mode 100644index 00000000000..20a0431510a--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/borders-005-ref.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<style>+ .container {+ float: left;+ width: 200px;+ height: 100px;+ margin-right: 10px;+ }+ .box {+ border-radius: 80px;+ border: 20px solid hotpink;+ background: yellow;+ }+ .skip-start {+ border-top-left-radius: 0;+ border-top-right-radius: 0;+ border-top: none;+ }+ .skip-end {+ border-bottom-left-radius: 0;+ border-bottom-right-radius: 0;+ border-bottom: none;+ }+</style>+<p>There should be a yellow box that starts in the first column and ends in the+ third. The border should be rounded at the start (first column) and at the end+ (last column).</p>+<div class="container">+ <div class="box skip-end" style="height:80px;"></div>+</div>+<div class="container">+ <div class="box skip-start skip-end" style="height:100px;"></div>+</div>+<div class="container">+ <div class="box skip-start" style="height:70px;"></div>+</div>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/box-shadow-005-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/box-shadow-005-ref.htmlnew file mode 100644index 00000000000..f675826ac35--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-break/box-shadow-005-ref.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<style>+ #mc > div {+ position: absolute;+ inset-block-start:-10px;+ inline-size: 50px;+ border: 10px solid;+ }+</style>+<p>Box shadows should be painted around all of the three fragments.</p>+<div id="mc" style="position:relative; margin:50px; inline-size:400px; block-size:100px; background:yellow;">+ <div style="inset-inline-start:-10px; block-size:100px;"></div>+ <div style="inset-inline-start: 140px; block-size:100px;"></div>+ <div style="inset-inline-start: 290px; block-size:50px;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/avoid-border-break.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/avoid-border-break.htmlnew file mode 100644index 00000000000..bb86a64b861--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/avoid-border-break.html@@ -0,0 +1,9 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/css-break/#possible-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<p>Test passes if there is a filled green square.</p>+<div style="margin-left:-100px; columns:2; column-fill:auto; column-gap:0; width:200px; height:200px;">+ <div style="height:175px;"></div>+ <div style="border:30px solid green; box-sizing:border-box; height:100px; background:green;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-000.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-000.htmlnew file mode 100644index 00000000000..792f89f8875--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-000.html@@ -0,0 +1,9 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-decoration">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/borders-000-ref.html">+<p>There should be a yellow box with a hotpink border in the second column.</p>+<div style="columns:4; column-gap:10px; column-fill:auto; width:430px; height:100px;">+ <div style="height:95px;"></div>+ <div style="border:10px solid hotpink; height:80px; background:yellow;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-001.htmlnew file mode 100644index 00000000000..5a3e64c83f7--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-001.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-decoration">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/borders-001-ref.html">+<p>There should be a yellow box that starts in the second column and ends in the+ third. The top border should be in the second column, and the bottom border+ should be in the third.</p>+<div style="columns:4; column-gap:10px; column-fill:auto; width:430px; height:100px;">+ <div style="height:95px;"></div>+ <div style="border:10px solid hotpink; height:100px; background:yellow;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-002.htmlnew file mode 100644index 00000000000..5d965a13fc9--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-002.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-decoration">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/borders-002-ref.html">+<p>There should be a yellow box that starts in the second column and ends in the+ fourth. The top border should be in the second column, and the bottom border+ should be in the fourth.</p>+<div style="columns:4; column-gap:10px; column-fill:auto; width:430px; height:100px;">+ <div style="height:95px;"></div>+ <div style="border:10px solid hotpink; height:250px; background:yellow;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-003.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-003.htmlnew file mode 100644index 00000000000..106436fc58c--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-003.html@@ -0,0 +1,10 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-decoration">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/borders-003-ref.html">+<p>There should be a yellow box that starts in the first column and ends in the+ third. The border should be rounded at the start (first column) and at the end+ (last column).</p>+<div style="columns:3; column-gap:10px; column-fill:auto; width:620px; height:100px;">+ <div style="border-radius:15px; border:20px solid hotpink; height:250px; background:yellow;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-004.htmlnew file mode 100644index 00000000000..1154db8ecf2--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-004.html@@ -0,0 +1,10 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-decoration">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/borders-004-ref.html">+<p>There should be a yellow box that starts in the first column and ends in the+ third. The border should be rounded at the start (first column) and at the end+ (last column).</p>+<div style="columns:3; column-gap:10px; column-fill:auto; width:620px; height:100px;">+ <div style="border-radius:40px; border:20px solid hotpink; height:250px; background:yellow;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-005.htmlnew file mode 100644index 00000000000..f970fc2b946--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/borders-005.html@@ -0,0 +1,10 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-decoration">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/borders-005-ref.html">+<p>There should be a yellow box that starts in the first column and ends in the+ third. The border should be rounded at the start (first column) and at the end+ (last column).</p>+<div style="columns:3; column-gap:10px; column-fill:auto; width:620px; height:100px;">+ <div style="border-radius:80px; border:20px solid hotpink; height:250px; background:yellow;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/box-shadow-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/box-shadow-005.htmlnew file mode 100644index 00000000000..24db9553f42--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/box-shadow-005.html@@ -0,0 +1,8 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-decoration">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/box-shadow-005-ref.html">+<p>Box shadows should be painted around all of the three fragments.</p>+<div style="columns:3; column-gap:50px; column-fill:auto; margin:50px; inline-size:400px; block-size:100px; background:yellow;">+ <div style="box-decoration-break:clone; box-shadow:0px 0px 0px 10px; inline-size:50px; block-size:250px;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-000.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-000.htmlnew file mode 100644index 00000000000..2407c34a755--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-000.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="Three blocks could fit in the first fragmentainer, but there's a break-before:avoid between the third and fourth block, so we should break between the second and third">+<style>+ .square {+ height: 50px;+ break-inside: avoid;+ background:green;+ }+</style>+<p>Test passes if there is a filled green square.</p>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:160px;">+ <div class="square"></div>+ <div class="square"></div>+ <div class="square"></div>+ <div class="square" style="break-before:avoid;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-001.htmlnew file mode 100644index 00000000000..c3f459e296c--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-001.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="Three blocks could fit in the first fragmentainer, but there's a break-after:avoid between the third and fourth block, so we should break between the second and third">+<style>+ .square {+ height: 50px;+ break-inside: avoid;+ background:green;+ }+</style>+<p>Test passes if there is a filled green square.</p>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:160px;">+ <div class="square"></div>+ <div class="square"></div>+ <div class="square" style="break-after:avoid;"></div>+ <div class="square"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-002.htmlnew file mode 100644index 00000000000..570154c13c9--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-002.html@@ -0,0 +1,33 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="Need to violate break-before:avoid and break-after:avoid if there are no better breakpoints">+<style>+ .container {+ break-before: avoid;+ break-after: avoid;+ }+ .square {+ display: inline-block;+ vertical-align: top;+ width: 100%;+ height: 50px;+ background:green;+ }+</style>+<p>Test passes if there is a filled green square.</p>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:120px;">+ <div class="container">+ <div class="square"></div>+ </div>+ <div class="container">+ <div class="square"></div>+ </div>+ <div class="container">+ <div class="square"></div>+ </div>+ <div class="container">+ <div class="square"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-004.htmlnew file mode 100644index 00000000000..9b43ee5577b--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-004.html@@ -0,0 +1,31 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="Violate orphans/widows requirements rather than break-before:avoid and break-after:avoid">+<style>+ .container {+ break-before: avoid;+ break-after: avoid;+ }+ .square {+ display: inline-block;+ vertical-align: top;+ width: 100%;+ height: 50px;+ background:green;+ }+</style>+<p>Test passes if there is a filled green square.</p>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:120px; orphans:2; widows:2;">+ <div class="container">+ <div class="square"></div>+ </div>+ <div class="container">+ <div class="square"></div>+ <div class="square"></div>+ </div>+ <div class="container">+ <div class="square"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-005.htmlnew file mode 100644index 00000000000..55cb381d8c3--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-005.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="A forced break trumps break avoidance preferences">+<style>+ .square {+ height: 50px;+ break-inside: avoid;+ background:green;+ }+</style>+<p>Test passes if there is a filled green square.</p>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:110px;">+ <div class="square"></div>+ <div class="square" style="break-after:column;"></div>+ <div class="square" style="break-before:avoid;"></div>+ <div class="square"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-006.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-006.htmlnew file mode 100644index 00000000000..3300752af2e--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-006.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="A forced break trumps break avoidance preferences">+<style>+ .square {+ height: 50px;+ break-inside: avoid;+ background:green;+ }+</style>+<p>Test passes if there is a filled green square.</p>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:110px;">+ <div class="square"></div>+ <div>+ <div>+ <div class="square" style="break-after:column;"></div>+ </div>+ </div>+ <div>+ <div>+ <div class="square" style="break-before:avoid;"></div>+ </div>+ </div>+ <div class="square"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-008.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-008.htmlnew file mode 100644index 00000000000..053df08dda1--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-008.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<meta name="assert" content="Prefer violating a later break-before:avoid instead of violating an earlier break-inside:avoid">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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="columns:2; column-gap:0; column-fill:auto; width:100px; height:100px; background:red;">+ <div style="break-inside:avoid;">+ <div style="contain:size; height:50px; background:green;"></div>+ <div style="contain:size; height:50px; background:green;"></div>+ </div>+ <div style="break-before:avoid; contain:size; height:100px; background:green;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-009.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-009.htmlnew file mode 100644index 00000000000..e0373ec1465--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-009.html@@ -0,0 +1,16 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-propagation">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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; column-fill:auto; column-gap:0; height:250px;">+ <div style="height:100px; background:green;"></div>+ <div style="height:100px; background:green;"></div>+ <div style="break-inside:avoid;">+ <div>+ <div style="break-before:avoid; height:100px;"></div>+ </div>+ </div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-010.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-010.htmlnew file mode 100644index 00000000000..6d0c487ec09--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-010.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-propagation">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square.xht">+<style>+ .multicol {+ column-count: 4;+ column-gap: 0px;+ column-fill: auto;+ height: 100px;+ width: 100px;+ position: relative;+ background: red;+ }+ .abs {+ position: absolute;+ height: 50px;+ width: 25px;+ }+</style>+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>+<div class="multicol">+ <div style="width: 25px; height: 50px; background: green;"></div>+ <div style="width: 25px; height: 50px; background: green;"></div>+ <div>+ <div style="height: 50px; break-before: avoid; background: green;"></div>+ <div style="height: 200px; background: green;"></div>+ </div>+ <div class="abs" style="background: green; top: 50px; left: 0px;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-011.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-011.htmlnew file mode 100644index 00000000000..b1c4c7479ac--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-011.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-propagation">+<link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1337586">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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; gap:0; column-fill:auto; height:150px;">+ <div style="height:50px; background:green;"></div>+ <div style="height:50px; background:green;"></div>+ <div style="height:10px;">+ <div style="height:20px; contain:size; background:green;"></div>+ <div style="height:20px; contain:size; background:green;"></div>+ </div>+ <div style="break-before:avoid; break-inside:avoid; height:90px;">+ <div style="height:30px;"></div>+ <div style="height:60px; background:green;"></div>+ </div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-012.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-012.htmlnew file mode 100644index 00000000000..c43e4de093d--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-avoid-012.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-propagation">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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; gap:0; column-fill:auto; height:150px;">+ <div style="height:100px; background:green;"></div>+ <div style="height:30px; background:green;"></div>+ <div style="float:left; width:50%;">+ <div style="height:10px; contain:size; background:green;"></div>+ <div style="height:10px; contain:size; background:green;"></div>+ </div>+ <div style="break-before:avoid; break-inside:avoid;">+ <div style="margin-left:auto; width:50%; height:20px; background:green;"></div>+ <div style="height:50px; background:green;"></div>+ </div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-000.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-000.htmlnew file mode 100644index 00000000000..b8b787d2540--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-000.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-propagation">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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; column-fill:auto; column-gap:0; height:250px;">+ <div style="height:100px; background:green;"></div>+ <div style="break-inside:avoid;">+ <div>+ <div style="break-before:column; height:100px; background:green;"></div>+ </div>+ </div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-001.htmlnew file mode 100644index 00000000000..5f0fddfece5--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-001.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-propagation">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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; column-fill:auto; column-gap:0; height:250px;">+ <div style="height:100px; background:green;"></div>+ <div>+ <div style="break-before:column;"></div>+ </div>+ <div style="height:100px; background:green;"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-002.htmlnew file mode 100644index 00000000000..c6903de61db--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/break-between-force-002.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-propagation">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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; column-fill:auto; column-gap:0; height:250px;">+ <div style="height:100px; background:green;"></div>+ <div>+ <div style="break-after:column;"></div>+ </div>+ <div style="height:100px; background:green;"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/forced-break-at-fragmentainer-start-000.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/forced-break-at-fragmentainer-start-000.htmlnew file mode 100644index 00000000000..440c3a42347--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/forced-break-at-fragmentainer-start-000.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#forced-breaks">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<meta name="assert" content="A forced break at the block-start of the fragmentainer is allowed, as long as it's otherwise at a valid class A break point">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<p>Test passes if there is a filled green square.</p>+<div style="columns:1; column-fill:auto; width:100px; height:100px; background:green;">+ <div style="break-after:column;"></div>+ <div style="height:99px; background:white;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/forced-break-at-fragmentainer-start-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/forced-break-at-fragmentainer-start-001.htmlnew file mode 100644index 00000000000..9b6e826fe3d--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/forced-break-at-fragmentainer-start-001.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#forced-breaks">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<meta name="assert" content="A forced break at the block-start of the fragmentainer is not allowed unless it's at a valid class A break point">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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="columns:2; column-fill:auto; column-gap:0; width:100px; height:100px; background:red;">+ <div>+ <div style="break-before:column; height:200px; background:green;"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/overflowed-block-with-no-room-after-000.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/overflowed-block-with-no-room-after-000.htmlnew file mode 100644index 00000000000..0d531699498--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/overflowed-block-with-no-room-after-000.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#parallel-flows">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<p>Test passes if there is a filled green square.</p>+<div style="margin-bottom:-30px; width:50px; height:30px; background:green;"></div>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:70px; margin-top:30px;">+ <div style="height:80px;">+ <div style="height:140px; background:green;"></div>+ </div>+ <div style="margin-top:-40px; height:30px; background:green;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/overflowed-block-with-no-room-after-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/overflowed-block-with-no-room-after-001.htmlnew file mode 100644index 00000000000..ddc034fc6c0--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/overflowed-block-with-no-room-after-001.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#parallel-flows">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square-only.html">+<p>Test passes if there is a filled green square.</p>+<div style="margin-bottom:-30px; width:50px; height:30px; background:green;"></div>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:70px; margin-top:30px;">+ <div>+ <div style="height:80px;">+ <div style="height:140px; background:green;"></div>+ </div>+ </div>+ <div style="margin-top:-40px; height:30px; background:green;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-break-inside-avoid-at-start.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-break-inside-avoid-at-start.htmlnew file mode 100644index 00000000000..41f62000bed--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-break-inside-avoid-at-start.html@@ -0,0 +1,10 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../reference/ref-filled-green-100px-square.xht">+<meta name="assert" content="Cannot break before a child if we're at the block-start of a fragmentainer">+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>+<div style="columns:2; column-fill:auto; column-gap:0; width:100px; height:100px; background:red;">+ <div></div>+ <div style="break-inside:avoid; height:200px; background:green;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-line-in-short-fragmentainer-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-line-in-short-fragmentainer-001.htmlnew file mode 100644index 00000000000..8f4b52998f2--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-line-in-short-fragmentainer-001.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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="columns:2; column-fill:auto; column-gap:0; width:100px; height:50px; background:red;">+ <div>+ <div style="display:inline-block; vertical-align:top; width:50px; height:100px; background:green;"></div>+ </div>+ <!-- We're at the very beginning of the second column here, so inserting a+ forced break will have no effect. -->+ <div style="break-before:column;">+ <div style="display:inline-block; vertical-align:top; width:50px; height:100px; background:green;"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-line-in-short-fragmentainer-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-line-in-short-fragmentainer-002.htmlnew file mode 100644index 00000000000..0324cb634a9--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-break/tall-line-in-short-fragmentainer-002.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#unforced-breaks">+<link rel="match" href="../../../../expected/wpt-import/css/css-break/../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="columns:2; column-fill:auto; column-gap:0; width:100px; height:50px; background:red;">+ <div style="width:50px; height:100px; line-height:200px; background:green;">+ <br>+ </div>+ <div style="break-before:column; width:50px; line-height:100px; background:green;">+ <br>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-000.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-000.htmlnew file mode 100644index 00000000000..398617e28df--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-000.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-multicol-1/#filling-columns">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-between">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-within">+<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:4; background:green;">+ <div style="break-inside:avoid; height:100px;"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-001.htmlnew file mode 100644index 00000000000..b2553e99c77--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-001.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<link rel="author" title="Morten Stenshorne" href="mailto:[email protected]">+<link rel="help" href="https://www.w3.org/TR/css-multicol-1/#filling-columns">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-between">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-within">+<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:4; background:green;">+ <div style="break-inside:avoid; break-after:avoid; height:50px;"></div>+ <div style="break-inside:avoid; height:50px;"></div>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-002.htmlnew file mode 100644index 00000000000..8d460aab6e3--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/balance-break-avoidance-002.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<link rel="help" href="https://www.w3.org/TR/css-multicol-1/#filling-columns">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-between">+<link rel="help" href="https://www.w3.org/TR/css-break-3/#break-within">+<link rel="match" href="../../../../expected/wpt-import/css/css-multicol/../reference/ref-filled-green-100px-square-only.html">+<p>Test passes if there is a filled green square.</p>+<div style="width:100px; columns:2; column-gap:0; background:green;">+ <div style="height:25px;"></div>+ <div style="height:50px;"></div>+ <div style="height:25px; break-before:avoid;"></div>+ <div style="height:50px;"></div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/multicol-br-inside-avoidcolumn-001.xht b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/multicol-br-inside-avoidcolumn-001.xhtnew file mode 100644index 00000000000..1b67e5a680a--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-multicol/multicol-br-inside-avoidcolumn-001.xht@@ -0,0 +1,36 @@+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">+<html xmlns="http://www.w3.org/1999/xhtml">+<head>+<title>multicol | break-inside: avoid-column</title>+<link rel="author" title="Opera Software ASA" href="http://www.opera.com/"/>+<link rel="help" href="http://www.w3.org/TR/css3-multicol/#column-breaks"/>+<link rel="match" href="../../../../expected/wpt-import/css/css-multicol/../reference/ref-filled-green-200px-square.html"/>+<style type="text/css"><![CDATA[+.multicol {+ column-count: 2;+ column-gap: 0;+ column-fill: auto;+ overflow: hidden;+ width: 200px;+ height: 300px;+}+.multicol > div {+ height: 200px;+ break-inside: avoid-column;+ background: green;+}+.multicol > div.red {+ background:red;+}+]]></style>+</head>+<body>+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>+<div class="multicol">+ <div></div>+ <div></div>+ <div class="red"></div>+</div>+</body>+</html>diff --git a/Tests/LibWeb/Text/expected/multicol-break-block-sizes.txt b/Tests/LibWeb/Text/expected/multicol-break-block-sizes.txtnew file mode 100644index 00000000000..e65db501059--- /dev/null+++ b/Tests/LibWeb/Text/expected/multicol-break-block-sizes.txt@@ -0,0 +1,16 @@+min-height box: 0,0 200x160 200,0 200x140+min-height after: 200,140 200x20+contained box: 0,0 200x300+contained after: 200,0 200x20+border-box-padding box: 0,0 100x100 110,0 100x100 220,0 100x50+border-box-padding after: 220,50 100x10+border-box-border box: 0,0 200x100 200,0 200x100+border-box-both box: 0,0 200x100 200,0 200x100+border-box-min box: 0,0 200x100 200,0 200x100+nested-margin box: 200,0 200x20+nested-margin inner: 200,0 200x20+nested-margin after: 200,20 200x60+percentage box: 220,0 200x100+relative box: 220,50 200x10+metrics: offset 400x100, client 190x95, computed height 120px, padding-bottom 10px, margin-bottom 7px+document scroll width: 800diff --git a/Tests/LibWeb/Text/expected/multicol-broken-box-script-geometry.txt b/Tests/LibWeb/Text/expected/multicol-broken-box-script-geometry.txtnew file mode 100644index 00000000000..55ea1076e42--- /dev/null+++ b/Tests/LibWeb/Text/expected/multicol-broken-box-script-geometry.txt@@ -0,0 +1,3 @@+ltr: offset 0,70 420x100, computed 200px 60px+rtl: offset 220,70 420x100, computed 200px 60px+border-box: offset 0,0 420x100, computed 200px 150pxdiff --git a/Tests/LibWeb/Text/expected/multicol-margin-truncation-after-empty-child.txt b/Tests/LibWeb/Text/expected/multicol-margin-truncation-after-empty-child.txtnew file mode 100644index 00000000000..bd5b1cd26c2--- /dev/null+++ b/Tests/LibWeb/Text/expected/multicol-margin-truncation-after-empty-child.txt@@ -0,0 +1,3 @@+after-empty-child: 200,0+after-nested-empty-child: 200,0+heading: 200,0diff --git a/Tests/LibWeb/Text/input/multicol-break-block-sizes.html b/Tests/LibWeb/Text/input/multicol-break-block-sizes.htmlnew file mode 100644index 00000000000..ca55274d428--- /dev/null+++ b/Tests/LibWeb/Text/input/multicol-break-block-sizes.html@@ -0,0 +1,49 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ body { margin: 0; }+ .case { columns: 2; column-gap: 0; width: 400px; margin-bottom: 20px; }+ .fixed { column-fill: auto; height: 100px; }+</style>+<div class="case" id="min-height"><div id="min-height-box" style="min-height: 300px"><div style="height: 20px"></div></div><div id="min-height-after" style="height: 20px"></div></div>+<div class="case" id="contained"><div id="contained-box" style="contain: size; contain-intrinsic-height: 300px"><div style="height: 20px"></div></div><div id="contained-after" style="height: 20px"></div></div>+<div class="case fixed" id="border-box-padding" style="columns: 3; column-gap: 10px; width: 320px"><div id="border-box-padding-box" style="box-sizing: border-box; height: 250px; padding-top: 50px"></div><div id="border-box-padding-after" style="height: 10px"></div></div>+<div class="case fixed" id="border-box-border"><div id="border-box-border-box" style="border: 10px solid; box-sizing: border-box; height: 200px"></div></div>+<div class="case fixed" id="border-box-both"><div id="border-box-both-box" style="border: 10px solid; padding: 5px; box-sizing: border-box; height: 200px"></div></div>+<div class="case fixed" id="border-box-min"><div id="border-box-min-box" style="border: 10px solid; padding: 5px; box-sizing: border-box; min-height: 200px"></div></div>+<div class="case fixed" id="nested-margin"><div style="height: 90px"></div><div id="nested-margin-box"><div id="nested-margin-inner" style="margin-top: 30px; height: 20px"></div></div><div id="nested-margin-after" style="height: 60px"></div></div>+<div class="case fixed" id="percentage" style="column-gap: 20px; width: 420px"><div style="height: 200px"><div style="height: 100px"></div><div id="percentage-box" style="height: 50%"></div></div></div>+<div class="case fixed" id="relative" style="column-gap: 20px; width: 420px"><div style="height: 200px"><div style="height: 100px"></div><div id="relative-box" style="position: relative; top: 25%; height: 10px"></div></div></div>+<div class="case fixed" id="metrics"><div id="metrics-box" style="border: 5px solid; padding: 10px; height: 120px; margin-bottom: 7px"></div></div>+<script>+ function rectsIn(element, container) {+ const origin = container.getBoundingClientRect();+ return [...element.getClientRects()]+ .map(rect => `${rect.x - origin.x},${rect.y - origin.y} ${rect.width}x${rect.height}`)+ .join(" ");+ }++ test(() => {+ const report = (id, part) => {+ const element = document.getElementById(`${id}-${part}`);+ println(`${id} ${part}: ${rectsIn(element, document.getElementById(id))}`);+ };+ report("min-height", "box");+ report("min-height", "after");+ report("contained", "box");+ report("contained", "after");+ report("border-box-padding", "box");+ report("border-box-padding", "after");+ for (const id of ["border-box-border", "border-box-both", "border-box-min"])+ report(id, "box");+ report("nested-margin", "box");+ report("nested-margin", "inner");+ report("nested-margin", "after");+ report("percentage", "box");+ report("relative", "box");+ const box = document.getElementById("metrics-box");+ const style = getComputedStyle(box);+ println(`metrics: offset ${box.offsetWidth}x${box.offsetHeight}, client ${box.clientWidth}x${box.clientHeight}, computed height ${style.height}, padding-bottom ${style.paddingBottom}, margin-bottom ${style.marginBottom}`);+ println(`document scroll width: ${document.documentElement.scrollWidth}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/multicol-broken-box-script-geometry.html b/Tests/LibWeb/Text/input/multicol-broken-box-script-geometry.htmlnew file mode 100644index 00000000000..90ce5a28f93--- /dev/null+++ b/Tests/LibWeb/Text/input/multicol-broken-box-script-geometry.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ body { margin: 0; }+ .mc { columns: 2; column-gap: 20px; column-fill: auto; height: 100px; width: 420px; }+</style>+<div class="mc"><div style="height: 70px"></div><div id="ltr" style="height: 60px"></div></div>+<div class="mc" style="direction: rtl"><div style="height: 70px"></div><div id="rtl" style="height: 60px"></div></div>+<div class="mc"><div id="border-box" style="box-sizing: border-box; height: 150px; padding: 5px; border: 2px solid"></div></div>+<script>+ test(() => {+ for (const id of ["ltr", "rtl", "border-box"]) {+ const element = document.getElementById(id);+ const container = element.parentElement;+ const style = getComputedStyle(element);+ println(`${id}: offset ${element.offsetLeft - container.offsetLeft},${element.offsetTop - container.offsetTop} ${element.offsetWidth}x${element.offsetHeight}, computed ${style.width} ${style.height}`);+ }+ });+</script>diff --git a/Tests/LibWeb/Text/input/multicol-margin-truncation-after-empty-child.html b/Tests/LibWeb/Text/input/multicol-margin-truncation-after-empty-child.htmlnew file mode 100644index 00000000000..abebac94df1--- /dev/null+++ b/Tests/LibWeb/Text/input/multicol-margin-truncation-after-empty-child.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ body { margin: 0; }+ .multicol { columns: 2; column-gap: 0; column-fill: auto; height: 100px; width: 400px; margin-bottom: 10px; }+ .box { margin-top: 30px; height: 20px; }+</style>+<div class="multicol"><div style="height: 90px"></div><div><div></div><div class="box" id="after-empty-child"></div></div></div>+<div class="multicol"><div style="height: 90px"></div><div><div><div></div><div class="box" id="after-nested-empty-child"></div></div></div></div>+<div class="multicol"><div style="height: 90px"></div><section><a id="anchor"></a><h2 style="margin: 30px 0 0 0; height: 20px" id="heading">Heading</h2></section></div>+<script>+ test(() => {+ for (const id of ["after-empty-child", "after-nested-empty-child", "heading"]) {+ const element = document.getElementById(id);+ const origin = element.closest(".multicol").getBoundingClientRect();+ const rect = element.getBoundingClientRect();+ println(`${id}: ${rect.x - origin.x},${rect.y - origin.y}`);+ }+ });+</script>