2020-09-12 18:56:11 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-12 18:56:11 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibGfx/Font.h>
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-11-22 17:53:01 +03:00
|
|
|
#include <LibWeb/Layout/ButtonBox.h>
|
2022-03-10 16:02:25 +03:00
|
|
|
#include <LibWeb/Painting/ButtonPaintable.h>
|
2020-09-12 18:56:11 +03:00
|
|
|
|
2020-11-22 17:53:01 +03:00
|
|
|
namespace Web::Layout {
|
2020-09-12 18:56:11 +03:00
|
|
|
|
2020-11-22 17:53:01 +03:00
|
|
|
ButtonBox::ButtonBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> style)
|
2022-03-15 02:05:55 +03:00
|
|
|
: FormAssociatedLabelableNode(document, element, move(style))
|
2020-09-12 18:56:11 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 22:21:51 +03:00
|
|
|
ButtonBox::~ButtonBox() = default;
|
2020-09-12 18:56:11 +03:00
|
|
|
|
2020-11-22 17:53:01 +03:00
|
|
|
void ButtonBox::prepare_for_replaced_layout()
|
2020-09-12 18:56:11 +03:00
|
|
|
{
|
2022-03-15 02:05:55 +03:00
|
|
|
// For <input type="submit" /> and <input type="button" />, the contents of
|
|
|
|
// the button does not appear as the contents of the element but as the
|
|
|
|
// value attribute. This is not the case with <button />, which contains
|
|
|
|
// its contents normally.
|
|
|
|
if (is<HTML::HTMLInputElement>(dom_node())) {
|
|
|
|
set_intrinsic_width(font().width(static_cast<HTML::HTMLInputElement&>(dom_node()).value()));
|
|
|
|
set_intrinsic_height(font().glyph_height());
|
|
|
|
}
|
2020-09-12 18:56:11 +03:00
|
|
|
}
|
|
|
|
|
2022-03-11 00:38:08 +03:00
|
|
|
RefPtr<Painting::Paintable> ButtonBox::create_paintable() const
|
2022-03-10 16:02:25 +03:00
|
|
|
{
|
|
|
|
return Painting::ButtonPaintable::create(*this);
|
|
|
|
}
|
|
|
|
|
2020-09-12 18:56:11 +03:00
|
|
|
}
|