@@ -623,16 +623,12 @@ fn layout_atomic(
623
623
let pbm = style. padding_border_margin ( & ifc. containing_block ) ;
624
624
let margin = pbm. margin . auto_is ( Length :: zero) ;
625
625
let pbm_sums = & ( & pbm. padding + & pbm. border ) + & margin;
626
- ifc. inline_position += pbm_sums. inline_start ;
627
- let mut start_corner = Vec2 {
628
- block : pbm_sums. block_start ,
629
- inline : ifc. inline_position - ifc. current_nesting_level . inline_start ,
630
- } ;
631
- if style. clone_position ( ) . is_relative ( ) {
632
- start_corner += & relative_adjustement ( & style, ifc. containing_block )
633
- }
626
+ let position = style. clone_position ( ) ;
634
627
635
- let fragment = match atomic {
628
+ let mut child_positioning_context = None ;
629
+
630
+ // We need to know the inline size of the atomic before deciding whether to do the line break.
631
+ let mut fragment = match atomic {
636
632
IndependentFormattingContext :: Replaced ( replaced) => {
637
633
let size = replaced. contents . used_size_as_if_inline_element (
638
634
ifc. containing_block ,
@@ -643,7 +639,10 @@ fn layout_atomic(
643
639
let fragments = replaced
644
640
. contents
645
641
. make_fragments ( & replaced. style , size. clone ( ) ) ;
646
- let content_rect = Rect { start_corner, size } ;
642
+ let content_rect = Rect {
643
+ start_corner : Vec2 :: zero ( ) ,
644
+ size,
645
+ } ;
647
646
BoxFragment :: new (
648
647
replaced. base_fragment_info ,
649
648
replaced. style . clone ( ) ,
@@ -696,16 +695,14 @@ fn layout_atomic(
696
695
let collects_for_nearest_positioned_ancestor = ifc
697
696
. positioning_context
698
697
. collects_for_nearest_positioned_ancestor ( ) ;
699
- let mut child_positioning_context =
700
- PositioningContext :: new_for_subtree ( collects_for_nearest_positioned_ancestor) ;
698
+ child_positioning_context = Some ( PositioningContext :: new_for_subtree (
699
+ collects_for_nearest_positioned_ancestor,
700
+ ) ) ;
701
701
let independent_layout = non_replaced. layout (
702
702
layout_context,
703
- & mut child_positioning_context,
703
+ child_positioning_context. as_mut ( ) . unwrap ( ) ,
704
704
& containing_block_for_children,
705
705
) ;
706
- child_positioning_context
707
- . adjust_static_position_of_hoisted_fragments_with_offset ( & start_corner) ;
708
- ifc. positioning_context . append ( child_positioning_context) ;
709
706
710
707
// https://drafts.csswg.org/css2/visudet.html#block-root-margin
711
708
let tentative_block_size = box_size
@@ -719,7 +716,7 @@ fn layout_atomic(
719
716
. clamp_between_extremums ( min_box_size. block , max_box_size. block ) ;
720
717
721
718
let content_rect = Rect {
722
- start_corner,
719
+ start_corner : Vec2 :: zero ( ) ,
723
720
size : Vec2 {
724
721
block : block_size,
725
722
inline : inline_size,
@@ -740,6 +737,31 @@ fn layout_atomic(
740
737
} ,
741
738
} ;
742
739
740
+ if fragment. content_rect . size . inline + pbm_sums. inline_sum ( ) >
741
+ ifc. containing_block . inline_size - ifc. inline_position &&
742
+ ifc. current_nesting_level . white_space . allow_wrap ( ) &&
743
+ ifc. current_nesting_level . fragments_so_far . len ( ) != 0
744
+ {
745
+ ifc. finish_line_and_reset ( layout_context) ;
746
+ }
747
+
748
+ ifc. inline_position += pbm_sums. inline_start ;
749
+ let mut start_corner = Vec2 {
750
+ block : pbm_sums. block_start ,
751
+ inline : ifc. inline_position - ifc. current_nesting_level . inline_start ,
752
+ } ;
753
+ if position. is_relative ( ) {
754
+ start_corner += & relative_adjustement ( atomic. style ( ) , ifc. containing_block )
755
+ }
756
+
757
+ if let Some ( mut child_positioning_context) = child_positioning_context. take ( ) {
758
+ child_positioning_context
759
+ . adjust_static_position_of_hoisted_fragments_with_offset ( & start_corner) ;
760
+ ifc. positioning_context . append ( child_positioning_context) ;
761
+ }
762
+
763
+ fragment. content_rect . start_corner = start_corner;
764
+
743
765
ifc. inline_position += pbm_sums. inline_end + fragment. content_rect . size . inline ;
744
766
ifc. current_nesting_level
745
767
. max_block_size_of_fragments_so_far
0 commit comments