#include #include #include #include #include #include #include #include HTMLInputElement::HTMLInputElement(Document& document, const String& tag_name) : HTMLElement(document, tag_name) { } HTMLInputElement::~HTMLInputElement() { } RefPtr HTMLInputElement::create_layout_node(const StyleProperties*) const { ASSERT(document().frame()); auto& frame = *document().frame(); ASSERT(frame.html_view()); auto& html_view = const_cast(*frame.html_view()); RefPtr widget; if (type() == "submit") { auto button = GButton::construct(value(), &html_view); int text_width = Font::default_font().width(value()); button->set_relative_rect(0, 0, text_width + 20, 20); button->on_click = [this](auto&) { if (auto* form = first_ancestor_of_type()) { // FIXME: Remove this const_cast once we have a non-const first_ancestor_of_type. const_cast(form)->submit(); } }; widget = button; } else { auto text_box = GTextBox::construct(&html_view); text_box->set_text(value()); text_box->on_change = [this] { auto& widget = to(layout_node())->widget(); const_cast(this)->set_attribute("value", static_cast(widget).text()); }; int text_width = Font::default_font().width(value()); text_box->set_relative_rect(0, 0, text_width + 20, 20); widget = text_box; } return adopt(*new LayoutWidget(*this, *widget)); }