Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / painting / paintable_box_1.lucb

#==============================================================================================
#
#   paintable_box_1 - Painting::PaintableBox: creation, geometry and scrolling
#
#   DESCRIPTION:
#       Port of LibWeb/Painting/PaintableBox.cpp (lines 1-518) and PaintableBox.h's inline
#       members: resolve_css_filter, creation and relayout reset, the box model and content
#       size, the offset and the absolute (content, padding, border, overflow clip edge, united)
#       rectangles, the CSS clip rect, scroll offsets and scrolling into view, scrollbars and
#       whether the box can be scrolled, and whether overflow applies.
#
#       Copyright (c) 2022-2023, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
#       Copyright (c) 2024-2026, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
#       Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: PaintableBox.h: the stacking context, the box model and the content size ================

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:47 Web::Painting::PaintableBox::stacking_context.
pub func paint_paintable_box_stacking_context(this: PaintPaintableBox*) -> PaintStackingContext*?:
    return this.m_stacking_context

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:48 Web::Painting::PaintableBox::stacking_context.
pub func paint_paintable_box_stacking_context_const(this: PaintPaintableBox*) -> PaintStackingContext*?:
    return this.m_stacking_context

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:53 Web::Painting::PaintableBox::get_mask_area (virtual).
pub func paint_paintable_box_get_mask_area_impl(this: PaintPaintableBox*) -> gfx.CssPixelRect?:
    _ = this
    return none

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:54 Web::Painting::PaintableBox::get_mask_type (virtual).
pub func paint_paintable_box_get_mask_type_impl(this: PaintPaintableBox*) -> gfx.MaskKind?:
    _ = this
    return none

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:55 Web::Painting::PaintableBox::calculate_mask (virtual).
pub func paint_paintable_box_calculate_mask_impl(this: PaintPaintableBox*, arg0: DisplayListRecordingContext*, arg1: gfx.CssPixelRect) -> display_list.DisplayList*?:
    _ = this
    _ = arg0
    _ = arg1
    return none

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:57 Web::Painting::PaintableBox::get_clip_area (virtual).
pub func paint_paintable_box_get_clip_area_impl(this: PaintPaintableBox*) -> gfx.CssPixelRect?:
    _ = this
    return none

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:58 Web::Painting::PaintableBox::calculate_clip (virtual).
pub func paint_paintable_box_calculate_clip_impl(this: PaintPaintableBox*, arg0: DisplayListRecordingContext*, arg1: gfx.CssPixelRect) -> display_list.DisplayList*?:
    _ = this
    _ = arg0
    _ = arg1
    return none

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:60 Web::Painting::PaintableBox::layout_node_with_style_and_box_metrics.
pub func paint_paintable_box_layout_node_with_style_and_box_metrics(this: PaintPaintableBox*) -> LayoutNodeWithStyleAndBoxModelMetrics*:
    return as_layout_node_with_style_and_box_model_metrics(paint_paintable_layout_node(this.paint_paintable()))

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:62 Web::Painting::PaintableBox::box_model.
pub func paint_paintable_box_box_model(this: PaintPaintableBox*) -> PaintBoxModelMetrics*:
    return &this.m_box_model

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:63 Web::Painting::PaintableBox::box_model.
pub func paint_paintable_box_box_model_const(this: PaintPaintableBox*) -> PaintBoxModelMetrics:
    return this.m_box_model

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:87 Web::Painting::PaintableBox::set_offset.
pub func paint_paintable_box_set_offset_f32(this: PaintPaintableBox*, x: f32, y: f32):
    paint_paintable_box_set_offset_css_pixel_point(this, gfx.CssPixelPoint(gfx.CssPixels.from_f32(x), gfx.CssPixels.from_f32(y)))

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:89 Web::Painting::PaintableBox::content_size.
pub func paint_paintable_box_content_size(this: PaintPaintableBox*) -> gfx.CssPixelSize:
    return this.m_content_size

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:91 Web::Painting::PaintableBox::set_content_size.
pub func paint_paintable_box_set_content_size_css_pixels(this: PaintPaintableBox*, width: gfx.CssPixels, height: gfx.CssPixels):
    paint_paintable_box_set_content_size_css_pixel_size(this, gfx.CssPixelSize(width, height))

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:93 Web::Painting::PaintableBox::set_content_width.
pub func paint_paintable_box_set_content_width(this: PaintPaintableBox*, width: gfx.CssPixels):
    paint_paintable_box_set_content_size_css_pixels(this, width, paint_paintable_box_content_height(this))

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:94 Web::Painting::PaintableBox::set_content_height.
pub func paint_paintable_box_set_content_height(this: PaintPaintableBox*, height: gfx.CssPixels):
    paint_paintable_box_set_content_size_css_pixels(this, paint_paintable_box_content_width(this), height)

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:95 Web::Painting::PaintableBox::content_width.
pub func paint_paintable_box_content_width(this: PaintPaintableBox*) -> gfx.CssPixels:
    return this.m_content_size.m_width

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:96 Web::Painting::PaintableBox::content_height.
pub func paint_paintable_box_content_height(this: PaintPaintableBox*) -> gfx.CssPixels:
    return this.m_content_size.m_height

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:107 Web::Painting::PaintableBox::border_box_width.
pub func paint_paintable_box_border_box_width(this: PaintPaintableBox*) -> gfx.CssPixels:
    let border_box = paint_box_model_metrics_border_box(&this.m_box_model)
    return paint_paintable_box_content_width(this).add(border_box.left).add(border_box.right)

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:113 Web::Painting::PaintableBox::border_box_height.
pub func paint_paintable_box_border_box_height(this: PaintPaintableBox*) -> gfx.CssPixels:
    let border_box = paint_box_model_metrics_border_box(&this.m_box_model)
    return paint_paintable_box_content_height(this).add(border_box.top).add(border_box.bottom)

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:119 Web::Painting::PaintableBox::absolute_x.
pub func paint_paintable_box_absolute_x(this: PaintPaintableBox*) -> gfx.CssPixels:
    let rect = paint_paintable_box_absolute_rect(this)
    return gfx.css_pixel_rect_x(&rect)

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:120 Web::Painting::PaintableBox::absolute_y.
pub func paint_paintable_box_absolute_y(this: PaintPaintableBox*) -> gfx.CssPixels:
    let rect = paint_paintable_box_absolute_rect(this)
    return gfx.css_pixel_rect_y(&rect)

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:121 Web::Painting::PaintableBox::absolute_position.
pub func paint_paintable_box_absolute_position(this: PaintPaintableBox*) -> gfx.CssPixelPoint:
    let rect = paint_paintable_box_absolute_rect(this)
    return gfx.css_pixel_rect_location(&rect)

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:125 Web::Painting::PaintableBox::has_scrollable_overflow.
pub func paint_paintable_box_has_scrollable_overflow(this: PaintPaintableBox*) -> bool:
    let overflow_data = this.m_overflow_data else return false
    return overflow_data.has_scrollable_overflow

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:132 Web::Painting::PaintableBox::has_css_transform.
pub func paint_paintable_box_has_css_transform(this: PaintPaintableBox*) -> bool:
    let computed_values = &paint_paintable_computed_values(this.paint_paintable()).computed_values
    var transformations = css_computed_values_transformations(computed_values)
    return not ak.vector_is_empty(&transformations) or css_computed_values_rotate(computed_values) != none or css_computed_values_translate(computed_values) != none or css_computed_values_scale(computed_values) != none

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:141 Web::Painting::PaintableBox::has_non_invertible_css_transform.
pub func paint_paintable_box_has_non_invertible_css_transform(this: PaintPaintableBox*) -> bool:
    return this.m_has_non_invertible_css_transform

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:142 Web::Painting::PaintableBox::set_has_non_invertible_css_transform.
pub func paint_paintable_box_set_has_non_invertible_css_transform(this: PaintPaintableBox*, value: bool):
    this.m_has_non_invertible_css_transform = value

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:146 Web::Painting::PaintableBox::scrollable_overflow_rect.
pub func paint_paintable_box_scrollable_overflow_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect?:
    let overflow_data = this.m_overflow_data else return none
    return overflow_data.scrollable_overflow_rect

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:153 Web::Painting::PaintableBox::set_overflow_data.
pub func paint_paintable_box_set_overflow_data(this: PaintPaintableBox*, data: PaintPaintableBoxOverflowData):
    this.m_overflow_data = data

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:197 Web::Painting::PaintableBox::set_override_borders_data.
pub func paint_paintable_box_set_override_borders_data(this: PaintPaintableBox*, override_borders_data: PaintPaintableBoxBordersDataWithElementKind):
    this.m_override_borders_data = override_borders_data

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:198 Web::Painting::PaintableBox::override_borders_data.
pub func paint_paintable_box_override_borders_data(this: PaintPaintableBox*) -> PaintPaintableBoxBordersDataWithElementKind?:
    return this.m_override_borders_data

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:209 Web::Painting::PaintableBox::set_table_cell_coordinates.
pub func paint_paintable_box_set_table_cell_coordinates(this: PaintPaintableBox*, table_cell_coordinates: PaintPaintableBoxTableCellCoordinates):
    this.m_table_cell_coordinates = table_cell_coordinates

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:210 Web::Painting::PaintableBox::table_cell_coordinates.
pub func paint_paintable_box_table_cell_coordinates(this: PaintPaintableBox*) -> PaintPaintableBoxTableCellCoordinates?:
    return this.m_table_cell_coordinates

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:226 Web::Painting::PaintableBox::set_filter.
pub func paint_paintable_box_set_filter(this: PaintPaintableBox*, filter: PaintResolvedCssFilter):
    this.m_filter = filter

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:227 Web::Painting::PaintableBox::filter.
pub func paint_paintable_box_filter(this: PaintPaintableBox*) -> PaintResolvedCssFilter:
    return this.m_filter

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:250 Web::Painting::PaintableBox::sticky_insets.
pub func paint_paintable_box_sticky_insets(this: PaintPaintableBox*) -> display_list.StickyInsets:
    let sticky_insets = this.m_sticky_insets else trap("a sticky box without insets")
    return *sticky_insets

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:251 Web::Painting::PaintableBox::set_sticky_insets.
pub func paint_paintable_box_set_sticky_insets(this: PaintPaintableBox*, sticky_insets: display_list.StickyInsets*?):
    this.m_sticky_insets = sticky_insets

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:255 Web::Painting::PaintableBox::set_used_values_for_grid_template_columns.
pub func paint_paintable_box_set_used_values_for_grid_template_columns(this: PaintPaintableBox*, style_value: CssGridTrackSizeListStyleValue*?):
    this.m_used_values_for_grid_template_columns = style_value

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:256 Web::Painting::PaintableBox::used_values_for_grid_template_columns.
pub func paint_paintable_box_used_values_for_grid_template_columns(this: PaintPaintableBox*) -> CssGridTrackSizeListStyleValue*?:
    return this.m_used_values_for_grid_template_columns

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:258 Web::Painting::PaintableBox::set_used_values_for_grid_template_rows.
pub func paint_paintable_box_set_used_values_for_grid_template_rows(this: PaintPaintableBox*, style_value: CssGridTrackSizeListStyleValue*?):
    this.m_used_values_for_grid_template_rows = style_value

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:259 Web::Painting::PaintableBox::used_values_for_grid_template_rows.
pub func paint_paintable_box_used_values_for_grid_template_rows(this: PaintPaintableBox*) -> CssGridTrackSizeListStyleValue*?:
    return this.m_used_values_for_grid_template_rows

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:261 Web::Painting::PaintableBox::set_enclosing_scroll_frame_index.
pub func paint_paintable_box_set_enclosing_scroll_frame_index(this: PaintPaintableBox*, index: u64):
    this.m_enclosing_scroll_frame_index = index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:262 Web::Painting::PaintableBox::set_own_scroll_frame_index.
