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