1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:48:11 +00:00

LibHTML: Implement basic <form> and <input> element support

This patch adds "submit" inputs and default (text box) inputs, as well
as form elements that can be submitted.

Layout of input elements is implemented via a new LayoutWidget class
that allows you to put an arbitrary GWidget in the layout tree.
At the moment, the DOM node sets the initial size of the LayoutWidget,
and then the positioning is done by the normal layout algorithm.

We also now support submitting a <form method="GET">, which does a full
replacing load with a URL based on the form's action + a query string
built from the name/value of input elements within the submitted form.

This is pretty neat! :^)
This commit is contained in:
Andreas Kling 2019-11-25 21:21:55 +01:00
parent a91c17c0eb
commit 6d1c4ae5a9
11 changed files with 229 additions and 0 deletions

View file

@ -57,6 +57,7 @@ public:
virtual bool is_text() const { return false; }
virtual bool is_block() const { return false; }
virtual bool is_replaced() const { return false; }
virtual bool is_widget() const { return false; }
virtual bool is_box() const { return false; }
virtual bool is_table() const { return false; }
virtual bool is_table_row() const { return false; }

View file

@ -0,0 +1,28 @@
#include <LibDraw/Font.h>
#include <LibDraw/StylePainter.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GWidget.h>
#include <LibHTML/Layout/LayoutWidget.h>
LayoutWidget::LayoutWidget(const Element& element, GWidget& widget)
: LayoutReplaced(element, StyleProperties::create())
, m_widget(widget)
{
}
LayoutWidget::~LayoutWidget()
{
widget().remove_from_parent();
}
void LayoutWidget::layout()
{
rect().set_size(FloatSize(widget().width(), widget().height()));
LayoutReplaced::layout();
widget().move_to(rect().x(), rect().y());
}
void LayoutWidget::render(RenderingContext& context)
{
LayoutReplaced::render(context);
}

View file

@ -0,0 +1,30 @@
#pragma once
#include <LibHTML/Layout/LayoutReplaced.h>
class GWidget;
class LayoutWidget : public LayoutReplaced {
public:
LayoutWidget(const Element&, GWidget&);
virtual ~LayoutWidget() override;
virtual void layout() override;
virtual void render(RenderingContext&) override;
GWidget& widget() { return m_widget; }
const GWidget& widget() const { return m_widget; }
virtual bool is_widget() const final { return true; }
private:
virtual const char* class_name() const override { return "LayoutWidget"; }
NonnullRefPtr<GWidget> m_widget;
};
template<>
inline bool is<LayoutWidget>(const LayoutNode& node)
{
return node.is_widget();
}