Serenity Operating System
1/*
2 * Copyright (c) 2020-2021, the SerenityOS developers.
3 * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <LibWeb/CSS/Parser/Declaration.h>
11#include <LibWeb/CSS/Parser/Rule.h>
12
13namespace Web::CSS::Parser {
14
15class DeclarationOrAtRule {
16public:
17 explicit DeclarationOrAtRule(RefPtr<Rule> at);
18 explicit DeclarationOrAtRule(Declaration declaration);
19 ~DeclarationOrAtRule();
20
21 enum class DeclarationType {
22 At,
23 Declaration,
24 };
25
26 bool is_at_rule() const { return m_type == DeclarationType::At; }
27 bool is_declaration() const { return m_type == DeclarationType::Declaration; }
28
29 Rule const& at_rule() const
30 {
31 VERIFY(is_at_rule());
32 return *m_at;
33 }
34
35 Declaration const& declaration() const
36 {
37 VERIFY(is_declaration());
38 return *m_declaration;
39 }
40
41private:
42 DeclarationType m_type;
43 RefPtr<Rule> m_at;
44 Optional<Declaration> m_declaration;
45};
46
47}