1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 11:34:59 +00:00

LibWeb: Remove WidgetBox layout node

The approach of attaching sub-widgets to the web view widget was only
ever going to work in single-process mode, and that's not what we're
about anymore, so let's just get rid of WidgetBox so we don't have the
dead-end architecture hanging over us.

The next step here is to re-implement <input type=text> using LibWeb
primitives.
This commit is contained in:
Andreas Kling 2021-02-10 08:58:26 +01:00
parent 1ad65b173b
commit 5e91e61900
10 changed files with 2 additions and 172 deletions

View file

@ -24,8 +24,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibGUI/Button.h>
#include <LibGUI/TextBox.h>
#include <LibGfx/FontDatabase.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
@ -35,7 +33,6 @@
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/ButtonBox.h>
#include <LibWeb/Layout/CheckBox.h>
#include <LibWeb/Layout/WidgetBox.h>
#include <LibWeb/Page/Frame.h>
namespace Web::HTML {
@ -64,10 +61,6 @@ void HTMLInputElement::did_click_button(Badge<Layout::ButtonBox>)
RefPtr<Layout::Node> HTMLInputElement::create_layout_node()
{
ASSERT(document().page());
auto& page = *document().page();
auto& page_view = const_cast<InProcessWebView&>(static_cast<const InProcessWebView&>(page.client()));
if (type() == "hidden")
return nullptr;
@ -82,24 +75,7 @@ RefPtr<Layout::Node> HTMLInputElement::create_layout_node()
return adopt(*new Layout::CheckBox(document(), *this, move(style)));
// FIXME: Implement <input type=text> in terms of LibWeb primitives.
if (page.client().is_multi_process())
return nullptr;
auto& text_box = page_view.add<GUI::TextBox>();
text_box.set_text(value());
text_box.on_change = [this] {
auto& widget = downcast<Layout::WidgetBox>(layout_node())->widget();
const_cast<HTMLInputElement*>(this)->set_attribute(HTML::AttributeNames::value, static_cast<const GUI::TextBox&>(widget).text());
};
int text_width = Gfx::FontDatabase::default_font().width(value());
auto size_value = attribute(HTML::AttributeNames::size);
if (!size_value.is_null()) {
auto size = size_value.to_uint();
if (size.has_value())
text_width = Gfx::FontDatabase::default_font().glyph_width('x') * size.value();
}
text_box.set_relative_rect(0, 0, text_width + 20, 20);
return adopt(*new Layout::WidgetBox(document(), *this, text_box));
return nullptr;
}
void HTMLInputElement::set_checked(bool checked)