ladybird/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h
Sam Atkins 8b538b1578 LibWeb: Rename StyleComponentValueRule -> ComponentValue
"Component value" is the term used in the spec, and it doesn't conflict
 with any other types, so let's use the shorter name. :^)

Also, this doesn't need to be friends with the Parser any more.
2022-04-07 21:20:14 +02:00

44 lines
1.4 KiB
C++

/*
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/RefPtr.h>
#include <LibWeb/CSS/Parser/Token.h>
namespace Web::CSS {
class StyleBlockRule;
class StyleFunctionRule;
// https://www.w3.org/TR/css-syntax-3/#component-value
class ComponentValue {
public:
ComponentValue(Token);
explicit ComponentValue(NonnullRefPtr<StyleFunctionRule>);
explicit ComponentValue(NonnullRefPtr<StyleBlockRule>);
~ComponentValue();
bool is_block() const { return m_value.has<NonnullRefPtr<StyleBlockRule>>(); }
StyleBlockRule const& block() const { return m_value.get<NonnullRefPtr<StyleBlockRule>>(); }
bool is_function() const { return m_value.has<NonnullRefPtr<StyleFunctionRule>>(); }
StyleFunctionRule const& function() const { return m_value.get<NonnullRefPtr<StyleFunctionRule>>(); }
bool is_token() const { return m_value.has<Token>(); }
bool is(Token::Type type) const { return is_token() && token().is(type); }
Token const& token() const { return m_value.get<Token>(); }
operator Token() const { return m_value.get<Token>(); }
String to_string() const;
String to_debug_string() const;
private:
Variant<Token, NonnullRefPtr<StyleFunctionRule>, NonnullRefPtr<StyleBlockRule>> m_value;
};
}