2026-01-11 01:56:52 -06:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2025-2026, Jonathan Gamble <gamblej@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Layout/TextInputBox.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Layout {
|
|
|
|
|
|
2026-06-06 14:03:41 +02:00
|
|
|
TextInputBox::TextInputBox(DOM::Document& document, GC::Ptr<DOM::Element> element, CSS::ComputedProperties const& style)
|
|
|
|
|
: BlockContainer(document, element, style)
|
2026-01-11 01:56:52 -06:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSS::SizeWithAspectRatio TextInputBox::compute_auto_content_box_size() const
|
|
|
|
|
{
|
2026-05-20 20:44:07 +02:00
|
|
|
return auto_content_box_size_for_text_control(dom_node(), *this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSS::SizeWithAspectRatio TextInputBox::auto_content_box_size_for_text_control(HTML::HTMLInputElement const& input_element, Box const& box)
|
|
|
|
|
{
|
2026-06-04 00:16:25 -05:00
|
|
|
// FIXME: Per https://html.spec.whatwg.org/multipage/rendering.html#the-input-element-as-a-text-entry-widget the
|
|
|
|
|
// size attribute should only affect the width of the text entry types (text, search, tel, url, email,
|
|
|
|
|
// password). The other types using this box are domain-specific widgets that should ignore it.
|
2026-05-20 20:44:07 +02:00
|
|
|
auto width = CSS::Length(input_element.size(), CSS::LengthUnit::Ch).to_px(box);
|
|
|
|
|
auto height = box.computed_values().line_height() + CSSPixels(2);
|
2026-06-04 00:16:25 -05:00
|
|
|
// FIXME: 2px is inline shadow DOM padding in HTMLInputElement::create_text_input_shadow_tree(). Find a better way
|
|
|
|
|
// to handle sizing to the line height.
|
2026-01-11 01:56:52 -06:00
|
|
|
|
2026-05-20 20:44:07 +02:00
|
|
|
if (box.computed_values().writing_mode() != CSS::WritingMode::HorizontalTb)
|
2026-01-11 01:56:52 -06:00
|
|
|
swap(width, height);
|
|
|
|
|
|
|
|
|
|
return { width, height, {} };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|