diff options
author | Andreas Kling <kling@serenityos.org> | 2020-10-18 13:43:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-18 13:43:44 +0200 |
commit | b92bc9c6e5b927a75d494b219d19243c4495b58d (patch) | |
tree | 2a8d015bda1ebbd0bc693ecbf4380a39630528de /Libraries | |
parent | 77c1957961dc247ad26432ded454d3dabb0264e6 (diff) | |
download | serenity-b92bc9c6e5b927a75d494b219d19243c4495b58d.zip |
LibWeb: Make DOM::Window into an EventTarget
This will allow us to dispatch window events.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/DOM/Window.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Window.h | 13 |
2 files changed, 26 insertions, 2 deletions
diff --git a/Libraries/LibWeb/DOM/Window.cpp b/Libraries/LibWeb/DOM/Window.cpp index 05868bcf86..cb76b91bea 100644 --- a/Libraries/LibWeb/DOM/Window.cpp +++ b/Libraries/LibWeb/DOM/Window.cpp @@ -28,6 +28,8 @@ #include <LibGUI/MessageBox.h> #include <LibJS/Runtime/Function.h> #include <LibWeb/DOM/Document.h> +#include <LibWeb/DOM/Event.h> +#include <LibWeb/DOM/EventDispatcher.h> #include <LibWeb/DOM/Timer.h> #include <LibWeb/DOM/Window.h> #include <LibWeb/HighResolutionTime/Performance.h> @@ -42,7 +44,8 @@ NonnullRefPtr<Window> Window::create_with_document(Document& document) } Window::Window(Document& document) - : m_document(document) + : EventTarget(static_cast<Bindings::ScriptExecutionContext&>(document)) + , m_document(document) , m_performance(make<HighResolutionTime::Performance>(*this)) { } @@ -157,4 +160,14 @@ void Window::did_call_location_reload(Badge<Bindings::LocationObject>) frame->loader().load(document().url(), FrameLoader::Type::Reload); } +void Window::dispatch_event(NonnullRefPtr<Event> event) +{ + EventDispatcher::dispatch(*this, event); +} + +Bindings::EventTargetWrapper* Window::create_wrapper(JS::GlobalObject&) +{ + ASSERT_NOT_REACHED(); +} + } diff --git a/Libraries/LibWeb/DOM/Window.h b/Libraries/LibWeb/DOM/Window.h index 9844141286..5cb4c01363 100644 --- a/Libraries/LibWeb/DOM/Window.h +++ b/Libraries/LibWeb/DOM/Window.h @@ -32,14 +32,25 @@ #include <AK/RefPtr.h> #include <LibWeb/Bindings/WindowObject.h> #include <LibWeb/Bindings/Wrappable.h> +#include <LibWeb/DOM/EventTarget.h> namespace Web::DOM { -class Window : public RefCounted<Window> { +class Window final + : public RefCounted<Window> + , public EventTarget { public: static NonnullRefPtr<Window> create_with_document(Document&); ~Window(); + using RefCounted::ref; + using RefCounted::unref; + + virtual void ref_event_target() override { RefCounted::ref(); } + virtual void unref_event_target() override { RefCounted::unref(); } + virtual void dispatch_event(NonnullRefPtr<Event>) override; + virtual Bindings::EventTargetWrapper* create_wrapper(JS::GlobalObject&) override; + const Document& document() const { return m_document; } Document& document() { return m_document; } |