From 9e338a2be20b6ea343d141b28513e9c89f3da4db Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 6 Apr 2021 17:06:23 +0100 Subject: [PATCH] LibWeb: Add ProcessingInstruction node Not particuarly useful right now, but is used in ensure_pre_insertion_validity. I'm not totally sure on the constructor arguments. --- .../LibWeb/Bindings/WindowObjectHelper.h | 3 ++ Userland/Libraries/LibWeb/CMakeLists.txt | 2 + .../LibWeb/DOM/ProcessingInstruction.cpp | 42 ++++++++++++++++ .../LibWeb/DOM/ProcessingInstruction.h | 49 +++++++++++++++++++ .../LibWeb/DOM/ProcessingInstruction.idl | 3 ++ Userland/Libraries/LibWeb/Forward.h | 2 + 6 files changed, 101 insertions(+) create mode 100644 Userland/Libraries/LibWeb/DOM/ProcessingInstruction.cpp create mode 100644 Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h create mode 100644 Userland/Libraries/LibWeb/DOM/ProcessingInstruction.idl diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index f5b6b78254..7db67a481e 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -205,6 +205,8 @@ #include #include #include +#include +#include #include #include #include @@ -337,6 +339,7 @@ ADD_WINDOW_OBJECT_INTERFACE(Node) \ ADD_WINDOW_OBJECT_INTERFACE(Performance) \ ADD_WINDOW_OBJECT_INTERFACE(PerformanceTiming) \ + ADD_WINDOW_OBJECT_INTERFACE(ProcessingInstruction) \ ADD_WINDOW_OBJECT_INTERFACE(ProgressEvent) \ ADD_WINDOW_OBJECT_INTERFACE(Screen) \ ADD_WINDOW_OBJECT_INTERFACE(ShadowRoot) \ diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 6c51c0d2db..fb893793a4 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -54,6 +54,7 @@ set(SOURCES DOM/Node.cpp DOM/ParentNode.cpp DOM/Position.cpp + DOM/ProcessingInstruction.cpp DOM/ShadowRoot.cpp DOM/Text.cpp DOM/Text.idl @@ -305,6 +306,7 @@ libweb_js_wrapper(DOM/DOMImplementation) libweb_js_wrapper(DOM/Element) libweb_js_wrapper(DOM/Event) libweb_js_wrapper(DOM/EventTarget) +libweb_js_wrapper(DOM/ProcessingInstruction) libweb_js_wrapper(DOM/ShadowRoot) libweb_js_wrapper(DOM/Node) libweb_js_wrapper(DOM/Range) diff --git a/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.cpp b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.cpp new file mode 100644 index 0000000000..527a59a9c2 --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021, the SerenityOS developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +namespace Web::DOM { + +ProcessingInstruction::ProcessingInstruction(Document& document, const String& data, const String& target) + : CharacterData(document, NodeType::PROCESSING_INSTRUCTION_NODE, data) + , m_target(target) +{ +} + +ProcessingInstruction::~ProcessingInstruction() +{ +} + +} diff --git a/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h new file mode 100644 index 0000000000..0ff536994d --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021, the SerenityOS developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include +#include + +namespace Web::DOM { + +class ProcessingInstruction final : public CharacterData { +public: + using WrapperType = Bindings::ProcessingInstructionWrapper; + + ProcessingInstruction(Document&, const String&, const String&); + virtual ~ProcessingInstruction() override; + + virtual FlyString node_name() const override { return m_target; } + + const String& target() const { return m_target; } + +private: + String m_target; +}; + +} diff --git a/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.idl b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.idl new file mode 100644 index 0000000000..05a3761045 --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.idl @@ -0,0 +1,3 @@ +interface ProcessingInstruction : CharacterData { + readonly attribute DOMString target; +}; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index de6bcbe836..f134478073 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -60,6 +60,7 @@ class MouseEvent; class Node; class ParentNode; class Position; +class ProcessingInstruction; class ShadowRoot; class Text; class Timer; @@ -300,6 +301,7 @@ class MouseEventWrapper; class NodeWrapper; class PerformanceTimingWrapper; class PerformanceWrapper; +class ProcessingInstructionWrapper; class ProgressEventWrapper; class ScreenWrapper; class ScriptExecutionContext;