pub func paint_paintable_box_set_own_scroll_frame_index(this: PaintPaintableBox*, index: u64):
    this.m_own_scroll_frame_index = index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:264 Web::Painting::PaintableBox::set_accumulated_visual_context.
pub func paint_paintable_box_set_accumulated_visual_context(this: PaintPaintableBox*, index: u64):
    this.m_accumulated_visual_context_index = index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:265 Web::Painting::PaintableBox::accumulated_visual_context_index.
pub func paint_paintable_box_accumulated_visual_context_index(this: PaintPaintableBox*) -> u64:
    return this.m_accumulated_visual_context_index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:266 Web::Painting::PaintableBox::set_accumulated_visual_context_for_descendants.
pub func paint_paintable_box_set_accumulated_visual_context_for_descendants(this: PaintPaintableBox*, index: u64):
    this.m_accumulated_visual_context_for_descendants_index = index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:267 Web::Painting::PaintableBox::accumulated_visual_context_for_descendants_index.
pub func paint_paintable_box_accumulated_visual_context_for_descendants_index(this: PaintPaintableBox*) -> u64:
    return this.m_accumulated_visual_context_for_descendants_index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:276 Web::Painting::PaintableBox::invalidate_paint_cache.
pub func paint_paintable_box_invalidate_paint_cache(this: PaintPaintableBox*):
    var empty: (ak.Vector[display_list.DisplayListCommand]?)[6]
    this.m_cached_phase_commands = empty

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:278 Web::Painting::PaintableBox::has_cached_commands.
pub func paint_paintable_box_has_cached_commands(this: PaintPaintableBox*, phase: PaintPhase) -> bool:
    return this.m_cached_phase_commands[(usize)phase] != none

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:283 Web::Painting::PaintableBox::cached_commands.
pub func paint_paintable_box_cached_commands(this: PaintPaintableBox*, phase: PaintPhase) -> ak.Vector[display_list.DisplayListCommand]:
    return this.m_cached_phase_commands[(usize)phase] else trap("VERIFY: no cached commands for the phase")

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:288 Web::Painting::PaintableBox::set_cached_commands.
pub func paint_paintable_box_set_cached_commands(this: PaintPaintableBox*, phase: PaintPhase, commands: ak.Vector[display_list.DisplayListCommand]):
    this.m_cached_phase_commands[(usize)phase] = commands

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:293 Web::Painting::PaintableBox::enclosing_scroll_frame_index.
pub func paint_paintable_box_enclosing_scroll_frame_index(this: PaintPaintableBox*) -> u64:
    return this.m_enclosing_scroll_frame_index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:295 Web::Painting::PaintableBox::own_scroll_frame_index.
