LibWeb: Implement CSSImportRule.supportsText

Returns the supports condition specified by the given import at-rule.
This commit is contained in:
Tim Ledbetter 2025-03-19 11:32:34 +00:00 committed by Jelle Raaijmakers
commit 5d57723ebf
Notes: github-actions[bot] 2025-03-19 15:43:53 +00:00
7 changed files with 35 additions and 3 deletions

View file

@ -171,4 +171,11 @@ void CSSImportRule::set_style_sheet(GC::Ref<CSSStyleSheet> style_sheet)
m_document->invalidate_style(DOM::StyleInvalidationReason::CSSImportRule);
}
Optional<String> CSSImportRule::supports_text() const
{
if (!m_supports)
return {};
return m_supports->to_string();
}
}

View file

@ -33,6 +33,8 @@ public:
CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; }
CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; }
Optional<String> supports_text() const;
private:
CSSImportRule(URL::URL, DOM::Document&, RefPtr<Supports>);

View file

@ -9,5 +9,5 @@ interface CSSImportRule : CSSRule {
// FIXME: [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
[SameObject, ImplementedAs=style_sheet_for_bindings] readonly attribute CSSStyleSheet? styleSheet;
[FIXME] readonly attribute CSSOMString? layerName;
[FIXME] readonly attribute CSSOMString? supportsText;
readonly attribute CSSOMString? supportsText;
};

View file

@ -291,9 +291,11 @@ OwnPtr<BooleanExpression> Parser::parse_supports_feature(TokenStream<ComponentVa
// FIXME: Parsing and then converting back to a string is weird.
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
transaction.commit();
return Supports::Declaration::create(
auto supports_declaration = Supports::Declaration::create(
declaration->to_string(),
convert_to_style_property(*declaration).has_value());
return BooleanExpressionInParens::create(supports_declaration.release_nonnull<BooleanExpression>());
}
}

View file

@ -22,7 +22,7 @@ MatchResult Supports::Declaration::evaluate(HTML::Window const*) const
String Supports::Declaration::to_string() const
{
return MUST(String::formatted("({})", m_declaration));
return m_declaration;
}
void Supports::Declaration::dump(StringBuilder& builder, int indent_levels) const

View file

@ -0,0 +1,4 @@
cssText: @import url("https://something.invalid/") supports(foo: bar);
supportsText: foo: bar
cssText: @import url("https://something.invalid/") supports((display: block) and (foo: bar));
supportsText: (display: block) and (foo: bar)

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<style>
@import url("https://something.invalid") supports(foo: bar);
@import url("https://something.invalid") supports((display: block) and (foo: bar));
</style>
<script src="../include.js"></script>
<script>
test(() => {
function printImportRule(importRule) {
println(`cssText: ${importRule.cssText}`);
println(`supportsText: ${importRule.supportsText}`);
}
printImportRule(document.styleSheets[0].cssRules[0]);
printImportRule(document.styleSheets[0].cssRules[1]);
});
</script>