mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:57:44 +00:00
LibWeb: Generate Event and MouseEvent bindings from IDL :^)
We still have to hand-write a function to turn an Event& into a wrapper but this is still a hue improvement. Eventually we'll find a way to auto-generate that function as well.
This commit is contained in:
parent
dd29ff884f
commit
e1bd815a6a
12 changed files with 29 additions and 177 deletions
|
@ -44,18 +44,18 @@ public:
|
|||
|
||||
virtual ~Event() {}
|
||||
|
||||
const FlyString& name() const { return m_event_name; }
|
||||
const FlyString& type() const { return m_type; }
|
||||
|
||||
virtual bool is_mouse_event() const { return false; }
|
||||
|
||||
protected:
|
||||
Event(const FlyString& event_name)
|
||||
: m_event_name(event_name)
|
||||
explicit Event(const FlyString& type)
|
||||
: m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
FlyString m_event_name;
|
||||
FlyString m_type;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
5
Libraries/LibWeb/DOM/Event.idl
Normal file
5
Libraries/LibWeb/DOM/Event.idl
Normal file
|
@ -0,0 +1,5 @@
|
|||
interface Event {
|
||||
|
||||
readonly attribute DOMString type;
|
||||
|
||||
}
|
6
Libraries/LibWeb/DOM/MouseEvent.idl
Normal file
6
Libraries/LibWeb/DOM/MouseEvent.idl
Normal file
|
@ -0,0 +1,6 @@
|
|||
interface MouseEvent : Event {
|
||||
|
||||
readonly attribute double offsetX;
|
||||
readonly attribute double offsetY;
|
||||
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
#include <LibJS/Runtime/MarkedValueList.h>
|
||||
#include <LibJS/Runtime/ScriptFunction.h>
|
||||
#include <LibWeb/Bindings/EventWrapper.h>
|
||||
#include <LibWeb/Bindings/EventWrapperFactory.h>
|
||||
#include <LibWeb/Bindings/NodeWrapper.h>
|
||||
#include <LibWeb/Bindings/NodeWrapperFactory.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
|
@ -131,7 +132,7 @@ bool Node::is_link() const
|
|||
void Node::dispatch_event(NonnullRefPtr<Event> event)
|
||||
{
|
||||
for (auto& listener : listeners()) {
|
||||
if (listener.event_name == event->name()) {
|
||||
if (listener.event_name == event->type()) {
|
||||
auto& function = const_cast<EventListener&>(*listener.listener).function();
|
||||
#ifdef EVENT_DEBUG
|
||||
static_cast<const JS::ScriptFunction*>(function)->body().dump(0);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/Function.h>
|
||||
#include <LibWeb/Bindings/EventWrapper.h>
|
||||
#include <LibWeb/Bindings/EventWrapperFactory.h>
|
||||
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
|
@ -91,7 +92,7 @@ void XMLHttpRequest::send()
|
|||
void XMLHttpRequest::dispatch_event(NonnullRefPtr<Event> event)
|
||||
{
|
||||
for (auto& listener : listeners()) {
|
||||
if (listener.event_name == event->name()) {
|
||||
if (listener.event_name == event->type()) {
|
||||
auto& function = const_cast<EventListener&>(*listener.listener).function();
|
||||
auto& heap = function.heap();
|
||||
auto* this_value = wrap(heap, *this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue