Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / layout / node_6.lucb

#==============================================================================================
#
#   node_6 - Layout::Node, NodeWithStyle, NodeWithStyleAndBoxModelMetrics: Node.h inlines
#
#   DESCRIPTION:
#       Port of the inline members of LibWeb/Layout/Node.h (lines 38-415): flags and their
#       setters, the generated-for-pseudo-element state, the paintable list, the `is_*`
#       virtuals' defaults, containing blocks, fonts, computed values and the parent of a node,
#       and NodeWithStyle's and NodeWithStyleAndBoxModelMetrics's accessors and constructors.
#
#       Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: Node: layout updates and pseudo-elements (Node.h:53-68) =================================

## Ported from Libraries/LibWeb/Layout/Node.h:53 Web::Layout::Node::needs_layout_update.
pub func layout_node_needs_layout_update(this: LayoutNode*) -> bool:
    return this.m_needs_layout_update

## Ported from Libraries/LibWeb/Layout/Node.h:55 Web::Layout::Node::reset_needs_layout_update.
pub func layout_node_reset_needs_layout_update(this: LayoutNode*):
    this.m_needs_layout_update = false

## Ported from Libraries/LibWeb/Layout/Node.h:57 Web::Layout::Node::is_generated_for_pseudo_element.
pub func layout_node_is_generated_for_pseudo_element(this: LayoutNode*) -> bool:
    return this.m_generated_for != none

## Ported from Libraries/LibWeb/Layout/Node.h:58 Web::Layout::Node::generated_for_pseudo_element.
pub func layout_node_generated_for_pseudo_element(this: LayoutNode*) -> css_data.PseudoElement?:
    return this.m_generated_for

## Ported from Libraries/LibWeb/Layout/Node.h:59 Web::Layout::Node::is_generated_for_before_pseudo_element.
pub func layout_node_is_generated_for_before_pseudo_element(this: LayoutNode*) -> bool:
    return this.m_generated_for == css_data.PseudoElement.before

## Ported from Libraries/LibWeb/Layout/Node.h:60 Web::Layout::Node::is_generated_for_after_pseudo_element.
pub func layout_node_is_generated_for_after_pseudo_element(this: LayoutNode*) -> bool:
    return this.m_generated_for == css_data.PseudoElement.after

## Ported from Libraries/LibWeb/Layout/Node.h:61 Web::Layout::Node::is_generated_for_backdrop_pseudo_element.
pub func layout_node_is_generated_for_backdrop_pseudo_element(this: LayoutNode*) -> bool:
    return this.m_generated_for == css_data.PseudoElement.backdrop

## Ported from Libraries/LibWeb/Layout/Node.h:62 Web::Layout::Node::set_generated_for.
pub func layout_node_set_generated_for(this: LayoutNode*, type_: css_data.PseudoElement, element: DomElement*):
    this.m_generated_for = type_
    this.m_pseudo_element_generator = element

# mark: Node: paintables (Node.h:70-73) =========================================================

## Ported from Libraries/LibWeb/Layout/Node.h:70 Web::Layout::Node::first_paintable.
pub func layout_node_first_paintable(this: LayoutNode*) -> PaintPaintable*?:
    return ak.intrusive_list_first(&this.m_paintable)

## Ported from Libraries/LibWeb/Layout/Node.h:71 Web::Layout::Node::first_paintable.
pub func layout_node_first_paintable_const(this: LayoutNode*) -> PaintPaintable*?:
    return ak.intrusive_list_first(&this.m_paintable)

## Ported from Libraries/LibWeb/Layout/Node.h:72 Web::Layout::Node::paintables.
pub func layout_node_paintables(this: LayoutNode*) -> ak.IntrusiveList[PaintPaintable, PaintPaintable*?]*:
    return &this.m_paintable

## Ported from Libraries/LibWeb/Layout/Node.h:73 Web::Layout::Node::paintables.
pub func layout_node_paintables_const(this: LayoutNode*) -> const ak.IntrusiveList[PaintPaintable, PaintPaintable*?]*:
    return &this.m_paintable

# mark: Node: style and the is_* virtuals (Node.h:91-133) =======================================

