@@ -228,12 +228,17 @@ def relative_positioning(box, containing_block):
228
228
def _out_of_flow_layout (context , box , index , child , new_children ,
229
229
page_is_empty , absolute_boxes , fixed_boxes ,
230
230
adjoining_margins , bottom_space ):
231
- stop = False
232
- resume_at = None
233
- new_child = None
234
- out_of_flow_resume_at = None
235
-
231
+ stop = False # whether we should stop parent rendering after this layout
232
+ resume_at = None # where to resume in-flow rendering
233
+ new_child = None # child rendered by this layout
234
+ out_of_flow_resume_at = None # where to resume out-of-flow rendering
235
+
236
+ # Add the parent’s collapsing margins to shift the child’s position. Don’t
237
+ # include the out-of-flow child’s top margin because it doesn’t collapse
238
+ # with its parent.
236
239
child .position_y += collapse_margin (adjoining_margins )
240
+
241
+ # Absolute child layout: create placeholder.
237
242
if child .is_absolutely_positioned ():
238
243
new_child = placeholder = AbsolutePlaceholder (child )
239
244
placeholder .index = index
@@ -242,31 +247,41 @@ def _out_of_flow_layout(context, box, index, child, new_children,
242
247
absolute_boxes .append (placeholder )
243
248
else :
244
249
fixed_boxes .append (placeholder )
250
+
251
+ # Float child layout.
245
252
elif child .is_floated ():
246
253
new_child , out_of_flow_resume_at = float_layout (
247
254
context , child , box , absolute_boxes , fixed_boxes , bottom_space ,
248
255
skip_stack = None )
249
- # New page if overflow
256
+
257
+ # Check that child doesn’t overflow page.
250
258
page_overflow = context .overflows_page (
251
259
bottom_space , new_child .position_y + new_child .height )
252
260
add_child = (
253
261
(page_is_empty and not new_children ) or
254
262
not page_overflow or
255
263
box .is_monolithic ())
256
264
if add_child :
265
+ # Child fits or has to fit, add it.
257
266
new_child .index = index
258
267
new_children .append (new_child )
259
268
else :
269
+ # Child doesn’t fit and we can break, find where to break and stop
270
+ # parent rendering.
260
271
last_in_flow_child = find_last_in_flow_child (new_children )
261
272
page_break = block_level_page_break (last_in_flow_child , child )
262
273
resume_at = {index : None }
274
+ stop = True
263
275
if new_children and avoid_page_break (page_break , context ):
276
+ # Can’t break inside float, find an earlier page break.
264
277
result = find_earlier_page_break (
265
278
context , new_children , absolute_boxes , fixed_boxes )
266
279
if result :
267
- stop = True
280
+ # Earlier page break found, drop whole child rendering.
268
281
new_children [:], resume_at = result
269
282
new_child = out_of_flow_resume_at = None
283
+
284
+ # Running element layout.
270
285
elif child .is_running ():
271
286
running_name = child .style ['position' ][1 ]
272
287
page = context .current_page
0 commit comments