2020-03-28 05:12:13 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-28 05:12:13 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
2022-09-13 11:02:25 -03:00
|
|
|
#include <LibJS/Heap/GCPtr.h>
|
2020-03-28 05:12:13 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2020-08-12 09:46:53 -03:00
|
|
|
#include <LibWeb/HTML/AttributeNames.h>
|
2020-03-28 05:12:13 -03:00
|
|
|
#include <LibWeb/TreeNode.h>
|
|
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
namespace Web::DOM {
|
2020-03-28 05:12:13 -03:00
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
class NonElementParentNode {
|
|
|
|
|
public:
|
2022-08-28 08:42:07 -03:00
|
|
|
JS::GCPtr<Element> get_element_by_id(FlyString const& id) const
|
2020-03-28 05:12:13 -03:00
|
|
|
{
|
2022-08-28 08:42:07 -03:00
|
|
|
JS::GCPtr<Element> found_element;
|
2022-04-01 14:58:27 -03:00
|
|
|
static_cast<NodeType const*>(this)->template for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
2020-05-26 18:27:22 -03:00
|
|
|
if (element.attribute(HTML::AttributeNames::id) == id) {
|
2020-03-28 05:12:13 -03:00
|
|
|
found_element = &element;
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
});
|
|
|
|
|
return found_element;
|
|
|
|
|
}
|
2022-08-28 08:42:07 -03:00
|
|
|
JS::GCPtr<Element> get_element_by_id(FlyString const& id)
|
2020-03-28 05:12:13 -03:00
|
|
|
{
|
2022-04-01 14:58:27 -03:00
|
|
|
return const_cast<NonElementParentNode const*>(this)->get_element_by_id(id);
|
2020-03-28 05:12:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2021-09-16 03:24:47 -03:00
|
|
|
NonElementParentNode() = default;
|
2020-03-28 05:12:13 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|