## Ported from Libraries/LibWeb/Layout/Node.h:91 Web::Layout::Node::has_style.
pub func layout_node_has_style(this: LayoutNode*) -> bool:
    return this.m_has_style

## Ported from Libraries/LibWeb/Layout/Node.h:363 Web::Layout::Node::has_style_or_parent_with_style.
pub func layout_node_has_style_or_parent_with_style(this: LayoutNode*) -> bool:
    if this.m_has_style:
        return true
    let parent = layout_node_parent(this) else return false
    return layout_node_has_style_or_parent_with_style(parent.layout_node())

## Ported from Libraries/LibWeb/Layout/Node.h:94 Web::Layout::Node::can_have_children (virtual).
pub func layout_node_can_have_children_impl(this: LayoutNode*) -> bool:
    _ = this
    return true

## Ported from Libraries/LibWeb/Layout/Node.h:108 Web::Layout::Node::is_box (virtual).
pub func layout_node_is_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:109 Web::Layout::Node::is_block_container (virtual).
pub func layout_node_is_block_container_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:110 Web::Layout::Node::is_inline_node (virtual).
pub func layout_node_is_inline_node_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:111 Web::Layout::Node::is_break_node (virtual).
pub func layout_node_is_break_node_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:112 Web::Layout::Node::is_text_node (virtual).
pub func layout_node_is_text_node_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:113 Web::Layout::Node::is_viewport (virtual).
pub func layout_node_is_viewport_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:114 Web::Layout::Node::is_svg_box (virtual).
pub func layout_node_is_svg_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:115 Web::Layout::Node::is_svg_geometry_box (virtual).
pub func layout_node_is_svg_geometry_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:116 Web::Layout::Node::is_svg_clip_box (virtual).
pub func layout_node_is_svg_clip_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:117 Web::Layout::Node::is_svg_mask_box (virtual).
pub func layout_node_is_svg_mask_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:118 Web::Layout::Node::is_svg_pattern_box (virtual).
pub func layout_node_is_svg_pattern_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:119 Web::Layout::Node::is_svg_svg_box (virtual).
pub func layout_node_is_svg_svg_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:120 Web::Layout::Node::is_svg_graphics_box (virtual).
pub func layout_node_is_svg_graphics_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:121 Web::Layout::Node::is_svg_foreign_object_box (virtual).
pub func layout_node_is_svg_foreign_object_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:122 Web::Layout::Node::is_label (virtual).
pub func layout_node_is_label_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:123 Web::Layout::Node::is_replaced_box (virtual).
pub func layout_node_is_replaced_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:124 Web::Layout::Node::is_textarea_box (virtual).
pub func layout_node_is_textarea_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:125 Web::Layout::Node::is_list_item_box (virtual).
pub func layout_node_is_list_item_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:126 Web::Layout::Node::is_list_item_marker_box (virtual).
pub func layout_node_is_list_item_marker_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:127 Web::Layout::Node::is_fieldset_box (virtual).
pub func layout_node_is_fieldset_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:128 Web::Layout::Node::is_legend_box (virtual).
pub func layout_node_is_legend_box_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:129 Web::Layout::Node::is_table_wrapper (virtual).
pub func layout_node_is_table_wrapper_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:130 Web::Layout::Node::is_node_with_style (virtual).
pub func layout_node_is_node_with_style_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:131 Web::Layout::Node::is_node_with_style_and_box_model_metrics (virtual).
pub func layout_node_is_node_with_style_and_box_model_metrics_impl(this: LayoutNode*) -> bool:
    _ = this
    return false

## Ported from Libraries/LibWeb/Layout/Node.h:133 Web::Layout::Node::is_replaced_box_with_children.
pub func layout_node_is_replaced_box_with_children(this: LayoutNode*) -> bool:
    return layout_node_is_replaced_box(this) and layout_node_can_have_children(this)

# mark: Node: flex and grid items, containing blocks (Node.h:144-158) ===========================

## Ported from Libraries/LibWeb/Layout/Node.h:144 Web::Layout::Node::is_flex_item.
pub func layout_node_is_flex_item(this: LayoutNode*) -> bool:
    return this.m_is_flex_item

