1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibWeb: Add constructors for Text, DocumentFragment and Comment

These three nodes are the only nodes in the DOM spec with constructors.
This commit is contained in:
Luke Wilde 2021-09-06 01:07:11 +01:00 committed by Andreas Kling
parent 398f8e7c96
commit 6e80458515
9 changed files with 32 additions and 3 deletions

View file

@ -5,6 +5,7 @@
*/
#include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Layout/TextNode.h>
namespace Web::DOM {
@ -18,4 +19,10 @@ Comment::~Comment()
{
}
// https://dom.spec.whatwg.org/#dom-comment-comment
NonnullRefPtr<Comment> Comment::create_with_global_object(Bindings::WindowObject& window, String const& data)
{
return make_ref_counted<Comment>(window.impl().document(), data);
}
}

View file

@ -19,6 +19,8 @@ public:
virtual ~Comment() override;
virtual FlyString node_name() const override { return "#comment"; }
static NonnullRefPtr<Comment> create_with_global_object(Bindings::WindowObject& window, String const& data);
};
}

View file

@ -1,3 +1,3 @@
interface Comment : CharacterData {
constructor(optional DOMString data = "");
};

View file

@ -1,10 +1,11 @@
/*
* Copyright (c) 2020, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2020-2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/DocumentFragment.h>
#include <LibWeb/DOM/Window.h>
namespace Web::DOM {
@ -17,4 +18,10 @@ DocumentFragment::~DocumentFragment()
{
}
// https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment
NonnullRefPtr<DocumentFragment> DocumentFragment::create_with_global_object(Bindings::WindowObject& window)
{
return make_ref_counted<DocumentFragment>(window.impl().document());
}
}

View file

@ -19,6 +19,8 @@ class DocumentFragment
public:
using WrapperType = Bindings::DocumentFragmentWrapper;
static NonnullRefPtr<DocumentFragment> create_with_global_object(Bindings::WindowObject& window);
explicit DocumentFragment(Document& document);
virtual ~DocumentFragment() override;

View file

@ -1,5 +1,7 @@
interface DocumentFragment : Node {
constructor();
Element? getElementById(DOMString id);
// FIXME: These should all come from a ParentNode mixin

View file

@ -5,6 +5,7 @@
*/
#include <LibWeb/DOM/Text.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Layout/TextNode.h>
namespace Web::DOM {
@ -23,4 +24,10 @@ RefPtr<Layout::Node> Text::create_layout_node()
return adopt_ref(*new Layout::TextNode(document(), *this));
}
// https://dom.spec.whatwg.org/#dom-text-text
NonnullRefPtr<Text> Text::create_with_global_object(Bindings::WindowObject& window, String const& data)
{
return make_ref_counted<Text>(window.impl().document(), data);
}
}

View file

@ -19,6 +19,8 @@ public:
explicit Text(Document&, const String&);
virtual ~Text() override;
static NonnullRefPtr<Text> create_with_global_object(Bindings::WindowObject& window, String const& data);
// ^Node
virtual FlyString node_name() const override { return "#text"; }
virtual bool is_editable() const override { return m_always_editable || CharacterData::is_editable(); }

View file

@ -1,3 +1,3 @@
interface Text : CharacterData {
constructor(optional DOMString data = "");
};