mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWeb: Make document.title accessible from JavaScript :^)
This commit is contained in:
parent
d22512a024
commit
253aa7aa7d
Notes:
sideshowbarker
2024-07-19 01:00:51 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/253aa7aa7d3
3 changed files with 24 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -32,4 +32,6 @@ interface Document : Node {
|
|||
|
||||
readonly attribute DOMString readyState;
|
||||
|
||||
attribute DOMString title;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue