2020-09-12 12:56:11 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-12 12:56:11 -03:00
|
|
|
*/
|
|
|
|
|
|
2022-04-09 04:28:38 -03:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2020-09-12 12:56:11 -03:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-11-22 11:53:01 -03:00
|
|
|
#include <LibWeb/Layout/ButtonBox.h>
|
2022-03-10 10:02:25 -03:00
|
|
|
#include <LibWeb/Painting/ButtonPaintable.h>
|
2020-09-12 12:56:11 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
namespace Web::Layout {
|
2020-09-12 12:56:11 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
ButtonBox::ButtonBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> style)
|
2022-03-14 20:05:55 -03:00
|
|
|
: FormAssociatedLabelableNode(document, element, move(style))
|
2020-09-12 12:56:11 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
ButtonBox::~ButtonBox() = default;
|
2020-09-12 12:56:11 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
void ButtonBox::prepare_for_replaced_layout()
|
2020-09-12 12:56:11 -03:00
|
|
|
{
|
2022-03-14 20: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())) {
|
2023-12-09 19:42:02 -03:00
|
|
|
set_natural_width(CSSPixels::nearest_value_for(first_available_font().width(static_cast<HTML::HTMLInputElement&>(dom_node()).value())));
|
|
|
|
|
set_natural_height(first_available_font().pixel_size_rounded_up());
|
2022-03-14 20:05:55 -03:00
|
|
|
}
|
2020-09-12 12:56:11 -03:00
|
|
|
}
|
|
|
|
|
|
2023-01-11 08:51:49 -03:00
|
|
|
JS::GCPtr<Painting::Paintable> ButtonBox::create_paintable() const
|
2022-03-10 10:02:25 -03:00
|
|
|
{
|
|
|
|
|
return Painting::ButtonPaintable::create(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 12:56:11 -03:00
|
|
|
}
|