EventHandler.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <AK/Variant.h>
  9. #include <LibJS/Heap/Cell.h>
  10. #include <LibWeb/Bindings/CallbackType.h>
  11. namespace Web::HTML {
  12. class EventHandler final : public JS::Cell {
  13. public:
  14. explicit EventHandler(String);
  15. explicit EventHandler(Bindings::CallbackType&);
  16. // Either uncompiled source code or a callback.
  17. // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-value
  18. // NOTE: This does not contain Empty as part of the optimization of not allocating all event handler attributes up front.
  19. // 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.
  20. // https://html.spec.whatwg.org/multipage/webappapis.html#internal-raw-uncompiled-handler
  21. Variant<String, Bindings::CallbackType*> value;
  22. // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-listener
  23. DOM::DOMEventListener* listener { nullptr };
  24. private:
  25. virtual StringView class_name() const override { return "EventHandler"sv; }
  26. virtual void visit_edges(Cell::Visitor&) override;
  27. };
  28. }