summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-06-27 21:20:59 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-27 22:53:04 +0100
commit1ceba560f469e1d64c553eb5fb7951a9dd52c74c (patch)
treef07126dba37248611b9514c0c153290b06cc98a8 /Userland
parent2916b3bebfb377cb285178705175b5b5c5b0b57f (diff)
downloadserenity-1ceba560f469e1d64c553eb5fb7951a9dd52c74c.zip
LibWeb: Add CDATASection
Not used for anything currently other than exposing it on the Window object. This allows Web Components Polyfills to patch its prototype.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h3
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibWeb/DOM/CDATASection.cpp20
-rw-r--r--Userland/Libraries/LibWeb/DOM/CDATASection.h28
-rw-r--r--Userland/Libraries/LibWeb/DOM/CDATASection.idl3
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.h1
-rw-r--r--Userland/Libraries/LibWeb/DOM/Text.cpp5
-rw-r--r--Userland/Libraries/LibWeb/DOM/Text.h5
-rw-r--r--Userland/Libraries/LibWeb/Forward.h2
-rw-r--r--Userland/Libraries/LibWeb/idl_files.cmake1
10 files changed, 68 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
index 5968c8ae5b..092bde3c08 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
@@ -15,6 +15,8 @@
#include <LibWeb/Bindings/AbstractRangeConstructor.h>
#include <LibWeb/Bindings/AbstractRangePrototype.h>
#include <LibWeb/Bindings/AudioConstructor.h>
+#include <LibWeb/Bindings/CDATASectionConstructor.h>
+#include <LibWeb/Bindings/CDATASectionPrototype.h>
#include <LibWeb/Bindings/CSSConditionRuleConstructor.h>
#include <LibWeb/Bindings/CSSConditionRulePrototype.h>
#include <LibWeb/Bindings/CSSFontFaceRuleConstructor.h>
@@ -370,6 +372,7 @@
ADD_WINDOW_OBJECT_INTERFACE(AbortController) \
ADD_WINDOW_OBJECT_INTERFACE(AbortSignal) \
ADD_WINDOW_OBJECT_INTERFACE(AbstractRange) \
+ ADD_WINDOW_OBJECT_INTERFACE(CDATASection) \
ADD_WINDOW_OBJECT_INTERFACE(CSSConditionRule) \
ADD_WINDOW_OBJECT_INTERFACE(CSSFontFaceRule) \
ADD_WINDOW_OBJECT_INTERFACE(CSSGroupingRule) \
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 369e6d1be3..ef22701991 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -74,6 +74,7 @@ set(SOURCES
DOM/AbortSignal.cpp
DOM/Attribute.cpp
DOM/Attribute.idl
+ DOM/CDATASection.cpp
DOM/CharacterData.cpp
DOM/CharacterData.idl
DOM/Comment.cpp
diff --git a/Userland/Libraries/LibWeb/DOM/CDATASection.cpp b/Userland/Libraries/LibWeb/DOM/CDATASection.cpp
new file mode 100644
index 0000000000..bce61e89c3
--- /dev/null
+++ b/Userland/Libraries/LibWeb/DOM/CDATASection.cpp
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/DOM/CDATASection.h>
+
+namespace Web::DOM {
+
+CDATASection::CDATASection(Document& document, String const& data)
+ : Text(document, NodeType::CDATA_SECTION_NODE, data)
+{
+}
+
+CDATASection::~CDATASection()
+{
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/DOM/CDATASection.h b/Userland/Libraries/LibWeb/DOM/CDATASection.h
new file mode 100644
index 0000000000..bf57d3fad0
--- /dev/null
+++ b/Userland/Libraries/LibWeb/DOM/CDATASection.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/RefCounted.h>
+#include <LibWeb/DOM/Text.h>
+
+namespace Web::DOM {
+
+class CDATASection final : public Text {
+public:
+ using WrapperType = Bindings::CDATASectionWrapper;
+
+ CDATASection(Document&, String const&);
+ virtual ~CDATASection() override;
+
+ // ^Node
+ virtual FlyString node_name() const override { return "#cdata-section"; }
+};
+
+template<>
+inline bool Node::fast_is<CDATASection>() const { return is_cdata_section(); }
+
+}
diff --git a/Userland/Libraries/LibWeb/DOM/CDATASection.idl b/Userland/Libraries/LibWeb/DOM/CDATASection.idl
new file mode 100644
index 0000000000..22f66ba820
--- /dev/null
+++ b/Userland/Libraries/LibWeb/DOM/CDATASection.idl
@@ -0,0 +1,3 @@
+[Exposed=Window]
+interface CDATASection : Text {
+};
diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h
index 5e0f7a7b3c..89710a38a4 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.h
+++ b/Userland/Libraries/LibWeb/DOM/Node.h
@@ -72,6 +72,7 @@ public:
bool is_parent_node() const { return is_element() || is_document() || is_document_fragment(); }
bool is_slottable() const { return is_element() || is_text(); }
bool is_attribute() const { return type() == NodeType::ATTRIBUTE_NODE; }
+ bool is_cdata_section() const { return type() == NodeType::CDATA_SECTION_NODE; }
virtual bool is_shadow_root() const { return false; }
virtual bool requires_svg_container() const { return false; }
diff --git a/Userland/Libraries/LibWeb/DOM/Text.cpp b/Userland/Libraries/LibWeb/DOM/Text.cpp
index d2ea61a2bb..3225e9d6b0 100644
--- a/Userland/Libraries/LibWeb/DOM/Text.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Text.cpp
@@ -17,6 +17,11 @@ Text::Text(Document& document, String const& data)
{
}
+Text::Text(Document& document, NodeType type, String const& data)
+ : CharacterData(document, type, data)
+{
+}
+
// https://dom.spec.whatwg.org/#dom-text-text
NonnullRefPtr<Text> Text::create_with_global_object(Bindings::WindowObject& window, String const& data)
{
diff --git a/Userland/Libraries/LibWeb/DOM/Text.h b/Userland/Libraries/LibWeb/DOM/Text.h
index bccfc2024e..44762c8e55 100644
--- a/Userland/Libraries/LibWeb/DOM/Text.h
+++ b/Userland/Libraries/LibWeb/DOM/Text.h
@@ -12,7 +12,7 @@
namespace Web::DOM {
-class Text final : public CharacterData {
+class Text : public CharacterData {
public:
using WrapperType = Bindings::TextWrapper;
@@ -32,6 +32,9 @@ public:
ExceptionOr<NonnullRefPtr<Text>> split_text(size_t offset);
+protected:
+ Text(Document&, NodeType, String const&);
+
private:
WeakPtr<HTML::HTMLInputElement> m_owner_input_element;
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 898f5036f5..b62e6bf275 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -118,6 +118,7 @@ class AbstractRange;
class AbortController;
class AbortSignal;
class Attribute;
+class CDATASection;
class CharacterData;
class Comment;
class CustomEvent;
@@ -410,6 +411,7 @@ class AttributeWrapper;
struct CallbackType;
class CanvasGradientWrapper;
class CanvasRenderingContext2DWrapper;
+class CDATASectionWrapper;
class CharacterDataWrapper;
class CloseEventWrapper;
class CommentWrapper;
diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake
index b379a86e95..410d1c8604 100644
--- a/Userland/Libraries/LibWeb/idl_files.cmake
+++ b/Userland/Libraries/LibWeb/idl_files.cmake
@@ -24,6 +24,7 @@ libweb_js_wrapper(DOM/AbstractRange)
libweb_js_wrapper(DOM/Attribute)
libweb_js_wrapper(DOM/AbortController)
libweb_js_wrapper(DOM/AbortSignal)
+libweb_js_wrapper(DOM/CDATASection)
libweb_js_wrapper(DOM/CharacterData)
libweb_js_wrapper(DOM/Comment)
libweb_js_wrapper(DOM/CustomEvent)