HTMLDialogElement.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibWeb/ARIA/Roles.h>
  9. #include <LibWeb/HTML/HTMLElement.h>
  10. #include <LibWeb/HTML/ToggleTaskTracker.h>
  11. namespace Web::HTML {
  12. class HTMLDialogElement final : public HTMLElement {
  13. WEB_PLATFORM_OBJECT(HTMLDialogElement, HTMLElement);
  14. GC_DECLARE_ALLOCATOR(HTMLDialogElement);
  15. public:
  16. virtual ~HTMLDialogElement() override;
  17. virtual void removed_from(Node*) override;
  18. String return_value() const;
  19. void set_return_value(String);
  20. WebIDL::ExceptionOr<void> show();
  21. WebIDL::ExceptionOr<void> show_modal();
  22. void close(Optional<String> return_value);
  23. // https://www.w3.org/TR/html-aria/#el-dialog
  24. virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::dialog; }
  25. bool is_modal() const { return m_is_modal; }
  26. private:
  27. HTMLDialogElement(DOM::Document&, DOM::QualifiedName);
  28. virtual void initialize(JS::Realm&) override;
  29. virtual void visit_edges(Cell::Visitor&) override;
  30. void queue_a_dialog_toggle_event_task(String old_state, String new_state);
  31. void close_the_dialog(Optional<String> result);
  32. void run_dialog_focusing_steps();
  33. String m_return_value;
  34. bool m_is_modal { false };
  35. GC::Ptr<CloseWatcher> m_close_watcher;
  36. // https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-toggle-task-tracker
  37. Optional<ToggleTaskTracker> m_dialog_toggle_task_tracker;
  38. };
  39. }