2022-03-10 10:02:25 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-10 18:46:35 -03:00
|
|
|
#include <LibGUI/Event.h>
|
|
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
2022-03-10 10:02:25 -03:00
|
|
|
#include <LibWeb/HTML/HTMLImageElement.h>
|
|
|
|
|
#include <LibWeb/Layout/ButtonBox.h>
|
2022-03-10 18:46:35 -03:00
|
|
|
#include <LibWeb/Layout/Label.h>
|
2022-03-10 10:02:25 -03:00
|
|
|
#include <LibWeb/Painting/ButtonPaintable.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
|
2022-03-10 18:38:08 -03:00
|
|
|
NonnullRefPtr<ButtonPaintable> ButtonPaintable::create(Layout::ButtonBox const& layout_box)
|
2022-03-10 10:02:25 -03:00
|
|
|
{
|
2022-03-10 18:38:08 -03:00
|
|
|
return adopt_ref(*new ButtonPaintable(layout_box));
|
2022-03-10 10:02:25 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ButtonPaintable::ButtonPaintable(Layout::ButtonBox const& layout_box)
|
2022-03-10 18:46:35 -03:00
|
|
|
: LabelablePaintable(layout_box)
|
2022-03-10 10:02:25 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Layout::ButtonBox const& ButtonPaintable::layout_box() const
|
|
|
|
|
{
|
2022-03-10 11:50:57 -03:00
|
|
|
return static_cast<Layout::ButtonBox const&>(layout_node());
|
2022-03-10 10:02:25 -03:00
|
|
|
}
|
|
|
|
|
|
2022-03-10 18:46:35 -03:00
|
|
|
Layout::ButtonBox& ButtonPaintable::layout_box()
|
|
|
|
|
{
|
|
|
|
|
return static_cast<Layout::ButtonBox&>(layout_node());
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 10:02:25 -03:00
|
|
|
void ButtonPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|
|
|
|
{
|
|
|
|
|
if (!is_visible())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-03-10 11:50:57 -03:00
|
|
|
PaintableBox::paint(context, phase);
|
2022-03-10 10:02:25 -03:00
|
|
|
|
2022-03-14 20:05:55 -03:00
|
|
|
auto const& dom_node = layout_box().dom_node();
|
|
|
|
|
if (is<HTML::HTMLInputElement>(dom_node) && phase == PaintPhase::Foreground) {
|
2022-03-10 10:02:25 -03:00
|
|
|
auto text_rect = enclosing_int_rect(absolute_rect());
|
2022-03-14 20:05:55 -03:00
|
|
|
if (being_pressed())
|
2022-03-10 10:02:25 -03:00
|
|
|
text_rect.translate_by(1, 1);
|
2022-03-14 20:05:55 -03:00
|
|
|
context.painter().draw_text(text_rect, static_cast<HTML::HTMLInputElement const&>(dom_node).value(), layout_box().font(), Gfx::TextAlignment::Center, computed_values().color());
|
2022-03-10 10:02:25 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|