## Ported from Libraries/LibWeb/Layout/Node.h:145 Web::Layout::Node::set_flex_item.
pub func layout_node_set_flex_item(this: LayoutNode*, b: bool):
    this.m_is_flex_item = b

## Ported from Libraries/LibWeb/Layout/Node.h:147 Web::Layout::Node::is_grid_item.
pub func layout_node_is_grid_item(this: LayoutNode*) -> bool:
    return this.m_is_grid_item

## Ported from Libraries/LibWeb/Layout/Node.h:148 Web::Layout::Node::set_grid_item.
pub func layout_node_set_grid_item(this: LayoutNode*, b: bool):
    this.m_is_grid_item = b

## Ported from Libraries/LibWeb/Layout/Node.h:150 Web::Layout::Node::containing_block.
pub func layout_node_containing_block_const(this: LayoutNode*) -> LayoutBox*?:
    return this.m_containing_block

## Ported from Libraries/LibWeb/Layout/Node.h:151 Web::Layout::Node::containing_block.
pub func layout_node_containing_block(this: LayoutNode*) -> LayoutBox*?:
    return this.m_containing_block

## Ported from Libraries/LibWeb/Layout/Node.h:158 Web::Layout::Node::inline_containing_block_if_applicable.
pub func layout_node_inline_containing_block_if_applicable(this: LayoutNode*) -> LayoutInlineNode*?:
    return this.m_inline_containing_block_if_applicable

# mark: Node: fonts, computed values and parent (Node.h:363-404) ================================

## Ported from Libraries/LibWeb/Layout/Node.h:368 Web::Layout::Node::first_available_font.
pub func layout_node_first_available_font(this: LayoutNode*) -> const web_fonts.Font*:
    assert(layout_node_has_style_or_parent_with_style(this))
    if this.m_has_style:
        return layout_node_with_style_first_available_font((LayoutNodeWithStyle*)this)
    let parent = layout_node_parent(this) else trap("VERIFY: a parent with style")
    return layout_node_first_available_font(parent.layout_node())

## Ported from Libraries/LibWeb/Layout/Node.h:376 Web::Layout::Node::font.
pub func layout_node_font_display_list_recording_context(this: LayoutNode*, context: DisplayListRecordingContext*) -> const web_fonts.Font*:
    return layout_node_font_f32(this, (f32)display_list_recording_context_device_pixels_per_css_pixel(context))

## Ported from Libraries/LibWeb/Layout/Node.h:381 Web::Layout::Node::font.
pub func layout_node_font_f32(this: LayoutNode*, scale_factor: f32) -> const web_fonts.Font*:
    let font = layout_node_first_available_font(this)
    return web_fonts.font_with_size(font, web_fonts.font_point_size(font) * scale_factor)

## Ported from Libraries/LibWeb/Layout/Node.h:387 Web::Layout::Node::computed_values.
pub func layout_node_computed_values(this: LayoutNode*) -> const CssImmutableComputedValues*:
    assert(layout_node_has_style_or_parent_with_style(this))

    if this.m_has_style:
        return layout_node_with_style_computed_values((LayoutNodeWithStyle*)this)
    let parent = layout_node_parent(this) else trap("VERIFY: a parent with style")
    return layout_node_with_style_computed_values(parent)

## Ported from Libraries/LibWeb/Layout/Node.h:401 Web::Layout::Node::parent.
pub func layout_node_parent(this: LayoutNode*) -> LayoutNodeWithStyle*?:
    return (LayoutNodeWithStyle*?)tree_node_parent(this)

## Ported from Libraries/LibWeb/Layout/Node.h:396 Web::Layout::Node::parent.
pub func layout_node_parent_const(this: LayoutNode*) -> LayoutNodeWithStyle*?:
    return (LayoutNodeWithStyle*?)tree_node_parent(this)

# mark: Node: tree hooks, flags and predicates (Node.h:186-224) =================================

## Ported from Libraries/LibWeb/Layout/Node.h:186 Web::Layout::Node::inserted_into.
pub func layout_node_inserted_into(this: LayoutNode*, arg0: LayoutNode*):
    _ = this
    _ = arg0

