mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb: Add an accessor for the document's title element
This commit is contained in:
parent
e8fde316f6
commit
43b3673198
Notes:
sideshowbarker
2024-07-17 02:06:40 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/43b3673198 Pull-request: https://github.com/SerenityOS/serenity/pull/19308
@ -631,6 +631,21 @@ HTML::HTMLHeadElement* Document::head()
|
||||
return html->first_child_of_type<HTML::HTMLHeadElement>();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#the-title-element-2
|
||||
JS::GCPtr<HTML::HTMLTitleElement> Document::title_element()
|
||||
{
|
||||
// The title element of a document is the first title element in the document (in tree order), if there is one, or
|
||||
// null otherwise.
|
||||
JS::GCPtr<HTML::HTMLTitleElement> title_element = nullptr;
|
||||
|
||||
for_each_in_subtree_of_type<HTML::HTMLTitleElement>([&](auto& title_element_in_tree) {
|
||||
title_element = title_element_in_tree;
|
||||
return IterationDecision::Break;
|
||||
});
|
||||
|
||||
return title_element;
|
||||
}
|
||||
|
||||
HTML::HTMLElement* Document::body()
|
||||
{
|
||||
auto* html = html_element();
|
||||
|
@ -147,6 +147,7 @@ public:
|
||||
|
||||
HTML::HTMLHtmlElement* html_element();
|
||||
HTML::HTMLHeadElement* head();
|
||||
JS::GCPtr<HTML::HTMLTitleElement> title_element();
|
||||
HTML::HTMLElement* body();
|
||||
|
||||
HTML::HTMLHtmlElement const* html_element() const
|
||||
@ -159,6 +160,11 @@ public:
|
||||
return const_cast<Document*>(this)->head();
|
||||
}
|
||||
|
||||
JS::GCPtr<HTML::HTMLTitleElement const> title_element() const
|
||||
{
|
||||
return const_cast<Document*>(this)->title_element();
|
||||
}
|
||||
|
||||
HTML::HTMLElement const* body() const
|
||||
{
|
||||
return const_cast<Document*>(this)->body();
|
||||
|
Loading…
Reference in New Issue
Block a user