@@ -14,7 +14,7 @@ use crate::{
1414} ;
1515
1616#[ cfg( feature = "float_layout" ) ]
17- use super :: { FloatContext , FloatDirection } ;
17+ use super :: { ContentSlot , FloatContext , FloatDirection } ;
1818#[ cfg( feature = "float_layout" ) ]
1919use crate :: { Clear , Float } ;
2020
@@ -93,6 +93,13 @@ impl BlockContext<'_> {
9393 pos
9494 }
9595
96+ pub fn find_content_slot ( & self , min_y : f32 , clear : Clear , after : Option < usize > ) -> ContentSlot {
97+ let mut slot = self . bfc . float_context . find_content_slot ( min_y + self . y_offset , self . insets , clear, after) ;
98+ slot. y -= self . y_offset ;
99+ slot. x -= self . insets [ 0 ] ;
100+ slot
101+ }
102+
96103 fn add_child_floated_content_height_contribution ( & mut self , child_contribution : f32 ) {
97104 self . float_content_contribution = self . float_content_contribution . max ( child_contribution) ;
98105 }
@@ -476,12 +483,15 @@ fn generate_item_list(
476483 if child_style. box_sizing ( ) == BoxSizing :: ContentBox { pb_sum } else { Size :: ZERO } ;
477484
478485 let position = child_style. position ( ) ;
486+ let overflow = child_style. overflow ( ) ;
479487 let float = child_style. float ( ) ;
480488
481489 let is_block = child_style. is_block ( ) ;
482490 let is_table = child_style. is_table ( ) ;
491+ let is_scroll_container = overflow. x . is_scroll_container ( ) || overflow. y . is_scroll_container ( ) ;
483492
484- let is_in_same_bfc: bool = is_block && !is_table && position != Position :: Absolute && float == Float :: None ;
493+ let is_in_same_bfc: bool =
494+ is_block && !is_table && position != Position :: Absolute && float == Float :: None && !is_scroll_container;
485495
486496 BlockItem {
487497 node_id : child_node_id,
@@ -507,7 +517,7 @@ fn generate_item_list(
507517 . maybe_resolve ( node_inner_size, |val, basis| tree. calc ( val, basis) )
508518 . maybe_apply_aspect_ratio ( aspect_ratio)
509519 . maybe_add ( box_sizing_adjustment) ,
510- overflow : child_style . overflow ( ) ,
520+ overflow,
511521 scrollbar_width : child_style. scrollbar_width ( ) ,
512522 position,
513523 inset : child_style. inset ( ) ,
@@ -669,18 +679,27 @@ fn perform_final_layout_on_in_flow_children(
669679
670680 // Handle non-floated boxes
671681
682+ let ( stretch_width, float_avoiding_position) = if item. is_in_same_bfc {
683+ let stretch_width = container_inner_width - item_non_auto_x_margin_sum;
684+ let position = Point { x : 0.0 , y : 0.0 } ;
685+
686+ ( stretch_width, position)
687+ } else {
688+ let min_y = committed_y_offset + active_collapsible_margin_set. resolve ( ) ;
689+ let slot = block_ctx. find_content_slot ( min_y, item. clear , None ) ;
690+ let stretch_width = slot. width - item_non_auto_x_margin_sum;
691+
692+ ( stretch_width, Point { x : slot. x , y : slot. y } )
693+ } ;
694+
672695 let known_dimensions = if item. is_table {
673696 Size :: NONE
674697 } else {
675698 item. size
676699 . map_width ( |width| {
677700 // TODO: Allow stretch-sizing to be conditional, as there are exceptions.
678701 // e.g. Table children of blocks do not stretch fit
679- Some (
680- width
681- . unwrap_or ( container_inner_width - item_non_auto_x_margin_sum)
682- . maybe_clamp ( item. min_size . width , item. max_size . width ) ,
683- )
702+ Some ( width. unwrap_or ( stretch_width) . maybe_clamp ( item. min_size . width , item. max_size . width ) )
684703 } )
685704 . maybe_clamp ( item. min_size , item. max_size )
686705 } ;
@@ -727,7 +746,7 @@ fn perform_final_layout_on_in_flow_children(
727746 // Expand auto margins to fill available space
728747 // Note: Vertical auto-margins for relatively positioned block items simply resolve to 0.
729748 // See: https://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width
730- let free_x_space = f32_max ( 0.0 , container_inner_width - final_size. width - item_non_auto_x_margin_sum ) ;
749+ let free_x_space = f32_max ( 0.0 , stretch_width - final_size. width ) ;
731750 let x_axis_auto_margin_size = {
732751 let auto_margin_count = item_margin. left . is_none ( ) as u8 + item_margin. right . is_none ( ) as u8 ;
733752 if auto_margin_count > 0 {
@@ -760,27 +779,43 @@ fn perform_final_layout_on_in_flow_children(
760779
761780 item. computed_size = item_layout. size ;
762781 item. can_be_collapsed_through = item_layout. margins_can_collapse_through ;
763- item. static_position = Point {
764- x : resolved_content_box_inset. left ,
765- y : committed_y_offset + active_collapsible_margin_set. resolve ( ) ,
782+ item. static_position = if item. is_in_same_bfc {
783+ Point {
784+ x : resolved_content_box_inset. left ,
785+ y : committed_y_offset + active_collapsible_margin_set. resolve ( ) ,
786+ }
787+ } else {
788+ // TODO: handle inset and margins
789+ Point { x : float_avoiding_position. x + resolved_content_box_inset. left , y : float_avoiding_position. y }
766790 } ;
767- let mut location = Point {
768- x : resolved_content_box_inset. left + inset_offset. x + resolved_margin. left ,
769- y : committed_y_offset + inset_offset. y + y_margin_offset,
791+ let mut location = if item. is_in_same_bfc {
792+ Point {
793+ x : resolved_content_box_inset. left + inset_offset. x + resolved_margin. left ,
794+ y : committed_y_offset + inset_offset. y + y_margin_offset,
795+ }
796+ } else {
797+ // TODO: handle inset and margins
798+ Point {
799+ x : float_avoiding_position. x
800+ + resolved_content_box_inset. left
801+ + inset_offset. x
802+ + resolved_margin. left ,
803+ y : float_avoiding_position. y + inset_offset. y + y_margin_offset,
804+ }
770805 } ;
771806
772807 // Apply alignment
773808 let item_outer_width = item_layout. size . width + resolved_margin. horizontal_axis_sum ( ) ;
774- if item_outer_width < container_inner_width {
809+ if item_outer_width < stretch_width {
775810 match text_align {
776811 TextAlign :: Auto => {
777812 // Do nothing
778813 }
779814 TextAlign :: LegacyLeft => {
780815 // Do nothing. Left aligned by default.
781816 }
782- TextAlign :: LegacyRight => location. x += container_inner_width - item_outer_width,
783- TextAlign :: LegacyCenter => location. x += ( container_inner_width - item_outer_width) / 2.0 ,
817+ TextAlign :: LegacyRight => location. x += stretch_width - item_outer_width,
818+ TextAlign :: LegacyCenter => location. x += ( stretch_width - item_outer_width) / 2.0 ,
784819 }
785820 }
786821
0 commit comments