LibWeb: Implement matches attribute on CSSSupportsRule and CSSMediaRule

Gains us 4 WPT tests.
This commit is contained in:
Callum Law 2025-07-11 17:09:30 +12:00 committed by Jelle Raaijmakers
commit 1a0d4487a8
Notes: github-actions[bot] 2025-07-11 08:58:53 +00:00
7 changed files with 132 additions and 0 deletions

View file

@ -24,6 +24,8 @@ public:
virtual ~CSSMediaRule() = default;
virtual String condition_text() const override;
bool matches() const { return condition_matches(); }
virtual bool condition_matches() const override { return m_media->matches(); }
MediaList* media() const { return m_media; }

View file

@ -5,4 +5,5 @@
[Exposed=Window]
interface CSSMediaRule : CSSConditionRule {
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
readonly attribute boolean matches;
};

View file

@ -25,6 +25,8 @@ public:
virtual ~CSSSupportsRule() = default;
String condition_text() const override;
bool matches() const { return condition_matches(); }
virtual bool condition_matches() const override { return m_supports->matches(); }
Supports const& supports() const { return m_supports; }

View file

@ -3,4 +3,5 @@
// https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface
[Exposed=Window]
interface CSSSupportsRule : CSSConditionRule {
readonly attribute boolean matches;
};

View file

@ -0,0 +1,50 @@
Harness status: OK
Found 45 tests
45 Pass
Pass idl_test setup
Pass idl_test validation
Pass Partial interface CSSRule: original interface defined
Pass Partial interface CSSRule: member names are unique
Pass Partial namespace CSS: original namespace defined
Pass Partial namespace CSS: member names are unique
Pass CSSConditionRule interface: existence and properties of interface object
Pass CSSConditionRule interface object length
Pass CSSConditionRule interface object name
Pass CSSConditionRule interface: existence and properties of interface prototype object
Pass CSSConditionRule interface: existence and properties of interface prototype object's "constructor" property
Pass CSSConditionRule interface: existence and properties of interface prototype object's @@unscopables property
Pass CSSConditionRule interface: attribute conditionText
Pass CSSMediaRule interface: existence and properties of interface object
Pass CSSMediaRule interface object length
Pass CSSMediaRule interface object name
Pass CSSMediaRule interface: existence and properties of interface prototype object
Pass CSSMediaRule interface: existence and properties of interface prototype object's "constructor" property
Pass CSSMediaRule interface: existence and properties of interface prototype object's @@unscopables property
Pass CSSMediaRule interface: attribute media
Pass CSSMediaRule interface: attribute matches
Pass CSSMediaRule must be primary interface of cssMediaRule
Pass Stringification of cssMediaRule
Pass CSSMediaRule interface: cssMediaRule must inherit property "media" with the proper type
Pass CSSMediaRule interface: cssMediaRule must inherit property "matches" with the proper type
Pass CSSConditionRule interface: cssMediaRule must inherit property "conditionText" with the proper type
Pass CSSRule interface: cssMediaRule must inherit property "SUPPORTS_RULE" with the proper type
Pass CSSSupportsRule interface: existence and properties of interface object
Pass CSSSupportsRule interface object length
Pass CSSSupportsRule interface object name
Pass CSSSupportsRule interface: existence and properties of interface prototype object
Pass CSSSupportsRule interface: existence and properties of interface prototype object's "constructor" property
Pass CSSSupportsRule interface: existence and properties of interface prototype object's @@unscopables property
Pass CSSSupportsRule interface: attribute matches
Pass CSSSupportsRule must be primary interface of cssSupportsRule
Pass Stringification of cssSupportsRule
Pass CSSSupportsRule interface: cssSupportsRule must inherit property "matches" with the proper type
Pass CSSConditionRule interface: cssSupportsRule must inherit property "conditionText" with the proper type
Pass CSSRule interface: cssSupportsRule must inherit property "SUPPORTS_RULE" with the proper type
Pass CSSRule interface: constant SUPPORTS_RULE on interface object
Pass CSSRule interface: constant SUPPORTS_RULE on interface prototype object
Pass CSSRule interface: cssRule must inherit property "SUPPORTS_RULE" with the proper type
Pass CSS namespace: operation escape(CSSOMString)
Pass CSS namespace: operation supports(CSSOMString, CSSOMString)
Pass CSS namespace: operation supports(CSSOMString)

View file

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Conditional Rules IDL tests</title>
<link rel="help" href="https://drafts.csswg.org/css-conditional/">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/WebIDLParser.js"></script>
<script src="../../resources/idlharness.js"></script>
<!-- used to provide objects -->
<style>
div { display: block; }
</style>
<style>
@media print { }
</style>
<style>
@supports (display: block) { }
</style>
</head>
<body>
<div id="log"></div>
<script>
'use strict';
idl_test(
['css-conditional'],
['cssom', 'dom'],
idl_array => {
idl_array.add_objects({
CSSRule: ['cssRule'],
CSSMediaRule: ['cssMediaRule'],
CSSSupportsRule: ['cssSupportsRule'],
});
self.cssRule = document.styleSheets[0].cssRules[0];
self.cssMediaRule = document.styleSheets[1].cssRules[0];
self.cssSupportsRule = document.styleSheets[2].cssRules[0];
}
);
</script>
</body>
</html>

View file

@ -0,0 +1,29 @@
// GENERATED CONTENT - DO NOT EDIT
// Content was automatically extracted by Reffy into webref
// (https://github.com/w3c/webref)
// Source: CSS Conditional Rules Module Level 3 (https://drafts.csswg.org/css-conditional-3/)
partial interface CSSRule {
const unsigned short SUPPORTS_RULE = 12;
};
[Exposed=Window]
interface CSSConditionRule : CSSGroupingRule {
readonly attribute CSSOMString conditionText;
};
[Exposed=Window]
interface CSSMediaRule : CSSConditionRule {
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
readonly attribute boolean matches;
};
[Exposed=Window]
interface CSSSupportsRule : CSSConditionRule {
readonly attribute boolean matches;
};
partial namespace CSS {
boolean supports(CSSOMString property, CSSOMString value);
boolean supports(CSSOMString conditionText);
};