summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp
blob: f108e52fd129568b04e743c7a85b85746243bc1e (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
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/Layout/BlockBox.h>

namespace Web::DOM {

ShadowRoot::ShadowRoot(Document& document, Element& host)
    : DocumentFragment(document)
{
    set_host(host);
}

EventTarget* ShadowRoot::get_parent(const Event& event)
{
    if (!event.composed()) {
        auto& events_first_invocation_target = downcast<Node>(*event.path().first().invocation_target);
        if (events_first_invocation_target.root() == this)
            return nullptr;
    }

    return host();
}

RefPtr<Layout::Node> ShadowRoot::create_layout_node()
{
    return adopt(*new Layout::BlockBox(document(), this, CSS::ComputedValues {}));
}

}