1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00
serenity/Userland/Libraries/LibWeb/UIEvents/UIEvent.h
Andreas Kling 6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00

55 lines
1.4 KiB
C++

/*
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/RefPtr.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/Window.h>
namespace Web::UIEvents {
struct UIEventInit : public DOM::EventInit {
JS::GCPtr<HTML::Window> view;
int detail { 0 };
};
class UIEvent : public DOM::Event {
WEB_PLATFORM_OBJECT(UIEvent, DOM::Event);
public:
static UIEvent* create(HTML::Window&, FlyString const& type);
static UIEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, UIEventInit const& event_init);
UIEvent(HTML::Window&, FlyString const& event_name);
UIEvent(HTML::Window&, FlyString const& event_name, UIEventInit const& event_init);
virtual ~UIEvent() override;
HTML::Window const* view() const { return m_view.ptr(); }
int detail() const { return m_detail; }
virtual u32 which() const { return 0; }
void init_ui_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, int detail)
{
init_event(type, bubbles, cancelable);
m_view = view;
m_detail = detail;
}
protected:
virtual void visit_edges(Cell::Visitor&) override;
JS::GCPtr<HTML::Window> m_view;
int m_detail { 0 };
};
}
namespace Web::Bindings {
inline JS::Object* wrap(JS::Realm&, Web::UIEvents::UIEvent& object) { return &object; }
using UIEventWrapper = Web::UIEvents::UIEvent;
}