pub func paint_paintable_box_own_scroll_frame_index(this: PaintPaintableBox*) -> u64:
    return this.m_own_scroll_frame_index

## Ported from Libraries/LibWeb/Painting/PaintableBox.h:338 Web::Painting::PaintableBox::is_paintable_box (override).
pub func paint_paintable_box_is_paintable_box_impl(base: PaintPaintable*) -> bool:
    _ = base
    return true

# mark: Filters ==================================================================================

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:42 Web::Painting::set_paint_viewport_scrollbars.
pub func paint_set_paint_viewport_scrollbars(enabled: bool):
    paint_g_paint_viewport_scrollbars = enabled

## `CSS::Length::from_style_value(length, {}).absolute_length_to_px()`: the `to_css_px` lambda of resolve_css_filter.
func paint_resolve_css_filter_to_css_px(length: CssStyleValue*) -> gfx.CssPixels:
    let resolved = css_length_from_style_value(length, none)
    return css_length_absolute_length_to_px(&resolved)

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:47 Web::Painting::resolve_css_filter.
pub func paint_resolve_css_filter(computed_filter: CssFilter, paintable_box: PaintPaintableBox*) -> PaintResolvedCssFilter:
    let computed_values = &paint_paintable_computed_values(paintable_box.paint_paintable()).computed_values
    let layout_node = paint_paintable_box_layout_node_with_style_and_box_metrics(paintable_box)

    var result = PaintResolvedCssFilter()
    for filter_operation in css_filter_filters(&computed_filter):
        match filter_operation:
            .css_blur(blur):
                let resolved_radius = css_blur_resolved_radius(&blur)
                ak.vector_append_t(&result.operations, PaintResolvedCssFilterResolvedFilterValue.paint_resolved_css_filter_blur(PaintResolvedCssFilterBlur(
                    radius = gfx.css_pixels_nearest_value_for_f32(resolved_radius),
                )))
            .css_drop_shadow(drop_shadow):
                let color_context = css_color_resolution_context_for_layout_node_with_style(layout_node.layout_node_with_style())
                var resolved_color = css_computed_values_color(computed_values)
                if let drop_shadow_color = drop_shadow.color:
                    resolved_color = css_style_value_to_color(drop_shadow_color, color_context) else css_computed_values_color(computed_values)

                var radius = gfx.CssPixels.from_int(0)
                if let drop_shadow_radius = drop_shadow.radius:
                    radius = paint_resolve_css_filter_to_css_px(drop_shadow_radius)
                ak.vector_append_t(&result.operations, PaintResolvedCssFilterResolvedFilterValue.paint_resolved_css_filter_drop_shadow(PaintResolvedCssFilterDropShadow(
                    offset_x = paint_resolve_css_filter_to_css_px(drop_shadow.offset_x),
                    offset_y = paint_resolve_css_filter_to_css_px(drop_shadow.offset_y),
                    radius = radius,
                    color = resolved_color,
                )))
            .css_color(color_operation):
                ak.vector_append_t(&result.operations, PaintResolvedCssFilterResolvedFilterValue.paint_resolved_css_filter_color(PaintResolvedCssFilterColor(
                    operation = color_operation.operation,
                    amount = css_color_resolved_amount(&color_operation),
                )))
            .css_hue_rotate(hue_rotate):
                ak.vector_append_t(&result.operations, PaintResolvedCssFilterResolvedFilterValue.paint_resolved_css_filter_hue_rotate(PaintResolvedCssFilterHueRotate(
                    angle_degrees = css_hue_rotate_angle_degrees(&hue_rotate),
                )))
            .css_url(css_url):
                let url_string = css_url_url(&css_url)
                if ak.string_is_empty(&url_string) or not ak.string_starts_with(&url_string, (u32)'#'):
                    continue
                let fragment = ak.string_substring_from_byte_offset(&url_string, 1) else continue
                let maybe_filter = dom_parent_node_get_element_by_id(paint_paintable_document(paintable_box.paint_paintable()).dom_parent_node(), ak.fly_string_from_string(fragment)) else continue
                if let filter_element = as_if_svg_filter_element(maybe_filter):
                    result.svg_filter = svg_filter_element_gfx_filter(filter_element, layout_node.layout_node_with_style())
                    let bounds = paint_paintable_box_absolute_border_box_rect(paintable_box)
                    if gfx.css_pixel_rect_is_empty(&bounds):
                        if let svg_ancestor = tree_node_first_ancestor_of_type(paintable_box.paint_paintable(), &paint_svgsvg_paintable_class):
                            result.svg_filter_bounds = paint_paintable_box_absolute_rect((PaintPaintableBox*)svg_ancestor)
                    if not gfx.css_pixel_rect_is_empty(&bounds):
                        result.svg_filter_bounds = bounds
    return result

