Skip to content

Commit b4fbbbb

Browse files
committed
Bug 1846251 - Make CSSStyleRule inherit from CSSGroupingRule. r=peterv,devtools-reviewers
As per w3c/csswg-drafts#8940. I didn't do this in bug 1837638 because that's what the spec said at the time, that's what other browsers did, and specially because if we did this we had no way of runtime-disable nesting during development or if things went south. This means that we can't keep the nesting pref in 118, but that seems fine (it's already enabled everywhere in 117). Differential Revision: https://phabricator.services.mozilla.com/D184930
1 parent e6cea60 commit b4fbbbb

19 files changed

+8
-47
lines changed

devtools/client/inspector/changes/test/browser_changes_nested_rules.js

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ const EXPECTED_AFTER_SPAN_PROP_CHANGES = EXPECTED_AFTER_DIV_PROP_CHANGE.map(
110110
]);
111111

112112
add_task(async function () {
113-
await pushPref("layout.css.nesting.enabled", true);
114-
115113
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
116114
const { inspector, view: ruleView } = await openRuleView();
117115
const changesView = selectChangesView(inspector);

devtools/client/inspector/rules/test/browser_rules_content_01.js

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const TEST_URI = `
3535
`;
3636

3737
add_task(async function () {
38-
await pushPref("layout.css.nesting.enabled", true);
3938
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
4039
const { inspector, view } = await openRuleView();
4140

devtools/client/inspector/rules/test/browser_rules_edit-property-nested-rules.js

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ add_task(async function test_constructed_sheet() {
4646
});
4747

4848
async function runTest(uri) {
49-
await pushPref("layout.css.nesting.enabled", true);
5049
await addTab(`data:text/html,<meta charset=utf8>${encodeURIComponent(uri)}`);
5150
const { inspector, view } = await openRuleView();
5251

devtools/client/inspector/rules/test/browser_rules_edit-selector-nested-rules.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ add_task(async function test_constructed_sheet() {
3939
});
4040

4141
async function runTest(uri) {
42-
await pushPref("layout.css.nesting.enabled", true);
4342
await addTab(`data:text/html,<meta charset=utf8>${encodeURIComponent(uri)}`);
4443
const { inspector, view } = await openRuleView();
4544

devtools/client/inspector/rules/test/browser_rules_nested_rules.js

-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const TEST_URI = `
4747
`;
4848

4949
add_task(async function () {
50-
await pushPref("layout.css.nesting.enabled", true);
51-
5250
await addTab(
5351
"https://example.com/document-builder.sjs?html=" +
5452
encodeURIComponent(TEST_URI)

devtools/client/inspector/rules/test/browser_rules_selector-highlighter-nested-rules.js

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const TEST_URI = `
3838
</main>`;
3939

4040
add_task(async function () {
41-
await pushPref("layout.css.nesting.enabled", true);
4241
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
4342
const { inspector, view } = await openRuleView();
4443

devtools/client/styleeditor/test/browser_styleeditor_at_rules_sidebar.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ waitForExplicitFinish();
3939

4040
add_task(async function () {
4141
await pushPref("layout.css.container-queries.enabled", true);
42-
await pushPref("layout.css.nesting.enabled", true);
4342

4443
const { ui } = await openStyleEditorForURL(TESTCASE_URI);
4544

devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_links.js

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const TESTCASE_URI = TEST_BASE_HTTPS + "media-rules.html";
1616
const responsiveModeToggleClass = ".media-responsive-mode-toggle";
1717

1818
add_task(async function () {
19-
await pushPref("layout.css.nesting.enabled", true);
2019
const { ui } = await openStyleEditorForURL(TESTCASE_URI);
2120

2221
const editor = ui.editors[1];

devtools/client/styleeditor/test/browser_styleeditor_sidebars.js

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const MEDIA_WIDTH = 250;
1818

1919
// Test that sidebar in the styleeditor can be resized.
2020
add_task(async function () {
21-
await pushPref("layout.css.nesting.enabled", true);
2221
await pushPref(PREF_SHOW_AT_RULES_SIDEBAR, true);
2322
await pushPref(PREF_NAV_WIDTH, NAV_WIDTH);
2423
await pushPref(PREF_SIDEBAR_WIDTH, MEDIA_WIDTH);

devtools/client/webconsole/test/browser/browser_webconsole_css_error_impacted_elements.js

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8>
4343
add_task(async function () {
4444
// Enable CSS Warnings
4545
await pushPref("devtools.webconsole.filter.css", true);
46-
await pushPref("layout.css.nesting.enabled", true);
4746

4847
const hud = await openNewTabAndConsole(TEST_URI);
4948
const toolbox = hud.toolbox;

devtools/shared/commands/resource/tests/browser_resources_css_messages.js

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ httpServer.registerPathHandler(`/test_css_messages.html`, (req, res) => {
2525
const TEST_URI = `http://localhost:${httpServer.identity.primaryPort}/test_css_messages.html`;
2626

2727
add_task(async function () {
28-
await pushPref("layout.css.nesting.enabled", true);
2928
await testWatchingCssMessages();
3029
await testWatchingCachedCssMessages();
3130
});

dom/webidl/CSSStyleRule.webidl

+1-8
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99

1010
// https://drafts.csswg.org/cssom/#the-cssstylerule-interface
1111
[Exposed=Window]
12-
interface CSSStyleRule : CSSRule {
12+
interface CSSStyleRule : CSSGroupingRule {
1313
attribute UTF8String selectorText;
1414
[SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
1515

16-
// https://drafts.csswg.org/css-nesting/#cssom-style
17-
// FIXME: Ideally CSSStyleRule should inherit from CSSGroupingRule instead,
18-
// see https://github.com/w3c/csswg-drafts/issues/8940
19-
[Pref="layout.css.nesting.enabled", SameObject] readonly attribute CSSRuleList cssRules;
20-
[Pref="layout.css.nesting.enabled", Throws] unsigned long insertRule(UTF8String rule, optional unsigned long index = 0);
21-
[Pref="layout.css.nesting.enabled", Throws] undefined deleteRule(unsigned long index);
22-
2316
[ChromeOnly] readonly attribute unsigned long selectorCount;
2417
[ChromeOnly] UTF8String selectorTextAt(unsigned long index, optional boolean desugared = false);
2518
[ChromeOnly] unsigned long long selectorSpecificityAt(unsigned long index, optional boolean desugared = false);

layout/inspector/tests/mochitest.ini

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[DEFAULT]
22
prefs =
3-
layout.css.nesting.enabled=true
43
layout.css.basic-shape-rect.enabled=true
54
layout.css.basic-shape-xywh.enabled=true
65
support-files =

modules/libpref/init/StaticPrefList.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -8176,13 +8176,6 @@
81768176
mirror: always
81778177
rust: true
81788178

8179-
# Whether CSS nesting is enabled.
8180-
- name: layout.css.nesting.enabled
8181-
type: RelaxedAtomicBool
8182-
value: true
8183-
mirror: always
8184-
rust: true
8185-
81868179
# Should we look for counter ancestor scopes first?
81878180
- name: layout.css.counter-ancestor-scope.enabled
81888181
type: bool

servo/components/style/gecko/selector_parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
307307
type Impl = SelectorImpl;
308308
type Error = StyleParseErrorKind<'i>;
309309

310+
#[inline]
310311
fn parse_parent_selector(&self) -> bool {
311-
static_prefs::pref!("layout.css.nesting.enabled")
312+
true
312313
}
313314

314315
#[inline]

servo/components/style/stylesheets/rule_parser.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,6 @@ impl NestedParseResult {
501501
}
502502

503503
impl<'a, 'i> NestedRuleParser<'a, 'i> {
504-
/// When nesting is disabled, we prevent parsing at rules and qualified rules inside style
505-
/// rules.
506-
fn allow_at_and_qualified_rules(&self) -> bool {
507-
if !self.in_style_rule() {
508-
return true;
509-
}
510-
static_prefs::pref!("layout.css.nesting.enabled")
511-
}
512-
513504
#[inline]
514505
fn in_style_rule(&self) -> bool {
515506
self.context.rule_types.contains(CssRuleType::Style)
@@ -622,9 +613,6 @@ impl<'a, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'i> {
622613
name: CowRcStr<'i>,
623614
input: &mut Parser<'i, 't>,
624615
) -> Result<Self::Prelude, ParseError<'i>> {
625-
if self.in_style_rule() && !static_prefs::pref!("layout.css.nesting.enabled") {
626-
return Err(input.new_error(BasicParseErrorKind::AtRuleInvalid(name)));
627-
}
628616
Ok(match_ignore_ascii_case! { &*name,
629617
"media" => {
630618
let media_queries = MediaList::parse(&self.context, input);
@@ -934,9 +922,7 @@ impl<'a, 'i> DeclarationParser<'i> for NestedRuleParser<'a, 'i> {
934922
}
935923

936924
impl<'a, 'i> RuleBodyItemParser<'i, (), StyleParseErrorKind<'i>> for NestedRuleParser<'a, 'i> {
937-
fn parse_qualified(&self) -> bool {
938-
self.allow_at_and_qualified_rules()
939-
}
925+
fn parse_qualified(&self) -> bool { true }
940926

941927
/// If nesting is disabled, we can't get there for a non-style-rule. If it's enabled, we parse
942928
/// raw declarations there.

testing/web-platform/meta/css/CSS2/syntax/malformed-decl-block-001.xht.ini

-1
This file was deleted.

testing/web-platform/meta/css/css-nesting/__dir__.ini

-1
This file was deleted.

testing/web-platform/tests/css/css-nesting/cssom.html

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<style id="ss"></style>
99

1010
<script>
11+
test(() => {
12+
assert_equals(CSSStyleRule.__proto__, CSSGroupingRule);
13+
}, "CSSStyleRule is a CSSGroupingRule");
14+
1115
test(() => {
1216
let [ss] = document.styleSheets;
1317
assert_equals(ss.cssRules.length, 0);

0 commit comments

Comments
 (0)