2020-03-28 09:12:13 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-28 09:12:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
2022-09-13 16:02:25 +02:00
|
|
|
#include <LibJS/Heap/GCPtr.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:
|
2023-02-25 10:44:51 -07:00
|
|
|
JS::GCPtr<Element const> get_element_by_id(DeprecatedFlyString const& id) const
|
2020-03-28 09:12:13 +01:00
|
|
|
{
|
2023-02-25 10:44:51 -07: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-09-03 14:58:18 +12:00
|
|
|
if (element.deprecated_attribute(HTML::AttributeNames::id) == id) {
|
2020-03-28 09:12:13 +01:00
|
|
|
found_element = &element;
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
});
|
|
|
|
|
return found_element;
|
|
|
|
|
}
|
2023-02-25 10:44:51 -07:00
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
JS::GCPtr<Element> get_element_by_id(DeprecatedFlyString const& id)
|
2020-03-28 09:12:13 +01:00
|
|
|
{
|
2023-02-25 10:44:51 -07:00
|
|
|
JS::GCPtr<Element> found_element;
|
|
|
|
|
static_cast<NodeType*>(this)->template for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
2023-09-03 14:58:18 +12:00
|
|
|
if (element.deprecated_attribute(HTML::AttributeNames::id) == id) {
|
2023-02-25 10:44:51 -07:00
|
|
|
found_element = &element;
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
});
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|