LibWeb: Start working on DOM event support

This patch adds the EventTarget class and makes Node inherit from it.

You can register event listeners on an EventTarget, and when you call
dispatch_event() on it, the event listeners will get invoked.

An event listener is basically a wrapper around a JS::Function*.

This is pretty far from how DOM events should eventually work, but it's
a place to start and we'll build more on top of this. :^)
This commit is contained in:
Andreas Kling 2020-03-18 15:22:31 +01:00
commit f39e5352f0
Notes: sideshowbarker 2024-07-19 08:15:29 +09:00
17 changed files with 310 additions and 11 deletions

View file

@ -31,6 +31,7 @@
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/TreeNode.h>
namespace Web {
@ -56,10 +57,19 @@ class StyleProperties;
class Node
: public TreeNode<Node>
, public EventTarget
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::NodeWrapper;
using TreeNode<Node>::ref;
using TreeNode<Node>::unref;
// ^EventTarget
virtual void ref_event_target() final { ref(); }
virtual void unref_event_target() final { unref(); }
virtual void dispatch_event(String event_name) final;
virtual ~Node();
NodeType type() const { return m_type; }