2020-03-28 09:12:13 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2020-03-28 09:12:13 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-28 09:12:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-09-11 18:23:48 +12:00
|
|
|
#include <AK/FlyString.h>
|
2020-03-28 09:12:13 +01:00
|
|
|
#include <AK/Forward.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Ptr.h>
|
2020-03-28 09:12:13 +01:00
|
|
|
#include <LibWeb/Forward.h>
|
2020-08-12 14:46:53 +02:00
|
|
|
#include <LibWeb/HTML/AttributeNames.h>
|
2020-03-28 09:12:13 +01:00
|
|
|
#include <LibWeb/TreeNode.h>
|
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
namespace Web::DOM {
|
2020-03-28 09:12:13 +01:00
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
class NonElementParentNode {
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Element> get_element_by_id(FlyString const& id) const
|
2020-03-28 09:12:13 +01:00
|
|
|
{
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Element> found_element;
|
2024-07-21 11:43:59 +02:00
|
|
|
const_cast<NodeType*>(static_cast<NodeType const*>(this))->template for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
2023-11-02 14:58:18 +01:00
|
|
|
if (element.id() == id) {
|
2023-02-25 10:44:51 -07:00
|
|
|
found_element = &element;
|
2024-07-21 11:43:59 +02:00
|
|
|
return TraversalDecision::Break;
|
2023-02-25 10:44:51 -07:00
|
|
|
}
|
2024-05-04 14:47:04 +01:00
|
|
|
return TraversalDecision::Continue;
|
2023-02-25 10:44:51 -07:00
|
|
|
});
|
|
|
|
return found_element;
|
2020-03-28 09:12:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2021-09-15 23:24:47 -07:00
|
|
|
NonElementParentNode() = default;
|
2020-03-28 09:12:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|