(node, context)
Implements S10.3.3
Implements S10.3.3
Implements S10 . 3 . 3
def calculate_block_non_replaced_normal_flow_width(node, context):
    "Implements S10.3.3"
    if node.style.width is not AUTO:  # P2
        content_width = node.style.width.px(**context)
        if node.style.max_width is not None:  # 10.4 Maximum width
            content_max_width = node.style.max_width.px(**context)
            if content_width > content_max_width:
                content_width = content_max_width
        if node.style.min_width is not AUTO:  # 10.4 Minimum width
            content_min_width = node.style.min_width.px(**context)
            if content_width < content_min_width:
                content_width = content_min_width
        size = (
            node.layout.border_left_width
            + node.layout.padding_left
            + content_width
            + node.layout.padding_right
            + node.layout.border_right_width
        )
        if node.layout.margin_left is not AUTO:
            size += node.layout.margin_left
        if node.layout.margin_right is not AUTO:
            size += node.layout.margin_right
        if size > context['size']:
            if node.layout.margin_left is AUTO:
                node.layout.margin_left = 0
            if node.layout.margin_right is AUTO:
                node.layout.margin_right = 0

    if (node.layout.margin_left is not AUTO
            and node.style.width is not AUTO
            and node.layout.margin_right is not AUTO):  # P3
        if node.style.direction is LTR:
            node.layout.margin_right = (
                context['size']
                - node.layout.margin_left
                - node.layout.border_left_width
                - node.layout.padding_left
                - content_width
                - node.layout.padding_right
                - node.layout.border_right_width
            )
        else:
            node.layout.margin_left = (
                context['size']
                - node.layout.border_left_width
                - node.layout.padding_left
                - content_width
                - node.layout.padding_right
                - node.layout.border_right_width
                - node.layout.margin_right
            )

    elif (node.layout.margin_left is AUTO
            and node.style.width is not AUTO
            and node.layout.margin_right is not AUTO):  # P4
        node.layout.margin_left = (
            context['size']
            - node.layout.border_left_width
            - node.layout.padding_left
            - content_width
            - node.layout.padding_right
            - node.layout.border_right_width
            - node.layout.margin_right
        )

    elif (node.layout.margin_left is not AUTO
            and node.style.width is AUTO
            and node.layout.margin_right is not AUTO):  # P4
        content_width = (
            context['size']
            - node.layout.margin_left
            - node.layout.border_left_width
            - node.layout.padding_left
            - node.layout.padding_right
            - node.layout.border_right_width
            - node.layout.margin_right
        )

    elif (node.layout.margin_left is not AUTO
            and node.style.width is not AUTO
            and node.layout.margin_right is AUTO):  # P4
        node.layout.margin_right = (
            context['size']
            - node.layout.margin_left
            - node.layout.border_left_width
            - node.layout.padding_left
            - content_width
            - node.layout.padding_right
            - node.layout.border_right_width
        )

    elif node.style.width is AUTO:  # P5
        if node.layout.margin_left is AUTO:
            node.layout.margin_left = 0
        if node.layout.margin_right is AUTO:
            node.layout.margin_right = 0

        content_width = (
            context['size']
            - node.layout.margin_left
            - node.layout.border_left_width
            - node.layout.padding_left
            - node.layout.padding_right
            - node.layout.border_right_width
            - node.layout.margin_right
        )

    elif node.layout.margin_left is AUTO and node.layout.margin_right is AUTO:
        avail_margin = (
            context['size']
            - node.layout.border_left_width
            - node.layout.padding_left
            - content_width
            - node.layout.padding_right
            - node.layout.border_right_width
        )
        node.layout.margin_left = avail_margin // 2
        node.layout.margin_right = avail_margin // 2

    else:
        # This branch should never execute.
        # If it does, we've missed something along the way.
        raise Exception('Unknown S10.3.3 layout case')  # pragma: no cover

    node.layout.content_width = content_width
    node.layout.content_left = node.layout.margin_left + node.layout.border_left_width + node.layout.padding_left
def calculate_block_non_replaced_normal_flow_width ( node , context ) : if node . style . width is not AUTO : # P2 content_width = node . style . width . px ( * * context ) if node . style . max_width is not None : # 10.4 Maximum width content_max_width = node . style . max_width . px ( * * context ) if content_width > content_max_width : content_width = content_max_width if node . style . min_width is not AUTO : # 10.4 Minimum width content_min_width = node . style . min_width . px ( * * context ) if content_width < content_min_width : content_width = content_min_width size = ( node . layout . border_left_width + node . layout . padding_left + content_width + node . layout . padding_right + node . layout . border_right_width ) if node . layout . margin_left is not AUTO : size += node . layout . margin_left if node . layout . margin_right is not AUTO : size += node . layout . margin_right if size > context [ 'size' ] : if node . layout . margin_left is AUTO : node . layout . margin_left = 0 if node . layout . margin_right is AUTO : node . layout . margin_right = 0 if ( node . layout . margin_left is not AUTO and node . style . width is not AUTO and node . layout . margin_right is not AUTO ) : # P3 if node . style . direction is LTR : node . layout . margin_right = ( context [ 'size' ] - node . layout . margin_left - node . layout . border_left_width - node . layout . padding_left - content_width - node . layout . padding_right - node . layout . border_right_width ) else : node . layout . margin_left = ( context [ 'size' ] - node . layout . border_left_width - node . layout . padding_left - content_width - node . layout . padding_right - node . layout . border_right_width - node . layout . margin_right ) elif ( node . layout . margin_left is AUTO and node . style . width is not AUTO and node . layout . margin_right is not AUTO ) : # P4 node . layout . margin_left = ( context [ 'size' ] - node . layout . border_left_width - node . layout . padding_left - content_width - node . layout . padding_right - node . layout . border_right_width - node . layout . margin_right ) elif ( node . layout . margin_left is not AUTO and node . style . width is AUTO and node . layout . margin_right is not AUTO ) : # P4 content_width = ( context [ 'size' ] - node . layout . margin_left - node . layout . border_left_width - node . layout . padding_left - node . layout . padding_right - node . layout . border_right_width - node . layout . margin_right ) elif ( node . layout . margin_left is not AUTO and node . style . width is not AUTO and node . layout . margin_right is AUTO ) : # P4 node . layout . margin_right = ( context [ 'size' ] - node . layout . margin_left - node . layout . border_left_width - node . layout . padding_left - content_width - node . layout . padding_right - node . layout . border_right_width ) elif node . style . width is AUTO : # P5 if node . layout . margin_left is AUTO : node . layout . margin_left = 0 if node . layout . margin_right is AUTO : node . layout . margin_right = 0 content_width = ( context [ 'size' ] - node . layout . margin_left - node . layout . border_left_width - node . layout . padding_left - node . layout . padding_right - node . layout . border_right_width - node . layout . margin_right ) elif node . layout . margin_left is AUTO and node . layout . margin_right is AUTO : avail_margin = ( context [ 'size' ] - node . layout . border_left_width - node . layout . padding_left - content_width - node . layout . padding_right - node . layout . border_right_width ) node . layout . margin_left = avail_margin // 2 node . layout . margin_right = avail_margin // 2 else : # This branch should never execute. # If it does, we've missed something along the way. raise Exception ( 'Unknown S10.3.3 layout case' ) # pragma: no cover node . layout . content_width = content_width node . layout . content_left = node . layout . margin_left + node . layout . border_left_width + node . layout . padding_left