summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Hodgen <ant1441@gmail.com>2022-02-18 22:11:43 +0000
committerAndreas Kling <kling@serenityos.org>2022-02-21 16:31:45 +0100
commitc6dd8a1f66651e30993c8dda8bd9b2bb9ea98b18 (patch)
tree857e16dec702f0eca4ad6d5a75029c7f7a742c24
parent929074ddeac1e9d98789872b0432dea0897f4773 (diff)
downloadserenity-c6dd8a1f66651e30993c8dda8bd9b2bb9ea98b18.zip
LibWeb: Implement `Node.nodeValue` DOM attribute
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp26
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.h3
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.idl1
3 files changed, 30 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp
index d4c5ab7475..dff4980614 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Node.cpp
@@ -145,6 +145,32 @@ void Node::set_text_content(String const& content)
set_needs_style_update(true);
}
+// https://dom.spec.whatwg.org/#dom-node-nodevalue
+String Node::node_value() const
+{
+ if (is<Attribute>(this)) {
+ return verify_cast<Attribute>(this)->value();
+ }
+ if (is<CharacterData>(this)) {
+ return verify_cast<CharacterData>(this)->data();
+ }
+
+ return {};
+}
+
+// https://dom.spec.whatwg.org/#ref-for-dom-node-nodevalue%E2%91%A0
+void Node::set_node_value(const String& value)
+{
+
+ if (is<Attribute>(this)) {
+ verify_cast<Attribute>(this)->set_value(value);
+ } else if (is<CharacterData>(this)) {
+ verify_cast<CharacterData>(this)->set_data(value);
+ }
+
+ // Otherwise: Do nothing.
+}
+
void Node::invalidate_style()
{
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h
index d5076f228a..77ebef33f6 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.h
+++ b/Userland/Libraries/LibWeb/DOM/Node.h
@@ -111,6 +111,9 @@ public:
String text_content() const;
void set_text_content(String const&);
+ String node_value() const;
+ void set_node_value(String const&);
+
Document& document() { return *m_document; }
const Document& document() const { return *m_document; }
diff --git a/Userland/Libraries/LibWeb/DOM/Node.idl b/Userland/Libraries/LibWeb/DOM/Node.idl
index a25bfb6d81..40705aa025 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.idl
+++ b/Userland/Libraries/LibWeb/DOM/Node.idl
@@ -19,6 +19,7 @@ interface Node : EventTarget {
readonly attribute Document? ownerDocument;
Node getRootNode(optional GetRootNodeOptions options = {});
+ [CEReactions] attribute DOMString? nodeValue;
// FIXME: [LegacyNullToEmptyString] is not allowed on nullable types as per the Web IDL spec.
// However, we only apply it to setters, so this works as a stop gap.
// Replace this with something like a special cased [LegacyNullToEmptyString].