summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/ParentNode.h
blob: 856c5a459714b8c5a10a83d0356e7ef2b5994f1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/NonnullRefPtrVector.h>
#include <LibWeb/DOM/Node.h>

namespace Web::DOM {

class ParentNode : public Node {
public:
    template<typename F>
    void for_each_child(F) const;
    template<typename F>
    void for_each_child(F);

    RefPtr<Element> first_element_child();
    RefPtr<Element> last_element_child();
    u32 child_element_count() const;

    RefPtr<Element> query_selector(const StringView&);
    NonnullRefPtrVector<Element> query_selector_all(const StringView&);

protected:
    ParentNode(Document& document, NodeType type)
        : Node(document, type)
    {
    }
};

template<typename Callback>
inline void ParentNode::for_each_child(Callback callback) const
{
    for (auto* node = first_child(); node; node = node->next_sibling())
        callback(*node);
}

template<typename Callback>
inline void ParentNode::for_each_child(Callback callback)
{
    for (auto* node = first_child(); node; node = node->next_sibling())
        callback(*node);
}

}