@@ -27,6 +27,8 @@ pub struct BlockFormattingContext {
2727impl BlockFormattingContext {
2828 /// Create a new `BlockFormattingContext` with the specified width constraint
2929 pub fn new ( available_space : AvailableSpace ) -> Self {
30+ #[ cfg( not( feature = "float_layout" ) ) ]
31+ let _ = available_space;
3032 Self {
3133 #[ cfg( feature = "float_layout" ) ]
3234 float_context : FloatContext :: new ( available_space) ,
@@ -64,7 +66,6 @@ pub struct BlockContext<'bfc> {
6466 is_root : bool ,
6567}
6668
67- #[ cfg( feature = "float_layout" ) ]
6869impl BlockContext < ' _ > {
6970 /// Create a sub-`BlockContext` for a child block node
7071 pub fn sub_context ( & mut self , additional_y_offset : f32 , insets : [ f32 ; 2 ] ) -> BlockContext < ' _ > {
@@ -78,7 +79,10 @@ impl BlockContext<'_> {
7879 is_root : false ,
7980 }
8081 }
82+ }
8183
84+ #[ cfg( feature = "float_layout" ) ]
85+ impl BlockContext < ' _ > {
8286 /// Set the width of the overall Block Formatting Context. This is used to resolve positions
8387 /// that are relative to the right of the context such as right-floated boxes.
8488 ///
@@ -101,11 +105,13 @@ impl BlockContext<'_> {
101105 }
102106
103107 /// Whether the float context contains any floats
108+ #[ inline( always) ]
104109 pub fn has_floats ( & self ) -> bool {
105110 self . bfc . float_context . has_floats ( )
106111 }
107112
108113 /// Whether the float context contains any floats that extend to or below min_y
114+ #[ inline( always) ]
109115 pub fn has_active_floats ( & self , min_y : f32 ) -> bool {
110116 self . bfc . float_context . has_active_floats ( min_y + self . y_offset )
111117 }
@@ -157,6 +163,7 @@ impl BlockContext<'_> {
157163
158164#[ cfg( not( feature = "float_layout" ) ) ]
159165impl BlockContext < ' _ > {
166+ #[ inline( always) ]
160167 fn floated_content_contribution ( & self ) -> f32 {
161168 0.0
162169 }
@@ -340,6 +347,7 @@ fn compute_inner(
340347 let container_content_box_size = known_dimensions. maybe_sub ( content_box_inset. sum_axes ( ) ) ;
341348
342349 // Apply content box inset
350+ #[ cfg( feature = "float_layout" ) ]
343351 block_ctx. apply_content_box_inset ( [ content_box_inset. left , content_box_inset. right ] ) ;
344352
345353 let box_sizing_adjustment =
@@ -424,8 +432,8 @@ fn compute_inner(
424432 ) ;
425433
426434 // Root BFCs contain floats
427- let contains_floats = block_ctx . is_bfc_root ( ) || is_scroll_container ;
428- if contains_floats {
435+ # [ cfg ( feature = "float_layout" ) ]
436+ if block_ctx . is_bfc_root ( ) || is_scroll_container {
429437 intrinsic_outer_height = intrinsic_outer_height. max ( block_ctx. floated_content_height_contribution ( ) ) ;
430438 }
431439
@@ -516,14 +524,21 @@ fn generate_item_list(
516524
517525 let position = child_style. position ( ) ;
518526 let overflow = child_style. overflow ( ) ;
527+
528+ #[ cfg( feature = "float_layout" ) ]
519529 let float = child_style. float ( ) ;
530+ #[ cfg( feature = "float_layout" ) ]
531+ let is_not_floated = float == Float :: None ;
532+
533+ #[ cfg( not( feature = "float_layout" ) ) ]
534+ let is_not_floated = true ;
520535
521536 let is_block = child_style. is_block ( ) ;
522537 let is_table = child_style. is_table ( ) ;
523538 let is_scroll_container = overflow. x . is_scroll_container ( ) || overflow. y . is_scroll_container ( ) ;
524539
525540 let is_in_same_bfc: bool =
526- is_block && !is_table && position != Position :: Absolute && float == Float :: None && !is_scroll_container;
541+ is_block && !is_table && position != Position :: Absolute && is_not_floated && !is_scroll_container;
527542
528543 BlockItem {
529544 node_id : child_node_id,
@@ -578,6 +593,7 @@ fn determine_content_based_container_width(
578593 let available_space = Size { width : available_width, height : AvailableSpace :: MinContent } ;
579594
580595 let mut max_child_width = 0.0 ;
596+ #[ cfg( feature = "float_layout" ) ]
581597 let mut float_contribution: f32 = 0.0 ;
582598 for item in items. iter ( ) . filter ( |item| item. position != Position :: Absolute ) {
583599 let known_dimensions = item. size . maybe_clamp ( item. min_size , item. max_size ) ;
@@ -614,7 +630,12 @@ fn determine_content_based_container_width(
614630 max_child_width = f32_max ( max_child_width, width) ;
615631 }
616632
617- max_child_width. max ( float_contribution)
633+ #[ cfg( feature = "float_layout" ) ]
634+ {
635+ max_child_width = max_child_width. max ( float_contribution) ;
636+ }
637+
638+ max_child_width
618639}
619640
620641/// Compute each child's final size and position
@@ -636,6 +657,7 @@ fn perform_final_layout_on_in_flow_children(
636657 Size { width : AvailableSpace :: Definite ( container_inner_width) , height : AvailableSpace :: MinContent } ;
637658
638659 // TODO: handle nested blocks with different widths
660+ #[ cfg( feature = "float_layout" ) ]
639661 if block_ctx. is_bfc_root ( ) {
640662 block_ctx. set_width ( AvailableSpace :: Definite ( container_outer_width) ) ;
641663 block_ctx. apply_content_box_inset ( [ resolved_content_box_inset. left , resolved_content_box_inset. right ] ) ;
@@ -645,10 +667,17 @@ fn perform_final_layout_on_in_flow_children(
645667 let mut inflow_content_size = Size :: ZERO ;
646668 let mut committed_y_offset = resolved_content_box_inset. top ;
647669 let mut y_offset_for_absolute = resolved_content_box_inset. top ;
648- let mut y_offset_for_float = resolved_content_box_inset. top ;
649670 let mut first_child_top_margin_set = CollapsibleMarginSet :: ZERO ;
650671 let mut active_collapsible_margin_set = CollapsibleMarginSet :: ZERO ;
651672 let mut is_collapsing_with_first_margin_set = true ;
673+
674+ #[ cfg( feature = "float_layout" ) ]
675+ let mut has_active_floats = block_ctx. has_active_floats ( committed_y_offset) ;
676+ #[ cfg( not( feature = "float_layout" ) ) ]
677+ let has_active_floats = false ;
678+ #[ cfg( feature = "float_layout" ) ]
679+ let mut y_offset_for_float = resolved_content_box_inset. top ;
680+
652681 for item in items. iter_mut ( ) {
653682 if item. position == Position :: Absolute {
654683 item. static_position = Point { x : resolved_content_box_inset. left , y : y_offset_for_absolute }
@@ -667,6 +696,8 @@ fn perform_final_layout_on_in_flow_children(
667696 // Handle floated boxes
668697 #[ cfg( feature = "float_layout" ) ]
669698 if let Some ( float_direction) = item. float . float_direction ( ) {
699+ has_active_floats = true ;
700+
670701 let item_layout = tree. perform_child_layout (
671702 item. node_id ,
672703 Size :: NONE ,
@@ -735,11 +766,24 @@ fn perform_final_layout_on_in_flow_children(
735766
736767 ( stretch_width, position)
737768 } else {
738- let min_y = committed_y_offset + active_collapsible_margin_set. resolve ( ) ;
739- let slot = block_ctx. find_content_slot ( min_y, item. clear , None ) ;
740- let stretch_width = slot. width - item_non_auto_x_margin_sum;
769+ ' block: {
770+ #[ cfg( feature = "float_layout" ) ]
771+ if has_active_floats {
772+ let min_y = committed_y_offset + active_collapsible_margin_set. resolve ( ) ;
773+ let slot = block_ctx. find_content_slot ( min_y, item. clear , None ) ;
774+ has_active_floats = slot. segment_id . is_some ( ) ;
775+ let stretch_width = slot. width - item_non_auto_x_margin_sum;
776+ break ' block ( stretch_width, Point { x : slot. x , y : slot. y } ) ;
777+ }
741778
742- ( stretch_width, Point { x : slot. x , y : slot. y } )
779+ if !has_active_floats {
780+ let min_y = committed_y_offset + active_collapsible_margin_set. resolve ( ) ;
781+ let stretch_width = container_inner_width - item_non_auto_x_margin_sum;
782+ break ' block ( stretch_width, Point { x : 0.0 , y : min_y } ) ;
783+ }
784+
785+ unreachable ! ( "One of the above cases will always be hit" ) ;
786+ }
743787 } ;
744788
745789 let known_dimensions = if item. is_table {
@@ -782,8 +826,11 @@ fn perform_final_layout_on_in_flow_children(
782826 let output = tree. compute_block_child_layout ( item. node_id , inputs, Some ( & mut child_block_ctx) ) ;
783827
784828 // Extract float contribution from child block context
785- let child_contribution = child_block_ctx. floated_content_height_contribution ( ) ;
786- block_ctx. add_child_floated_content_height_contribution ( y_offset_for_absolute + child_contribution) ;
829+ #[ cfg( feature = "float_layout" ) ]
830+ {
831+ let child_contribution = child_block_ctx. floated_content_height_contribution ( ) ;
832+ block_ctx. add_child_floated_content_height_contribution ( y_offset_for_absolute + child_contribution) ;
833+ }
787834
788835 output
789836 } else {
@@ -913,12 +960,18 @@ fn perform_final_layout_on_in_flow_children(
913960 . collapse_with_set ( top_margin_set)
914961 . collapse_with_set ( bottom_margin_set) ;
915962 y_offset_for_absolute = committed_y_offset + item_layout. size . height + y_margin_offset;
916- y_offset_for_float = committed_y_offset + item_layout. size . height + y_margin_offset;
963+ #[ cfg( feature = "float_layout" ) ]
964+ {
965+ y_offset_for_float = committed_y_offset + item_layout. size . height + y_margin_offset;
966+ }
917967 } else {
918968 committed_y_offset += item_layout. size . height + y_margin_offset;
919969 active_collapsible_margin_set = bottom_margin_set;
920970 y_offset_for_absolute = committed_y_offset + active_collapsible_margin_set. resolve ( ) ;
921- y_offset_for_float = committed_y_offset;
971+ #[ cfg( feature = "float_layout" ) ]
972+ {
973+ y_offset_for_float = committed_y_offset;
974+ }
922975 }
923976 }
924977 }
0 commit comments