summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp
blob: 2870c97f4ca3b0339d915be14dba6f8402b23e35 (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
/*
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/TypeCasts.h>
#include <LibWeb/Bindings/CSSFontFaceRuleWrapper.h>
#include <LibWeb/Bindings/CSSImportRuleWrapper.h>
#include <LibWeb/Bindings/CSSMediaRuleWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
#include <LibWeb/Bindings/CSSStyleRuleWrapper.h>
#include <LibWeb/Bindings/CSSSupportsRuleWrapper.h>
#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/CSS/CSSImportRule.h>
#include <LibWeb/CSS/CSSMediaRule.h>
#include <LibWeb/CSS/CSSStyleRule.h>
#include <LibWeb/CSS/CSSSupportsRule.h>

namespace Web::Bindings {

CSSRuleWrapper* wrap(JS::Realm& realm, CSS::CSSRule& rule)
{
    if (rule.wrapper())
        return static_cast<CSSRuleWrapper*>(rule.wrapper());

    if (is<CSS::CSSStyleRule>(rule))
        return static_cast<CSSRuleWrapper*>(wrap_impl(realm, verify_cast<CSS::CSSStyleRule>(rule)));
    if (is<CSS::CSSImportRule>(rule))
        return static_cast<CSSRuleWrapper*>(wrap_impl(realm, verify_cast<CSS::CSSImportRule>(rule)));
    if (is<CSS::CSSMediaRule>(rule))
        return static_cast<CSSRuleWrapper*>(wrap_impl(realm, verify_cast<CSS::CSSMediaRule>(rule)));
    if (is<CSS::CSSFontFaceRule>(rule))
        return static_cast<CSSRuleWrapper*>(wrap_impl(realm, verify_cast<CSS::CSSFontFaceRule>(rule)));
    if (is<CSS::CSSSupportsRule>(rule))
        return static_cast<CSSRuleWrapper*>(wrap_impl(realm, verify_cast<CSS::CSSSupportsRule>(rule)));
    return static_cast<CSSRuleWrapper*>(wrap_impl(realm, rule));
}

}