1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

LibWeb: Allow <input type="button/submit/reset"> to be styled

Previously we used a native ui button to draw the buttons.
These buttons can however not be styled with css.
To allow these to be styled with css, we create a button with
the UA stylesheet that resembles the system ui button.
This commit is contained in:
Vrins 2022-02-21 02:16:21 +01:00 committed by Linus Groh
parent c8f6a20c02
commit a8cfb34551
3 changed files with 16 additions and 9 deletions

View file

@ -26,8 +26,8 @@ ButtonBox::~ButtonBox()
void ButtonBox::prepare_for_replaced_layout()
{
set_intrinsic_width(font().width(dom_node().value()) + 20);
set_intrinsic_height(20);
set_intrinsic_width(font().width(dom_node().value()));
set_intrinsic_height(font().glyph_height());
}
void ButtonBox::paint(PaintContext& context, PaintPhase phase)
@ -38,16 +38,10 @@ void ButtonBox::paint(PaintContext& context, PaintPhase phase)
LabelableNode::paint(context, phase);
if (phase == PaintPhase::Foreground) {
bool hovered = document().hovered_node() == &dom_node();
if (!hovered)
hovered = Label::is_associated_label_hovered(*this);
Gfx::StylePainter::paint_button(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), Gfx::ButtonStyle::Normal, m_being_pressed, hovered, dom_node().checked(), dom_node().enabled());
auto text_rect = enclosing_int_rect(absolute_rect());
if (m_being_pressed)
text_rect.translate_by(1, 1);
context.painter().draw_text(text_rect, dom_node().value(), font(), Gfx::TextAlignment::Center, context.palette().button_text());
context.painter().draw_text(text_rect, dom_node().value(), font(), Gfx::TextAlignment::Center, computed_values().color());
}
}