2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2025-04-18 05:27:59 -03:00
|
|
|
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-10-20 05:37:44 -03:00
|
|
|
#include <AK/DistinctNumeric.h>
|
2023-03-18 11:59:48 -03:00
|
|
|
#include <AK/FlyString.h>
|
2024-07-23 17:55:48 -03:00
|
|
|
#include <AK/GenericShorthands.h>
|
2021-06-07 12:32:24 -03:00
|
|
|
#include <AK/JsonObjectSerializer.h>
|
2020-07-26 12:16:18 -03:00
|
|
|
#include <AK/TypeCasts.h>
|
2019-06-15 13:55:47 -03:00
|
|
|
#include <AK/Vector.h>
|
2025-01-12 12:38:05 -03:00
|
|
|
#include <LibWeb/CSS/InvalidationSet.h>
|
2022-12-11 13:56:37 -03:00
|
|
|
#include <LibWeb/DOM/AccessibilityTreeNode.h>
|
2020-03-18 11:22:31 -03:00
|
|
|
#include <LibWeb/DOM/EventTarget.h>
|
2025-02-14 12:31:44 -03:00
|
|
|
#include <LibWeb/DOM/NodeType.h>
|
2023-09-05 14:07:35 -03:00
|
|
|
#include <LibWeb/DOM/Slottable.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2025-03-03 10:04:14 -03:00
|
|
|
#include <LibWeb/HTML/XMLSerializer.h>
|
2024-05-04 10:47:04 -03:00
|
|
|
#include <LibWeb/TraversalDecision.h>
|
2025-02-03 11:25:24 -03:00
|
|
|
#include <LibWeb/TreeNode.h>
|
2022-09-25 13:03:42 -03:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2019-06-15 13:55:47 -03:00
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
namespace Web::DOM {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2023-02-05 14:21:59 -03:00
|
|
|
enum class NameOrDescription {
|
|
|
|
|
Name,
|
|
|
|
|
Description
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-15 23:04:55 -03:00
|
|
|
struct GetRootNodeOptions {
|
|
|
|
|
bool composed { false };
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-09 09:44:58 -03:00
|
|
|
enum class FragmentSerializationMode {
|
|
|
|
|
Inner,
|
|
|
|
|
Outer,
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-01 09:11:32 -03:00
|
|
|
enum class IsDescendant {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-19 11:21:48 -03:00
|
|
|
enum class ShouldComputeRole {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 05:01:08 -03:00
|
|
|
#define ENUMERATE_STYLE_INVALIDATION_REASONS(X) \
|
|
|
|
|
X(AdoptedStyleSheetsList) \
|
2025-08-07 09:37:11 -03:00
|
|
|
X(BaseURLChanged) \
|
2024-09-04 05:01:08 -03:00
|
|
|
X(CSSFontLoaded) \
|
|
|
|
|
X(CSSImportRule) \
|
2025-04-24 09:25:50 -03:00
|
|
|
X(CSSStylePropertiesRemoveProperty) \
|
|
|
|
|
X(CSSStylePropertiesSetProperty) \
|
2025-04-12 06:44:41 -03:00
|
|
|
X(CSSStylePropertiesTextChange) \
|
2024-11-06 11:49:22 -03:00
|
|
|
X(CustomElementStateChange) \
|
2025-07-03 13:32:10 -03:00
|
|
|
X(CustomStateSetChange) \
|
2024-09-04 05:01:08 -03:00
|
|
|
X(DidLoseFocus) \
|
|
|
|
|
X(DidReceiveFocus) \
|
|
|
|
|
X(EditingInsertion) \
|
2025-08-30 13:55:52 -03:00
|
|
|
X(EditingDeletion) \
|
2024-09-04 05:01:08 -03:00
|
|
|
X(ElementAttributeChange) \
|
|
|
|
|
X(ElementSetShadowRoot) \
|
2025-08-18 18:20:20 -03:00
|
|
|
X(HTMLDialogElementSetIsModal) \
|
2024-11-06 14:00:18 -03:00
|
|
|
X(HTMLHyperlinkElementHrefChange) \
|
2024-12-23 13:51:10 -03:00
|
|
|
X(HTMLIFrameElementGeometryChange) \
|
2024-09-04 05:01:08 -03:00
|
|
|
X(HTMLInputElementSetChecked) \
|
2025-01-31 12:34:34 -03:00
|
|
|
X(HTMLInputElementSetIsOpen) \
|
2024-09-04 05:01:08 -03:00
|
|
|
X(HTMLObjectElementUpdateLayoutAndChildObjects) \
|
2025-01-03 10:46:24 -03:00
|
|
|
X(HTMLOptionElementSelectedChange) \
|
2024-09-04 05:01:08 -03:00
|
|
|
X(HTMLSelectElementSetIsOpen) \
|
2025-03-04 10:50:11 -03:00
|
|
|
X(MediaListSetMediaText) \
|
|
|
|
|
X(MediaListAppendMedium) \
|
|
|
|
|
X(MediaListDeleteMedium) \
|
2024-09-04 05:01:08 -03:00
|
|
|
X(MediaQueryChangedMatchState) \
|
|
|
|
|
X(NavigableSetViewportSize) \
|
|
|
|
|
X(NodeInsertBefore) \
|
|
|
|
|
X(NodeRemove) \
|
|
|
|
|
X(NodeSetTextContent) \
|
|
|
|
|
X(Other) \
|
|
|
|
|
X(SetSelectorText) \
|
|
|
|
|
X(SettingsChange) \
|
|
|
|
|
X(StyleSheetDeleteRule) \
|
|
|
|
|
X(StyleSheetInsertRule) \
|
|
|
|
|
X(StyleSheetListAddSheet) \
|
2025-04-17 09:43:56 -03:00
|
|
|
X(StyleSheetListRemoveSheet)
|
2024-09-04 05:01:08 -03:00
|
|
|
|
|
|
|
|
enum class StyleInvalidationReason {
|
|
|
|
|
#define __ENUMERATE_STYLE_INVALIDATION_REASON(reason) reason,
|
|
|
|
|
ENUMERATE_STYLE_INVALIDATION_REASONS(__ENUMERATE_STYLE_INVALIDATION_REASON)
|
|
|
|
|
#undef __ENUMERATE_STYLE_INVALIDATION_REASON
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-08 09:52:23 -03:00
|
|
|
#define ENUMERATE_SET_NEEDS_LAYOUT_REASONS(X) \
|
|
|
|
|
X(CharacterDataReplaceData) \
|
|
|
|
|
X(FinalizeACrossDocumentNavigation) \
|
2025-07-27 10:55:16 -03:00
|
|
|
X(GeneratedContentImageFinishedLoading) \
|
2025-05-19 06:04:13 -03:00
|
|
|
X(HTMLCanvasElementWidthOrHeightChange) \
|
2025-03-08 09:52:23 -03:00
|
|
|
X(HTMLImageElementReactToChangesInTheEnvironment) \
|
|
|
|
|
X(HTMLImageElementUpdateTheImageData) \
|
|
|
|
|
X(HTMLVideoElementSetVideoTrack) \
|
|
|
|
|
X(KeyframeEffect) \
|
|
|
|
|
X(LayoutTreeUpdate) \
|
|
|
|
|
X(NavigableSetViewportSize) \
|
|
|
|
|
X(SVGImageElementFetchTheDocument) \
|
2025-08-06 18:52:29 -03:00
|
|
|
X(SVGImageFilterFetch) \
|
2025-03-08 09:52:23 -03:00
|
|
|
X(StyleChange)
|
|
|
|
|
|
|
|
|
|
enum class SetNeedsLayoutReason {
|
|
|
|
|
#define ENUMERATE_SET_NEEDS_LAYOUT_REASON(e) e,
|
|
|
|
|
ENUMERATE_SET_NEEDS_LAYOUT_REASONS(ENUMERATE_SET_NEEDS_LAYOUT_REASON)
|
|
|
|
|
#undef ENUMERATE_SET_NEEDS_LAYOUT_REASON
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] StringView to_string(SetNeedsLayoutReason);
|
|
|
|
|
|
2025-04-19 05:49:33 -03:00
|
|
|
#define ENUMERATE_SET_NEEDS_LAYOUT_TREE_UPDATE_REASONS(X) \
|
|
|
|
|
X(ElementSetInnerHTML) \
|
2025-05-09 11:35:07 -03:00
|
|
|
X(DetailsElementOpenedOrClosed) \
|
2025-04-19 05:49:33 -03:00
|
|
|
X(HTMLInputElementSrcAttribute) \
|
2025-05-10 14:08:24 -03:00
|
|
|
X(HTMLOListElementOrdinalValues) \
|
2025-04-19 05:49:33 -03:00
|
|
|
X(HTMLObjectElementUpdateLayoutAndChildObjects) \
|
|
|
|
|
X(KeyframeEffect) \
|
|
|
|
|
X(NodeInsertBefore) \
|
|
|
|
|
X(NodeInsertBeforeWithDisplayContents) \
|
|
|
|
|
X(NodeRemove) \
|
|
|
|
|
X(NodeSetTextContent) \
|
|
|
|
|
X(None) \
|
|
|
|
|
X(SVGGraphicsElementTransformChange) \
|
2025-08-27 18:19:12 -03:00
|
|
|
X(SVGViewBoxChange) \
|
2025-04-19 05:49:33 -03:00
|
|
|
X(StyleChange)
|
|
|
|
|
|
|
|
|
|
enum class SetNeedsLayoutTreeUpdateReason {
|
|
|
|
|
#define ENUMERATE_SET_NEEDS_LAYOUT_TREE_UPDATE_REASON(e) e,
|
|
|
|
|
ENUMERATE_SET_NEEDS_LAYOUT_TREE_UPDATE_REASONS(ENUMERATE_SET_NEEDS_LAYOUT_TREE_UPDATE_REASON)
|
|
|
|
|
#undef ENUMERATE_SET_NEEDS_LAYOUT_TREE_UPDATE_REASON
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] StringView to_string(SetNeedsLayoutTreeUpdateReason);
|
|
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API Node : public EventTarget
|
2025-02-03 11:25:24 -03:00
|
|
|
, public TreeNode<Node> {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(Node, EventTarget);
|
2020-03-18 11:22:31 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
public:
|
2021-02-10 14:22:20 -03:00
|
|
|
ParentNode* parent_or_shadow_host();
|
2022-04-01 14:58:27 -03:00
|
|
|
ParentNode const* parent_or_shadow_host() const { return const_cast<Node*>(this)->parent_or_shadow_host(); }
|
2021-02-10 14:22:20 -03:00
|
|
|
|
2022-11-05 13:06:19 -03:00
|
|
|
Element* parent_or_shadow_host_element();
|
|
|
|
|
Element const* parent_or_shadow_host_element() const { return const_cast<Node*>(this)->parent_or_shadow_host_element(); }
|
|
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
virtual ~Node();
|
|
|
|
|
|
|
|
|
|
NodeType type() const { return m_type; }
|
|
|
|
|
bool is_element() const { return type() == NodeType::ELEMENT_NODE; }
|
2024-11-19 11:35:31 -03:00
|
|
|
bool is_text() const { return type() == NodeType::TEXT_NODE || type() == NodeType::CDATA_SECTION_NODE; }
|
2024-11-20 07:31:59 -03:00
|
|
|
bool is_exclusive_text() const { return type() == NodeType::TEXT_NODE; }
|
2019-06-15 13:55:47 -03:00
|
|
|
bool is_document() const { return type() == NodeType::DOCUMENT_NODE; }
|
2019-10-09 15:17:01 -03:00
|
|
|
bool is_document_type() const { return type() == NodeType::DOCUMENT_TYPE_NODE; }
|
2019-10-12 18:26:47 -03:00
|
|
|
bool is_comment() const { return type() == NodeType::COMMENT_NODE; }
|
2024-07-23 17:55:48 -03:00
|
|
|
bool is_character_data() const { return first_is_one_of(type(), NodeType::TEXT_NODE, NodeType::COMMENT_NODE, NodeType::CDATA_SECTION_NODE, NodeType::PROCESSING_INSTRUCTION_NODE); }
|
2019-11-06 16:27:53 -03:00
|
|
|
bool is_document_fragment() const { return type() == NodeType::DOCUMENT_FRAGMENT_NODE; }
|
2020-03-25 14:48:10 -03:00
|
|
|
bool is_parent_node() const { return is_element() || is_document() || is_document_fragment(); }
|
2024-03-23 12:46:08 -03:00
|
|
|
bool is_slottable() const { return is_element() || is_text() || is_cdata_section(); }
|
2022-01-31 15:05:54 -03:00
|
|
|
bool is_attribute() const { return type() == NodeType::ATTRIBUTE_NODE; }
|
2022-06-27 17:20:59 -03:00
|
|
|
bool is_cdata_section() const { return type() == NodeType::CDATA_SECTION_NODE; }
|
2022-03-13 13:21:27 -03:00
|
|
|
virtual bool is_shadow_root() const { return false; }
|
2019-06-15 13:55:47 -03:00
|
|
|
|
2021-08-05 05:26:09 -03:00
|
|
|
virtual bool requires_svg_container() const { return false; }
|
|
|
|
|
virtual bool is_svg_container() const { return false; }
|
2023-05-24 00:41:55 -03:00
|
|
|
virtual bool is_svg_element() const { return false; }
|
2023-08-03 08:26:29 -03:00
|
|
|
virtual bool is_svg_graphics_element() const { return false; }
|
2023-09-22 17:56:49 -03:00
|
|
|
virtual bool is_svg_script_element() const { return false; }
|
2024-08-23 06:42:35 -03:00
|
|
|
virtual bool is_svg_style_element() const { return false; }
|
2022-03-12 12:08:40 -03:00
|
|
|
virtual bool is_svg_svg_element() const { return false; }
|
2023-06-22 20:15:03 -03:00
|
|
|
virtual bool is_svg_use_element() const { return false; }
|
2025-07-12 10:26:50 -03:00
|
|
|
virtual bool is_svg_view_element() const { return false; }
|
2025-04-18 05:27:59 -03:00
|
|
|
virtual bool is_svg_a_element() const { return false; }
|
|
|
|
|
virtual bool is_svg_foreign_object_element() const { return false; }
|
2021-08-05 05:26:09 -03:00
|
|
|
|
2021-09-29 17:23:28 -03:00
|
|
|
bool in_a_document_tree() const;
|
|
|
|
|
|
2021-03-06 14:06:25 -03:00
|
|
|
// NOTE: This is intended for the JS bindings.
|
|
|
|
|
u16 node_type() const { return (u16)m_type; }
|
|
|
|
|
|
2024-12-06 07:41:20 -03:00
|
|
|
bool is_editable() const;
|
|
|
|
|
bool is_editing_host() const;
|
|
|
|
|
bool is_editable_or_editing_host() const { return is_editable() || is_editing_host(); }
|
2025-07-31 07:29:05 -03:00
|
|
|
GC::Ptr<Node> editing_host();
|
2020-08-02 11:05:59 -03:00
|
|
|
|
2023-07-13 14:54:03 -03:00
|
|
|
virtual bool is_dom_node() const final { return true; }
|
2022-07-27 11:04:31 -03:00
|
|
|
virtual bool is_html_element() const { return false; }
|
2021-10-27 12:58:57 -03:00
|
|
|
virtual bool is_html_html_element() const { return false; }
|
2022-03-02 11:14:38 -03:00
|
|
|
virtual bool is_html_anchor_element() const { return false; }
|
2025-04-18 05:27:59 -03:00
|
|
|
virtual bool is_html_area_element() const { return false; }
|
2022-07-27 11:03:43 -03:00
|
|
|
virtual bool is_html_base_element() const { return false; }
|
2023-03-10 17:16:18 -03:00
|
|
|
virtual bool is_html_body_element() const { return false; }
|
2025-04-18 05:27:59 -03:00
|
|
|
virtual bool is_html_head_element() const { return false; }
|
2023-03-10 17:16:18 -03:00
|
|
|
virtual bool is_html_input_element() const { return false; }
|
2024-08-23 06:42:35 -03:00
|
|
|
virtual bool is_html_link_element() const { return false; }
|
2025-04-18 05:27:59 -03:00
|
|
|
virtual bool is_html_media_element() const { return false; }
|
2023-03-10 17:16:18 -03:00
|
|
|
virtual bool is_html_progress_element() const { return false; }
|
2023-05-07 02:43:21 -03:00
|
|
|
virtual bool is_html_script_element() const { return false; }
|
2024-08-23 06:42:35 -03:00
|
|
|
virtual bool is_html_style_element() const { return false; }
|
2021-09-15 19:52:10 -03:00
|
|
|
virtual bool is_html_template_element() const { return false; }
|
2023-08-22 09:55:10 -03:00
|
|
|
virtual bool is_html_table_element() const { return false; }
|
|
|
|
|
virtual bool is_html_table_section_element() const { return false; }
|
|
|
|
|
virtual bool is_html_table_row_element() const { return false; }
|
|
|
|
|
virtual bool is_html_table_cell_element() const { return false; }
|
2025-04-18 05:27:59 -03:00
|
|
|
virtual bool is_html_title_element() const { return false; }
|
2023-09-01 04:55:56 -03:00
|
|
|
virtual bool is_html_br_element() const { return false; }
|
2023-09-09 12:13:41 -03:00
|
|
|
virtual bool is_html_button_element() const { return false; }
|
2023-09-23 08:03:59 -03:00
|
|
|
virtual bool is_html_slot_element() const { return false; }
|
2023-12-24 10:41:33 -03:00
|
|
|
virtual bool is_html_embed_element() const { return false; }
|
|
|
|
|
virtual bool is_html_object_element() const { return false; }
|
|
|
|
|
virtual bool is_html_form_element() const { return false; }
|
|
|
|
|
virtual bool is_html_image_element() const { return false; }
|
2025-01-07 13:06:51 -03:00
|
|
|
virtual bool is_html_iframe_element() const { return false; }
|
2025-04-24 15:09:14 -03:00
|
|
|
virtual bool is_html_div_element() const { return false; }
|
|
|
|
|
virtual bool is_html_span_element() const { return false; }
|
2025-04-18 05:27:59 -03:00
|
|
|
virtual bool is_html_frameset_element() const { return false; }
|
|
|
|
|
virtual bool is_html_fieldset_element() const { return false; }
|
2025-04-23 11:06:11 -03:00
|
|
|
virtual bool is_html_li_element() const { return false; }
|
|
|
|
|
virtual bool is_html_menu_element() const { return false; }
|
|
|
|
|
virtual bool is_html_olist_element() const { return false; }
|
|
|
|
|
virtual bool is_html_ulist_element() const { return false; }
|
|
|
|
|
ALWAYS_INLINE bool is_html_ol_ul_menu_element() const
|
|
|
|
|
{
|
|
|
|
|
return is_html_olist_element() || is_html_ulist_element() || is_html_menu_element();
|
|
|
|
|
}
|
2022-12-12 08:20:02 -03:00
|
|
|
virtual bool is_navigable_container() const { return false; }
|
2023-11-21 15:50:09 -03:00
|
|
|
virtual bool is_lazy_loading() const { return false; }
|
2021-09-15 19:52:10 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> pre_insert(GC::Ref<Node>, GC::Ptr<Node>);
|
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> pre_remove(GC::Ref<Node>);
|
2021-04-06 15:34:49 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> append_child(GC::Ref<Node>);
|
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> remove_child(GC::Ref<Node>);
|
2022-02-21 18:21:59 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void insert_before(GC::Ref<Node> node, GC::Ptr<Node> child, bool suppress_observers = false);
|
2021-04-06 15:34:49 -03:00
|
|
|
void remove(bool suppress_observers = false);
|
|
|
|
|
void remove_all_children(bool suppress_observers = false);
|
2023-03-30 06:14:26 -03:00
|
|
|
|
|
|
|
|
enum DocumentPosition : u16 {
|
|
|
|
|
DOCUMENT_POSITION_EQUAL = 0,
|
|
|
|
|
DOCUMENT_POSITION_DISCONNECTED = 1,
|
|
|
|
|
DOCUMENT_POSITION_PRECEDING = 2,
|
|
|
|
|
DOCUMENT_POSITION_FOLLOWING = 4,
|
|
|
|
|
DOCUMENT_POSITION_CONTAINS = 8,
|
|
|
|
|
DOCUMENT_POSITION_CONTAINED_BY = 16,
|
|
|
|
|
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32,
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
u16 compare_document_position(GC::Ptr<Node> other);
|
2020-06-20 20:00:58 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> replace_child(GC::Ref<Node> node, GC::Ref<Node> child);
|
2021-05-06 20:52:23 -03:00
|
|
|
|
2025-01-11 14:37:08 -03:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> clone_node(Document* document = nullptr, bool subtree = false, Node* parent = nullptr) const;
|
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> clone_single_node(Document&) const;
|
2025-01-03 12:24:30 -03:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<Node>> clone_node_binding(bool subtree);
|
2021-04-13 20:25:10 -03:00
|
|
|
|
2025-03-07 20:45:26 -03:00
|
|
|
WebIDL::ExceptionOr<void> move_node(Node& new_parent, Node* child);
|
|
|
|
|
|
2021-03-06 14:06:25 -03:00
|
|
|
// NOTE: This is intended for the JS bindings.
|
|
|
|
|
bool has_child_nodes() const { return has_children(); }
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<NodeList> child_nodes();
|
|
|
|
|
Vector<GC::Root<Node>> children_as_vector() const;
|
2021-03-06 14:06:25 -03:00
|
|
|
|
2023-09-16 19:51:43 -03:00
|
|
|
virtual FlyString node_name() const = 0;
|
2019-09-28 17:59:16 -03:00
|
|
|
|
2023-09-16 19:51:43 -03:00
|
|
|
String base_uri() const;
|
2022-04-12 13:20:13 -03:00
|
|
|
|
2024-11-09 11:45:09 -03:00
|
|
|
virtual Optional<String> alternative_text() const;
|
|
|
|
|
|
2025-07-28 10:46:06 -03:00
|
|
|
Utf16String descendant_text_content() const;
|
|
|
|
|
Optional<Utf16String> text_content() const;
|
|
|
|
|
void set_text_content(Optional<Utf16String> const&);
|
2019-09-29 11:22:15 -03:00
|
|
|
|
2024-07-11 17:52:03 -03:00
|
|
|
WebIDL::ExceptionOr<void> normalize();
|
|
|
|
|
|
2023-09-16 19:51:43 -03:00
|
|
|
Optional<String> node_value() const;
|
|
|
|
|
void set_node_value(Optional<String> const&);
|
2022-02-18 19:11:43 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<HTML::Navigable> navigable() const;
|
2023-04-22 18:21:59 -03:00
|
|
|
|
2020-06-25 18:42:08 -03:00
|
|
|
Document& document() { return *m_document; }
|
2022-04-01 14:58:27 -03:00
|
|
|
Document const& document() const { return *m_document; }
|
2019-09-29 06:43:07 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Document> owner_document() const;
|
2021-05-02 17:03:50 -03:00
|
|
|
|
2025-08-29 09:02:52 -03:00
|
|
|
HTML::HTMLAnchorElement const* enclosing_link_element() const;
|
|
|
|
|
HTML::HTMLElement const* enclosing_html_element() const;
|
|
|
|
|
HTML::HTMLElement const* enclosing_html_element_with_attribute(FlyString const&) const;
|
2019-09-29 07:24:36 -03:00
|
|
|
|
2025-07-28 10:46:06 -03:00
|
|
|
Utf16String child_text_content() const;
|
2020-05-24 16:59:24 -03:00
|
|
|
|
2021-09-02 15:27:42 -03:00
|
|
|
Node& shadow_including_root();
|
2022-04-01 14:58:27 -03:00
|
|
|
Node const& shadow_including_root() const
|
2020-11-21 15:32:39 -03:00
|
|
|
{
|
|
|
|
|
return const_cast<Node*>(this)->shadow_including_root();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-16 12:48:15 -03:00
|
|
|
bool is_closed_shadow_hidden_from(Node const&) const;
|
|
|
|
|
|
2020-05-24 16:59:24 -03:00
|
|
|
bool is_connected() const;
|
|
|
|
|
|
2024-04-26 04:29:27 -03:00
|
|
|
[[nodiscard]] bool is_browsing_context_connected() const;
|
|
|
|
|
|
2020-06-20 17:26:54 -03:00
|
|
|
Node* parent_node() { return parent(); }
|
2022-04-01 14:58:27 -03:00
|
|
|
Node const* parent_node() const { return parent(); }
|
2020-06-20 17:26:54 -03:00
|
|
|
|
2025-04-17 23:19:19 -03:00
|
|
|
GC::Ptr<Element> parent_element();
|
|
|
|
|
GC::Ptr<Element const> parent_element() const;
|
2020-06-20 17:26:54 -03:00
|
|
|
|
2021-04-06 13:58:20 -03:00
|
|
|
virtual void inserted();
|
2024-12-10 03:34:50 -03:00
|
|
|
virtual void post_connection();
|
2025-01-23 13:37:18 -03:00
|
|
|
virtual void removed_from(Node* old_parent, Node& old_root);
|
2025-03-07 20:45:26 -03:00
|
|
|
virtual void moved_from(GC::Ptr<Node> old_parent);
|
|
|
|
|
|
2025-01-26 09:16:33 -03:00
|
|
|
struct ChildrenChangedMetadata {
|
|
|
|
|
enum class Type {
|
|
|
|
|
Inserted,
|
|
|
|
|
Removal,
|
|
|
|
|
Mutation,
|
|
|
|
|
};
|
|
|
|
|
Type type {};
|
|
|
|
|
GC::Ref<Node> node;
|
|
|
|
|
};
|
|
|
|
|
// FIXME: It would be good if we could always provide this metadata for use in optimizations.
|
|
|
|
|
virtual void children_changed(ChildrenChangedMetadata const*) { }
|
|
|
|
|
|
2021-07-05 01:33:35 -03:00
|
|
|
virtual void adopted_from(Document&) { }
|
2025-01-11 14:37:08 -03:00
|
|
|
virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) const { return {}; }
|
2019-09-29 12:40:39 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
Layout::Node const* layout_node() const { return m_layout_node; }
|
2020-11-22 11:53:01 -03:00
|
|
|
Layout::Node* layout_node() { return m_layout_node; }
|
2019-10-04 16:05:52 -03:00
|
|
|
|
2023-04-20 12:01:16 -03:00
|
|
|
Painting::PaintableBox const* paintable_box() const;
|
2023-08-06 19:59:23 -03:00
|
|
|
Painting::PaintableBox* paintable_box();
|
2022-03-10 18:46:35 -03:00
|
|
|
Painting::Paintable const* paintable() const;
|
2023-08-19 04:29:04 -03:00
|
|
|
Painting::Paintable* paintable();
|
2022-03-09 19:53:41 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void set_paintable(GC::Ptr<Painting::Paintable>);
|
2024-10-14 11:07:56 -03:00
|
|
|
void clear_paintable();
|
2023-08-19 07:00:42 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void set_layout_node(Badge<Layout::Node>, GC::Ref<Layout::Node>);
|
2023-08-01 03:23:13 -03:00
|
|
|
void detach_layout_node(Badge<Layout::TreeBuilder>);
|
2019-10-04 16:05:52 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
virtual bool is_child_allowed(Node const&) const { return true; }
|
2019-10-12 18:26:47 -03:00
|
|
|
|
2025-01-13 08:23:40 -03:00
|
|
|
[[nodiscard]] bool needs_layout_tree_update() const { return m_needs_layout_tree_update; }
|
2025-04-19 05:49:33 -03:00
|
|
|
void set_needs_layout_tree_update(bool, SetNeedsLayoutTreeUpdateReason);
|
2025-01-13 08:23:40 -03:00
|
|
|
|
|
|
|
|
[[nodiscard]] bool child_needs_layout_tree_update() const { return m_child_needs_layout_tree_update; }
|
|
|
|
|
void set_child_needs_layout_tree_update(bool b) { m_child_needs_layout_tree_update = b; }
|
|
|
|
|
|
2019-10-19 13:57:02 -03:00
|
|
|
bool needs_style_update() const { return m_needs_style_update; }
|
2020-12-13 11:19:42 -03:00
|
|
|
void set_needs_style_update(bool);
|
2025-01-26 15:00:51 -03:00
|
|
|
void set_needs_style_update_internal(bool) { m_needs_style_update = true; }
|
2019-10-19 13:57:02 -03:00
|
|
|
|
2020-12-14 08:04:30 -03:00
|
|
|
bool child_needs_style_update() const { return m_child_needs_style_update; }
|
|
|
|
|
void set_child_needs_style_update(bool b) { m_child_needs_style_update = b; }
|
|
|
|
|
|
2025-01-26 15:00:51 -03:00
|
|
|
[[nodiscard]] bool entire_subtree_needs_style_update() const { return m_entire_subtree_needs_style_update; }
|
|
|
|
|
void set_entire_subtree_needs_style_update(bool b) { m_entire_subtree_needs_style_update = b; }
|
|
|
|
|
|
2024-09-04 05:01:08 -03:00
|
|
|
void invalidate_style(StyleInvalidationReason);
|
2025-01-27 17:19:30 -03:00
|
|
|
struct StyleInvalidationOptions {
|
|
|
|
|
bool invalidate_self { false };
|
|
|
|
|
};
|
|
|
|
|
void invalidate_style(StyleInvalidationReason, Vector<CSS::InvalidationSet::Property> const&, StyleInvalidationOptions);
|
2019-10-14 13:32:02 -03:00
|
|
|
|
2020-06-25 18:42:08 -03:00
|
|
|
void set_document(Badge<Document>, Document&);
|
2025-02-21 09:01:20 -03:00
|
|
|
void set_document(Badge<NamedNodeMap>, Document&);
|
2020-06-25 18:42:08 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
virtual EventTarget* get_parent(Event const&) override;
|
2020-11-21 15:32:39 -03:00
|
|
|
|
2021-01-17 05:34:01 -03:00
|
|
|
template<typename T>
|
|
|
|
|
bool fast_is() const = delete;
|
|
|
|
|
|
2025-07-24 23:35:01 -03:00
|
|
|
WebIDL::ExceptionOr<void> ensure_pre_insertion_validity(JS::Realm&, GC::Ref<Node> node, GC::Ptr<Node> child) const;
|
2021-04-06 15:34:49 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
bool is_host_including_inclusive_ancestor_of(Node const&) const;
|
2021-04-06 15:34:49 -03:00
|
|
|
|
2022-03-30 18:28:28 -03:00
|
|
|
bool is_scripting_enabled() const;
|
2021-07-04 23:59:47 -03:00
|
|
|
bool is_scripting_disabled() const;
|
|
|
|
|
|
2021-06-07 12:32:24 -03:00
|
|
|
// Used for dumping the DOM Tree
|
|
|
|
|
void serialize_tree_as_json(JsonObjectSerializer<StringBuilder>&) const;
|
2025-07-02 12:13:52 -03:00
|
|
|
IterationDecision serialize_child_as_json(JsonArraySerializer<StringBuilder>& children_array, Node const& child) const;
|
2021-06-07 12:32:24 -03:00
|
|
|
|
2021-09-01 22:17:13 -03:00
|
|
|
bool is_shadow_including_descendant_of(Node const&) const;
|
|
|
|
|
bool is_shadow_including_inclusive_descendant_of(Node const&) const;
|
|
|
|
|
bool is_shadow_including_ancestor_of(Node const&) const;
|
|
|
|
|
bool is_shadow_including_inclusive_ancestor_of(Node const&) const;
|
|
|
|
|
|
2024-10-20 05:37:44 -03:00
|
|
|
[[nodiscard]] UniqueNodeID unique_id() const { return m_unique_id; }
|
|
|
|
|
static Node* from_unique_id(UniqueNodeID);
|
2021-08-30 11:52:08 -03:00
|
|
|
|
2025-03-03 10:04:14 -03:00
|
|
|
WebIDL::ExceptionOr<String> serialize_fragment(HTML::RequireWellFormed, FragmentSerializationMode = FragmentSerializationMode::Inner) const;
|
2021-09-13 18:42:15 -03:00
|
|
|
|
2024-06-25 16:55:58 -03:00
|
|
|
WebIDL::ExceptionOr<void> unsafely_set_html(Element&, StringView);
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void replace_all(GC::Ptr<Node>);
|
2025-07-28 10:46:06 -03:00
|
|
|
void string_replace_all(Utf16String);
|
2021-09-05 21:25:58 -03:00
|
|
|
|
2021-09-13 07:49:23 -03:00
|
|
|
bool is_same_node(Node const*) const;
|
2021-09-13 07:54:24 -03:00
|
|
|
bool is_equal_node(Node const*) const;
|
2021-09-13 07:49:23 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<Node> get_root_node(GetRootNodeOptions const& options = {});
|
2021-10-15 23:04:55 -03:00
|
|
|
|
2021-11-02 15:20:57 -03:00
|
|
|
bool is_uninteresting_whitespace_node() const;
|
|
|
|
|
|
2023-12-02 16:24:04 -03:00
|
|
|
String debug_description() const;
|
2022-02-26 04:18:14 -03:00
|
|
|
|
2022-01-31 15:05:54 -03:00
|
|
|
size_t length() const;
|
|
|
|
|
|
2023-11-18 07:22:51 -03:00
|
|
|
auto& registered_observer_list() { return m_registered_observer_list; }
|
|
|
|
|
auto const& registered_observer_list() const { return m_registered_observer_list; }
|
2022-07-11 12:37:51 -03:00
|
|
|
|
2023-11-18 07:22:51 -03:00
|
|
|
void add_registered_observer(RegisteredObserver&);
|
2022-07-11 12:37:51 -03:00
|
|
|
|
2025-03-06 19:32:43 -03:00
|
|
|
void queue_mutation_record(FlyString const& type, Optional<FlyString> const& attribute_name, Optional<FlyString> const& attribute_namespace, Optional<String> const& old_value, Vector<GC::Root<Node>> added_nodes, Vector<GC::Root<Node>> removed_nodes, Node* previous_sibling, Node* next_sibling);
|
2022-07-11 12:39:14 -03:00
|
|
|
|
2023-03-29 19:46:18 -03:00
|
|
|
// https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-descendant
|
|
|
|
|
template<typename Callback>
|
2024-05-04 10:47:04 -03:00
|
|
|
TraversalDecision for_each_shadow_including_inclusive_descendant(Callback);
|
2023-03-29 19:46:18 -03:00
|
|
|
|
2022-07-12 18:13:57 -03:00
|
|
|
// https://dom.spec.whatwg.org/#concept-shadow-including-descendant
|
|
|
|
|
template<typename Callback>
|
2024-05-04 10:47:04 -03:00
|
|
|
TraversalDecision for_each_shadow_including_descendant(Callback);
|
2022-07-12 18:13:57 -03:00
|
|
|
|
2023-09-05 14:07:35 -03:00
|
|
|
Slottable as_slottable();
|
|
|
|
|
|
2024-11-08 12:41:49 -03:00
|
|
|
template<typename U, typename Callback>
|
|
|
|
|
WebIDL::ExceptionOr<void> for_each_child_of_type_fallible(Callback callback)
|
|
|
|
|
{
|
|
|
|
|
for (auto* node = first_child(); node; node = node->next_sibling()) {
|
2025-01-25 22:05:57 -03:00
|
|
|
if (auto* maybe_node_of_type = as_if<U>(node)) {
|
|
|
|
|
if (TRY(callback(*maybe_node_of_type)) == IterationDecision::Break)
|
2024-11-08 12:41:49 -03:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2023-05-28 14:27:35 -03:00
|
|
|
template<typename U>
|
|
|
|
|
U const* shadow_including_first_ancestor_of_type() const
|
|
|
|
|
{
|
|
|
|
|
return const_cast<Node*>(this)->template shadow_including_first_ancestor_of_type<U>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
|
U* shadow_including_first_ancestor_of_type();
|
|
|
|
|
|
2024-12-19 11:21:48 -03:00
|
|
|
ErrorOr<String> accessible_name(Document const&, ShouldComputeRole = ShouldComputeRole::Yes) const;
|
2023-02-05 14:21:59 -03:00
|
|
|
ErrorOr<String> accessible_description(Document const&) const;
|
|
|
|
|
|
2024-07-14 18:50:38 -03:00
|
|
|
Optional<String> locate_a_namespace(Optional<String> const& prefix) const;
|
|
|
|
|
Optional<String> lookup_namespace_uri(Optional<String> prefix) const;
|
2024-07-27 15:51:36 -03:00
|
|
|
Optional<String> lookup_prefix(Optional<String> namespace_) const;
|
2024-07-17 10:42:45 -03:00
|
|
|
bool is_default_namespace(Optional<String> namespace_) const;
|
2024-07-14 18:50:38 -03:00
|
|
|
|
2025-02-05 20:24:47 -03:00
|
|
|
bool is_inert() const;
|
|
|
|
|
|
2025-03-04 11:32:06 -03:00
|
|
|
bool has_inclusive_ancestor_with_display_none();
|
|
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
protected:
|
2022-08-28 08:42:07 -03:00
|
|
|
Node(JS::Realm&, Document&, NodeType);
|
2019-09-29 06:43:07 -03:00
|
|
|
Node(Document&, NodeType);
|
2019-06-15 13:55:47 -03:00
|
|
|
|
2025-01-03 12:24:30 -03:00
|
|
|
void set_document(Document&);
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2022-10-20 14:30:29 -03:00
|
|
|
virtual void finalize() override;
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Document> m_document;
|
|
|
|
|
GC::Ptr<Layout::Node> m_layout_node;
|
|
|
|
|
GC::Ptr<Painting::Paintable> m_paintable;
|
2019-06-15 13:55:47 -03:00
|
|
|
NodeType m_type { NodeType::INVALID };
|
2025-01-13 08:23:40 -03:00
|
|
|
bool m_needs_layout_tree_update { false };
|
|
|
|
|
bool m_child_needs_layout_tree_update { false };
|
|
|
|
|
|
2020-12-14 08:04:30 -03:00
|
|
|
bool m_needs_style_update { false };
|
|
|
|
|
bool m_child_needs_style_update { false };
|
2025-01-26 15:00:51 -03:00
|
|
|
bool m_entire_subtree_needs_style_update { false };
|
2021-08-30 11:52:08 -03:00
|
|
|
|
2024-10-20 05:37:44 -03:00
|
|
|
UniqueNodeID m_unique_id;
|
2022-07-11 12:37:51 -03:00
|
|
|
|
|
|
|
|
// https://dom.spec.whatwg.org/#registered-observer-list
|
|
|
|
|
// "Nodes have a strong reference to registered observers in their registered observer list." https://dom.spec.whatwg.org/#garbage-collection
|
2024-11-14 12:01:23 -03:00
|
|
|
OwnPtr<Vector<GC::Ref<RegisteredObserver>>> m_registered_observer_list;
|
2022-07-11 12:39:14 -03:00
|
|
|
|
2023-02-25 14:44:51 -03:00
|
|
|
void build_accessibility_tree(AccessibilityTreeNode& parent);
|
2022-12-11 13:56:37 -03:00
|
|
|
|
2024-12-19 11:21:48 -03:00
|
|
|
ErrorOr<String> name_or_description(NameOrDescription, Document const&, HashTable<UniqueNodeID>&, IsDescendant = IsDescendant::No, ShouldComputeRole = ShouldComputeRole::Yes) const;
|
2023-02-05 14:21:59 -03:00
|
|
|
|
2022-07-11 12:39:14 -03:00
|
|
|
private:
|
2024-11-14 12:01:23 -03:00
|
|
|
void queue_tree_mutation_record(Vector<GC::Root<Node>> added_nodes, Vector<GC::Root<Node>> removed_nodes, Node* previous_sibling, Node* next_sibling);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2025-03-07 11:45:12 -03:00
|
|
|
void live_range_pre_remove();
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void insert_before_impl(GC::Ref<Node>, GC::Ptr<Node> child);
|
|
|
|
|
void append_child_impl(GC::Ref<Node>);
|
|
|
|
|
void remove_child_impl(GC::Ref<Node>);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2023-12-02 16:24:04 -03:00
|
|
|
static Optional<StringView> first_valid_id(StringView, Document const&);
|
2023-02-05 14:21:59 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<NodeList> m_child_nodes;
|
2019-06-15 13:55:47 -03:00
|
|
|
};
|
2019-10-06 15:37:39 -03:00
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|
2023-07-13 14:54:03 -03:00
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline bool JS::Object::fast_is<Web::DOM::Node>() const { return is_dom_node(); }
|