EventHandler.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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/DeprecatedString.h>
  8. #include <AK/Variant.h>
  9. #include <LibJS/Heap/Cell.h>
  10. #include <LibWeb/WebIDL/CallbackType.h>
  11. namespace Web::HTML {
  12. class EventHandler final : public JS::Cell {
  13. JS_CELL(EventHandler, JS::Cell);
  14. public:
  15. explicit EventHandler(DeprecatedString);
  16. explicit EventHandler(WebIDL::CallbackType&);
  17. // Either uncompiled source code or a callback.
  18. // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-value
  19. // NOTE: This does not contain Empty as part of the optimization of not allocating all event handler attributes up front.
  20. // 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.
  21. // https://html.spec.whatwg.org/multipage/webappapis.html#internal-raw-uncompiled-handler
  22. Variant<DeprecatedString, JS::GCPtr<WebIDL::CallbackType>> value;
  23. // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-listener
  24. JS::GCPtr<DOM::DOMEventListener> listener;
  25. private:
  26. virtual void visit_edges(Cell::Visitor&) override;
  27. };
  28. }