Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / layout / layout_state_1.lucb

#==============================================================================================
#
#   layout_state_1 - Layout::LayoutState's inline members: the static position rectangle, the
#                    paged store of used values and UsedValues' accessors
#
#   DESCRIPTION:
#       Port of the inline members of LibWeb/Layout/LayoutState.h (lines 29-352):
#       StaticPositionRect::aligned_position_for_box_with_size, PagedStore (the two-level page
#       table that maps a layout index to its UsedValues), UsedValues' content size, definiteness,
#       box edges, rare data and collapsed borders, and clamp_to_max_dimension_value. Also the
#       CSSPixels / integer helpers the layout fragments of region r44 share.
#
#       PagedStore<T> is instantiated once, with T = LayoutState::UsedValues. A generic Luce body
#       cannot make T's zero value (`entry = T {}`, `make<Page>()`), so its members are written
#       for that instantiation; the iteration of `for_each(callback)` is an iterator loop
#       (DESIGN.md ยง2.9).
#
#       Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: CSSPixels arithmetic shared by the layout fragments ======================================

## `value / divisor` read as CSSPixels: `CSSPixels / int` is a CSSPixelFraction, converted by its operator CSSPixels.
func layout_div_int(value: gfx.CssPixels, divisor: i64) -> gfx.CssPixels:
    let fraction = gfx.div_css_pixels_int(value, divisor)
    return gfx.css_pixel_fraction_to_css_pixels(&fraction)

## `CSSPixels(0)`.
func layout_zero_px() -> gfx.CssPixels:
    return gfx.CssPixels.from_int(0)

# mark: StaticPositionRect ======================================================================

## Ported from Libraries/LibWeb/Layout/LayoutState.h:40 Web::Layout::StaticPositionRect::aligned_position_for_box_with_size.
pub func layout_static_position_rect_aligned_position_for_box_with_size(this: const LayoutStaticPositionRect*, size: gfx.CssPixelSize) -> gfx.CssPixelPoint:
    var position = gfx.css_pixel_rect_location(&this.rect)
    let rect_width = gfx.css_pixel_rect_width(&this.rect)
    let rect_height = gfx.css_pixel_rect_height(&this.rect)
    if this.horizontal_alignment == LayoutStaticPositionRectAlignment.center:
        gfx.css_pixel_point_set_x(&position, position.m_x.add(layout_div_int(rect_width.sub(size.m_width), 2)))
    elif this.horizontal_alignment == LayoutStaticPositionRectAlignment.end:
        gfx.css_pixel_point_set_x(&position, position.m_x.add(rect_width).sub(size.m_width))

    if this.vertical_alignment == LayoutStaticPositionRectAlignment.center:
        gfx.css_pixel_point_set_y(&position, position.m_y.add(layout_div_int(rect_height.sub(size.m_height), 2)))
    elif this.vertical_alignment == LayoutStaticPositionRectAlignment.end:
        gfx.css_pixel_point_set_y(&position, position.m_y.add(rect_height).sub(size.m_height))

    return position

# mark: PagedStore ==============================================================================

## PagedStore's PageBits: a page holds 1 << 4 entries.
let layout_paged_store_page_bits: u32 = 4

## PagedStore's PageSize.
let layout_paged_store_page_size: u32 = 1 << layout_paged_store_page_bits

## PagedStore's PageMask.
let layout_paged_store_page_mask: u32 = layout_paged_store_page_size - 1

## Ported from Libraries/LibWeb/Layout/LayoutState.h:73 Web::Layout::PagedStore::ensure_capacity.
pub func layout_paged_store_ensure_capacity(this: LayoutPagedStore[LayoutStateUsedValues]*, count: u32):
    ak.vector_resize(&this.m_pages, (usize)((count + layout_paged_store_page_size - 1) >> layout_paged_store_page_bits))

## Ported from Libraries/LibWeb/Layout/LayoutState.h:78 Web::Layout::PagedStore::get.
pub func layout_paged_store_get(this: const LayoutPagedStore[LayoutStateUsedValues]*, index: u32) -> LayoutStateUsedValues*?:
    let page_index = (usize)(index >> layout_paged_store_page_bits)
    if page_index >= ak.vector_size(&this.m_pages):
        return none
    let page = *ak.vector_at_const(&this.m_pages, page_index) else return none
    let entry_index = (usize)(index & layout_paged_store_page_mask)
    if not page.has_value[entry_index]:
        return none
    return &page.entries[entry_index]

