ladybird/Libraries/LibWeb/Layout/TextInputBox.cpp
Andreas Kling ec29db716c LibWeb: Size appearance-none text inputs for max-content
Use the text-control auto content size when calculating max-content
width for primitive text input widgets. CSS Sizing treats cyclic
percentage preferred sizes as initial values for non-replaced
max-content contributions, so an `appearance: none` input with
`width: 100%` should contribute its `width: auto` size instead of
collapsing to zero.

Keep the min-content path unchanged so the percentage-sized replaced
element rule can still compress non-button-like input controls for
flex automatic minimum sizing. Add coverage for an inline-flex
control matching the GitHub file search layout.
2026-05-20 22:31:38 +02:00

35 lines
1.1 KiB
C++

/*
* Copyright (c) 2025-2026, Jonathan Gamble <gamblej@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Layout/TextInputBox.h>
namespace Web::Layout {
GC_DEFINE_ALLOCATOR(TextInputBox);
TextInputBox::TextInputBox(DOM::Document& document, GC::Ptr<DOM::Element> element, GC::Ref<CSS::ComputedProperties> style)
: BlockContainer(document, element, move(style))
{
}
CSS::SizeWithAspectRatio TextInputBox::compute_auto_content_box_size() const
{
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)
{
auto width = CSS::Length(input_element.size(), CSS::LengthUnit::Ch).to_px(box);
auto height = box.computed_values().line_height() + CSSPixels(2);
// AD-HOC: 2px is inline shadow DOM padding in HTMLInputElement::create_text_input_shadow_tree()
if (box.computed_values().writing_mode() != CSS::WritingMode::HorizontalTb)
swap(width, height);
return { width, height, {} };
}
}