| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-02-15 00:25:51 +01:00
										 |  |  |  * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 11:59:38 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/DOM/Element.h>
 | 
					
						
							| 
									
										
										
										
											2021-02-03 22:47:50 +01:00
										 |  |  | #include <LibWeb/HTML/EventNames.h>
 | 
					
						
							|  |  |  | #include <LibWeb/HTML/GlobalEventHandlers.h>
 | 
					
						
							| 
									
										
										
										
											2023-06-18 16:22:10 +01:00
										 |  |  | #include <LibWeb/HTML/TokenizedFeatures.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-29 11:59:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 18:20:36 +02:00
										 |  |  | namespace Web::HTML { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-04 22:56:42 -03:00
										 |  |  | // https://html.spec.whatwg.org/multipage/dom.html#attr-dir
 | 
					
						
							|  |  |  | #define ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTES   \
 | 
					
						
							|  |  |  |     __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(ltr) \ | 
					
						
							|  |  |  |     __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(rtl) \ | 
					
						
							|  |  |  |     __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(auto) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 22:47:50 +01:00
										 |  |  | class HTMLElement | 
					
						
							|  |  |  |     : public DOM::Element | 
					
						
							|  |  |  |     , public HTML::GlobalEventHandlers { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(HTMLElement, DOM::Element); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(HTMLElement); | 
					
						
							| 
									
										
										
										
											2020-06-21 14:35:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-09-29 11:59:38 +02:00
										 |  |  |     virtual ~HTMLElement() override; | 
					
						
							| 
									
										
										
										
											2019-09-29 12:24:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-10 15:00:58 +03:30
										 |  |  |     Optional<String> title() const { return attribute(HTML::AttributeNames::title); } | 
					
						
							| 
									
										
										
										
											2019-09-29 12:24:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 16:42:25 +12:00
										 |  |  |     StringView dir() const; | 
					
						
							|  |  |  |     void set_dir(String const&); | 
					
						
							| 
									
										
										
										
											2022-11-04 22:56:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-03 02:57:28 +01:00
										 |  |  |     virtual bool is_editable() const final; | 
					
						
							| 
									
										
										
										
											2024-02-23 21:29:43 +01:00
										 |  |  |     virtual bool is_focusable() const override; | 
					
						
							| 
									
										
										
										
											2024-02-25 07:00:04 +01:00
										 |  |  |     bool is_content_editable() const; | 
					
						
							| 
									
										
										
										
											2023-09-03 16:42:25 +12:00
										 |  |  |     StringView content_editable() const; | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_content_editable(StringView); | 
					
						
							| 
									
										
										
										
											2020-08-03 02:57:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 16:42:25 +12:00
										 |  |  |     String inner_text(); | 
					
						
							| 
									
										
										
										
											2020-11-11 09:46:53 +00:00
										 |  |  |     void set_inner_text(StringView); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 18:26:44 +02:00
										 |  |  |     [[nodiscard]] String outer_text(); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_outer_text(String); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 01:35:19 +02:00
										 |  |  |     int offset_top() const; | 
					
						
							|  |  |  |     int offset_left() const; | 
					
						
							|  |  |  |     int offset_width() const; | 
					
						
							|  |  |  |     int offset_height() const; | 
					
						
							| 
									
										
										
										
											2023-12-10 13:47:16 +01:00
										 |  |  |     JS::GCPtr<Element> offset_parent() const; | 
					
						
							| 
									
										
										
										
											2021-04-15 20:48:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 21:53:18 +00:00
										 |  |  |     bool cannot_navigate() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     DOMStringMap* dataset() { return m_dataset.ptr(); } | 
					
						
							|  |  |  |     DOMStringMap const* dataset() const { return m_dataset.ptr(); } | 
					
						
							| 
									
										
										
										
											2021-09-26 15:24:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-06 18:46:26 +01:00
										 |  |  |     void focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-15 00:25:51 +01:00
										 |  |  |     void click(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-02 14:42:47 -06:00
										 |  |  |     void blur(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 17:55:48 +02:00
										 |  |  |     [[nodiscard]] String access_key_label() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-09 11:26:59 +02:00
										 |  |  |     bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted); | 
					
						
							| 
									
										
										
										
											2022-02-25 20:45:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 21:03:30 +00:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/forms.html#category-label
 | 
					
						
							|  |  |  |     virtual bool is_labelable() const { return false; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-28 22:23:16 +00:00
										 |  |  |     virtual Optional<ARIA::Role> default_role() const override; | 
					
						
							| 
									
										
										
										
											2022-11-28 17:58:13 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-20 13:34:37 +13:00
										 |  |  |     String get_an_elements_target() const; | 
					
						
							| 
									
										
										
										
											2023-06-18 16:22:10 +01:00
										 |  |  |     TokenizedFeature::NoOpener get_an_elements_noopener(StringView target) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 22:47:50 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     HTMLElement(DOM::Document&, DOM::QualifiedName); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2022-09-03 18:49:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 18:10:36 +13:00
										 |  |  |     virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override; | 
					
						
							| 
									
										
										
										
											2021-02-03 22:47:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 12:24:36 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-07-27 16:04:31 +02:00
										 |  |  |     virtual bool is_html_element() const final { return true; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 22:47:50 +01:00
										 |  |  |     // ^HTML::GlobalEventHandlers
 | 
					
						
							| 
									
										
										
										
											2024-03-10 08:41:18 +01:00
										 |  |  |     virtual JS::GCPtr<DOM::EventTarget> global_event_handlers_to_event_target(FlyString const&) override { return *this; } | 
					
						
							| 
									
										
										
										
											2024-02-24 02:43:57 +01:00
										 |  |  |     virtual void did_receive_focus() override; | 
					
						
							| 
									
										
										
										
											2021-02-03 22:47:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 18:26:44 +02:00
										 |  |  |     [[nodiscard]] String get_the_text_steps(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 20:32:44 +01:00
										 |  |  |     JS::GCPtr<DOMStringMap> m_dataset; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-03 02:57:28 +01:00
										 |  |  |     enum class ContentEditableState { | 
					
						
							|  |  |  |         True, | 
					
						
							|  |  |  |         False, | 
					
						
							|  |  |  |         Inherit, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2023-05-15 10:08:13 +02:00
										 |  |  |     ContentEditableState m_content_editable_state { ContentEditableState::Inherit }; | 
					
						
							| 
									
										
										
										
											2021-09-26 15:24:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-06 18:46:26 +01:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/interaction.html#locked-for-focus
 | 
					
						
							|  |  |  |     bool m_locked_for_focus { false }; | 
					
						
							| 
									
										
										
										
											2022-02-15 00:25:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag
 | 
					
						
							|  |  |  |     bool m_click_in_progress { false }; | 
					
						
							| 
									
										
										
										
											2019-09-29 11:59:38 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-10-06 20:37:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-07-27 16:04:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::DOM { | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | inline bool Node::fast_is<HTML::HTMLElement>() const { return is_html_element(); } | 
					
						
							|  |  |  | } |