Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / layout / text_area_box.lucb

#==============================================================================================
#
#   text_area_box - Layout::TextAreaBox: the box of <textarea>
#
#   DESCRIPTION:
#       Port of LibWeb/Layout/TextAreaBox.cpp (lines 1-29) and TextAreaBox.h: its auto size is
#       `cols` characters by `rows` lines.
#
#       Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Layout/TextAreaBox.cpp:13 Web::Layout::TextAreaBox::TextAreaBox.
pub func layout_text_area_box_construct(this: LayoutTextAreaBox*, document: DomDocument*, element: DomElement*?, style: CssComputedProperties*):
    layout_block_container_construct_css_computed_properties(this.layout_block_container(), document, (DomNode*?)element, style)

## Ported from Libraries/LibWeb/Layout/TextAreaBox.h:21 Web::Layout::TextAreaBox::dom_node.
pub func layout_text_area_box_dom_node(this: LayoutTextAreaBox*) -> HtmlTextAreaElement*:
    let dom_node = layout_node_dom_node(this.layout_node()) else trap("VERIFY: a textarea box has a DOM node")
    return (HtmlTextAreaElement*)dom_node

## Ported from Libraries/LibWeb/Layout/TextAreaBox.cpp:18 Web::Layout::TextAreaBox::compute_auto_content_box_size (override).
pub func layout_text_area_box_compute_auto_content_box_size_impl(base: LayoutBox*) -> CssSizeWithAspectRatio:
    let this = (LayoutTextAreaBox*)base
    let cols_length = css_length_new(f64(html_text_area_element_cols(layout_text_area_box_dom_node(this))), css_data.LengthUnit.ch)
    let rows_length = css_length_new(f64(html_text_area_element_rows(layout_text_area_box_dom_node(this))), css_data.LengthUnit.lh)
    var width = css_length_to_px_layout_node(&cols_length, this.layout_node())
    var height = css_length_to_px_layout_node(&rows_length, this.layout_node())

    if css_computed_values_writing_mode(&layout_node_computed_values(this.layout_node()).computed_values) != css_data.WritingMode.horizontal_tb:
        let swapped = width
        width = height
        height = swapped

    return CssSizeWithAspectRatio(width = width, height = height, aspect_ratio = none)

## Ported from Libraries/LibWeb/Layout/TextAreaBox.h:27 Web::Layout::TextAreaBox::has_auto_content_box_size (override).
pub func layout_text_area_box_has_auto_content_box_size_impl(base: LayoutBox*) -> bool:
    _ = base
    return true

## Ported from Libraries/LibWeb/Layout/TextAreaBox.h:28 Web::Layout::TextAreaBox::is_textarea_box (override).
pub func layout_text_area_box_is_textarea_box_impl(base: LayoutNode*) -> bool:
    _ = base
    return true