mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb/CSS: Include guaranteed-invalid value in ComponentValue
Treating these like any other ComponentValue means not having to convert between different types of Vector, and that we will be able to use TokenStream to parse the "argument grammars" of arbitrary substitution functions.
This commit is contained in:
parent
b5ed910f1f
commit
9079be850b
Notes:
github-actions[bot]
2025-07-09 15:46:20 +00:00
Author: https://github.com/AtkinsSJ
Commit: 9079be850b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5226
Reviewed-by: https://github.com/tcl3 ✅
4 changed files with 44 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -10,7 +10,7 @@
|
|||
namespace Web::CSS::Parser {
|
||||
|
||||
ComponentValue::ComponentValue(Token token)
|
||||
: m_value(token)
|
||||
: m_value(move(token))
|
||||
{
|
||||
}
|
||||
ComponentValue::ComponentValue(Function&& function)
|
||||
|
@ -21,6 +21,10 @@ ComponentValue::ComponentValue(SimpleBlock&& block)
|
|||
: m_value(move(block))
|
||||
{
|
||||
}
|
||||
ComponentValue::ComponentValue(GuaranteedInvalidValue&& invalid)
|
||||
: m_value(move(invalid))
|
||||
{
|
||||
}
|
||||
|
||||
ComponentValue::~ComponentValue() = default;
|
||||
|
||||
|
@ -50,6 +54,9 @@ String ComponentValue::to_debug_string() const
|
|||
},
|
||||
[](Function const& function) {
|
||||
return MUST(String::formatted("Function: {}", function.to_string()));
|
||||
},
|
||||
[](GuaranteedInvalidValue const&) {
|
||||
return "Guaranteed-invalid value"_string;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -58,4 +65,25 @@ String ComponentValue::original_source_text() const
|
|||
return m_value.visit([](auto const& it) { return it.original_source_text(); });
|
||||
}
|
||||
|
||||
bool ComponentValue::contains_guaranteed_invalid_value() const
|
||||
{
|
||||
return m_value.visit(
|
||||
[](Token const&) {
|
||||
return false;
|
||||
},
|
||||
[](SimpleBlock const& block) {
|
||||
return block.value
|
||||
.first_matching([](auto const& it) { return it.contains_guaranteed_invalid_value(); })
|
||||
.has_value();
|
||||
},
|
||||
[](Function const& function) {
|
||||
return function.value
|
||||
.first_matching([](auto const& it) { return it.contains_guaranteed_invalid_value(); })
|
||||
.has_value();
|
||||
},
|
||||
[](GuaranteedInvalidValue const&) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
||||
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -24,6 +24,7 @@ public:
|
|||
ComponentValue(Token);
|
||||
explicit ComponentValue(Function&&);
|
||||
explicit ComponentValue(SimpleBlock&&);
|
||||
explicit ComponentValue(GuaranteedInvalidValue&&);
|
||||
~ComponentValue();
|
||||
|
||||
bool is_block() const { return m_value.has<SimpleBlock>(); }
|
||||
|
@ -40,12 +41,15 @@ public:
|
|||
Token const& token() const { return m_value.get<Token>(); }
|
||||
operator Token() const { return m_value.get<Token>(); }
|
||||
|
||||
bool is_guaranteed_invalid() const { return m_value.has<GuaranteedInvalidValue>(); }
|
||||
bool contains_guaranteed_invalid_value() const;
|
||||
|
||||
String to_string() const;
|
||||
String to_debug_string() const;
|
||||
String original_source_text() const;
|
||||
|
||||
private:
|
||||
Variant<Token, Function, SimpleBlock> m_value;
|
||||
Variant<Token, Function, SimpleBlock, GuaranteedInvalidValue> m_value;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -88,4 +88,11 @@ struct Function {
|
|||
bool contains_arbitrary_substitution_function() const;
|
||||
};
|
||||
|
||||
// https://drafts.csswg.org/css-variables/#guaranteed-invalid-value
|
||||
struct GuaranteedInvalidValue {
|
||||
GuaranteedInvalidValue() = default;
|
||||
String to_string() const { return {}; }
|
||||
String original_source_text() const { return {}; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -342,6 +342,7 @@ class Tokenizer;
|
|||
struct AtRule;
|
||||
struct Declaration;
|
||||
struct Function;
|
||||
struct GuaranteedInvalidValue;
|
||||
struct QualifiedRule;
|
||||
struct SimpleBlock;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue