1
Fork 0
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:
Luke Wilde 2021-09-29 16:25:48 +01:00 committed by Andreas Kling
parent 2202428ca4
commit 7bdf0be667
7 changed files with 49 additions and 1 deletions

View file

@ -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;

View file

@ -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();
};

View 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 thiss parent is null, then return.
if (!node->parent())
return;
// 2. Remove this.
node->remove();
}
protected:
ChildNode() = default;
};
}

View file

@ -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;

View file

@ -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();
};

View file

@ -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:

View file

@ -37,4 +37,7 @@ interface Element : Node {
DOMRect getBoundingClientRect();
// FIXME: This should come from a ChildNode mixin
[CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove();
};