# mark: Creation ==================================================================================

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:110 Web::Painting::PaintableBox::create.
pub func paint_paintable_box_create_layout_box(layout_box: LayoutBox*) -> PaintPaintableBox*:
    let heap = gc.cell_heap(layout_box.cell())
    let this = (PaintPaintableBox*)web_heap_allocate_cell(heap, &paint_paintable_box_class)
    gc.heap_defer_gc(heap)
    paint_paintable_box_construct_layout_box(this, layout_box)
    gc.heap_undefer_gc(heap)
    return this

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:115 Web::Painting::PaintableBox::create.
pub func paint_paintable_box_create_layout_inline_node(layout_box: LayoutInlineNode*) -> PaintPaintableBox*:
    let heap = gc.cell_heap(layout_box.cell())
    let this = (PaintPaintableBox*)web_heap_allocate_cell(heap, &paint_paintable_box_class)
    gc.heap_defer_gc(heap)
    paint_paintable_box_construct_layout_inline_node(this, layout_box)
    gc.heap_undefer_gc(heap)
    return this

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:120 Web::Painting::PaintableBox::PaintableBox.
pub func paint_paintable_box_construct_layout_box(this: PaintPaintableBox*, layout_box: LayoutBox*):
    paint_paintable_construct(this.paint_paintable(), layout_box.layout_node())

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:125 Web::Painting::PaintableBox::PaintableBox.
pub func paint_paintable_box_construct_layout_inline_node(this: PaintPaintableBox*, layout_box: LayoutInlineNode*):
    paint_paintable_construct(this.paint_paintable(), layout_box.layout_node())

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:134 Web::Painting::PaintableBox::reset_for_relayout (virtual).
pub func paint_paintable_box_reset_for_relayout_impl(this: PaintPaintableBox*):
    let paintable = this.paint_paintable()
    if tree_node_parent(paintable) != none:
        tree_node_remove(paintable)
    while let child = tree_node_first_child(paintable):
        tree_node_remove(child)

    paintable.m_containing_block = none
    paintable.m_has_containing_block = false

    this.m_offset = gfx.CssPixelPoint()
    this.m_content_size = gfx.CssPixelSize()

    this.m_box_model = PaintBoxModelMetrics()

    this.m_overflow_data = none
    this.m_override_borders_data = none
    this.m_table_cell_coordinates = none
    this.m_sticky_insets = none

    this.m_absolute_rect = none
    this.m_absolute_padding_box_rect = none
    this.m_absolute_border_box_rect = none

    this.m_enclosing_scroll_frame_index = 0
    this.m_own_scroll_frame_index = 0
    this.m_accumulated_visual_context_index = 0
    this.m_accumulated_visual_context_for_descendants_index = 0

    this.m_used_values_for_grid_template_columns = none
    this.m_used_values_for_grid_template_rows = none

    paint_paintable_box_invalidate_paint_cache(this)

    paint_paintable_box_invalidate_stacking_context(this)

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:170 Web::Painting::PaintableBox::visit_edges (override).
pub func paint_paintable_box_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (PaintPaintableBox*)base
    paint_paintable_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_t(visitor, this.m_stacking_context)
    gc.cell_visitor_visit_t(visitor, this.m_horizontal_scrollbar)
    gc.cell_visitor_visit_t(visitor, this.m_vertical_scrollbar)
    gc.cell_visitor_visit_t(visitor, this.m_resize_handle)

