From 48f367adbbe79406215600d15ecb747c17bf3a31 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 8 Oct 2023 13:34:11 +1300 Subject: [PATCH] LibWeb: Port get_element_by_id from DeprecatedFlyString We needed to keep the old versions of these functions around before all of the IDL interfaces were ported over to new AK String, but now that is done, we can remove the deprecated versions of these functions. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 8 ++++---- Userland/Libraries/LibWeb/DOM/Document.h | 2 +- Userland/Libraries/LibWeb/DOM/Element.cpp | 2 +- Userland/Libraries/LibWeb/DOM/Node.cpp | 6 +++--- .../Libraries/LibWeb/DOM/NonElementParentNode.h | 14 ++------------ Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp | 2 +- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 08c2c577e9..a8be077ecc 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1733,7 +1733,7 @@ Document::IndicatedPart Document::determine_the_indicated_part() const return Document::TopOfTheDocument {}; // 3. Let potentialIndicatedElement be the result of finding a potential indicated element given document and fragment. - auto* potential_indicated_element = find_a_potential_indicated_element(fragment.to_deprecated_string()); + auto* potential_indicated_element = find_a_potential_indicated_element(fragment); // 4. If potentialIndicatedElement is not null, then return potentialIndicatedElement. if (potential_indicated_element) @@ -1744,7 +1744,7 @@ Document::IndicatedPart Document::determine_the_indicated_part() const auto decoded_fragment = AK::URL::percent_decode(fragment); // 7. Set potentialIndicatedElement to the result of finding a potential indicated element given document and decodedFragment. - potential_indicated_element = find_a_potential_indicated_element(decoded_fragment); + potential_indicated_element = find_a_potential_indicated_element(MUST(FlyString::from_deprecated_fly_string(decoded_fragment))); // 8. If potentialIndicatedElement is not null, then return potentialIndicatedElement. if (potential_indicated_element) @@ -1759,7 +1759,7 @@ Document::IndicatedPart Document::determine_the_indicated_part() const } // https://html.spec.whatwg.org/multipage/browsing-the-web.html#find-a-potential-indicated-element -Element* Document::find_a_potential_indicated_element(DeprecatedString fragment) const +Element* Document::find_a_potential_indicated_element(FlyString const& fragment) const { // To find a potential indicated element given a Document document and a string fragment, run these steps: @@ -1772,7 +1772,7 @@ Element* Document::find_a_potential_indicated_element(DeprecatedString fragment) // whose value is equal to fragment, then return the first such element in tree order. Element* element_with_name; root().for_each_in_subtree_of_type([&](Element const& element) { - if (element.name() == fragment) { + if (element.attribute(HTML::AttributeNames::name) == fragment) { element_with_name = const_cast(&element); return IterationDecision::Break; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 8c8c7bfabe..d416d1c648 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -554,7 +554,7 @@ private: void queue_intersection_observer_task(); void queue_an_intersection_observer_entry(IntersectionObserver::IntersectionObserver&, HighResolutionTime::DOMHighResTimeStamp time, JS::NonnullGCPtr root_bounds, JS::NonnullGCPtr bounding_client_rect, JS::NonnullGCPtr intersection_rect, bool is_intersecting, double intersection_ratio, JS::NonnullGCPtr target); - Element* find_a_potential_indicated_element(DeprecatedString fragment) const; + Element* find_a_potential_indicated_element(FlyString const& fragment) const; OwnPtr m_style_computer; JS::GCPtr m_style_sheets; diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index c145996c10..5753013028 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1937,7 +1937,7 @@ void Element::scroll(HTML::ScrollToOptions const&) bool Element::id_reference_exists(DeprecatedString const& id_reference) const { - return document().get_element_by_id(id_reference); + return document().get_element_by_id(MUST(FlyString::from_deprecated_fly_string(id_reference))); } void Element::register_intersection_observer(Badge, IntersectionObserver::IntersectionObserverRegistration registration) diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 875eb60ac8..c60af7f90b 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -1802,7 +1802,7 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con } // ii. For each IDREF: for (auto const& id_ref : id_list) { - auto node = document.get_element_by_id(id_ref); + auto node = document.get_element_by_id(MUST(FlyString::from_utf8(id_ref))); if (!node) continue; @@ -1922,7 +1922,7 @@ ErrorOr Node::accessible_description(Document const& document) const StringBuilder builder; auto id_list = described_by->bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace); for (auto const& id : id_list) { - if (auto description_element = document.get_element_by_id(id)) { + if (auto description_element = document.get_element_by_id(MUST(FlyString::from_utf8(id)))) { auto description = TRY( description_element->name_or_description(NameOrDescription::Description, document, visited_nodes)); @@ -1943,7 +1943,7 @@ Optional Node::first_valid_id(DeprecatedString const& value, Documen { auto id_list = value.split_view(Infra::is_ascii_whitespace); for (auto const& id : id_list) { - if (document.get_element_by_id(id)) + if (document.get_element_by_id(MUST(FlyString::from_utf8(id)))) return id; } return {}; diff --git a/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h b/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h index 0332be2df1..d0e3792bbd 100644 --- a/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h +++ b/Userland/Libraries/LibWeb/DOM/NonElementParentNode.h @@ -19,15 +19,10 @@ template class NonElementParentNode { public: JS::GCPtr get_element_by_id(FlyString const& id) const - { - return get_element_by_id(id.to_deprecated_fly_string()); - } - - JS::GCPtr get_element_by_id(DeprecatedFlyString const& id) const { JS::GCPtr found_element; static_cast(this)->template for_each_in_inclusive_subtree_of_type([&](auto& element) { - if (element.deprecated_attribute(HTML::AttributeNames::id) == id) { + if (element.attribute(HTML::AttributeNames::id) == id) { found_element = &element; return IterationDecision::Break; } @@ -37,15 +32,10 @@ public: } JS::GCPtr get_element_by_id(FlyString const& id) - { - return get_element_by_id(id.to_deprecated_fly_string()); - } - - JS::GCPtr get_element_by_id(DeprecatedFlyString const& id) { JS::GCPtr found_element; static_cast(this)->template for_each_in_inclusive_subtree_of_type([&](auto& element) { - if (element.deprecated_attribute(HTML::AttributeNames::id) == id) { + if (element.attribute(HTML::AttributeNames::id) == id) { found_element = &element; return IterationDecision::Break; } diff --git a/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp index 16e471f1ba..066a7c4bcb 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGUseElement.cpp @@ -115,7 +115,7 @@ JS::GCPtr SVGUseElement::referenced_element() } // FIXME: Support loading of external svg documents - return document().get_element_by_id(m_referenced_id.value()); + return document().get_element_by_id(MUST(FlyString::from_utf8(m_referenced_id.value()))); } // https://svgwg.org/svg2-draft/struct.html#UseShadowTree