diff --git a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp index c458206e3e..46fea5f0c7 100644 --- a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp @@ -30,12 +30,13 @@ #include #include #include +#include #include namespace Web::Layout { ButtonBox::ButtonBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr style) - : ReplacedBox(document, element, move(style)) + : LabelableNode(document, element, move(style)) { } @@ -57,10 +58,13 @@ void ButtonBox::paint(PaintContext& context, PaintPhase phase) if (!is_visible()) return; - ReplacedBox::paint(context, 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()); @@ -91,8 +95,11 @@ void ButtonBox::handle_mouseup(Badge, const Gfx::IntPoint& positio NonnullRefPtr protected_this = *this; NonnullRefPtr protected_frame = frame(); - bool is_inside = enclosing_int_rect(absolute_rect()).contains(position); - if (is_inside) + bool is_inside_node_or_label = enclosing_int_rect(absolute_rect()).contains(position); + if (!is_inside_node_or_label) + is_inside_node_or_label = Label::is_inside_associated_label(*this, position); + + if (is_inside_node_or_label) dom_node().did_click_button({}); m_being_pressed = false; @@ -106,11 +113,39 @@ void ButtonBox::handle_mousemove(Badge, const Gfx::IntPoint& posit if (!m_tracking_mouse || !dom_node().enabled()) return; - bool is_inside = enclosing_int_rect(absolute_rect()).contains(position); - if (m_being_pressed == is_inside) + bool is_inside_node_or_label = enclosing_int_rect(absolute_rect()).contains(position); + if (!is_inside_node_or_label) + is_inside_node_or_label = Label::is_inside_associated_label(*this, position); + + if (m_being_pressed == is_inside_node_or_label) return; - m_being_pressed = is_inside; + m_being_pressed = is_inside_node_or_label; + set_needs_display(); +} + +void ButtonBox::handle_associated_label_mousedown(Badge