# mark: Scrolling =================================================================================

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:179 Web::Painting::PaintableBox::scroll_offset.
pub func paint_paintable_box_scroll_offset(this: PaintPaintableBox*) -> gfx.CssPixelPoint:
    if paint_paintable_is_viewport_paintable(this.paint_paintable()):
        let navigable = dom_document_navigable(paint_paintable_document(this.paint_paintable())) else trap("VERIFY: the viewport's document has a navigable")
        return html_navigable_viewport_scroll_offset(navigable)

    let node = paint_paintable_layout_node(this.paint_paintable())
    if let pseudo_element = layout_node_generated_for_pseudo_element(node):
        let generator = layout_node_pseudo_element_generator(node) else trap("a pseudo-element without a generator")
        return dom_element_scroll_offset(generator, pseudo_element)

    if let dom_node = paint_paintable_dom_node(this.paint_paintable()):
        if let element = as_if_dom_element(dom_node):
            return dom_element_scroll_offset(element, none)
    return gfx.CssPixelPoint()

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:194 Web::Painting::PaintableBox::set_scroll_offset.
pub func paint_paintable_box_set_scroll_offset(this: PaintPaintableBox*, offset: gfx.CssPixelPoint) -> PaintPaintableBoxScrollHandled:
    let scrollable_overflow_rect = paint_paintable_box_scrollable_overflow_rect(this) else return PaintPaintableBoxScrollHandled.no

    let zero = gfx.CssPixels.from_int(0)
    let padding_rect = paint_paintable_box_absolute_padding_box_rect(this)
    let max_x_offset = ak.max(gfx.css_pixel_rect_width(&scrollable_overflow_rect).sub(gfx.css_pixel_rect_width(&padding_rect)), zero)
    let max_y_offset = ak.max(gfx.css_pixel_rect_height(&scrollable_overflow_rect).sub(gfx.css_pixel_rect_height(&padding_rect)), zero)

    var clamped = offset
    gfx.css_pixel_point_set_x(&clamped, ak.clamp(clamped.m_x, zero, max_x_offset))
    gfx.css_pixel_point_set_y(&clamped, ak.clamp(clamped.m_y, zero, max_y_offset))

    # FIXME: If there is horizontal and vertical scroll ignore only part of the new offset
    let current_offset = paint_paintable_box_scroll_offset(this)
    if clamped.m_y.lt(zero) or gfx.css_pixel_point_eq(&current_offset, clamped):
        return PaintPaintableBoxScrollHandled.no

    if paint_paintable_is_viewport_paintable(this.paint_paintable()):
        let navigable = dom_document_navigable(paint_paintable_document(this.paint_paintable())) else trap("VERIFY: the viewport's document has a navigable")
        html_navigable_perform_scroll_of_viewport_scrolling_box(navigable, clamped)
        return PaintPaintableBoxScrollHandled.yes

    dom_document_set_needs_to_refresh_scroll_state(paint_paintable_document(this.paint_paintable()), true)

    let node = paint_paintable_layout_node(this.paint_paintable())
    if let pseudo_element = layout_node_generated_for_pseudo_element(node):
        let generator = layout_node_pseudo_element_generator(node) else trap("a pseudo-element without a generator")
        dom_element_set_scroll_offset(generator, pseudo_element, clamped)
    else:
        let dom_node = paint_paintable_dom_node(this.paint_paintable()) else trap("as_if<DOM::Element>(*dom_node()): no DOM node")
        let element = as_if_dom_element(dom_node) else return PaintPaintableBoxScrollHandled.no
        dom_element_set_scroll_offset(element, none, clamped)

    # https://drafts.csswg.org/cssom-view-1/#scrolling-events
    # Whenever an element gets scrolled (whether in response to user interaction or by an API),
    # the user agent must run these steps:

    # 1. Let doc be the element’s node document.
    let document = layout_node_document(paint_paintable_layout_node(this.paint_paintable()))

    # FIXME: 2. If the element is a snap container, run the steps to update snapchanging targets for the element with
    #           the element’s eventual snap target in the block axis as newBlockTarget and the element’s eventual snap
    #           target in the inline axis as newInlineTarget.

    var event_target_or_none: DomEventTarget*? = none
    if layout_node_generated_for_pseudo_element(node) != none:
        if let generator = layout_node_pseudo_element_generator(node):
            event_target_or_none = generator.dom_event_target()
    elif let dom_node = paint_paintable_dom_node(this.paint_paintable()):
        event_target_or_none = dom_node.dom_event_target()

    let event_target = event_target_or_none else return PaintPaintableBoxScrollHandled.yes

    # 3. If (element, "scroll") is already in doc’s pending scroll events, abort these steps.
    let pending_scroll_events = dom_document_pending_scroll_events(document)
    for pending in &ak.vector_span(pending_scroll_events):
        if pending.event_target == event_target and ak.fly_string_eq_fly_string(&pending.event_type, &html_event_names_scroll):
            return PaintPaintableBoxScrollHandled.yes

    # 4. Append (element, "scroll") to doc’s pending scroll events.
    ak.vector_append_t(pending_scroll_events, DomDocumentPendingScrollEvent(event_target = event_target, event_type = html_event_names_scroll))

    paint_paintable_set_needs_repaint(this.paint_paintable(), InvalidateDisplayList.no)
    return PaintPaintableBoxScrollHandled.yes

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:258 Web::Painting::PaintableBox::scroll_by.
pub func paint_paintable_box_scroll_by(this: PaintPaintableBox*, delta_x: i32, delta_y: i32) -> PaintPaintableBoxScrollHandled:
    let current = paint_paintable_box_scroll_offset(this)
    return paint_paintable_box_set_scroll_offset(this, gfx.css_pixel_point_translated_css_pixels_css_pixels(&current, gfx.CssPixels.from_int(delta_x), gfx.CssPixels.from_int(delta_y)))

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:263 Web::Painting::PaintableBox::scroll_into_view.
pub func paint_paintable_box_scroll_into_view(this: PaintPaintableBox*, rect: gfx.CssPixelRect):
    let scrollport = paint_paintable_box_absolute_padding_box_rect(this)
    let current_offset = paint_paintable_box_scroll_offset(this)

    # Both rect and scrollport are in layout coordinate space (not scroll-adjusted).
    let content_rect = gfx.css_pixel_rect_translated_css_pixels_css_pixels(&rect, gfx.css_pixel_rect_x(&scrollport).neg(), gfx.css_pixel_rect_y(&scrollport).neg())
    var new_offset = current_offset

    if gfx.css_pixel_rect_right(&content_rect).gt(current_offset.m_x.add(gfx.css_pixel_rect_width(&scrollport))):
        gfx.css_pixel_point_set_x(&new_offset, gfx.css_pixel_rect_right(&content_rect).sub(gfx.css_pixel_rect_width(&scrollport)))
    elif gfx.css_pixel_rect_left(&content_rect).lt(current_offset.m_x):
        gfx.css_pixel_point_set_x(&new_offset, gfx.css_pixel_rect_left(&content_rect))

    if gfx.css_pixel_rect_bottom(&content_rect).gt(current_offset.m_y.add(gfx.css_pixel_rect_height(&scrollport))):
        gfx.css_pixel_point_set_y(&new_offset, gfx.css_pixel_rect_bottom(&content_rect).sub(gfx.css_pixel_rect_height(&scrollport)))
    elif gfx.css_pixel_rect_top(&content_rect).lt(current_offset.m_y):
        gfx.css_pixel_point_set_y(&new_offset, gfx.css_pixel_rect_top(&content_rect))

    _ = paint_paintable_box_set_scroll_offset(this, new_offset)