## Ported from Libraries/LibWeb/Layout/LayoutState.h:92 Web::Layout::PagedStore::allocate.
pub func layout_paged_store_allocate(this: LayoutPagedStore[LayoutStateUsedValues]*, index: u32) -> LayoutStateUsedValues*:
    let page_index = (usize)(index >> layout_paged_store_page_bits)
    if page_index >= ak.vector_size(&this.m_pages):
        ak.vector_resize(&this.m_pages, page_index + 1)
    let slot = ak.vector_at(&this.m_pages, page_index)
    if *slot == none:
        *slot = (new LayoutPage[LayoutStateUsedValues]) else trap("out of memory")
    let page = *slot else trap("unreachable: the page was just made")
    let entry_index = (usize)(index & layout_paged_store_page_mask)
    # entry = T {};
    page.entries[entry_index] = LayoutStateUsedValues()
    page.has_value[entry_index] = true
    return &page.entries[entry_index]

## Ported from Libraries/LibWeb/Layout/LayoutState.h:106 Web::Layout::PagedStore::for_each: `for used_values in
## layout_paged_store_for_each(&store)` visits every allocated entry, page by page.
pub func layout_paged_store_for_each(this: LayoutPagedStore[LayoutStateUsedValues]*) -> LayoutPagedStoreEntries:
    return LayoutPagedStoreEntries(store = this)

## The entries of a PagedStore, as an iterable (PagedStore::for_each's loop).
pub struct LayoutPagedStoreEntries: luce.Iterable[LayoutStateUsedValues*, LayoutPagedStoreEntryIterator]:
    pub var store: LayoutPagedStore[LayoutStateUsedValues]*

    func iterator() -> LayoutPagedStoreEntryIterator:
        return LayoutPagedStoreEntryIterator(store = self.store, page_index = 0, entry_index = 0)

## The iterator of LayoutPagedStoreEntries: the allocated entries in page order.
pub struct LayoutPagedStoreEntryIterator: luce.Iterator[LayoutStateUsedValues*]:
    pub var store: LayoutPagedStore[LayoutStateUsedValues]*
    pub var page_index: usize
    pub var entry_index: usize

    func next() -> LayoutStateUsedValues*?:
        while self.page_index < ak.vector_size(&self.store.m_pages):
            if let page = *ak.vector_at(&self.store.m_pages, self.page_index):
                while self.entry_index < (usize)layout_paged_store_page_size:
                    let index = self.entry_index
                    self.entry_index += 1
                    if page.has_value[index]:
                        return &page.entries[index]
            self.page_index += 1
            self.entry_index = 0
        return none

# mark: UsedValues ==============================================================================

## Ported from Libraries/LibWeb/Layout/LayoutState.h:129 Web::Layout::LayoutState::UsedValues::node.
pub func layout_state_used_values_node_const(this: const LayoutStateUsedValues*) -> LayoutNodeWithStyle*:
    return this.m_node else trap("UsedValues without a node")

## Ported from Libraries/LibWeb/Layout/LayoutState.h:130 Web::Layout::LayoutState::UsedValues::node.
pub func layout_state_used_values_node(this: LayoutStateUsedValues*) -> LayoutNodeWithStyle*:
    return this.m_node else trap("UsedValues without a node")

## Ported from Libraries/LibWeb/Layout/LayoutState.h:133 Web::Layout::LayoutState::UsedValues::containing_block_used_values.
pub func layout_state_used_values_containing_block_used_values(this: const LayoutStateUsedValues*) -> const LayoutStateUsedValues*?:
    return this.m_containing_block_used_values

