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(this)) { + return verify_cast(this)->value(); + } + if (is(this)) { + return verify_cast(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(this)) { + verify_cast(this)->set_value(value); + } else if (is(this)) { + verify_cast(this)->set_data(value); + } + + // Otherwise: Do nothing. +} + void Node::invalidate_style() { for_each_in_inclusive_subtree_of_type([&](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].