mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
LibWeb/HTML: Implement text attribute in HTMLTitleElement
This commit is contained in:
parent
d6df13af6a
commit
24b9d05ea8
5 changed files with 48 additions and 19 deletions
|
@ -3,12 +3,16 @@
|
||||||
2b: 1
|
2b: 1
|
||||||
2c: "This is a title!"
|
2c: "This is a title!"
|
||||||
2d: "This is a title!"
|
2d: "This is a title!"
|
||||||
3: ""
|
3a: "This is a title!"
|
||||||
4a: 3
|
3b: "This is a title!"
|
||||||
4b: ""
|
3c: "Another title!"
|
||||||
4c: ""
|
3d: "Another title!"
|
||||||
4d: ""
|
4: ""
|
||||||
4e: 3
|
5a: 3
|
||||||
4f: "This is another title!"
|
5b: ""
|
||||||
4g: ""
|
5c: ""
|
||||||
4h: ""
|
5d: ""
|
||||||
|
5e: 3
|
||||||
|
5f: "This is another title!"
|
||||||
|
5g: ""
|
||||||
|
5h: ""
|
||||||
|
|
|
@ -15,9 +15,17 @@
|
||||||
println(`2c: "${titleElements[0].innerText}"`);
|
println(`2c: "${titleElements[0].innerText}"`);
|
||||||
println(`2d: "${document.title}"`);
|
println(`2d: "${document.title}"`);
|
||||||
|
|
||||||
|
// Getting and setting the title's text attribute.
|
||||||
|
println(`3a: "${titleElements[0].text}"`);
|
||||||
|
println(`3b: "${document.title}"`);
|
||||||
|
|
||||||
|
titleElements[0].text = "Another title!";
|
||||||
|
println(`3c: "${titleElements[0].text}"`);
|
||||||
|
println(`3d: "${document.title}"`);
|
||||||
|
|
||||||
// Removing the title element sets the title back to default.
|
// Removing the title element sets the title back to default.
|
||||||
titleElements[0].remove();
|
titleElements[0].remove();
|
||||||
println(`3: "${document.title}"`);
|
println(`4: "${document.title}"`);
|
||||||
|
|
||||||
// After adding several title elements to the body, setting the title updates the text
|
// After adding several title elements to the body, setting the title updates the text
|
||||||
// content of only the first title element.
|
// content of only the first title element.
|
||||||
|
@ -26,17 +34,17 @@
|
||||||
document.body.appendChild(document.createElement('title'));
|
document.body.appendChild(document.createElement('title'));
|
||||||
|
|
||||||
titleElements = document.getElementsByTagName('title');
|
titleElements = document.getElementsByTagName('title');
|
||||||
println(`4a: ${titleElements.length}`)
|
println(`5a: ${titleElements.length}`)
|
||||||
println(`4b: "${titleElements[0].innerText}"`);
|
println(`5b: "${titleElements[0].innerText}"`);
|
||||||
println(`4c: "${titleElements[1].innerText}"`);
|
println(`5c: "${titleElements[1].innerText}"`);
|
||||||
println(`4d: "${titleElements[2].innerText}"`);
|
println(`5d: "${titleElements[2].innerText}"`);
|
||||||
|
|
||||||
document.title = 'This is another title!';
|
document.title = 'This is another title!';
|
||||||
|
|
||||||
titleElements = document.getElementsByTagName('title');
|
titleElements = document.getElementsByTagName('title');
|
||||||
println(`4e: ${titleElements.length}`)
|
println(`5e: ${titleElements.length}`)
|
||||||
println(`4f: "${titleElements[0].innerText}"`);
|
println(`5f: "${titleElements[0].innerText}"`);
|
||||||
println(`4g: "${titleElements[1].innerText}"`);
|
println(`5g: "${titleElements[1].innerText}"`);
|
||||||
println(`4h: "${titleElements[2].innerText}"`);
|
println(`5h: "${titleElements[2].innerText}"`);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -34,4 +34,18 @@ void HTMLTitleElement::children_changed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
|
||||||
|
DeprecatedString HTMLTitleElement::text()
|
||||||
|
{
|
||||||
|
// The text attribute's getter must return this title element's child text content.
|
||||||
|
return child_text_content();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
|
||||||
|
void HTMLTitleElement::set_text(String const& value)
|
||||||
|
{
|
||||||
|
// The text attribute's setter must string replace all with the given value within this title element.
|
||||||
|
string_replace_all(value.to_deprecated_string());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ class HTMLTitleElement final : public HTMLElement {
|
||||||
public:
|
public:
|
||||||
virtual ~HTMLTitleElement() override;
|
virtual ~HTMLTitleElement() override;
|
||||||
|
|
||||||
|
DeprecatedString text();
|
||||||
|
void set_text(String const& value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HTMLTitleElement(DOM::Document&, DOM::QualifiedName);
|
HTMLTitleElement(DOM::Document&, DOM::QualifiedName);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,6 @@ interface HTMLTitleElement : HTMLElement {
|
||||||
|
|
||||||
[HTMLConstructor] constructor();
|
[HTMLConstructor] constructor();
|
||||||
|
|
||||||
// FIXME: [CEReactions] attribute DOMString text;
|
[CEReactions] attribute DOMString text;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue