2021-03-09 13:36:21 -03:00
|
|
|
/*
|
2021-04-28 17:46:44 -03:00
|
|
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
2021-09-03 07:14:37 -03:00
|
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
2021-03-09 13:36:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-03-09 13:36:21 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-07-01 10:13:48 -03:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
|
#include <AK/RefPtr.h>
|
2021-03-09 16:06:52 -03:00
|
|
|
#include <LibWeb/CSS/Parser/Token.h>
|
2021-03-09 13:36:21 -03:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2021-07-01 10:13:48 -03:00
|
|
|
class StyleBlockRule;
|
|
|
|
|
class StyleFunctionRule;
|
|
|
|
|
|
2021-03-09 13:36:21 -03:00
|
|
|
class StyleComponentValueRule {
|
|
|
|
|
friend class Parser;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum class ComponentType {
|
|
|
|
|
Token,
|
|
|
|
|
Function,
|
|
|
|
|
Block
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-03 10:54:19 -03:00
|
|
|
StyleComponentValueRule(Token);
|
|
|
|
|
explicit StyleComponentValueRule(NonnullRefPtr<StyleFunctionRule>);
|
|
|
|
|
explicit StyleComponentValueRule(NonnullRefPtr<StyleBlockRule>);
|
2021-03-09 13:36:21 -03:00
|
|
|
~StyleComponentValueRule();
|
|
|
|
|
|
2021-06-30 12:27:37 -03:00
|
|
|
bool is_block() const { return m_type == ComponentType::Block; }
|
2021-07-01 10:13:48 -03:00
|
|
|
StyleBlockRule const& block() const
|
|
|
|
|
{
|
|
|
|
|
VERIFY(is_block());
|
|
|
|
|
return *m_block;
|
|
|
|
|
}
|
2021-06-30 12:27:37 -03:00
|
|
|
|
|
|
|
|
bool is_function() const { return m_type == ComponentType::Function; }
|
2021-07-01 10:13:48 -03:00
|
|
|
StyleFunctionRule const& function() const
|
|
|
|
|
{
|
|
|
|
|
VERIFY(is_function());
|
|
|
|
|
return *m_function;
|
|
|
|
|
}
|
2021-06-30 12:27:37 -03:00
|
|
|
|
2022-03-13 13:46:51 -03:00
|
|
|
bool is_token() const { return m_type == ComponentType::Token; }
|
2021-07-09 16:54:06 -03:00
|
|
|
bool is(Token::Type type) const
|
2021-06-30 12:27:37 -03:00
|
|
|
{
|
|
|
|
|
return m_type == ComponentType::Token && m_token.is(type);
|
|
|
|
|
}
|
|
|
|
|
Token const& token() const { return m_token; }
|
|
|
|
|
operator Token() const { return m_token; }
|
|
|
|
|
|
2021-11-24 10:00:25 -03:00
|
|
|
String to_string() const;
|
2021-07-07 17:29:24 -03:00
|
|
|
String to_debug_string() const;
|
2021-03-09 13:36:21 -03:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ComponentType m_type;
|
|
|
|
|
Token m_token;
|
2021-07-01 10:13:48 -03:00
|
|
|
RefPtr<StyleFunctionRule> m_function;
|
|
|
|
|
RefPtr<StyleBlockRule> m_block;
|
2021-03-09 13:36:21 -03:00
|
|
|
};
|
|
|
|
|
}
|