mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:07:34 +00:00
LibWeb: Implement ChildNode.remove
This commit is contained in:
parent
2202428ca4
commit
7bdf0be667
7 changed files with 49 additions and 1 deletions
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/DOM/ChildNode.h>
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
|
||||
|
||||
|
@ -14,6 +15,7 @@ namespace Web::DOM {
|
|||
|
||||
class CharacterData
|
||||
: public Node
|
||||
, public ChildNode<CharacterData>
|
||||
, public NonDocumentTypeChildNode<CharacterData> {
|
||||
public:
|
||||
using WrapperType = Bindings::CharacterDataWrapper;
|
||||
|
|
|
@ -6,4 +6,7 @@ interface CharacterData : Node {
|
|||
readonly attribute Element? nextElementSibling;
|
||||
readonly attribute Element? previousElementSibling;
|
||||
|
||||
// FIXME: This should come from a ChildNode mixin
|
||||
[CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove();
|
||||
|
||||
};
|
||||
|
|
32
Userland/Libraries/LibWeb/DOM/ChildNode.h
Normal file
32
Userland/Libraries/LibWeb/DOM/ChildNode.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
// https://dom.spec.whatwg.org/#childnode
|
||||
template<typename NodeType>
|
||||
class ChildNode {
|
||||
public:
|
||||
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
||||
void remove_binding()
|
||||
{
|
||||
auto* node = static_cast<NodeType*>(this);
|
||||
|
||||
// 1. If this’s parent is null, then return.
|
||||
if (!node->parent())
|
||||
return;
|
||||
|
||||
// 2. Remove this.
|
||||
node->remove();
|
||||
}
|
||||
|
||||
protected:
|
||||
ChildNode() = default;
|
||||
};
|
||||
|
||||
}
|
|
@ -7,11 +7,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/DOM/ChildNode.h>
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
class DocumentType final : public Node {
|
||||
class DocumentType final
|
||||
: public Node
|
||||
, public ChildNode<DocumentType> {
|
||||
public:
|
||||
using WrapperType = Bindings::DocumentTypeWrapper;
|
||||
|
||||
|
|
|
@ -4,4 +4,7 @@ interface DocumentType : Node {
|
|||
readonly attribute DOMString publicId;
|
||||
readonly attribute DOMString systemId;
|
||||
|
||||
// FIXME: This should come from a ChildNode mixin
|
||||
[CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove();
|
||||
|
||||
};
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/DOM/Attribute.h>
|
||||
#include <LibWeb/DOM/ChildNode.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
|
@ -24,6 +25,7 @@ namespace Web::DOM {
|
|||
|
||||
class Element
|
||||
: public ParentNode
|
||||
, public ChildNode<Element>
|
||||
, public NonDocumentTypeChildNode<Element> {
|
||||
|
||||
public:
|
||||
|
|
|
@ -37,4 +37,7 @@ interface Element : Node {
|
|||
|
||||
DOMRect getBoundingClientRect();
|
||||
|
||||
// FIXME: This should come from a ChildNode mixin
|
||||
[CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove();
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue