mirror of
https://github.com/RGBCube/serenity
synced 2025-07-17 11:07:39 +00:00
LibWeb: Implement EventTarget.dispatchEvent
Used by Web Platform Tests to test events
This commit is contained in:
parent
7f6baf8b17
commit
2cc6b919f7
4 changed files with 23 additions and 0 deletions
|
@ -499,6 +499,8 @@ static bool is_wrappable_type(const IDL::Type& type)
|
||||||
return true;
|
return true;
|
||||||
if (type.name.ends_with("Element"))
|
if (type.name.ends_with("Element"))
|
||||||
return true;
|
return true;
|
||||||
|
if (type.name.ends_with("Event"))
|
||||||
|
return true;
|
||||||
if (type.name == "ImageData")
|
if (type.name == "ImageData")
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibWeb/Bindings/ScriptExecutionContext.h>
|
#include <LibWeb/Bindings/ScriptExecutionContext.h>
|
||||||
|
#include <LibWeb/DOM/Event.h>
|
||||||
#include <LibWeb/DOM/EventListener.h>
|
#include <LibWeb/DOM/EventListener.h>
|
||||||
#include <LibWeb/DOM/EventTarget.h>
|
#include <LibWeb/DOM/EventTarget.h>
|
||||||
|
|
||||||
|
@ -53,4 +54,18 @@ void EventTarget::remove_from_event_listener_list(NonnullRefPtr<EventListener> l
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
|
||||||
|
ExceptionOr<bool> EventTarget::dispatch_event_binding(NonnullRefPtr<Event> event)
|
||||||
|
{
|
||||||
|
if (event->dispatched())
|
||||||
|
return DOM::InvalidStateError::create("The event is already being dispatched.");
|
||||||
|
|
||||||
|
if (!event->initialized())
|
||||||
|
return DOM::InvalidStateError::create("Cannot dispatch an uninitialized event.");
|
||||||
|
|
||||||
|
event->set_is_trusted(false);
|
||||||
|
|
||||||
|
return dispatch_event(event);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
|
#include <LibWeb/DOM/ExceptionOr.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::DOM {
|
namespace Web::DOM {
|
||||||
|
@ -31,6 +32,8 @@ public:
|
||||||
void remove_from_event_listener_list(NonnullRefPtr<EventListener>);
|
void remove_from_event_listener_list(NonnullRefPtr<EventListener>);
|
||||||
|
|
||||||
virtual bool dispatch_event(NonnullRefPtr<Event>) = 0;
|
virtual bool dispatch_event(NonnullRefPtr<Event>) = 0;
|
||||||
|
ExceptionOr<bool> dispatch_event_binding(NonnullRefPtr<Event>);
|
||||||
|
|
||||||
virtual JS::Object* create_wrapper(JS::GlobalObject&) = 0;
|
virtual JS::Object* create_wrapper(JS::GlobalObject&) = 0;
|
||||||
Bindings::ScriptExecutionContext* script_execution_context() { return m_script_execution_context; }
|
Bindings::ScriptExecutionContext* script_execution_context() { return m_script_execution_context; }
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
interface EventTarget {
|
interface EventTarget {
|
||||||
|
|
||||||
|
// FIXME: Both of these should take in options
|
||||||
undefined addEventListener(DOMString type, EventListener? callback);
|
undefined addEventListener(DOMString type, EventListener? callback);
|
||||||
undefined removeEventListener(DOMString type, EventListener? callback);
|
undefined removeEventListener(DOMString type, EventListener? callback);
|
||||||
|
|
||||||
|
[ImplementedAs=dispatch_event_binding] boolean dispatchEvent(Event event);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue