HTMLTitleElement.cpp 1.5 KB

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