LibWeb: Turn <input type=button> into an actual button :^)

This commit is contained in:
Andreas Kling 2020-05-30 11:59:10 +02:00
parent 3c6801c3a5
commit e1e9fb8290
Notes: sideshowbarker 2024-07-19 05:57:33 +09:00

View file

@ -28,11 +28,12 @@
#include <LibGUI/Button.h>
#include <LibGUI/TextBox.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/HTMLFormElement.h>
#include <LibWeb/DOM/HTMLInputElement.h>
#include <LibWeb/Frame.h>
#include <LibWeb/PageView.h>
#include <LibWeb/Layout/LayoutWidget.h>
#include <LibWeb/PageView.h>
namespace Web {
@ -67,6 +68,14 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*)
}
};
widget = button;
} else if (type() == "button") {
auto& button = page_view.add<GUI::Button>(value());
int text_width = Gfx::Font::default_font().width(value());
button.set_relative_rect(0, 0, text_width + 20, 20);
button.on_click = [this](auto) {
const_cast<HTMLInputElement*>(this)->dispatch_event(Event::create("click"));
};
widget = button;
} else {
auto& text_box = page_view.add<GUI::TextBox>();
text_box.set_text(value());