80
80
#include < LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
81
81
#include < LibWeb/Platform/Timer.h>
82
82
#include < LibWeb/SVG/SVGElement.h>
83
+ #include < LibWeb/SVG/SVGTitleElement.h>
83
84
#include < LibWeb/SVG/TagNames.h>
84
85
#include < LibWeb/Selection/Selection.h>
85
86
#include < LibWeb/UIEvents/EventNames.h>
@@ -688,8 +689,9 @@ DeprecatedString Document::title() const
688
689
689
690
// 1. If the document element is an SVG svg element, then let value be the child text content of the first SVG title
690
691
// element that is a child of the document element.
691
- if (auto const * document_element = this ->document_element (); document_element && is<SVG::SVGElement>(document_element)) {
692
- // FIXME: Implement the SVG title element and get its child text content.
692
+ if (auto const * document_element = this ->document_element (); is<SVG::SVGElement>(document_element)) {
693
+ if (auto const * title_element = document_element->first_child_of_type <SVG::SVGTitleElement>())
694
+ value = title_element->child_text_content ();
693
695
}
694
696
695
697
// 2. Otherwise, let value be the child text content of the title element, or the empty string if the title element
@@ -712,13 +714,25 @@ WebIDL::ExceptionOr<void> Document::set_title(DeprecatedString const& title)
712
714
713
715
// -> If the document element is an SVG svg element
714
716
if (is<SVG::SVGElement>(document_element)) {
715
- // FIXME: 1. If there is an SVG title element that is a child of the document element, let element be the first such
716
- // element.
717
- // FIXME: 2. Otherwise:
718
- // 1. Let element be the result of creating an element given the document element's node document, title,
719
- // and the SVG namespace.
720
- // 2. Insert element as the first child of the document element.
721
- // FIXME: 3. String replace all with the given value within element.
717
+ JS::GCPtr<Element> element;
718
+
719
+ // 1. If there is an SVG title element that is a child of the document element, let element be the first such
720
+ // element.
721
+ if (auto * title_element = document_element->first_child_of_type <SVG::SVGTitleElement>()) {
722
+ element = title_element;
723
+ }
724
+ // 2. Otherwise:
725
+ else {
726
+ // 1. Let element be the result of creating an element given the document element's node document, title,
727
+ // and the SVG namespace.
728
+ element = TRY (DOM::create_element (*this , HTML::TagNames::title, Namespace::SVG));
729
+
730
+ // 2. Insert element as the first child of the document element.
731
+ document_element->insert_before (*element, nullptr );
732
+ }
733
+
734
+ // 3. String replace all with the given value within element.
735
+ element->string_replace_all (title);
722
736
}
723
737
724
738
// -> If the document element is in the HTML namespace
0 commit comments