diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-03 14:51:59 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-03 17:22:08 +0200 |
commit | 9749eda09fde78c3cd54cecb90191cb2556eae8f (patch) | |
tree | 04e76b58dd123aab8527d91e7f822d23354866b6 | |
parent | f260afedb15b9c326229733d1dc62956a4b066e7 (diff) | |
download | serenity-9749eda09fde78c3cd54cecb90191cb2556eae8f.zip |
LibWeb: Dispatch mouseenter and mouseleave events when required
I've left a FIXME here about populating the events with mouse
coordinates, button states, etc. We also need to verify that the
dispatch order either doesn't matter or at least match other engines.
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index a023d90572..20149b0d93 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -936,10 +936,29 @@ void Document::set_hovered_node(Node* node) JS::GCPtr<Node> old_hovered_node = move(m_hovered_node); m_hovered_node = node; - if (auto* common_ancestor = find_common_ancestor(old_hovered_node, m_hovered_node)) + auto* common_ancestor = find_common_ancestor(old_hovered_node, m_hovered_node); + if (common_ancestor) common_ancestor->invalidate_style(); else invalidate_style(); + + // https://w3c.github.io/uievents/#mouseleave + if (old_hovered_node && (!m_hovered_node || !m_hovered_node->is_descendant_of(*old_hovered_node))) { + // FIXME: Check if we need to dispatch these events in a specific order. + for (auto target = old_hovered_node; target && target.ptr() != common_ancestor; target = target->parent()) { + // FIXME: Populate the event with mouse coordinates, etc. + target->dispatch_event(*UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseleave)); + } + } + + // https://w3c.github.io/uievents/#mouseenter + if (m_hovered_node && (!old_hovered_node || !m_hovered_node->is_ancestor_of(*old_hovered_node))) { + // FIXME: Check if we need to dispatch these events in a specific order. + for (auto target = m_hovered_node; target.ptr() != common_ancestor; target = target->parent()) { + // FIXME: Populate the event with mouse coordinates, etc. + target->dispatch_event(*UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseenter)); + } + } } JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(String const& name) |