Serenity Operating System
at master 53 lines 1.5 kB view raw
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 <AK/FlyString.h> 11#include <AK/RefCounted.h> 12#include <AK/Vector.h> 13#include <LibWeb/CSS/Parser/Block.h> 14#include <LibWeb/CSS/Parser/ComponentValue.h> 15 16namespace Web::CSS::Parser { 17 18class Rule : public RefCounted<Rule> { 19public: 20 enum class Type { 21 At, 22 Qualified, 23 }; 24 25 static NonnullRefPtr<Rule> make_at_rule(FlyString name, Vector<ComponentValue> prelude, RefPtr<Block> block) 26 { 27 return adopt_ref(*new Rule(Type::At, move(name), move(prelude), move(block))); 28 } 29 30 static NonnullRefPtr<Rule> make_qualified_rule(Vector<ComponentValue> prelude, RefPtr<Block> block) 31 { 32 return adopt_ref(*new Rule(Type::Qualified, {}, move(prelude), move(block))); 33 } 34 35 ~Rule(); 36 37 bool is_qualified_rule() const { return m_type == Type::Qualified; } 38 bool is_at_rule() const { return m_type == Type::At; } 39 40 Vector<ComponentValue> const& prelude() const { return m_prelude; } 41 RefPtr<Block const> block() const { return m_block; } 42 StringView at_rule_name() const { return m_at_rule_name; } 43 44private: 45 Rule(Type, FlyString name, Vector<ComponentValue> prelude, RefPtr<Block>); 46 47 Type const m_type; 48 FlyString m_at_rule_name; 49 Vector<ComponentValue> m_prelude; 50 RefPtr<Block> m_block; 51}; 52 53}