diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-18 01:07:05 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-18 02:08:01 +0200 |
commit | 1903dff3653ab0817a3cbf5cf7c16a91d6d90b34 (patch) | |
tree | 0c36ef1479e48deaf7faf6e1513e1a1ff0c8ed6b /Userland/Libraries | |
parent | 530675993b64db89186f3e249682b11b9e3ca348 (diff) | |
download | serenity-1903dff3653ab0817a3cbf5cf7c16a91d6d90b34.zip |
LibWeb: Support getting and setting Attr.textContent
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 2f4f2572aa..3f880e343a 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -143,14 +143,18 @@ String Node::descendant_text_content() const String Node::text_content() const { // The textContent getter steps are to return the following, switching on the interface this implements: + // If DocumentFragment or Element, return the descendant text content of this. if (is<DocumentFragment>(this) || is<Element>(this)) return descendant_text_content(); - else if (is<CharacterData>(this)) - // If CharacterData, return this’s data. - return verify_cast<CharacterData>(this)->data(); - // FIXME: If this is an Attr node, return this's value. + // If CharacterData, return this’s data. + if (is<CharacterData>(this)) + return static_cast<CharacterData const&>(*this).data(); + + // If Attr node, return this's value. + if (is<Attr>(*this)) + return static_cast<Attr const&>(*this).value(); // Otherwise, return null return {}; @@ -165,16 +169,21 @@ void Node::set_text_content(String const& content) // If DocumentFragment or Element, string replace all with the given value within this. if (is<DocumentFragment>(this) || is<Element>(this)) { string_replace_all(content); - } else if (is<CharacterData>(this)) { - // If CharacterData, replace data with node this, offset 0, count this’s length, and data the given value. + } + + // If CharacterData, replace data with node this, offset 0, count this’s length, and data the given value. + else if (is<CharacterData>(this)) { + auto* character_data_node = verify_cast<CharacterData>(this); character_data_node->set_data(content); // FIXME: CharacterData::set_data is not spec compliant. Make this match the spec when set_data becomes spec compliant. // Do note that this will make this function able to throw an exception. - } else { - // FIXME: If this is an Attr node, set an existing attribute value with this and the given value. - return; + } + + // If Attr, set an existing attribute value with this and the given value. + if (is<Attr>(*this)) { + static_cast<Attr&>(*this).set_value(content); } // Otherwise, do nothing. |