Skip to content

Commit

Permalink
LibWeb: Implement Node.nodeValue DOM attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ant1441 authored and awesomekling committed Feb 21, 2022
1 parent 929074d commit c6dd8a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Userland/Libraries/LibWeb/DOM/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/DOM/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class Node
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; }

Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/DOM/Node.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down

0 comments on commit c6dd8a1

Please sign in to comment.