## Ported from Libraries/LibWeb/Layout/Node.h:187 Web::Layout::Node::removed_from.
pub func layout_node_removed_from(this: LayoutNode*, arg0: LayoutNode*):
    _ = this
    _ = arg0

## Ported from Libraries/LibWeb/Layout/Node.h:188 Web::Layout::Node::children_changed.
pub func layout_node_children_changed(this: LayoutNode*):
    _ = this

## Ported from Libraries/LibWeb/Layout/Node.h:190 Web::Layout::Node::children_are_inline.
pub func layout_node_children_are_inline(this: LayoutNode*) -> bool:
    return this.m_children_are_inline

## Ported from Libraries/LibWeb/Layout/Node.h:191 Web::Layout::Node::set_children_are_inline.
pub func layout_node_set_children_are_inline(this: LayoutNode*, value: bool):
    this.m_children_are_inline = value

## Ported from Libraries/LibWeb/Layout/Node.h:193 Web::Layout::Node::initial_quote_nesting_level.
pub func layout_node_initial_quote_nesting_level(this: LayoutNode*) -> u32:
    return this.m_initial_quote_nesting_level

## Ported from Libraries/LibWeb/Layout/Node.h:194 Web::Layout::Node::set_initial_quote_nesting_level.
pub func layout_node_set_initial_quote_nesting_level(this: LayoutNode*, value: u32):
    this.m_initial_quote_nesting_level = value

## Ported from Libraries/LibWeb/Layout/Node.h:198 Web::Layout::Node::is_out_of_flow.
# An element is called out of flow if it is floated, absolutely positioned, or is the root element.
# https://www.w3.org/TR/CSS22/visuren.html#positioning-scheme
pub func layout_node_is_out_of_flow(this: LayoutNode*) -> bool:
    return layout_node_is_floating(this) or layout_node_is_absolutely_positioned(this)

## Ported from Libraries/LibWeb/Layout/Node.h:202 Web::Layout::Node::is_in_flow.
# An element is called in-flow if it is not out-of-flow.
# https://www.w3.org/TR/CSS22/visuren.html#positioning-scheme
pub func layout_node_is_in_flow(this: LayoutNode*) -> bool:
    return not layout_node_is_out_of_flow(this)

## Ported from Libraries/LibWeb/Layout/Node.h:204 Web::Layout::Node::has_css_transform.
pub func layout_node_has_css_transform(this: LayoutNode*) -> bool:
    let computed_values = &layout_node_computed_values(this).computed_values
    let 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/Layout/Node.h:223 Web::Layout::Node::has_been_wrapped_in_table_wrapper.
pub func layout_node_has_been_wrapped_in_table_wrapper(this: LayoutNode*) -> bool:
    return this.m_has_been_wrapped_in_table_wrapper

## Ported from Libraries/LibWeb/Layout/Node.h:224 Web::Layout::Node::set_has_been_wrapped_in_table_wrapper.
pub func layout_node_set_has_been_wrapped_in_table_wrapper(this: LayoutNode*, value: bool):
    this.m_has_been_wrapped_in_table_wrapper = value

# mark: NodeWithStyle (Node.h:265-325, 406-411) =================================================

## Ported from Libraries/LibWeb/Layout/Node.h:284 Web::Layout::NodeWithStyle::computed_values.
pub func layout_node_with_style_computed_values(this: LayoutNodeWithStyle*) -> const CssImmutableComputedValues*:
    return (const CssImmutableComputedValues*)this.m_computed_values

## Ported from Libraries/LibWeb/Layout/Node.h:285 Web::Layout::NodeWithStyle::mutable_computed_values.
pub func layout_node_with_style_mutable_computed_values(this: LayoutNodeWithStyle*) -> CssMutableComputedValues*:
    return (CssMutableComputedValues*)this.m_computed_values

## Ported from Libraries/LibWeb/Layout/Node.h:406 Web::Layout::NodeWithStyle::first_available_font.
pub func layout_node_with_style_first_available_font(this: LayoutNodeWithStyle*) -> const web_fonts.Font*:
    # https://drafts.csswg.org/css-fonts/#first-available-font
    # First font for which the character U+0020 (space) is not excluded by a unicode-range
    return web_fonts.font_cascade_list_font_for_code_point(css_computed_values_font_list(&layout_node_with_style_computed_values(this).computed_values), (u32)' ')

