Skip to content

Commit

Permalink
Backed out changeset 085c31f150d3 (bug 1846251) for causing CSSStyleR…
Browse files Browse the repository at this point in the history
…ule related wpt failures.
  • Loading branch information
Iulian Moraru committed Jul 31, 2023
1 parent a73ecfd commit b0b02ef
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const EXPECTED_AFTER_SPAN_PROP_CHANGES = EXPECTED_AFTER_DIV_PROP_CHANGE.map(
]);

add_task(async function () {
await pushPref("layout.css.nesting.enabled", true);

await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, view: ruleView } = await openRuleView();
const changesView = selectChangesView(inspector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const TEST_URI = `
`;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ add_task(async function test_constructed_sheet() {
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_task(async function test_constructed_sheet() {
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const TEST_URI = `
`;

add_task(async function () {
await pushPref("layout.css.nesting.enabled", true);

await addTab(
"https://example.com/document-builder.sjs?html=" +
encodeURIComponent(TEST_URI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const TEST_URI = `
</main>`;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ waitForExplicitFinish();

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

const { ui } = await openStyleEditorForURL(TESTCASE_URI);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const TESTCASE_URI = TEST_BASE_HTTPS + "media-rules.html";
const responsiveModeToggleClass = ".media-responsive-mode-toggle";

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

const editor = ui.editors[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const MEDIA_WIDTH = 250;

// Test that sidebar in the styleeditor can be resized.
add_task(async function () {
await pushPref("layout.css.nesting.enabled", true);
await pushPref(PREF_SHOW_AT_RULES_SIDEBAR, true);
await pushPref(PREF_NAV_WIDTH, NAV_WIDTH);
await pushPref(PREF_SIDEBAR_WIDTH, MEDIA_WIDTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8>
add_task(async function () {
// Enable CSS Warnings
await pushPref("devtools.webconsole.filter.css", true);
await pushPref("layout.css.nesting.enabled", true);

const hud = await openNewTabAndConsole(TEST_URI);
const toolbox = hud.toolbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ httpServer.registerPathHandler(`/test_css_messages.html`, (req, res) => {
const TEST_URI = `http://localhost:${httpServer.identity.primaryPort}/test_css_messages.html`;

add_task(async function () {
await pushPref("layout.css.nesting.enabled", true);
await testWatchingCssMessages();
await testWatchingCachedCssMessages();
});
Expand Down
9 changes: 8 additions & 1 deletion dom/webidl/CSSStyleRule.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@

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

// https://drafts.csswg.org/css-nesting/#cssom-style
// FIXME: Ideally CSSStyleRule should inherit from CSSGroupingRule instead,
// see https://github.com/w3c/csswg-drafts/issues/8940
[Pref="layout.css.nesting.enabled", SameObject] readonly attribute CSSRuleList cssRules;
[Pref="layout.css.nesting.enabled", Throws] unsigned long insertRule(UTF8String rule, optional unsigned long index = 0);
[Pref="layout.css.nesting.enabled", Throws] undefined deleteRule(unsigned long index);

[ChromeOnly] readonly attribute unsigned long selectorCount;
[ChromeOnly] UTF8String selectorTextAt(unsigned long index, optional boolean desugared = false);
[ChromeOnly] unsigned long long selectorSpecificityAt(unsigned long index, optional boolean desugared = false);
Expand Down
1 change: 1 addition & 0 deletions layout/inspector/tests/mochitest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[DEFAULT]
prefs =
layout.css.nesting.enabled=true
layout.css.basic-shape-rect.enabled=true
layout.css.basic-shape-xywh.enabled=true
support-files =
Expand Down
7 changes: 7 additions & 0 deletions modules/libpref/init/StaticPrefList.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8176,6 +8176,13 @@
mirror: always
rust: true

# Whether CSS nesting is enabled.
- name: layout.css.nesting.enabled
type: RelaxedAtomicBool
value: true
mirror: always
rust: true

# Should we look for counter ancestor scopes first?
- name: layout.css.counter-ancestor-scope.enabled
type: bool
Expand Down
3 changes: 1 addition & 2 deletions servo/components/style/gecko/selector_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
type Impl = SelectorImpl;
type Error = StyleParseErrorKind<'i>;

#[inline]
fn parse_parent_selector(&self) -> bool {
true
static_prefs::pref!("layout.css.nesting.enabled")
}

#[inline]
Expand Down
16 changes: 15 additions & 1 deletion servo/components/style/stylesheets/rule_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ impl NestedParseResult {
}

impl<'a, 'i> NestedRuleParser<'a, 'i> {
/// When nesting is disabled, we prevent parsing at rules and qualified rules inside style
/// rules.
fn allow_at_and_qualified_rules(&self) -> bool {
if !self.in_style_rule() {
return true;
}
static_prefs::pref!("layout.css.nesting.enabled")
}

#[inline]
fn in_style_rule(&self) -> bool {
self.context.rule_types.contains(CssRuleType::Style)
Expand Down Expand Up @@ -613,6 +622,9 @@ impl<'a, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'i> {
name: CowRcStr<'i>,
input: &mut Parser<'i, 't>,
) -> Result<Self::Prelude, ParseError<'i>> {
if self.in_style_rule() && !static_prefs::pref!("layout.css.nesting.enabled") {
return Err(input.new_error(BasicParseErrorKind::AtRuleInvalid(name)));
}
Ok(match_ignore_ascii_case! { &*name,
"media" => {
let media_queries = MediaList::parse(&self.context, input);
Expand Down Expand Up @@ -922,7 +934,9 @@ impl<'a, 'i> DeclarationParser<'i> for NestedRuleParser<'a, 'i> {
}

impl<'a, 'i> RuleBodyItemParser<'i, (), StyleParseErrorKind<'i>> for NestedRuleParser<'a, 'i> {
fn parse_qualified(&self) -> bool { true }
fn parse_qualified(&self) -> bool {
self.allow_at_and_qualified_rules()
}

/// If nesting is disabled, we can't get there for a non-style-rule. If it's enabled, we parse
/// raw declarations there.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefs: [layout.css.nesting.enabled:true]
1 change: 1 addition & 0 deletions testing/web-platform/meta/css/css-nesting/__dir__.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefs: [layout.css.nesting.enabled:true]
4 changes: 0 additions & 4 deletions testing/web-platform/tests/css/css-nesting/cssom.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
<style id="ss"></style>

<script>
test(() => {
assert_equals(CSSStyleRule.__proto__, CSSGroupingRule);
}, "CSSStyleRule is a CSSGroupingRule");

test(() => {
let [ss] = document.styleSheets;
assert_equals(ss.cssRules.length, 0);
Expand Down

0 comments on commit b0b02ef

Please sign in to comment.