## Ported from Libraries/LibWeb/Layout/LayoutState.h:135 Web::Layout::LayoutState::UsedValues::content_width.
pub func layout_state_used_values_content_width(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.m_content_width

## Ported from Libraries/LibWeb/Layout/LayoutState.h:136 Web::Layout::LayoutState::UsedValues::content_height.
pub func layout_state_used_values_content_height(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.m_content_height

## Ported from Libraries/LibWeb/Layout/LayoutState.h:140 Web::Layout::LayoutState::UsedValues::content_size.
pub func layout_state_used_values_content_size(this: const LayoutStateUsedValues*) -> gfx.CssPixelSize:
    return gfx.CssPixelSize(layout_state_used_values_content_width(this), layout_state_used_values_content_height(this))

## Ported from Libraries/LibWeb/Layout/LayoutState.h:145 Web::Layout::LayoutState::UsedValues::set_has_definite_width.
pub func layout_state_used_values_set_has_definite_width(this: LayoutStateUsedValues*, has_definite_width: bool):
    this.m_has_definite_width = has_definite_width

## Ported from Libraries/LibWeb/Layout/LayoutState.h:146 Web::Layout::LayoutState::UsedValues::set_has_definite_height.
pub func layout_state_used_values_set_has_definite_height(this: LayoutStateUsedValues*, has_definite_height: bool):
    this.m_has_definite_height = has_definite_height

## Ported from Libraries/LibWeb/Layout/LayoutState.h:148 Web::Layout::LayoutState::UsedValues::has_definite_width.
pub func layout_state_used_values_has_definite_width(this: const LayoutStateUsedValues*) -> bool:
    return this.m_has_definite_width and this.width_constraint == LayoutSizeConstraint.none_

## Ported from Libraries/LibWeb/Layout/LayoutState.h:149 Web::Layout::LayoutState::UsedValues::has_definite_height.
pub func layout_state_used_values_has_definite_height(this: const LayoutStateUsedValues*) -> bool:
    return this.m_has_definite_height and this.height_constraint == LayoutSizeConstraint.none_

## Ported from Libraries/LibWeb/Layout/LayoutState.h:158 Web::Layout::LayoutState::UsedValues::set_content_offset.
pub func layout_state_used_values_set_content_offset(this: LayoutStateUsedValues*, new_offset: gfx.CssPixelPoint):
    this.offset = new_offset

## Ported from Libraries/LibWeb/Layout/LayoutState.h:159 Web::Layout::LayoutState::UsedValues::set_content_x.
pub func layout_state_used_values_set_content_x(this: LayoutStateUsedValues*, x: gfx.CssPixels):
    gfx.css_pixel_point_set_x(&this.offset, x)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:160 Web::Layout::LayoutState::UsedValues::set_content_y.
pub func layout_state_used_values_set_content_y(this: LayoutStateUsedValues*, y: gfx.CssPixels):
    gfx.css_pixel_point_set_y(&this.offset, y)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:165 Web::Layout::LayoutState::UsedValues::cumulative_offset.
# Offset from ICB (viewport) content edge to this box's content edge.
# Computed lazily by walking the containing block chain.
# For pre-populated nodes (partial relayout), returns the cached value from paintable absolute position.
pub func layout_state_used_values_cumulative_offset(this: const LayoutStateUsedValues*) -> gfx.CssPixelPoint:
    if let cumulative_offset = this.m_cumulative_offset:
        return cumulative_offset
    if let containing_block_used_values = this.m_containing_block_used_values:
        let containing_block_offset = layout_state_used_values_cumulative_offset(containing_block_used_values)
        return gfx.css_pixel_point_add(&containing_block_offset, this.offset)
    return this.offset

## Ported from Libraries/LibWeb/Layout/LayoutState.h:202 Web::Layout::LayoutState::UsedValues::margin_box_left.
pub func layout_state_used_values_margin_box_left(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.margin_left.add(layout_state_used_values_border_left_collapsed(this)).add(this.padding_left)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:203 Web::Layout::LayoutState::UsedValues::margin_box_right.
pub func layout_state_used_values_margin_box_right(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.margin_right.add(layout_state_used_values_border_right_collapsed(this)).add(this.padding_right)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:204 Web::Layout::LayoutState::UsedValues::margin_box_top.
pub func layout_state_used_values_margin_box_top(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.margin_top.add(layout_state_used_values_border_top_collapsed(this)).add(this.padding_top)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:205 Web::Layout::LayoutState::UsedValues::margin_box_bottom.
pub func layout_state_used_values_margin_box_bottom(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.margin_bottom.add(layout_state_used_values_border_bottom_collapsed(this)).add(this.padding_bottom)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:207 Web::Layout::LayoutState::UsedValues::margin_box_width.
pub func layout_state_used_values_margin_box_width(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_margin_box_left(this).add(layout_state_used_values_content_width(this)).add(layout_state_used_values_margin_box_right(this))

## Ported from Libraries/LibWeb/Layout/LayoutState.h:208 Web::Layout::LayoutState::UsedValues::margin_box_height.
pub func layout_state_used_values_margin_box_height(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_margin_box_top(this).add(layout_state_used_values_content_height(this)).add(layout_state_used_values_margin_box_bottom(this))

## Ported from Libraries/LibWeb/Layout/LayoutState.h:210 Web::Layout::LayoutState::UsedValues::border_box_left.
pub func layout_state_used_values_border_box_left(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_border_left_collapsed(this).add(this.padding_left)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:211 Web::Layout::LayoutState::UsedValues::border_box_right.
pub func layout_state_used_values_border_box_right(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_border_right_collapsed(this).add(this.padding_right)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:212 Web::Layout::LayoutState::UsedValues::border_box_top.
pub func layout_state_used_values_border_box_top(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_border_top_collapsed(this).add(this.padding_top)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:213 Web::Layout::LayoutState::UsedValues::border_box_bottom.
pub func layout_state_used_values_border_box_bottom(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_border_bottom_collapsed(this).add(this.padding_bottom)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:215 Web::Layout::LayoutState::UsedValues::border_box_width.
pub func layout_state_used_values_border_box_width(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_border_box_left(this).add(layout_state_used_values_content_width(this)).add(layout_state_used_values_border_box_right(this))

## Ported from Libraries/LibWeb/Layout/LayoutState.h:216 Web::Layout::LayoutState::UsedValues::border_box_height.
pub func layout_state_used_values_border_box_height(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return layout_state_used_values_border_box_top(this).add(layout_state_used_values_content_height(this)).add(layout_state_used_values_border_box_bottom(this))

## Ported from Libraries/LibWeb/Layout/LayoutState.h:218 Web::Layout::LayoutState::UsedValues::padding_box_width.
pub func layout_state_used_values_padding_box_width(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.padding_left.add(layout_state_used_values_content_width(this)).add(this.padding_right)

## Ported from Libraries/LibWeb/Layout/LayoutState.h:219 Web::Layout::LayoutState::UsedValues::padding_box_height.
pub func layout_state_used_values_padding_box_height(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return this.padding_top.add(layout_state_used_values_content_height(this)).add(this.padding_bottom)

# mark: UsedValues' rare data ===================================================================

## Ported from Libraries/LibWeb/Layout/LayoutState.h:223 Web::Layout::LayoutState::UsedValues::add_floating_descendant.
pub func layout_state_used_values_add_floating_descendant(this: LayoutStateUsedValues*, box: LayoutBox*):
    _ = ak.hash_table_set(&layout_state_used_values_ensure_rare_data(this).floating_descendants, box)

## UsedValues::floating_descendants()'s `static HashTable<GC::Ptr<Box const>> const empty`.
var layout_state_used_values_no_floating_descendants: ak.HashTable[LayoutBox*, ak.PtrTraits[LayoutBox]]

## Ported from Libraries/LibWeb/Layout/LayoutState.h:224 Web::Layout::LayoutState::UsedValues::floating_descendants.
pub func layout_state_used_values_floating_descendants(this: const LayoutStateUsedValues*) -> const ak.HashTable[LayoutBox*, ak.PtrTraits[LayoutBox]]*:
    if let rare = this.m_rare:
        return &rare.floating_descendants
    return &layout_state_used_values_no_floating_descendants

## Ported from Libraries/LibWeb/Layout/LayoutState.h:230 Web::Layout::LayoutState::UsedValues::set_override_borders_data.
pub func layout_state_used_values_set_override_borders_data(this: LayoutStateUsedValues*, override_borders_data: PaintPaintableBoxBordersDataWithElementKind):
    layout_state_used_values_ensure_rare_data(this).override_borders_data = override_borders_data

## Ported from Libraries/LibWeb/Layout/LayoutState.h:231 Web::Layout::LayoutState::UsedValues::override_borders_data.
pub func layout_state_used_values_override_borders_data(this: const LayoutStateUsedValues*) -> PaintPaintableBoxBordersDataWithElementKind?:
    let rare = this.m_rare else return none
    return rare.override_borders_data

## Ported from Libraries/LibWeb/Layout/LayoutState.h:237 Web::Layout::LayoutState::UsedValues::set_table_cell_coordinates.
pub func layout_state_used_values_set_table_cell_coordinates(this: LayoutStateUsedValues*, table_cell_coordinates: PaintPaintableBoxTableCellCoordinates):
    layout_state_used_values_ensure_rare_data(this).table_cell_coordinates = table_cell_coordinates

## Ported from Libraries/LibWeb/Layout/LayoutState.h:238 Web::Layout::LayoutState::UsedValues::table_cell_coordinates.
pub func layout_state_used_values_table_cell_coordinates(this: const LayoutStateUsedValues*) -> PaintPaintableBoxTableCellCoordinates?:
    let rare = this.m_rare else return none
    return rare.table_cell_coordinates

## Ported from Libraries/LibWeb/Layout/LayoutState.h:244 Web::Layout::LayoutState::UsedValues::set_computed_svg_path.
pub func layout_state_used_values_set_computed_svg_path(this: LayoutStateUsedValues*, svg_path: gfx.Path):
    let rare = layout_state_used_values_ensure_rare_data(this)
    rare.computed_svg_path = gfx.path_clone(&svg_path)
    rare.has_computed_svg_path = true

## Ported from Libraries/LibWeb/Layout/LayoutState.h:245 Web::Layout::LayoutState::UsedValues::computed_svg_path.
pub func layout_state_used_values_computed_svg_path(this: LayoutStateUsedValues*) -> gfx.Path*?:
    let rare = this.m_rare else return none
    if not rare.has_computed_svg_path:
        return none
    return &rare.computed_svg_path

## Ported from Libraries/LibWeb/Layout/LayoutState.h:252 Web::Layout::LayoutState::UsedValues::set_computed_svg_transforms.
pub func layout_state_used_values_set_computed_svg_transforms(this: LayoutStateUsedValues*, computed_transforms: PaintSvgGraphicsPaintableComputedTransforms):
    layout_state_used_values_ensure_rare_data(this).computed_svg_transforms = computed_transforms

## Ported from Libraries/LibWeb/Layout/LayoutState.h:253 Web::Layout::LayoutState::UsedValues::computed_svg_transforms.
pub func layout_state_used_values_computed_svg_transforms(this: const LayoutStateUsedValues*) -> PaintSvgGraphicsPaintableComputedTransforms?:
    let rare = this.m_rare else return none
    return rare.computed_svg_transforms

## Ported from Libraries/LibWeb/Layout/LayoutState.h:259 Web::Layout::LayoutState::UsedValues::set_grid_template_columns.
pub func layout_state_used_values_set_grid_template_columns(this: LayoutStateUsedValues*, used_values_for_grid_template_columns: CssGridTrackSizeListStyleValue*?):
    layout_state_used_values_ensure_rare_data(this).grid_template_columns = used_values_for_grid_template_columns

## Ported from Libraries/LibWeb/Layout/LayoutState.h:260 Web::Layout::LayoutState::UsedValues::grid_template_columns.
pub func layout_state_used_values_grid_template_columns(this: const LayoutStateUsedValues*) -> CssGridTrackSizeListStyleValue*?:
    let rare = this.m_rare else return none
    return rare.grid_template_columns

## Ported from Libraries/LibWeb/Layout/LayoutState.h:266 Web::Layout::LayoutState::UsedValues::set_grid_template_rows.
pub func layout_state_used_values_set_grid_template_rows(this: LayoutStateUsedValues*, used_values_for_grid_template_rows: CssGridTrackSizeListStyleValue*?):
    layout_state_used_values_ensure_rare_data(this).grid_template_rows = used_values_for_grid_template_rows

## Ported from Libraries/LibWeb/Layout/LayoutState.h:267 Web::Layout::LayoutState::UsedValues::grid_template_rows.
pub func layout_state_used_values_grid_template_rows(this: const LayoutStateUsedValues*) -> CssGridTrackSizeListStyleValue*?:
    let rare = this.m_rare else return none
    return rare.grid_template_rows

## Ported from Libraries/LibWeb/Layout/LayoutState.h:273 Web::Layout::LayoutState::UsedValues::set_static_position_rect.
pub func layout_state_used_values_set_static_position_rect(this: LayoutStateUsedValues*, static_position_rect: LayoutStaticPositionRect):
    layout_state_used_values_ensure_rare_data(this).static_position_rect = static_position_rect

## Ported from Libraries/LibWeb/Layout/LayoutState.h:274 Web::Layout::LayoutState::UsedValues::static_position.
pub func layout_state_used_values_static_position(this: const LayoutStateUsedValues*) -> gfx.CssPixelPoint:
    let rare = this.m_rare else return gfx.CssPixelPoint()
    let static_position_rect = rare.static_position_rect else return gfx.CssPixelPoint()
    return layout_static_position_rect_aligned_position_for_box_with_size(&static_position_rect,
                                                                          gfx.CssPixelSize(layout_state_used_values_margin_box_width(this), layout_state_used_values_margin_box_height(this)))

# mark: Collapsed borders =======================================================================

## Ported from Libraries/LibWeb/Layout/LayoutState.h:287 Web::Layout::LayoutState::UsedValues::use_collapsing_borders_model.
pub func layout_state_used_values_use_collapsing_borders_model(this: const LayoutStateUsedValues*) -> bool:
    let rare = this.m_rare else return false
    return rare.override_borders_data != none

## Ported from Libraries/LibWeb/Layout/LayoutState.h:289 Web::Layout::LayoutState::UsedValues::border_left_collapsed.
# Implement the collapsing border model https://www.w3.org/TR/CSS22/tables.html#collapsing-borders.
pub func layout_state_used_values_border_left_collapsed(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return gfx.round(layout_div_int(this.border_left, 2)) if layout_state_used_values_use_collapsing_borders_model(this) else this.border_left

## Ported from Libraries/LibWeb/Layout/LayoutState.h:290 Web::Layout::LayoutState::UsedValues::border_right_collapsed.
pub func layout_state_used_values_border_right_collapsed(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return gfx.round(layout_div_int(this.border_right, 2)) if layout_state_used_values_use_collapsing_borders_model(this) else this.border_right

## Ported from Libraries/LibWeb/Layout/LayoutState.h:291 Web::Layout::LayoutState::UsedValues::border_top_collapsed.
pub func layout_state_used_values_border_top_collapsed(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return gfx.round(layout_div_int(this.border_top, 2)) if layout_state_used_values_use_collapsing_borders_model(this) else this.border_top

## Ported from Libraries/LibWeb/Layout/LayoutState.h:292 Web::Layout::LayoutState::UsedValues::border_bottom_collapsed.
pub func layout_state_used_values_border_bottom_collapsed(this: const LayoutStateUsedValues*) -> gfx.CssPixels:
    return gfx.round(layout_div_int(this.border_bottom, 2)) if layout_state_used_values_use_collapsing_borders_model(this) else this.border_bottom

## Ported from Libraries/LibWeb/Layout/LayoutState.h:305 Web::Layout::LayoutState::UsedValues::ensure_rare_data.
pub func layout_state_used_values_ensure_rare_data(this: LayoutStateUsedValues*) -> LayoutStateUsedValuesRareData*:
    if this.m_rare == none:
        this.m_rare = (new LayoutStateUsedValuesRareData) else trap("out of memory")
    return this.m_rare else trap("unreachable: the rare data was just made")

# mark: clamp_to_max_dimension_value ============================================================

## Ported from Libraries/LibWeb/Layout/LayoutState.h:352 Web::Layout::clamp_to_max_dimension_value.
pub func layout_clamp_to_max_dimension_value(value: gfx.CssPixels) -> gfx.CssPixels:
    if value.might_be_saturated():
        return gfx.CssPixels.from_f32(gfx.css_pixels_max_dimension_value)
    return value