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