2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/HTMLTitleElement.h>
|
2020-12-16 22:02:00 -03:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-07-26 10:08:16 -03:00
|
|
|
#include <LibWeb/HTML/HTMLTitleElement.h>
|
2023-08-27 12:06:39 -03:00
|
|
|
#include <LibWeb/HTML/TraversableNavigable.h>
|
2020-12-16 22:02:00 -03:00
|
|
|
#include <LibWeb/Page/Page.h>
|
2019-09-29 11:24:57 -03:00
|
|
|
|
2020-07-28 13:20:36 -03:00
|
|
|
namespace Web::HTML {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(HTMLTitleElement);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
2022-02-18 17:00:52 -03:00
|
|
|
HTMLTitleElement::HTMLTitleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 07:20:15 -03:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2019-09-29 11:24:57 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
HTMLTitleElement::~HTMLTitleElement() = default;
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
void HTMLTitleElement::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTitleElement);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2023-01-10 08:28:20 -03:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 09:36:27 -03:00
|
|
|
void HTMLTitleElement::children_changed(ChildrenChangedMetadata const& metadata)
|
2020-12-16 22:02:00 -03:00
|
|
|
{
|
2025-01-26 09:16:33 -03:00
|
|
|
HTMLElement::children_changed(metadata);
|
2024-03-16 05:24:57 -03:00
|
|
|
auto navigable = this->navigable();
|
|
|
|
|
if (navigable && navigable->is_traversable()) {
|
2025-07-28 17:51:01 -03:00
|
|
|
navigable->traversable_navigable()->page().client().page_did_change_title(document().title());
|
2021-03-20 11:20:11 -03:00
|
|
|
}
|
2020-12-16 22:02:00 -03:00
|
|
|
}
|
|
|
|
|
|
2023-12-01 23:59:08 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
|
2025-07-28 10:46:06 -03:00
|
|
|
Utf16String HTMLTitleElement::text() const
|
2023-12-01 23:59:08 -03:00
|
|
|
{
|
|
|
|
|
// The text attribute's getter must return this title element's child text content.
|
2023-12-23 23:46:54 -03:00
|
|
|
return child_text_content();
|
2023-12-01 23:59:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
|
2025-07-28 10:46:06 -03:00
|
|
|
void HTMLTitleElement::set_text(Utf16String const& value)
|
2023-12-01 23:59:08 -03:00
|
|
|
{
|
|
|
|
|
// The text attribute's setter must string replace all with the given value within this title element.
|
2023-12-02 16:24:04 -03:00
|
|
|
string_replace_all(value);
|
2023-12-01 23:59:08 -03:00
|
|
|
}
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|