Skip to content

Commit 563545e

Browse files
committed
Add comments to out-of-flow blocks layout
Related to #2016.
1 parent 90441d2 commit 563545e

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

weasyprint/layout/block.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,17 @@ def relative_positioning(box, containing_block):
228228
def _out_of_flow_layout(context, box, index, child, new_children,
229229
page_is_empty, absolute_boxes, fixed_boxes,
230230
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.
236239
child.position_y += collapse_margin(adjoining_margins)
240+
241+
# Absolute child layout: create placeholder.
237242
if child.is_absolutely_positioned():
238243
new_child = placeholder = AbsolutePlaceholder(child)
239244
placeholder.index = index
@@ -242,31 +247,41 @@ def _out_of_flow_layout(context, box, index, child, new_children,
242247
absolute_boxes.append(placeholder)
243248
else:
244249
fixed_boxes.append(placeholder)
250+
251+
# Float child layout.
245252
elif child.is_floated():
246253
new_child, out_of_flow_resume_at = float_layout(
247254
context, child, box, absolute_boxes, fixed_boxes, bottom_space,
248255
skip_stack=None)
249-
# New page if overflow
256+
257+
# Check that child doesn’t overflow page.
250258
page_overflow = context.overflows_page(
251259
bottom_space, new_child.position_y + new_child.height)
252260
add_child = (
253261
(page_is_empty and not new_children) or
254262
not page_overflow or
255263
box.is_monolithic())
256264
if add_child:
265+
# Child fits or has to fit, add it.
257266
new_child.index = index
258267
new_children.append(new_child)
259268
else:
269+
# Child doesn’t fit and we can break, find where to break and stop
270+
# parent rendering.
260271
last_in_flow_child = find_last_in_flow_child(new_children)
261272
page_break = block_level_page_break(last_in_flow_child, child)
262273
resume_at = {index: None}
274+
stop = True
263275
if new_children and avoid_page_break(page_break, context):
276+
# Can’t break inside float, find an earlier page break.
264277
result = find_earlier_page_break(
265278
context, new_children, absolute_boxes, fixed_boxes)
266279
if result:
267-
stop = True
280+
# Earlier page break found, drop whole child rendering.
268281
new_children[:], resume_at = result
269282
new_child = out_of_flow_resume_at = None
283+
284+
# Running element layout.
270285
elif child.is_running():
271286
running_name = child.style['position'][1]
272287
page = context.current_page

0 commit comments

Comments
 (0)