Serenity Operating System
1/*
2 * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/DeprecatedString.h>
10#include <AK/Variant.h>
11#include <LibJS/Heap/Cell.h>
12#include <LibWeb/WebIDL/CallbackType.h>
13
14namespace Web::HTML {
15
16class EventHandler final : public JS::Cell {
17public:
18 explicit EventHandler(DeprecatedString);
19 explicit EventHandler(WebIDL::CallbackType&);
20
21 // Either uncompiled source code or a callback.
22 // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-value
23 // NOTE: This does not contain Empty as part of the optimization of not allocating all event handler attributes up front.
24 // FIXME: The string should actually be an "internal raw uncompiled handler" struct. This struct is just the uncompiled source code plus a source location for reporting parse errors.
25 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-raw-uncompiled-handler
26 Variant<DeprecatedString, WebIDL::CallbackType*> value;
27
28 // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-listener
29 DOM::DOMEventListener* listener { nullptr };
30
31private:
32 virtual StringView class_name() const override { return "EventHandler"sv; }
33 virtual void visit_edges(Cell::Visitor&) override;
34};
35
36}