mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +00:00
LibWeb: Support getting and setting Attr.textContent
This commit is contained in:
parent
530675993b
commit
1903dff365
1 changed files with 18 additions and 9 deletions
|
@ -143,14 +143,18 @@ String Node::descendant_text_content() const
|
||||||
String Node::text_content() const
|
String Node::text_content() const
|
||||||
{
|
{
|
||||||
// The textContent getter steps are to return the following, switching on the interface this implements:
|
// 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 DocumentFragment or Element, return the descendant text content of this.
|
||||||
if (is<DocumentFragment>(this) || is<Element>(this))
|
if (is<DocumentFragment>(this) || is<Element>(this))
|
||||||
return descendant_text_content();
|
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
|
// Otherwise, return null
|
||||||
return {};
|
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 DocumentFragment or Element, string replace all with the given value within this.
|
||||||
if (is<DocumentFragment>(this) || is<Element>(this)) {
|
if (is<DocumentFragment>(this) || is<Element>(this)) {
|
||||||
string_replace_all(content);
|
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);
|
auto* character_data_node = verify_cast<CharacterData>(this);
|
||||||
character_data_node->set_data(content);
|
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.
|
// 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.
|
// 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.
|
// Otherwise, do nothing.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue