HTMLTitleElement.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/HTML/HTMLTitleElement.h>
  8. #include <LibWeb/HTML/TraversableNavigable.h>
  9. #include <LibWeb/Page/Page.h>
  10. namespace Web::HTML {
  11. JS_DEFINE_ALLOCATOR(HTMLTitleElement);
  12. HTMLTitleElement::HTMLTitleElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLTitleElement::~HTMLTitleElement() = default;
  17. void HTMLTitleElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTitleElement);
  21. }
  22. void HTMLTitleElement::children_changed()
  23. {
  24. HTMLElement::children_changed();
  25. auto navigable = this->navigable();
  26. if (navigable && navigable->is_traversable()) {
  27. navigable->traversable_navigable()->page().client().page_did_change_title(document().title().to_byte_string());
  28. }
  29. }
  30. // https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
  31. String HTMLTitleElement::text() const
  32. {
  33. // The text attribute's getter must return this title element's child text content.
  34. return child_text_content();
  35. }
  36. // https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
  37. void HTMLTitleElement::set_text(String const& value)
  38. {
  39. // The text attribute's setter must string replace all with the given value within this title element.
  40. string_replace_all(value);
  41. }
  42. }