# mark: Offset, content size and absolute rectangles ===============================================

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:285 Web::Painting::PaintableBox::set_offset.
pub func paint_paintable_box_set_offset_css_pixel_point(this: PaintPaintableBox*, offset: gfx.CssPixelPoint):
    this.m_offset = offset

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:290 Web::Painting::PaintableBox::set_content_size.
pub func paint_paintable_box_set_content_size_css_pixel_size(this: PaintPaintableBox*, size: gfx.CssPixelSize):
    this.m_content_size = size
    if let layout_box = as_if_layout_box(paint_paintable_layout_node(this.paint_paintable())):
        layout_box_did_set_content_size(layout_box)

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:297 Web::Painting::PaintableBox::offset.
# Offset from the top left of the containing block's content edge.
pub func paint_paintable_box_offset(this: PaintPaintableBox*) -> gfx.CssPixelPoint:
    return this.m_offset

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:302 Web::Painting::PaintableBox::compute_absolute_rect (virtual).
pub func paint_paintable_box_compute_absolute_rect_impl(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    var rect = gfx.CssPixelRect(paint_paintable_box_offset(this), paint_paintable_box_content_size(this))
    var block_or_none = paint_paintable_containing_block(this.paint_paintable())
    while let block = block_or_none:
        gfx.css_pixel_rect_translate_by_css_pixel_point(&rect, paint_paintable_box_offset(block))
        block_or_none = paint_paintable_containing_block(block.paint_paintable())
    return rect

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:310 Web::Painting::PaintableBox::absolute_rect.
pub func paint_paintable_box_absolute_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    if this.m_absolute_rect == none:
        this.m_absolute_rect = paint_paintable_box_compute_absolute_rect(this)
    return this.m_absolute_rect else trap("unreachable: computed above")

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:317 Web::Painting::PaintableBox::absolute_padding_box_rect.
pub func paint_paintable_box_absolute_padding_box_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    if this.m_absolute_padding_box_rect == none:
        let absolute_rect = paint_paintable_box_absolute_rect(this)
        let padding = this.m_box_model.padding
        var rect = gfx.CssPixelRect()
        gfx.css_pixel_rect_set_x(&rect, gfx.css_pixel_rect_x(&absolute_rect).sub(padding.left))
        gfx.css_pixel_rect_set_width(&rect, paint_paintable_box_content_width(this).add(padding.left).add(padding.right))
        gfx.css_pixel_rect_set_y(&rect, gfx.css_pixel_rect_y(&absolute_rect).sub(padding.top))
        gfx.css_pixel_rect_set_height(&rect, paint_paintable_box_content_height(this).add(padding.top).add(padding.bottom))
        this.m_absolute_padding_box_rect = rect
    return this.m_absolute_padding_box_rect else trap("unreachable: computed above")

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:331 Web::Painting::PaintableBox::absolute_resizer_rect.
pub func paint_paintable_box_absolute_resizer_rect(this: PaintPaintableBox*, metrics: ChromeMetrics) -> gfx.CssPixelRect?:
    if not paint_paintable_box_has_resizer(this):
        return none
    let padding_rect = paint_paintable_box_absolute_padding_box_rect(this)
    let x = gfx.css_pixel_rect_x(&padding_rect) if paint_paintable_box_is_chrome_mirrored(this) else gfx.css_pixel_rect_right(&padding_rect).sub(metrics.resize_gripper_size)
    let y = gfx.css_pixel_rect_bottom(&padding_rect).sub(metrics.resize_gripper_size)
    return gfx.CssPixelRect(gfx.CssPixelPoint(x, y), gfx.CssPixelSize(metrics.resize_gripper_size, metrics.resize_gripper_size))

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:341 Web::Painting::PaintableBox::absolute_border_box_rect.
pub func paint_paintable_box_absolute_border_box_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    if this.m_absolute_border_box_rect == none:
        let padded_rect = paint_paintable_box_absolute_padding_box_rect(this)
        var rect = gfx.CssPixelRect()
        let use_collapsing_borders_model = paint_paintable_box_override_borders_data(this) != none
        # Implement the collapsing border model https://www.w3.org/TR/CSS22/tables.html#collapsing-borders.
        let border = this.m_box_model.border
        let border_top = gfx.round(layout_div_int(border.top, 2)) if use_collapsing_borders_model else border.top
        let border_bottom = gfx.round(layout_div_int(border.bottom, 2)) if use_collapsing_borders_model else border.bottom
        let border_left = gfx.round(layout_div_int(border.left, 2)) if use_collapsing_borders_model else border.left
        let border_right = gfx.round(layout_div_int(border.right, 2)) if use_collapsing_borders_model else border.right
        gfx.css_pixel_rect_set_x(&rect, gfx.css_pixel_rect_x(&padded_rect).sub(border_left))
        gfx.css_pixel_rect_set_width(&rect, gfx.css_pixel_rect_width(&padded_rect).add(border_left).add(border_right))
        gfx.css_pixel_rect_set_y(&rect, gfx.css_pixel_rect_y(&padded_rect).sub(border_top))
        gfx.css_pixel_rect_set_height(&rect, gfx.css_pixel_rect_height(&padded_rect).add(border_top).add(border_bottom))
        this.m_absolute_border_box_rect = rect
    return this.m_absolute_border_box_rect else trap("unreachable: computed above")

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:362 Web::Painting::PaintableBox::overflow_clip_edge_rect.
# https://drafts.csswg.org/css-overflow-4/#overflow-clip-edge
pub func paint_paintable_box_overflow_clip_edge_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    # https://drafts.csswg.org/css-overflow-4/#overflow-clip-margin
    # Values are defined as follows:
    # '<visual-box>'
    #     Specifies the box edge to use as the overflow clip edge origin, i.e. when the specified offset is zero.
    #     If omitted, defaults to 'padding-box' on non-replaced elements, or 'content-box' on replaced elements.
    # FIXME: We can't parse this yet so it's always omitted for now.
    var overflow_clip_edge = paint_paintable_box_absolute_padding_box_rect(this)
    if layout_node_is_replaced_box(paint_paintable_layout_node(this.paint_paintable())):
        overflow_clip_edge = paint_paintable_box_absolute_rect(this)

    # '<length [0,∞]>'
    #     The specified offset dictates how much the overflow clip edge is expanded from the specified box edge
    #     Negative values are invalid. Defaults to zero if omitted.
    let margin = css_computed_values_overflow_clip_margin(&paint_paintable_computed_values(this.paint_paintable()).computed_values)
    let top = css_length_box_top_const(&margin)
    let right = css_length_box_right_const(&margin)
    let bottom = css_length_box_bottom_const(&margin)
    let left = css_length_box_left_const(&margin)
    let top_length = css_length_percentage_or_auto_length(&top)
    let right_length = css_length_percentage_or_auto_length(&right)
    let bottom_length = css_length_percentage_or_auto_length(&bottom)
    let left_length = css_length_percentage_or_auto_length(&left)
    gfx.css_pixel_rect_inflate_css_pixels_css_pixels_css_pixels(&overflow_clip_edge,
                                                                css_length_absolute_length_to_px(&top_length),
                                                                css_length_absolute_length_to_px(&right_length),
                                                                css_length_absolute_length_to_px(&bottom_length),
                                                                css_length_absolute_length_to_px(&left_length))
    return overflow_clip_edge

## Which absolute rect of a paintable box united_rect_for_continuation_chain combines (its `get_rect` callable).
enum PaintUnitedRect:
    border_box
    content
    padding_box
    margin_box

## The rect `which` of `paintable_box` (the lambdas passed to united_rect_for_continuation_chain).
func paint_united_rect_of(paintable_box: PaintPaintableBox*, which: PaintUnitedRect) -> gfx.CssPixelRect:
    match which:
        .border_box: return paint_paintable_box_absolute_border_box_rect(paintable_box)
        .content: return paint_paintable_box_absolute_rect(paintable_box)
        .padding_box: return paint_paintable_box_absolute_padding_box_rect(paintable_box)
        .margin_box:
            # paint_inspector_overlay_internal's margin rect.
            let margin_box = paint_box_model_metrics_margin_box(paint_paintable_box_box_model(paintable_box))
            return gfx.CssPixelRect(
                gfx.CssPixelPoint(paint_paintable_box_absolute_x(paintable_box).sub(margin_box.left), paint_paintable_box_absolute_y(paintable_box).sub(margin_box.top)),
                gfx.CssPixelSize(paint_paintable_box_content_width(paintable_box).add(margin_box.left).add(margin_box.right),
                                 paint_paintable_box_content_height(paintable_box).add(margin_box.top).add(margin_box.bottom)))

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:386 Web::Painting::united_rect_for_continuation_chain.
## The C++ template's `get_rect` callable is the rect it names.
func paint_united_rect_for_continuation_chain(start: PaintPaintableBox*, get_rect: PaintUnitedRect) -> gfx.CssPixelRect:
    # Combine the absolute rects of all paintable boxes of all nodes in the continuation chain. Without this, we
    # calculate the wrong rect for inline nodes that were split because of block elements.
    var result: gfx.CssPixelRect? = none

    # FIXME: instead of walking the continuation chain in the layout tree, also keep track of this chain in the
    #        painting tree so we can skip visiting the layout nodes altogether.
    var node_or_none: LayoutNodeWithStyleAndBoxModelMetrics*? = paint_paintable_box_layout_node_with_style_and_box_metrics(start)
    while let node = node_or_none:
        for paintable in ak.intrusive_list_begin(layout_node_paintables(node.layout_node())):
            if not is_paint_paintable_box(paintable):
                continue
            let paintable_box = (PaintPaintableBox*)paintable
            let paintable_border_box_rect = paint_united_rect_of(paintable_box, get_rect)
            if let current = result:
                if not gfx.css_pixel_rect_is_empty(&paintable_border_box_rect):
                    var united = current
                    gfx.css_pixel_rect_unite(&united, paintable_border_box_rect)
                    result = united
            else:
                result = paintable_border_box_rect
        node_or_none = layout_node_with_style_and_box_model_metrics_continuation_of_node(node)
    return result else gfx.CssPixelRect()

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:411 Web::Painting::PaintableBox::absolute_united_border_box_rect.
pub func paint_paintable_box_absolute_united_border_box_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    return paint_united_rect_for_continuation_chain(this, PaintUnitedRect.border_box)

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:418 Web::Painting::PaintableBox::absolute_united_content_rect.
pub func paint_paintable_box_absolute_united_content_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    return paint_united_rect_for_continuation_chain(this, PaintUnitedRect.content)

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:425 Web::Painting::PaintableBox::absolute_united_padding_box_rect.
pub func paint_paintable_box_absolute_united_padding_box_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect:
    return paint_united_rect_for_continuation_chain(this, PaintUnitedRect.padding_box)

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:432 Web::Painting::PaintableBox::get_clip_rect.
pub func paint_paintable_box_get_clip_rect(this: PaintPaintableBox*) -> gfx.CssPixelRect?:
    let clip = css_computed_values_clip(&paint_paintable_computed_values(this.paint_paintable()).computed_values)
    if css_clip_is_rect(&clip) and layout_node_is_absolutely_positioned(paint_paintable_box_layout_node_with_style_and_box_metrics(this).layout_node()):
        let border_box = paint_paintable_box_absolute_border_box_rect(this)
        let edge_rect = css_clip_to_rect(&clip)
        return css_edge_rect_resolved(&edge_rect, border_box)
    return none

# mark: Scrollbars ================================================================================

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:442 Web::Painting::PaintableBox::scrollbar.
pub func paint_paintable_box_scrollbar(this: PaintPaintableBox*, direction: PaintPaintableBoxScrollDirection) -> PaintScrollbar*?:
    return this.m_horizontal_scrollbar if direction == PaintPaintableBoxScrollDirection.horizontal else this.m_vertical_scrollbar

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:447 Web::Painting::PaintableBox::ensure_scrollbar.
pub func paint_paintable_box_ensure_scrollbar(this: PaintPaintableBox*, direction: PaintPaintableBoxScrollDirection) -> PaintScrollbar*:
    let slot = &this.m_horizontal_scrollbar if direction == PaintPaintableBoxScrollDirection.horizontal else &this.m_vertical_scrollbar
    if *slot == none:
        *slot = paint_scrollbar_create(gc.cell_heap(this.cell()), this, direction)
    return *slot else trap("unreachable: created above")

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:455 Web::Painting::PaintableBox::could_be_scrolled_by_wheel_event.
pub func paint_paintable_box_could_be_scrolled_by_wheel_event_paint_paintable_box_scroll_dir(this: PaintPaintableBox*, direction: PaintPaintableBoxScrollDirection) -> bool:
    let is_horizontal = direction == PaintPaintableBoxScrollDirection.horizontal
    let orientation = gfx.Orientation.horizontal if is_horizontal else gfx.Orientation.vertical
    let computed_values = &paint_paintable_computed_values(this.paint_paintable()).computed_values
    let overflow = css_computed_values_overflow_x(computed_values) if is_horizontal else css_computed_values_overflow_y(computed_values)

    let scrollable_overflow_rect = paint_paintable_box_scrollable_overflow_rect(this) else return false

    let scrollable_overflow_size = gfx.css_pixel_rect_primary_size_for_orientation(&scrollable_overflow_rect, orientation)
    let padding_box_rect = paint_paintable_box_absolute_padding_box_rect(this)
    let scrollport_size = gfx.css_pixel_rect_primary_size_for_orientation(&padding_box_rect, orientation)

    let overflow_value_allows_scrolling = overflow == css_data.Overflow.auto or overflow == css_data.Overflow.scroll
    if (paint_paintable_is_viewport_paintable(this.paint_paintable()) and overflow != css_data.Overflow.hidden) or overflow_value_allows_scrolling:
        return scrollable_overflow_size.gt(scrollport_size)

    return false

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:474 Web::Painting::PaintableBox::could_be_scrolled_by_wheel_event.
pub func paint_paintable_box_could_be_scrolled_by_wheel_event(this: PaintPaintableBox*) -> bool:
    return paint_paintable_box_could_be_scrolled_by_wheel_event_paint_paintable_box_scroll_dir(this, PaintPaintableBoxScrollDirection.horizontal) or paint_paintable_box_could_be_scrolled_by_wheel_event_paint_paintable_box_scroll_dir(this, PaintPaintableBoxScrollDirection.vertical)

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:479 Web::Painting::PaintableBox::overflow_property_applies.
pub func paint_paintable_box_overflow_property_applies(this: PaintPaintableBox*) -> bool:
    # https://drafts.csswg.org/css-overflow-3/#overflow-control
    # Overflow properties apply to block containers, flex containers and grid containers.
    # FIXME: Ideally we would check whether overflow applies positively rather than listing exceptions. However,
    #        not all elements that should support overflow are currently identifiable that way.
    if is_paint_svg_paintable(this):
        return false
    let display = css_computed_values_display(&paint_paintable_computed_values(this.paint_paintable()).computed_values)
    if layout_node_is_inline_node(paint_paintable_layout_node(this.paint_paintable())):
        return false
    if css_display_is_ruby_inside(&display):
        return false
    if css_display_is_internal(&display) and not css_display_is_table_cell(&display) and not css_display_is_table_caption(&display):
        return false
    return true

## Ported from Libraries/LibWeb/Painting/PaintableBox.cpp:498 Web::Painting::PaintableBox::available_scrollbar_length.
pub func paint_paintable_box_available_scrollbar_length(this: PaintPaintableBox*, direction: PaintPaintableBoxScrollDirection, metrics: ChromeMetrics) -> gfx.CssPixels:
    let is_horizontal = direction == PaintPaintableBoxScrollDirection.horizontal
    let padding_rect = paint_paintable_box_absolute_padding_box_rect(this)
    var full_scrollport_length = gfx.css_pixel_rect_width(&padding_rect) if is_horizontal else gfx.css_pixel_rect_height(&padding_rect)
    if paint_paintable_box_has_resizer(this):
        full_scrollport_length = full_scrollport_length.sub(metrics.resize_gripper_size)
    else:
        if is_horizontal and paint_paintable_box_could_be_scrolled_by_wheel_event_paint_paintable_box_scroll_dir(this, PaintPaintableBoxScrollDirection.vertical):
            full_scrollport_length = full_scrollport_length.sub(metrics.scroll_gutter_thickness)
        if not is_horizontal and paint_paintable_box_could_be_scrolled_by_wheel_event_paint_paintable_box_scroll_dir(this, PaintPaintableBoxScrollDirection.horizontal):
            full_scrollport_length = full_scrollport_length.sub(metrics.scroll_gutter_thickness)
    return full_scrollport_length