1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibWeb: Use RefPtrs more in getElementById() and getElementsByName()

Passing around Vector<Element*> is not a great idea long-term.
This commit is contained in:
Andreas Kling 2020-10-07 12:47:17 +02:00
parent 9123920a19
commit 51dbea3a0e
4 changed files with 11 additions and 11 deletions

View file

@ -36,9 +36,9 @@ namespace Web::DOM {
template<typename NodeType>
class NonElementParentNode {
public:
const Element* get_element_by_id(const FlyString& id) const
RefPtr<Element> get_element_by_id(const FlyString& id) const
{
const Element* found_element = nullptr;
RefPtr<Element> found_element;
static_cast<const NodeType*>(this)->template for_each_in_subtree_of_type<Element>([&](auto& element) {
if (element.attribute(HTML::AttributeNames::id) == id) {
found_element = &element;
@ -48,9 +48,9 @@ public:
});
return found_element;
}
Element* get_element_by_id(const FlyString& id)
RefPtr<Element> get_element_by_id(const FlyString& id)
{
return const_cast<Element*>(const_cast<const NonElementParentNode*>(this)->get_element_by_id(id));
return const_cast<const NonElementParentNode*>(this)->get_element_by_id(id);
}
protected: