From 5d57723ebf85c58e38166859c70d09dfc96110c9 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 19 Mar 2025 11:32:34 +0000 Subject: [PATCH] LibWeb: Implement `CSSImportRule.supportsText` Returns the supports condition specified by the given import at-rule. --- Libraries/LibWeb/CSS/CSSImportRule.cpp | 7 +++++++ Libraries/LibWeb/CSS/CSSImportRule.h | 2 ++ Libraries/LibWeb/CSS/CSSImportRule.idl | 2 +- Libraries/LibWeb/CSS/Parser/Parser.cpp | 4 +++- Libraries/LibWeb/CSS/Supports.cpp | 2 +- .../expected/css/CSSImportRule-supportsText.txt | 4 ++++ .../input/css/CSSImportRule-supportsText.html | 17 +++++++++++++++++ 7 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/css/CSSImportRule-supportsText.txt create mode 100644 Tests/LibWeb/Text/input/css/CSSImportRule-supportsText.html diff --git a/Libraries/LibWeb/CSS/CSSImportRule.cpp b/Libraries/LibWeb/CSS/CSSImportRule.cpp index 9c9d77088e3..f0cc8d7fa8d 100644 --- a/Libraries/LibWeb/CSS/CSSImportRule.cpp +++ b/Libraries/LibWeb/CSS/CSSImportRule.cpp @@ -171,4 +171,11 @@ void CSSImportRule::set_style_sheet(GC::Ref style_sheet) m_document->invalidate_style(DOM::StyleInvalidationReason::CSSImportRule); } +Optional CSSImportRule::supports_text() const +{ + if (!m_supports) + return {}; + return m_supports->to_string(); +} + } diff --git a/Libraries/LibWeb/CSS/CSSImportRule.h b/Libraries/LibWeb/CSS/CSSImportRule.h index bfb6a2dcbe7..e6989188074 100644 --- a/Libraries/LibWeb/CSS/CSSImportRule.h +++ b/Libraries/LibWeb/CSS/CSSImportRule.h @@ -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 supports_text() const; + private: CSSImportRule(URL::URL, DOM::Document&, RefPtr); diff --git a/Libraries/LibWeb/CSS/CSSImportRule.idl b/Libraries/LibWeb/CSS/CSSImportRule.idl index d474386d076..d6f7446e4af 100644 --- a/Libraries/LibWeb/CSS/CSSImportRule.idl +++ b/Libraries/LibWeb/CSS/CSSImportRule.idl @@ -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; }; diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index f54ed099c31..f01ec0aa5ff 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -291,9 +291,11 @@ OwnPtr Parser::parse_supports_feature(TokenStreamto_string(), convert_to_style_property(*declaration).has_value()); + + return BooleanExpressionInParens::create(supports_declaration.release_nonnull()); } } diff --git a/Libraries/LibWeb/CSS/Supports.cpp b/Libraries/LibWeb/CSS/Supports.cpp index 99112242623..09ef0411099 100644 --- a/Libraries/LibWeb/CSS/Supports.cpp +++ b/Libraries/LibWeb/CSS/Supports.cpp @@ -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 diff --git a/Tests/LibWeb/Text/expected/css/CSSImportRule-supportsText.txt b/Tests/LibWeb/Text/expected/css/CSSImportRule-supportsText.txt new file mode 100644 index 00000000000..52162806d0d --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/CSSImportRule-supportsText.txt @@ -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) diff --git a/Tests/LibWeb/Text/input/css/CSSImportRule-supportsText.html b/Tests/LibWeb/Text/input/css/CSSImportRule-supportsText.html new file mode 100644 index 00000000000..6704b7af171 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/CSSImportRule-supportsText.html @@ -0,0 +1,17 @@ + + + +