EventHandler.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2021, 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/Handle.h>
  10. #include <LibJS/Runtime/FunctionObject.h>
  11. #include <LibWeb/Bindings/CallbackType.h>
  12. #include <LibWeb/DOM/DOMEventListener.h>
  13. namespace Web::HTML {
  14. struct EventHandler {
  15. EventHandler(String s)
  16. : value(move(s))
  17. {
  18. }
  19. EventHandler(Bindings::CallbackType c)
  20. : value(move(c))
  21. {
  22. }
  23. // Either uncompiled source code or a callback.
  24. // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-value
  25. // NOTE: This does not contain Empty as part of the optimization of not allocating all event handler attributes up front.
  26. // 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.
  27. // https://html.spec.whatwg.org/multipage/webappapis.html#internal-raw-uncompiled-handler
  28. Variant<String, Bindings::CallbackType> value;
  29. // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-listener
  30. RefPtr<DOM::DOMEventListener> listener;
  31. };
  32. }