diff options
author | Luke <luke.wilde@live.co.uk> | 2020-11-21 18:32:39 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-22 18:20:56 +0100 |
commit | e8b3a6558191e97ffab28943865a9459f013969e (patch) | |
tree | d332303702f9ab31773668fac51b6b4a03dd4b47 /Libraries/LibWeb/Bindings | |
parent | 819f099a8eb595689bc37933c10d2a4fdb7737b1 (diff) | |
download | serenity-e8b3a6558191e97ffab28943865a9459f013969e.zip |
LibWeb: Make event dispatching spec-compliant
Specification: https://dom.spec.whatwg.org/#concept-event-dispatch
This also introduces shadow roots due to it being a requirement of
the event dispatcher.
However, it does not introduce the full shadow DOM, that can be
left for future work.
This changes some event dispatches which require certain attributes
to be initialised to a value.
Diffstat (limited to 'Libraries/LibWeb/Bindings')
-rw-r--r-- | Libraries/LibWeb/Bindings/WindowObject.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibWeb/Bindings/WindowObject.h | 7 |
2 files changed, 22 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index 44f424c6ec..eec88e5504 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -35,6 +35,7 @@ #include <LibJS/Runtime/Shape.h> #include <LibTextCodec/Decoder.h> #include <LibWeb/Bindings/DocumentWrapper.h> +#include <LibWeb/Bindings/EventWrapper.h> #include <LibWeb/Bindings/LocationObject.h> #include <LibWeb/Bindings/NavigatorObject.h> #include <LibWeb/Bindings/NodeWrapperFactory.h> @@ -43,6 +44,7 @@ #include <LibWeb/Bindings/XMLHttpRequestConstructor.h> #include <LibWeb/Bindings/XMLHttpRequestPrototype.h> #include <LibWeb/DOM/Document.h> +#include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/Window.h> #include <LibWeb/Origin.h> @@ -75,6 +77,9 @@ void WindowObject::initialize() define_native_function("atob", atob, 1); define_native_function("btoa", btoa, 1); + // Legacy + define_native_property("event", event_getter, nullptr, JS::Attribute::Enumerable); + define_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); define_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); @@ -337,5 +342,15 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::performance_getter) return wrap(global_object, impl->performance()); } +JS_DEFINE_NATIVE_GETTER(WindowObject::event_getter) +{ + auto* impl = impl_from(vm, global_object); + if (!impl) + return {}; + if (!impl->current_event()) + return JS::js_undefined(); + return wrap(global_object, const_cast<DOM::Event&>(*impl->current_event())); +} + } } diff --git a/Libraries/LibWeb/Bindings/WindowObject.h b/Libraries/LibWeb/Bindings/WindowObject.h index bddabf3334..a1a9a27c9d 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.h +++ b/Libraries/LibWeb/Bindings/WindowObject.h @@ -26,6 +26,7 @@ #pragma once +#include <AK/TypeCasts.h> #include <AK/Weakable.h> #include <LibJS/Runtime/GlobalObject.h> #include <LibWeb/Forward.h> @@ -58,6 +59,8 @@ private: JS_DECLARE_NATIVE_GETTER(performance_getter); + JS_DECLARE_NATIVE_GETTER(event_getter); + JS_DECLARE_NATIVE_FUNCTION(alert); JS_DECLARE_NATIVE_FUNCTION(confirm); JS_DECLARE_NATIVE_FUNCTION(set_interval); @@ -77,3 +80,7 @@ private: } } + +AK_BEGIN_TYPE_TRAITS(Web::Bindings::WindowObject) +static bool is_type(const JS::GlobalObject& global) { return String(global.class_name()) == "WindowObject"; } +AK_END_TYPE_TRAITS() |