mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-15 23:01:52 +00:00
For example, in the following HTML: ```html <label> <input type="radio" name="fruit" value="apple" id="radio1"> <span class="box"></span> </label> ``` When any descendant of a <label> element is clicked, a "click" event must be dispatched on the <input> element nested within the <label>, in addition to the "click" event dispatched on the clicked descendant. Previously, this behavior was implemented only for text node descendants by "overriding" the mouse event target using `mouse_event_target()` in the TextPaintable. This approach was incorrect because it was limited to text nodes, whereas the behavior should apply to any box. Moreover, the "click" event for the input control must be dispatched *in addition* to the event on the clicked element, rather than redirecting it.
42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/Layout/TextNode.h>
|
|
#include <LibWeb/Painting/PaintableBox.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
class TextPaintable final : public Paintable {
|
|
GC_CELL(TextPaintable, Paintable);
|
|
GC_DECLARE_ALLOCATOR(TextPaintable);
|
|
|
|
public:
|
|
static GC::Ref<TextPaintable> create(Layout::TextNode const&, String const& text_for_rendering);
|
|
|
|
Layout::TextNode const& layout_node() const { return static_cast<Layout::TextNode const&>(Paintable::layout_node()); }
|
|
|
|
virtual bool wants_mouse_events() const override;
|
|
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
|
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
|
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
|
|
|
void set_text_decoration_thickness(CSSPixels thickness) { m_text_decoration_thickness = thickness; }
|
|
CSSPixels text_decoration_thickness() const { return m_text_decoration_thickness; }
|
|
|
|
String const& text_for_rendering() const { return m_text_for_rendering; }
|
|
|
|
private:
|
|
virtual bool is_text_paintable() const override { return true; }
|
|
|
|
TextPaintable(Layout::TextNode const&, String const& text_for_rendering);
|
|
|
|
String m_text_for_rendering;
|
|
CSSPixels m_text_decoration_thickness { 0 };
|
|
};
|
|
|
|
}
|