HTMLTitleElement.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLTitleElementPrototype>(realm, "HTMLTitleElement"_fly_string));
  21. }
  22. void HTMLTitleElement::children_changed()
  23. {
  24. HTMLElement::children_changed();
  25. if (navigable() && navigable()->is_traversable()) {
  26. navigable()->traversable_navigable()->page().client().page_did_change_title(document().title().to_byte_string());
  27. }
  28. }
  29. // https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
  30. String HTMLTitleElement::text() const
  31. {
  32. // The text attribute's getter must return this title element's child text content.
  33. return child_text_content();
  34. }
  35. // https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
  36. void HTMLTitleElement::set_text(String const& value)
  37. {
  38. // The text attribute's setter must string replace all with the given value within this title element.
  39. string_replace_all(value);
  40. }
  41. }