1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 14:15:08 +00:00
serenity/Userland/Libraries/LibWeb/Painting/LabelablePaintable.h
sin-ack 29583104d2 LibWeb: Refactor all LabelableNode subclasses + input event handling :^)
This commit is messy due to the Paintable and Layout classes being
tangled together.

The RadioButton, CheckBox and ButtonBox classes are now subclasses of
FormAssociatedLabelableNode. This subclass separates these layout nodes
from LabelableNode, which is also the superclass of non-form associated
labelable nodes (Progress).

ButtonPaintable, CheckBoxPaintable and RadioButtonPaintable no longer
call events on DOM nodes directly from their mouse event handlers;
instead, all the functionality is now directly in EventHandler, which
dispatches the related events. handle_mousedown and related methods
return a bool indicating whether the event handling should proceed.

Paintable classes can now return an alternative DOM::Node which should
be the target of the mouse event. Labels use this to indicate that the
labeled control should be the target of the mouse events.

HTMLInputElement put its activation behavior on run_activation_behavior,
which wasn't actually called anywhere and had to be manually called by
other places. We now use activation_behavior which is used by
EventDispatcher.

This commit also brings HTMLInputElement closer to spec by removing the
did_foo functions that did ad-hoc event dispatching and unifies the
behavior under run_input_activation_behavior.
2022-03-16 00:38:31 +01:00

44 lines
1.7 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, sin-ack <sin-ack@protonmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/Layout/FormAssociatedLabelableNode.h>
#include <LibWeb/Painting/PaintableBox.h>
namespace Web::Painting {
// FIXME: Splinter this into FormAssociatedLabelablePaintable once
// ProgressPaintable switches over to this.
class LabelablePaintable : public PaintableBox {
public:
Layout::FormAssociatedLabelableNode const& layout_box() const;
Layout::FormAssociatedLabelableNode& layout_box();
virtual bool wants_mouse_events() const override { return true; }
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, Gfx::IntPoint const&, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, Gfx::IntPoint const&, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, Gfx::IntPoint const&, unsigned buttons, unsigned modifiers) override;
void handle_associated_label_mousedown(Badge<Layout::Label>);
void handle_associated_label_mouseup(Badge<Layout::Label>);
void handle_associated_label_mousemove(Badge<Layout::Label>, bool is_inside_node_or_label);
bool being_pressed() const { return m_being_pressed; }
// NOTE: Only the HTML node associated with this paintable should call this!
void set_being_pressed(bool being_pressed);
protected:
LabelablePaintable(Layout::LabelableNode const&);
private:
bool m_being_pressed { false };
bool m_tracking_mouse { false };
};
}