/src/serenity/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/HTML/BrowsingContext.h> |
8 | | #include <LibWeb/Layout/Label.h> |
9 | | #include <LibWeb/Layout/LabelableNode.h> |
10 | | #include <LibWeb/Page/EventHandler.h> |
11 | | #include <LibWeb/Painting/TextPaintable.h> |
12 | | |
13 | | namespace Web::Painting { |
14 | | |
15 | | JS_DEFINE_ALLOCATOR(TextPaintable); |
16 | | |
17 | | JS::NonnullGCPtr<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node, String const& text_for_rendering) |
18 | 0 | { |
19 | 0 | return layout_node.heap().allocate_without_realm<TextPaintable>(layout_node, text_for_rendering); |
20 | 0 | } |
21 | | |
22 | | TextPaintable::TextPaintable(Layout::TextNode const& layout_node, String const& text_for_rendering) |
23 | 0 | : Paintable(layout_node) |
24 | 0 | , m_text_for_rendering(text_for_rendering) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | bool TextPaintable::wants_mouse_events() const |
29 | 0 | { |
30 | 0 | return layout_node().first_ancestor_of_type<Layout::Label>(); |
31 | 0 | } |
32 | | |
33 | | DOM::Node* TextPaintable::mouse_event_target() const |
34 | 0 | { |
35 | 0 | if (auto const* label = layout_node().first_ancestor_of_type<Layout::Label>()) |
36 | 0 | return label->dom_node().control().ptr(); |
37 | 0 | return nullptr; |
38 | 0 | } |
39 | | |
40 | | TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned) |
41 | 0 | { |
42 | 0 | auto* label = layout_node().first_ancestor_of_type<Layout::Label>(); |
43 | 0 | if (!label) |
44 | 0 | return DispatchEventOfSameName::No; |
45 | 0 | const_cast<Layout::Label*>(label)->handle_mousedown_on_label({}, position, button); |
46 | 0 | const_cast<HTML::Navigable&>(*navigable()).event_handler().set_mouse_event_tracking_paintable(this); |
47 | 0 | return DispatchEventOfSameName::Yes; |
48 | 0 | } |
49 | | |
50 | | TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned) |
51 | 0 | { |
52 | 0 | auto* label = layout_node().first_ancestor_of_type<Layout::Label>(); |
53 | 0 | if (!label) |
54 | 0 | return DispatchEventOfSameName::No; |
55 | | |
56 | 0 | const_cast<Layout::Label*>(label)->handle_mouseup_on_label({}, position, button); |
57 | 0 | const_cast<HTML::Navigable&>(*navigable()).event_handler().set_mouse_event_tracking_paintable(nullptr); |
58 | 0 | return DispatchEventOfSameName::Yes; |
59 | 0 | } |
60 | | |
61 | | TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned) |
62 | 0 | { |
63 | 0 | auto* label = layout_node().first_ancestor_of_type<Layout::Label>(); |
64 | 0 | if (!label) |
65 | 0 | return DispatchEventOfSameName::No; |
66 | 0 | const_cast<Layout::Label*>(label)->handle_mousemove_on_label({}, position, button); |
67 | 0 | return DispatchEventOfSameName::Yes; |
68 | 0 | } |
69 | | |
70 | | } |