Skip to content

Commit

Permalink
Remove workaround for flex percentages
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Feb 18, 2025
1 parent 15ab3c4 commit 7024f63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
6 changes: 1 addition & 5 deletions weasyprint/layout/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,11 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block, page_i
context.running_elements[running_name][page].append(child)
continue
# See https://www.w3.org/TR/css-flexbox-1/#min-size-auto.
if child.style['overflow'] == 'visible':
main_flex_direction = main
else:
main_flex_direction = None
if main == 'width':
child_containing_block = (available_main_space, parent_box.height)
else:
child_containing_block = (parent_box.width, available_main_space)
percent.resolve_percentages(child, child_containing_block, main_flex_direction)
percent.resolve_percentages(child, child_containing_block)
if child.is_table_wrapper:
table_wrapper_width(context, child, child_containing_block)
child.position_x = position_x
Expand Down
23 changes: 9 additions & 14 deletions weasyprint/layout/percent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def percentage(value, refer_to):
return refer_to * value.value / 100


def resolve_one_percentage(box, property_name, refer_to,
main_flex_direction=None):
def resolve_one_percentage(box, property_name, refer_to):
"""Set a used length value from a computed length value.
``refer_to`` is the length for 100%. If ``refer_to`` is not a number, it
Expand All @@ -35,9 +34,7 @@ def resolve_one_percentage(box, property_name, refer_to,
percent = percentage(value, refer_to)
setattr(box, property_name, percent)
if property_name in ('min_width', 'min_height') and percent == 'auto':
if (main_flex_direction is None or
property_name != (f'min_{main_flex_direction}')):
setattr(box, property_name, 0)
setattr(box, property_name, 0)


def resolve_position_percentages(box, containing_block):
Expand All @@ -48,7 +45,7 @@ def resolve_position_percentages(box, containing_block):
resolve_one_percentage(box, 'bottom', cb_height)


def resolve_percentages(box, containing_block, main_flex_direction=None):
def resolve_percentages(box, containing_block):
"""Set used values as attributes of the box object."""
if isinstance(containing_block, boxes.Box):
# cb is short for containing block
Expand All @@ -69,8 +66,8 @@ def resolve_percentages(box, containing_block, main_flex_direction=None):
resolve_one_percentage(box, 'padding_top', maybe_height)
resolve_one_percentage(box, 'padding_bottom', maybe_height)
resolve_one_percentage(box, 'width', cb_width)
resolve_one_percentage(box, 'min_width', cb_width, main_flex_direction)
resolve_one_percentage(box, 'max_width', cb_width, main_flex_direction)
resolve_one_percentage(box, 'min_width', cb_width)
resolve_one_percentage(box, 'max_width', cb_width)

# XXX later: top, bottom, left and right on positioned elements

Expand All @@ -83,14 +80,12 @@ def resolve_percentages(box, containing_block, main_flex_direction=None):
else:
assert height.unit == 'px'
box.height = height.value
resolve_one_percentage(box, 'min_height', 0, main_flex_direction)
resolve_one_percentage(box, 'max_height', inf, main_flex_direction)
resolve_one_percentage(box, 'min_height', 0)
resolve_one_percentage(box, 'max_height', inf)
else:
resolve_one_percentage(box, 'height', cb_height)
resolve_one_percentage(
box, 'min_height', cb_height, main_flex_direction)
resolve_one_percentage(
box, 'max_height', cb_height, main_flex_direction)
resolve_one_percentage(box, 'min_height', cb_height)
resolve_one_percentage(box, 'max_height', cb_height)

collapse = box.style['border_collapse'] == 'collapse'
# Used value == computed value
Expand Down

0 comments on commit 7024f63

Please sign in to comment.