Coverage Report

Created: 2026-09-26 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2020-2021, the SerenityOS developers.
3
 * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
4
 * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
5
 *
6
 * SPDX-License-Identifier: BSD-2-Clause
7
 */
8
9
#pragma once
10
11
#include <AK/NonnullRefPtr.h>
12
#include <AK/RefPtr.h>
13
#include <LibWeb/CSS/Parser/Token.h>
14
#include <LibWeb/CSS/Parser/Types.h>
15
16
namespace Web::CSS::Parser {
17
18
// https://drafts.csswg.org/css-syntax/#component-value
19
class ComponentValue {
20
public:
21
    ComponentValue(Token);
22
    explicit ComponentValue(Function&&);
23
    explicit ComponentValue(SimpleBlock&&);
24
    ~ComponentValue();
25
26
0
    bool is_block() const { return m_value.has<SimpleBlock>(); }
27
0
    SimpleBlock& block() { return m_value.get<SimpleBlock>(); }
28
0
    SimpleBlock const& block() const { return m_value.get<SimpleBlock>(); }
29
30
0
    bool is_function() const { return m_value.has<Function>(); }
31
    bool is_function(StringView name) const;
32
0
    Function& function() { return m_value.get<Function>(); }
33
0
    Function const& function() const { return m_value.get<Function>(); }
34
35
0
    bool is_token() const { return m_value.has<Token>(); }
36
0
    bool is(Token::Type type) const { return is_token() && token().is(type); }
37
0
    bool is_delim(u32 delim) const { return is(Token::Type::Delim) && token().delim() == delim; }
38
    bool is_ident(StringView ident) const;
39
0
    Token const& token() const { return m_value.get<Token>(); }
40
0
    operator Token() const { return m_value.get<Token>(); }
41
42
    String to_string() const;
43
    String to_debug_string() const;
44
    String original_source_text() const;
45
46
private:
47
    Variant<Token, Function, SimpleBlock> m_value;
48
};
49
}
50
51
template<>
52
struct AK::Formatter<Web::CSS::Parser::ComponentValue> : Formatter<StringView> {
53
    ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Parser::ComponentValue const& component_value)
54
0
    {
55
0
        return Formatter<StringView>::format(builder, component_value.to_string());
56
0
    }
57
};