summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h
blob: 7444607cfd86ea5d37c08264428669c1c196177d (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
/*
 * Copyright (c) 2022, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Variant.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/HTMLCollection.h>

namespace Web::HTML {

using HTMLOptionOrOptGroupElement = Variant<NonnullRefPtr<HTMLOptionElement>, NonnullRefPtr<HTMLOptGroupElement>>;
using HTMLElementOrElementIndex = Variant<NonnullRefPtr<HTMLElement>, i32>;

class HTMLOptionsCollection final : public DOM::HTMLCollection {
public:
    using WrapperType = Bindings::HTMLOptionsCollectionWrapper;

    static NonnullRefPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
    {
        return adopt_ref(*new HTMLOptionsCollection(root, move(filter)));
    }

    DOM::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});

protected:
    HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter);
};

}

namespace Web::Bindings {

HTMLOptionsCollectionWrapper* wrap(JS::GlobalObject&, HTML::HTMLOptionsCollection&);

}