LibWeb: Make document.title accessible from JavaScript :^)

This commit is contained in:
Andreas Kling 2020-12-06 21:39:36 +01:00
parent d22512a024
commit 253aa7aa7d
Notes: sideshowbarker 2024-07-19 01:00:51 +09:00
3 changed files with 24 additions and 0 deletions

View file

@ -259,6 +259,27 @@ String Document::title() const
return builder.to_string();
}
void Document::set_title(const String& title)
{
auto* head_element = const_cast<HTML::HTMLHeadElement*>(head());
if (!head_element)
return;
RefPtr<HTML::HTMLTitleElement> title_element = head_element->first_child_of_type<HTML::HTMLTitleElement>();
if (!title_element) {
title_element = static_ptr_cast<HTML::HTMLTitleElement>(create_element(HTML::TagNames::title));
head_element->append_child(*title_element);
}
while (RefPtr<Node> child = title_element->first_child())
title_element->remove_child(child.release_nonnull());
title_element->append_child(adopt(*new Text(*this, title)));
if (auto* page = this->page())
page->client().page_did_change_title(title);
}
void Document::attach_to_frame(Badge<Frame>, Frame& frame)
{
m_frame = frame;

View file

@ -94,6 +94,7 @@ public:
void set_body(HTML::HTMLElement& new_body);
String title() const;
void set_title(const String&);
void attach_to_frame(Badge<Frame>, Frame&);
void detach_from_frame(Badge<Frame>, Frame&);

View file

@ -32,4 +32,6 @@ interface Document : Node {
readonly attribute DOMString readyState;
attribute DOMString title;
}