## Ported from Libraries/LibWeb/Layout/Node.h:290 Web::Layout::NodeWithStyle::background_layers.
pub func layout_node_with_style_background_layers(this: LayoutNodeWithStyle*) -> const ak.Vector[CssBackgroundLayerData]*:
    # computed_values().background_layers(): a reference to the computed value's vector.
    return &this.m_computed_values.m_noninherited.background_layers

## Ported from Libraries/LibWeb/Layout/Node.h:291 Web::Layout::NodeWithStyle::list_style_image.
pub func layout_node_with_style_list_style_image(this: LayoutNodeWithStyle*) -> CssAbstractImageStyleValue*?:
    return this.m_list_style_image

## Ported from Libraries/LibWeb/Layout/Node.h:298 Web::Layout::NodeWithStyle::is_body.
pub func layout_node_with_style_is_body(this: LayoutNodeWithStyle*) -> bool:
    return this.node.m_is_body

## Ported from Libraries/LibWeb/Layout/Node.h:305 Web::Layout::NodeWithStyle::layout_index.
pub func layout_node_with_style_layout_index(this: LayoutNodeWithStyle*) -> u32:
    return this.m_layout_index

## Ported from Libraries/LibWeb/Layout/Node.h:306 Web::Layout::NodeWithStyle::set_layout_index.
pub func layout_node_with_style_set_layout_index(this: LayoutNodeWithStyle*, index: u32):
    this.m_layout_index = index

## Ported from Libraries/LibWeb/Layout/Node.h:313 Web::Layout::NodeWithStyle::is_node_with_style (override).
pub func layout_node_with_style_is_node_with_style_impl(base: LayoutNode*) -> bool:
    _ = base
    return true

# mark: NodeWithStyleAndBoxModelMetrics (Node.h:330-356) ========================================

## Ported from Libraries/LibWeb/Layout/Node.h:334 Web::Layout::NodeWithStyleAndBoxModelMetrics::continuation_of_node.
pub func layout_node_with_style_and_box_model_metrics_continuation_of_node(this: LayoutNodeWithStyleAndBoxModelMetrics*) -> LayoutNodeWithStyleAndBoxModelMetrics*?:
    return this.m_continuation_of_node

## Ported from Libraries/LibWeb/Layout/Node.h:335 Web::Layout::NodeWithStyleAndBoxModelMetrics::set_continuation_of_node.
pub func layout_node_with_style_and_box_model_metrics_set_continuation_of_node(this: LayoutNodeWithStyleAndBoxModelMetrics*, node: LayoutNodeWithStyleAndBoxModelMetrics*?):
    this.m_continuation_of_node = node

## Ported from Libraries/LibWeb/Layout/Node.h:344 Web::Layout::NodeWithStyleAndBoxModelMetrics::NodeWithStyleAndBoxModelMetrics.
pub func layout_node_with_style_and_box_model_metrics_construct_css_computed_properties(this: LayoutNodeWithStyleAndBoxModelMetrics*, document: DomDocument*, node: DomNode*?, style: CssComputedProperties*):
    layout_node_with_style_construct_css_computed_properties(this.layout_node_with_style(), document, node, style)

## Ported from Libraries/LibWeb/Layout/Node.h:349 Web::Layout::NodeWithStyleAndBoxModelMetrics::NodeWithStyleAndBoxModelMetrics.
pub func layout_node_with_style_and_box_model_metrics_construct_css_computed_values(this: LayoutNodeWithStyleAndBoxModelMetrics*, document: DomDocument*, node: DomNode*?, computed_values: CssComputedValues*):
    layout_node_with_style_construct_css_computed_values(this.layout_node_with_style(), document, node, computed_values)

## Ported from Libraries/LibWeb/Layout/Node.h:355 Web::Layout::NodeWithStyleAndBoxModelMetrics::is_node_with_style_and_box_model_metrics (override).
pub func layout_node_with_style_and_box_model_metrics_is_node_with_style_and_box_model_metrics_impl(base: LayoutNode*) -> bool:
    _ = base
    return true