diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-21 16:45:21 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-21 17:42:00 +0200 |
commit | 213e2793bd4fcfc6fec2b32ce2039dd05bba64cd (patch) | |
tree | 5cb0d84ea1fd926431685f2f6a485ecf74ce9d05 /Libraries/LibWeb/DOM | |
parent | 82a75bcf5fc1cffb00e45f06723ef06ce42c8830 (diff) | |
download | serenity-213e2793bd4fcfc6fec2b32ce2039dd05bba64cd.zip |
LibWeb: Add Node.insertBefore(Node node, Node? child)
Diffstat (limited to 'Libraries/LibWeb/DOM')
-rw-r--r-- | Libraries/LibWeb/DOM/Node.cpp | 12 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Node.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Node.idl | 2 |
3 files changed, 15 insertions, 0 deletions
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 4f66b7de38..43bab85987 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -200,4 +200,16 @@ RefPtr<Node> Node::append_child(NonnullRefPtr<Node> node, bool notify) return node; } +RefPtr<Node> Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify) +{ + if (!child) + return append_child(move(node), notify); + if (child->parent_node() != this) { + dbg() << "FIXME: Trying to insert_before() a bogus child"; + return nullptr; + } + TreeNode<Node>::insert_before(node, child, notify); + return node; +} + } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 30504abcaf..eab5b49a70 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -83,6 +83,7 @@ public: bool is_parent_node() const { return is_element() || is_document() || is_document_fragment(); } RefPtr<Node> append_child(NonnullRefPtr<Node>, bool notify = true); + RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true); virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const; diff --git a/Libraries/LibWeb/DOM/Node.idl b/Libraries/LibWeb/DOM/Node.idl index 3bb148197d..33c883049d 100644 --- a/Libraries/LibWeb/DOM/Node.idl +++ b/Libraries/LibWeb/DOM/Node.idl @@ -9,5 +9,7 @@ interface Node : EventTarget { readonly attribute Element? parentElement; Node appendChild(Node node); + Node insertBefore(Node node, Node? child); + } |