2020-07-31 23:04:26 -03:00
|
|
|
/*
|
2021-04-28 17:46:44 -03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2024-11-08 08:51:45 -03:00
|
|
|
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
|
2020-07-31 23:04:26 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-31 23:04:26 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-01-16 17:37:18 -03:00
|
|
|
#include <AK/Forward.h>
|
2023-01-28 19:23:16 -03:00
|
|
|
#include <LibWeb/ARIA/Roles.h>
|
2020-07-31 23:04:26 -03:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2024-11-08 08:51:45 -03:00
|
|
|
#include <LibWeb/HTML/ToggleTaskTracker.h>
|
2020-07-31 23:04:26 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
|
|
|
|
class HTMLDialogElement final : public HTMLElement {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLDialogElement, HTMLElement);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLDialogElement);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2020-07-31 23:04:26 -03:00
|
|
|
public:
|
2022-08-28 08:42:07 -03:00
|
|
|
virtual ~HTMLDialogElement() override;
|
2020-07-31 23:04:26 -03:00
|
|
|
|
2025-01-23 13:37:18 -03:00
|
|
|
virtual void removed_from(Node* old_parent, Node& old_root) override;
|
2024-03-28 12:53:27 -03:00
|
|
|
|
2025-08-22 06:04:24 -03:00
|
|
|
// ^EventTarget
|
|
|
|
|
virtual bool is_focusable() const override { return true; }
|
|
|
|
|
|
2023-09-02 14:23:04 -03:00
|
|
|
String return_value() const;
|
|
|
|
|
void set_return_value(String);
|
|
|
|
|
|
2025-06-04 02:35:43 -03:00
|
|
|
static WebIDL::ExceptionOr<void> show_a_modal_dialog(HTMLDialogElement&, GC::Ptr<DOM::Element> source);
|
|
|
|
|
|
|
|
|
|
void close_the_dialog(Optional<String> result, GC::Ptr<DOM::Element> source);
|
2025-06-04 02:35:43 -03:00
|
|
|
void request_close_the_dialog(Optional<String> return_value, GC::Ptr<DOM::Element> source);
|
2025-01-30 11:50:23 -03:00
|
|
|
|
2024-02-13 19:37:16 -03:00
|
|
|
WebIDL::ExceptionOr<void> show();
|
2024-03-28 12:53:27 -03:00
|
|
|
WebIDL::ExceptionOr<void> show_modal();
|
2023-09-02 14:23:04 -03:00
|
|
|
void close(Optional<String> return_value);
|
2025-01-16 17:37:18 -03:00
|
|
|
void request_close(Optional<String> return_value);
|
2023-09-02 14:23:04 -03:00
|
|
|
|
2025-04-28 20:44:49 -03:00
|
|
|
static void light_dismiss_open_dialogs(UIEvents::PointerEvent const&, GC::Ptr<DOM::Node>);
|
|
|
|
|
|
2022-11-28 20:58:13 -03:00
|
|
|
// https://www.w3.org/TR/html-aria/#el-dialog
|
2023-01-28 19:23:16 -03:00
|
|
|
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::dialog; }
|
2022-11-28 20:58:13 -03:00
|
|
|
|
2024-07-01 20:36:36 -03:00
|
|
|
bool is_modal() const { return m_is_modal; }
|
2025-04-17 10:40:48 -03:00
|
|
|
void set_is_modal(bool);
|
2024-07-01 20:36:36 -03:00
|
|
|
|
2025-11-27 10:52:14 -03:00
|
|
|
bool is_valid_command(String&) override;
|
|
|
|
|
void command_steps(DOM::Element&, String&) override;
|
2025-04-04 09:30:56 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
private:
|
2022-02-18 17:00:52 -03:00
|
|
|
HTMLDialogElement(DOM::Document&, DOM::QualifiedName);
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2024-06-22 19:09:51 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2023-09-02 14:23:04 -03:00
|
|
|
|
2025-12-01 14:26:50 -03:00
|
|
|
virtual void inserted() override;
|
|
|
|
|
virtual void attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
|
|
|
|
|
2025-06-04 02:35:43 -03:00
|
|
|
void queue_a_dialog_toggle_event_task(String old_state, String new_state, GC::Ptr<DOM::Element> source);
|
2024-02-13 19:37:16 -03:00
|
|
|
|
2025-12-01 14:26:50 -03:00
|
|
|
void run_dialog_setup_steps();
|
|
|
|
|
void run_dialog_cleanup_steps();
|
2024-02-13 19:37:16 -03:00
|
|
|
void run_dialog_focusing_steps();
|
|
|
|
|
|
2025-01-24 09:44:17 -03:00
|
|
|
void set_close_watcher();
|
|
|
|
|
|
2025-04-28 20:44:49 -03:00
|
|
|
static GC::Ptr<HTMLDialogElement> nearest_clicked_dialog(UIEvents::PointerEvent const&, GC::Ptr<DOM::Node>);
|
|
|
|
|
|
2023-09-02 14:23:04 -03:00
|
|
|
String m_return_value;
|
2024-03-28 12:53:27 -03:00
|
|
|
bool m_is_modal { false };
|
2025-01-16 17:37:18 -03:00
|
|
|
Optional<String> m_request_close_return_value;
|
2025-06-04 02:35:43 -03:00
|
|
|
GC::Ptr<DOM::Element> m_request_close_source_element;
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<CloseWatcher> m_close_watcher;
|
2024-11-08 08:51:45 -03:00
|
|
|
|
2025-12-01 14:14:29 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#enable-close-watcher-for-requestclose()
|
|
|
|
|
bool m_enable_close_watcher_for_request_close { false };
|
|
|
|
|
|
2024-11-08 08:51:45 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-toggle-task-tracker
|
|
|
|
|
Optional<ToggleTaskTracker> m_dialog_toggle_task_tracker;
|
2025-09-11 15:17:37 -03:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#previously-focused-element
|
|
|
|
|
GC::Ptr<Node> m_previously_focused_element;
|
2020-07-31 23:04:26 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|