mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:57:35 +00:00
LibWeb: Implement @supports selector(.foo)
This is defined in https://www.w3.org/TR/css-conditional-4/#at-supports-ext which just became a CR. :^)
This commit is contained in:
parent
c50ea8c1dd
commit
7880718fa8
4 changed files with 93 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -1309,12 +1309,23 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<StyleComp
|
|||
// `<supports-decl>`
|
||||
if (first_token.is_block() && first_token.block().is_paren()) {
|
||||
TokenStream block_tokens { first_token.block().values() };
|
||||
// FIXME: Parsing and then converting back to a string is weird.
|
||||
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
|
||||
return Supports::Feature {
|
||||
.declaration = declaration->to_string()
|
||||
Supports::Declaration { declaration->to_string() }
|
||||
};
|
||||
}
|
||||
}
|
||||
// `<supports-selector-fn>`
|
||||
if (first_token.is_function() && first_token.function().name().equals_ignoring_case("selector"sv)) {
|
||||
// FIXME: Parsing and then converting back to a string is weird.
|
||||
StringBuilder builder;
|
||||
for (auto const& item : first_token.function().values())
|
||||
builder.append(item.to_string());
|
||||
return Supports::Feature {
|
||||
Supports::Selector { builder.to_string() }
|
||||
};
|
||||
}
|
||||
|
||||
tokens.rewind_to_position(start_position);
|
||||
return {};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -50,10 +50,27 @@ bool Supports::InParens::evaluate() const
|
|||
});
|
||||
}
|
||||
|
||||
bool Supports::Feature::evaluate() const
|
||||
bool Supports::Declaration::evaluate() const
|
||||
{
|
||||
auto style_property = Parser({}, declaration).parse_as_declaration();
|
||||
return style_property.has_value();
|
||||
}
|
||||
|
||||
bool Supports::Selector::evaluate() const
|
||||
{
|
||||
auto style_property = Parser({}, selector).parse_as_selector();
|
||||
return style_property.has_value();
|
||||
}
|
||||
|
||||
bool Supports::Feature::evaluate() const
|
||||
{
|
||||
return value.visit(
|
||||
[&](Declaration const& declaration) {
|
||||
return declaration.evaluate();
|
||||
},
|
||||
[&](Selector const& selector) {
|
||||
return selector.evaluate();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -16,16 +16,26 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
// https://www.w3.org/TR/css-conditional-3/#at-supports
|
||||
// https://www.w3.org/TR/css-conditional-4/#at-supports
|
||||
class Supports final : public RefCounted<Supports> {
|
||||
friend class Parser;
|
||||
|
||||
public:
|
||||
struct Feature {
|
||||
struct Declaration {
|
||||
String declaration;
|
||||
bool evaluate() const;
|
||||
};
|
||||
|
||||
struct Selector {
|
||||
String selector;
|
||||
bool evaluate() const;
|
||||
};
|
||||
|
||||
struct Feature {
|
||||
Variant<Declaration, Selector> value;
|
||||
bool evaluate() const;
|
||||
};
|
||||
|
||||
struct Condition;
|
||||
struct InParens {
|
||||
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue