dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / layout / text_input_box.lucb
#==============================================================================================
#
# text_input_box - Layout::TextInputBox: the box of a text-like <input>
#
# DESCRIPTION:
# Port of LibWeb/Layout/TextInputBox.cpp (lines 1-30) and TextInputBox.h: its auto size
# is `size` characters by one line (and the shadow tree's 2px padding).
#
# Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/Layout/TextInputBox.cpp:13 Web::Layout::TextInputBox::TextInputBox.
pub func layout_text_input_box_construct(this: LayoutTextInputBox*, 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/TextInputBox.h:21 Web::Layout::TextInputBox::dom_node.
pub func layout_text_input_box_dom_node(this: LayoutTextInputBox*) -> HtmlInputElement*:
let dom_node = layout_node_dom_node(this.layout_node()) else trap("VERIFY: a text input box has a DOM node")
return (HtmlInputElement*)dom_node
## Ported from Libraries/LibWeb/Layout/TextInputBox.cpp:18 Web::Layout::TextInputBox::compute_auto_content_box_size (override).
pub func layout_text_input_box_compute_auto_content_box_size_impl(base: LayoutBox*) -> CssSizeWithAspectRatio:
let this = (LayoutTextInputBox*)base
let size_length = css_length_new(f64(html_input_element_size(layout_text_input_box_dom_node(this))), css_data.LengthUnit.ch)
let computed_values = &layout_node_computed_values(this.layout_node()).computed_values
var width = css_length_to_px_layout_node(&size_length, this.layout_node())
var height = css_computed_values_line_height(computed_values).add(gfx.CssPixels.from_int(2))
# AD-HOC: 2px is inline shadow DOM padding in HTMLInputElement::create_text_input_shadow_tree()
if css_computed_values_writing_mode(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/TextInputBox.h:27 Web::Layout::TextInputBox::has_auto_content_box_size (override).
pub func layout_text_input_box_has_auto_content_box_size_impl(base: LayoutBox*) -> bool:
_ = base
return true