summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Page/EventHandler.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-11 18:15:47 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-11 18:42:43 +0200
commitd6889ecf35949ef1c5f9b9a794db2f33c9106a45 (patch)
tree04a32f93df6e408d22a0711b6568ae4a96023201 /Libraries/LibWeb/Page/EventHandler.cpp
parent5782099106f3e43f964d926b4523a1c01b4855e2 (diff)
downloadserenity-d6889ecf35949ef1c5f9b9a794db2f33c9106a45.zip
LibWeb: Allow layout nodes to receive and track mouse events
To implement form controls internally in LibWeb (necessary for multi process forms), we'll need the ability to handle events since we can't rely on LibGUI widgets anymore. A LayoutNode can now override wants_mouse_events() and if it returns true, it will now receive mousedown, mousemove and mouseup events. :^)
Diffstat (limited to 'Libraries/LibWeb/Page/EventHandler.cpp')
-rw-r--r--Libraries/LibWeb/Page/EventHandler.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 32b750a821..57b73c9673 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -75,9 +75,20 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
{
if (!layout_root())
return false;
+
+ if (m_mouse_event_tracking_layout_node) {
+ m_mouse_event_tracking_layout_node->handle_mouseup({}, position, button, modifiers);
+ return true;
+ }
+
bool handled_event = false;
auto result = layout_root()->hit_test(position, HitTestType::Exact);
+
+ if (result.layout_node && result.layout_node->wants_mouse_events()) {
+ result.layout_node->handle_mouseup({}, position, button, modifiers);
+ }
+
if (result.layout_node && result.layout_node->node()) {
RefPtr<DOM::Node> node = result.layout_node->node();
if (is<HTML::HTMLIFrameElement>(*node)) {
@@ -101,6 +112,12 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
{
if (!layout_root())
return false;
+
+ if (m_mouse_event_tracking_layout_node) {
+ m_mouse_event_tracking_layout_node->handle_mousedown({}, position, button, modifiers);
+ return true;
+ }
+
NonnullRefPtr document = *m_frame.document();
auto& page_client = m_frame.page().client();
@@ -108,6 +125,11 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
if (!result.layout_node)
return false;
+ if (result.layout_node->wants_mouse_events()) {
+ result.layout_node->handle_mousedown({}, position, button, modifiers);
+ return true;
+ }
+
RefPtr<DOM::Node> node = result.layout_node->node();
document->set_hovered_node(node);
if (!node)
@@ -171,6 +193,12 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
{
if (!layout_root())
return false;
+
+ if (m_mouse_event_tracking_layout_node) {
+ m_mouse_event_tracking_layout_node->handle_mousemove({}, position, buttons, modifiers);
+ return true;
+ }
+
auto& document = *m_frame.document();
auto& page_client = m_frame.page().client();
@@ -180,6 +208,14 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
auto result = layout_root()->hit_test(position, HitTestType::Exact);
const HTML::HTMLAnchorElement* hovered_link_element = nullptr;
if (result.layout_node) {
+
+ if (result.layout_node->wants_mouse_events()) {
+ result.layout_node->handle_mousemove({}, position, buttons, modifiers);
+ // FIXME: It feels a bit aggressive to always update the cursor like this.
+ page_client.page_did_request_cursor_change(Gfx::StandardCursor::None);
+ return true;
+ }
+
RefPtr<DOM::Node> node = result.layout_node->node();
if (node && is<HTML::HTMLIFrameElement>(*node)) {
@@ -313,4 +349,12 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
return false;
}
+void EventHandler::set_mouse_event_tracking_layout_node(LayoutNode* layout_node)
+{
+ if (layout_node)
+ m_mouse_event_tracking_layout_node = layout_node->make_weak_ptr();
+ else
+ m_mouse_event_tracking_layout_node = nullptr;
+}
+
}