Skip to content

Commit 88fc589

Browse files
committed
[css-nesting] Implement new cascade behavior for mixed declarations and rules
https://bugs.webkit.org/show_bug.cgi?id=275365 rdar://130094168 Reviewed by NOBODY (OOPS!). Previously, any bare declaration inside a style rule, whatever its position relative to other rules, would be shifted up at the top of the rule to be able to represent a style rule with a single continous leading block of declarations. This behavior has been fixed so the order of the declarations is respected during cascade. w3c/csswg-drafts#10234 This introduces a new CSSNestedDeclarations object (a new kind of CSS style rule) to be able to store those block of declarations in-between rules and fit with the already existing RuleData/RuleSet mechanism. It is purposely not exposed as a style rule in the CSSOM. The CSSOM insertRule() functions (on CSSStyleRule and on CSSGroupingRule) is modified to allow inserting block of declarations. w3c/csswg-drafts#10520 https://drafts.csswg.org/css-nesting/#the-cssnestrule * LayoutTests/TestExpectations: * LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/cssom-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/cssom.html: * LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/mixed-declarations-rules-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/mixed-declarations-rules.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-cssom-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-matching-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/serialize-group-rules-with-decls-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-syntax/custom-property-rule-ambiguity.html: Manual sync from WPT * Source/WebCore/CMakeLists.txt: * Source/WebCore/DerivedSources-input.xcfilelist: * Source/WebCore/DerivedSources-output.xcfilelist: * Source/WebCore/DerivedSources.make: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/bindings/js/JSCSSRuleCustom.cpp: (WebCore::toJSNewlyCreated): * Source/WebCore/css/CSSGradientValue.h: * Source/WebCore/css/CSSNestedDeclarations.cpp: Added. (WebCore::CSSNestedDeclarations::CSSNestedDeclarations): (WebCore::CSSNestedDeclarations::style): (WebCore::CSSNestedDeclarations::cssText const): (WebCore::CSSNestedDeclarations::reattach): * Source/WebCore/css/CSSNestedDeclarations.h: Added. * Source/WebCore/css/CSSNestedDeclarations.idl: Added. * Source/WebCore/css/CSSShapeSegmentValue.cpp: * Source/WebCore/css/CSSStyleRule.cpp: (WebCore::CSSStyleRule::insertRule): * Source/WebCore/css/CSSStyleRule.h: * Source/WebCore/css/StyleRule.cpp: (WebCore::StyleRuleBase::visitDerived): (WebCore::StyleRuleBase::createCSSOMWrapper const): (WebCore::StyleRuleNestedDeclarations::StyleRuleNestedDeclarations): (WebCore::StyleRuleNestedDeclarations::debugDescription const): * Source/WebCore/css/StyleRule.h: (WebCore::StyleRuleBase::isStyleRuleNestedDeclarations const): (isType): * Source/WebCore/css/StyleRuleType.h: * Source/WebCore/css/StyleSheetContents.cpp: (WebCore::StyleSheetContents::traverseRules const): (WebCore::StyleSheetContents::traverseSubresources const): (WebCore::StyleSheetContents::mayDependOnBaseURL const): * Source/WebCore/css/calc/CSSCalcTree+Simplification.cpp: * Source/WebCore/css/calc/CSSCalcTree+Simplification.h: * Source/WebCore/css/parser/CSSParser.h: * Source/WebCore/css/parser/CSSParserImpl.cpp: (WebCore::CSSParserImpl::parseNestedDeclarations): (WebCore::CSSParserImpl::createNestedDeclarationsRule): (WebCore::CSSParserImpl::consumeNestedGroupRules): (WebCore::CSSParserImpl::consumeBlockContent): (WebCore::CSSParserImpl::createNestingParentRule): Deleted. * Source/WebCore/css/parser/CSSParserImpl.h: * Source/WebCore/css/parser/CSSPropertyParserConsumer+Image.cpp: (WebCore::CSSPropertyParserHelpers::consumeImageSetResolutionOrTypeFunction): * Source/WebCore/css/parser/CSSPropertyParserConsumer+Image.h: * Source/WebCore/inspector/InspectorStyleSheet.cpp: (WebCore::flatteningStrategyForStyleRuleType): * Source/WebCore/style/RuleSetBuilder.cpp: (WebCore::Style::RuleSetBuilder::addChildRule): (WebCore::Style::RuleSetBuilder::addStyleRule): * Source/WebCore/style/RuleSetBuilder.h:
1 parent 8322df6 commit 88fc589

38 files changed

+416
-58
lines changed

LayoutTests/TestExpectations

+3-4
Original file line numberDiff line numberDiff line change
@@ -8068,10 +8068,6 @@ imported/w3c/web-platform-tests/css/css-anchor-position/anchor-scroll-js-expose.
80688068

80698069
fast/canvas/image-buffer-resource-limits.html [ Slow ]
80708070

8071-
# CSS Nesting interleaved declarations and rules
8072-
# https://bugs.webkit.org/show_bug.cgi?id=275365
8073-
imported/w3c/web-platform-tests/css/css-nesting/nesting-basic.html [ ImageOnlyFailure ]
8074-
80758071
# Standardized CSS zoom tests.
80768072
imported/w3c/web-platform-tests/css/css-viewport/width.html [ ImageOnlyFailure ]
80778073
imported/w3c/web-platform-tests/css/css-viewport/zoom/border-spacing.html [ ImageOnlyFailure ]
@@ -8091,6 +8087,9 @@ imported/w3c/web-platform-tests/css/css-viewport/zoom/word-spacing.html [ ImageO
80918087
# WebRTC Encoded Transform - Test Expectation - Crashes on 'mac-wk2' debug and gtk-wk2 / wpe-wk2
80928088
webkit.org/b/275663 imported/w3c/web-platform-tests/webrtc-encoded-transform/script-transform-generateKeyFrame-simulcast.https.html [ Skip ]
80938089

8090+
# https://bugs.webkit.org/show_bug.cgi?id=276663
8091+
inspector/css/getMatchedStylesForNodeNestingStyleGrouping.html [ ImageOnlyFailure ]
8092+
80948093
# https://bugs.webkit.org/show_bug.cgi?id=266843 flakey tests with racey promise console.logs
80958094
imported/w3c/web-platform-tests/dom/observable/tentative/observable-from.any.html [ Skip ]
80968095

LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/cssom-expected.txt

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ PASS Simple CSSOM manipulation of subrules 8
1616
PASS Simple CSSOM manipulation of subrules 9
1717
PASS Simple CSSOM manipulation of subrules 10
1818
PASS Mutating the selectorText of outer rule invalidates inner rules
19+
PASS Manipulation of nested declarations through CSSOM
1920

LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/cssom.html

+37
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,41 @@
185185
assert_equals(getComputedStyle(inner1).zIndex, '1');
186186
assert_equals(getComputedStyle(inner2).zIndex, '1');
187187
}, 'Mutating the selectorText of outer rule invalidates inner rules');
188+
189+
// CSSNestedDeclarations
190+
test((t) => {
191+
const main = document.createElement('main');
192+
main.innerHTML = `
193+
<style id="main_ss">
194+
div {
195+
z-index: 1;
196+
&.test { foo:bar; }
197+
}
198+
</style>
199+
<div id="outer" class="test">
200+
</div>
201+
`;
202+
document.documentElement.append(main);
203+
t.add_cleanup(() => main.remove());
204+
assert_equals(getComputedStyle(outer).zIndex, '1');
205+
const main_ss = document.getElementById("main_ss").sheet;
206+
const rule = main_ss.cssRules[0];
207+
assert_equals(rule.cssRules.length, 1);
208+
rule.insertRule('z-index: 3;');
209+
assert_equals(rule.cssRules.length, 2);
210+
assert_equals(getComputedStyle(outer).zIndex, '3');
211+
212+
// Throw only when no valid declaration https://github.com/w3c/csswg-drafts/issues/10520
213+
assert_throws_dom('SyntaxError', () => { rule.insertRule('nothing-to-insert-because-invalid-property-should-throw: 2;'); });
214+
assert_equals(rule.cssRules.length, 2);
215+
216+
// Test the insertion of nested declarations inside grouping rule
217+
rule.insertRule('@media screen { a { color: blue; }}',2);
218+
assert_equals(rule.cssRules.length, 3);
219+
const mediaRule = rule.cssRules[2];
220+
mediaRule.insertRule('z-index: 3;');
221+
assert_equals(mediaRule.cssRules.length, 2);
222+
assert_throws_dom('SyntaxError', () => { mediaRule.insertRule('nothing-to-insert-because-invalid-property-should-throw: 2;'); });
223+
}, 'Manipulation of nested declarations through CSSOM');
224+
188225
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<title>Conditional rules with nesting</title>
3+
<link rel="help" href="https://drafts.csswg.org/css-nesting-1/">
4+
<style>
5+
.test {
6+
background-color: green;
7+
width: 100px;
8+
height: 100px;
9+
}
10+
11+
body * + * {
12+
margin-top: 8px;
13+
}
14+
</style>
15+
<body>
16+
<p>Tests pass if <strong>block is green</strong></p>
17+
<div class="test"><div></div></div>
18+
</body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<title>Mixed declarations and rules</title>
3+
<link rel="help" href="https://drafts.csswg.org/css-nesting/#nested-declarations-rule">
4+
5+
<style>
6+
div {
7+
width: 100px;
8+
height: 100px;
9+
background-color: blue;
10+
@media all {
11+
background-color: red;
12+
}
13+
background-color: green;
14+
}
15+
</style>
16+
17+
<body>
18+
<p>Tests pass if <strong>block is green</strong></p>
19+
<div class="test"></div>
20+
</body>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
FAIL Trailing declarations assert_equals: expected 2 but got 1
3-
FAIL Mixed declarations assert_equals: expected 6 but got 3
4-
FAIL CSSNestedDeclarations.style assert_equals: expected 2 but got 1
5-
FAIL Nested group rule assert_equals: expected 2 but got 1
6-
FAIL Nested @scope rule assert_equals: expected 2 but got 1
7-
FAIL Inner rule starting with an ident assert_equals: expected 4 but got 2
2+
PASS Trailing declarations
3+
PASS Mixed declarations
4+
PASS CSSNestedDeclarations.style
5+
PASS Nested group rule
6+
PASS Nested @scope rule
7+
PASS Inner rule starting with an ident
88

LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/nested-declarations-matching-expected.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
A1
22
A2
33

4-
FAIL Trailing declarations apply after any preceding rules assert_equals: expected "PASS" but got "FAIL"
5-
FAIL Trailing declarations apply after any preceding rules (no leading) assert_equals: expected "PASS" but got "FAIL"
6-
FAIL Trailing declarations apply after any preceding rules (multiple) assert_equals: expected "PASS" but got "FAIL"
4+
PASS Trailing declarations apply after any preceding rules
5+
PASS Trailing declarations apply after any preceding rules (no leading)
6+
PASS Trailing declarations apply after any preceding rules (multiple)
77
PASS Nested declarations rule has same specificity as outer selector
88
PASS Nested declarations rule has top-level specificity behavior
9-
FAIL Nested declarations rule has top-level specificity behavior (max matching) assert_equals: expected "PASS" but got "FAIL"
10-
FAIL Bare declartaion in nested grouping rule can match pseudo-element assert_equals: expected "PASS" but got "FAIL"
11-
FAIL Nested group rules have top-level specificity behavior assert_equals: expected "PASS" but got "FAIL"
9+
PASS Nested declarations rule has top-level specificity behavior (max matching)
10+
PASS Bare declartaion in nested grouping rule can match pseudo-element
11+
PASS Nested group rules have top-level specificity behavior
1212
FAIL Nested @scope rules behave like :where(:scope) assert_equals: expected "PASS" but got "FAIL"
1313
FAIL Nested @scope rules behave like :where(:scope) (trailing) assert_equals: expected "PASS" but got "FAIL"
1414
FAIL Nested declarations rule responds to parent selector text change assert_equals: expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"

LayoutTests/imported/w3c/web-platform-tests/css/css-nesting/serialize-group-rules-with-decls-expected.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
PASS Declarations are serialized on one line, rules on two.
3-
FAIL Mixed declarations/rules are on two lines. assert_equals: Mixed declarations/rules are on two lines. expected "div {\n @media screen {\n color: red; background-color: green;\n}\n}" but got "div {\n @media screen {\n & { color: red; background-color: green; }\n}\n}"
4-
FAIL Implicit rule is serialized assert_equals: Implicit rule is serialized expected "div {\n @supports selector(&) {\n color: red; background-color: green;\n}\n &:hover { color: navy; }\n}" but got "div {\n @supports selector(&) {\n & { color: red; background-color: green; }\n}\n &:hover { color: navy; }\n}"
3+
PASS Mixed declarations/rules are on two lines.
4+
PASS Implicit rule is serialized
55
PASS Implicit rule not removed
66
PASS Implicit + empty hover rule
77
PASS Implicit like rule not in first position
88
PASS Two implicit-like rules
9-
FAIL Implicit like rule after decls assert_equals: Implicit like rule after decls expected "div {\n @media screen {\n color: red;\n & { color: red; }\n}\n}" but got "div {\n @media screen {\n & { color: red; }\n & { color: red; }\n}\n}"
10-
FAIL Implicit like rule after decls, missing closing braces assert_equals: Implicit like rule after decls, missing closing braces expected "div {\n @media screen {\n color: red;\n & { color: blue; }\n}\n}" but got "div {\n @media screen {\n & { color: red; }\n & { color: blue; }\n}\n}"
9+
PASS Implicit like rule after decls
10+
PASS Implicit like rule after decls, missing closing braces
1111
PASS Implicit like rule with other selectors
1212
PASS Implicit-like rule in style rule
1313
PASS Empty conditional rule

LayoutTests/imported/w3c/web-platform-tests/css/css-syntax/custom-property-rule-ambiguity.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
assert_equals(rules.length, 1);
4747
assert_equals(rules[0].selectorText, 'div');
4848
let div = rules[0];
49-
let x = div.style.getPropertyValue('--x');
50-
assert_equals(x.trim(), 'hover { }\n .b { }');
5149
let childRules = div.cssRules;
52-
assert_equals(childRules.length, 1);
50+
assert_equals(childRules.length, 2);
5351
assert_equals(childRules[0].selectorText, '& .a');
52+
assert_true(childRules[1] instanceof CSSNestedDeclarations)
53+
let x = childRules[1].style.getPropertyValue('--x');
54+
assert_equals(x.trim(), 'hover { }\n .b { }');
5455
}, 'Nested rule that looks like a custom property declaration');
5556
</script>
5657

Source/WebCore/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ set(WebCore_NON_SVG_IDL_FILES
929929
css/CSSLayerStatementRule.idl
930930
css/CSSMediaRule.idl
931931
css/CSSNamespaceRule.idl
932+
css/CSSNestedDeclarations.idl
932933
css/CSSPaintCallback.idl
933934
css/CSSPaintSize.idl
934935
css/CSSPageRule.idl

Source/WebCore/DerivedSources-input.xcfilelist

+1
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ $(PROJECT_DIR)/css/CSSLayerBlockRule.idl
12431243
$(PROJECT_DIR)/css/CSSLayerStatementRule.idl
12441244
$(PROJECT_DIR)/css/CSSMediaRule.idl
12451245
$(PROJECT_DIR)/css/CSSNamespaceRule.idl
1246+
$(PROJECT_DIR)/css/CSSNestedDeclarations.idl
12461247
$(PROJECT_DIR)/css/CSSPageRule.idl
12471248
$(PROJECT_DIR)/css/CSSPaintCallback.idl
12481249
$(PROJECT_DIR)/css/CSSPaintSize.idl

Source/WebCore/DerivedSources-output.xcfilelist

+2
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSMediaRule.cpp
433433
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSMediaRule.h
434434
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSNamespaceRule.cpp
435435
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSNamespaceRule.h
436+
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSNestedDeclarations.cpp
437+
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSNestedDeclarations.h
436438
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSNumericArray.cpp
437439
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSNumericArray.h
438440
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSNumericBaseType.cpp

Source/WebCore/DerivedSources.make

+1
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ JS_BINDING_IDLS := \
964964
$(WebCore)/css/CSSKeyframesRule.idl \
965965
$(WebCore)/css/CSSMediaRule.idl \
966966
$(WebCore)/css/CSSNamespaceRule.idl \
967+
$(WebCore)/css/CSSNestedDeclarations.idl \
967968
$(WebCore)/css/CSSPageRule.idl \
968969
$(WebCore)/css/CSSPaintCallback.idl \
969970
$(WebCore)/css/CSSPaintSize.idl \

Source/WebCore/Sources.txt

+2
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ css/CSSMarkup.cpp
896896
css/CSSMediaRule.cpp
897897
css/CSSNamedImageValue.cpp
898898
css/CSSNamespaceRule.cpp
899+
css/CSSNestedDeclarations.cpp
899900
css/CSSOffsetRotateValue.cpp
900901
css/CSSPageRule.cpp
901902
css/CSSPaintImageValue.cpp
@@ -3414,6 +3415,7 @@ JSCSSLayerBlockRule.cpp
34143415
JSCSSLayerStatementRule.cpp
34153416
JSCSSMediaRule.cpp
34163417
JSCSSNamespaceRule.cpp
3418+
JSCSSNestedDeclarations.cpp
34173419
JSCSSPageRule.cpp
34183420
JSCSSPaintCallback.cpp
34193421
JSCSSPaintSize.cpp

Source/WebCore/WebCore.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -4976,6 +4976,7 @@
49764976
BE913D80181EF92400DCB09E /* TrackPrivateBase.h in Headers */ = {isa = PBXBuildFile; fileRef = BE913D7F181EF8E500DCB09E /* TrackPrivateBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
49774977
BE961C5518AD338C00D07DC5 /* InbandDataTextTrack.h in Headers */ = {isa = PBXBuildFile; fileRef = BE961C5318AD337C00D07DC5 /* InbandDataTextTrack.h */; };
49784978
BEA807C90F714A0300524199 /* SelectionGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = BEA807C70F714A0300524199 /* SelectionGeometry.h */; settings = {ATTRIBUTES = (Private, ); }; };
4979+
BEAA24022C34A9E600C37BBE /* CSSNestedDeclarations.h in Headers */ = {isa = PBXBuildFile; fileRef = BEAA23FF2C34A63900C37BBE /* CSSNestedDeclarations.h */; settings = {ATTRIBUTES = (Private, ); }; };
49794980
BEF29EEB1715DD0900C4B4C9 /* AudioTrackPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = BEF29EE91715DD0900C4B4C9 /* AudioTrackPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
49804981
BEF29EEC1715DD0900C4B4C9 /* VideoTrackPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = BEF29EEA1715DD0900C4B4C9 /* VideoTrackPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
49814982
C0C054CB1118C8E400CE2636 /* CodeGenerator.pm in Headers */ = {isa = PBXBuildFile; fileRef = 93F8B3050A300FE100F61AB8 /* CodeGenerator.pm */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -18126,6 +18127,9 @@
1812618127
BE983D95052A2E0A00892D85 /* WebCoreKeyboardUIMode.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreKeyboardUIMode.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
1812718128
BEA807C60F714A0300524199 /* SelectionGeometry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionGeometry.cpp; sourceTree = "<group>"; };
1812818129
BEA807C70F714A0300524199 /* SelectionGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionGeometry.h; sourceTree = "<group>"; };
18130+
BEAA23FF2C34A63900C37BBE /* CSSNestedDeclarations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSNestedDeclarations.h; sourceTree = "<group>"; };
18131+
BEAA24002C34A64400C37BBE /* CSSNestedDeclarations.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = CSSNestedDeclarations.idl; sourceTree = "<group>"; };
18132+
BEAA24012C34A94300C37BBE /* CSSNestedDeclarations.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSNestedDeclarations.cpp; sourceTree = "<group>"; };
1812918133
BED8BAF528EB355F003C7D65 /* CSSFontFeatureValuesRule.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontFeatureValuesRule.cpp; sourceTree = "<group>"; };
1813018134
BED8BAF628EB3560003C7D65 /* CSSFontFeatureValuesRule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSFontFeatureValuesRule.h; sourceTree = "<group>"; };
1813118135
BEF29EE91715DD0900C4B4C9 /* AudioTrackPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioTrackPrivate.h; sourceTree = "<group>"; };
@@ -36347,6 +36351,9 @@
3634736351
94E8394E1DFB2700007BC6A7 /* CSSNamespaceRule.cpp */,
3634836352
94E8394F1DFB2700007BC6A7 /* CSSNamespaceRule.h */,
3634936353
94E839501DFB29A4007BC6A7 /* CSSNamespaceRule.idl */,
36354+
BEAA24012C34A94300C37BBE /* CSSNestedDeclarations.cpp */,
36355+
BEAA23FF2C34A63900C37BBE /* CSSNestedDeclarations.h */,
36356+
BEAA24002C34A64400C37BBE /* CSSNestedDeclarations.idl */,
3635036357
668500B8273EEB7800FCCAD6 /* CSSOffsetRotateValue.cpp */,
3635136358
668500B9273EEB7800FCCAD6 /* CSSOffsetRotateValue.h */,
3635236359
A80E6CCB0A1989CA007FB8C5 /* CSSPageRule.cpp */,
@@ -39074,6 +39081,7 @@
3907439081
A80E6D030A1989CA007FB8C5 /* CSSMediaRule.h in Headers */,
3907539082
314BE3A11B30F6B700141982 /* CSSNamedImageValue.h in Headers */,
3907639083
94E839511DFB2A0E007BC6A7 /* CSSNamespaceRule.h in Headers */,
39084+
BEAA24022C34A9E600C37BBE /* CSSNestedDeclarations.h in Headers */,
3907739085
2AEF6FDB26E7ECC700326D02 /* CSSNumericArray.h in Headers */,
3907839086
2AEF6FDC26E7ECCC00326D02 /* CSSNumericBaseType.h in Headers */,
3907939087
2ACB4D2B26DC4ACE00BEB753 /* CSSNumericFactory.h in Headers */,

Source/WebCore/bindings/js/JSCSSRuleCustom.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "CSSLayerStatementRule.h"
3939
#include "CSSMediaRule.h"
4040
#include "CSSNamespaceRule.h"
41+
#include "CSSNestedDeclarations.h"
4142
#include "CSSPageRule.h"
4243
#include "CSSPropertyRule.h"
4344
#include "CSSScopeRule.h"
@@ -57,6 +58,7 @@
5758
#include "JSCSSLayerStatementRule.h"
5859
#include "JSCSSMediaRule.h"
5960
#include "JSCSSNamespaceRule.h"
61+
#include "JSCSSNestedDeclarations.h"
6062
#include "JSCSSPageRule.h"
6163
#include "JSCSSPropertyRule.h"
6264
#include "JSCSSScopeRule.h"
@@ -87,6 +89,8 @@ JSValue toJSNewlyCreated(JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref<C
8789
return createWrapper<CSSStyleRule>(globalObject, WTFMove(rule));
8890
case StyleRuleType::StyleWithNesting:
8991
return createWrapper<CSSStyleRule>(globalObject, WTFMove(rule));
92+
case StyleRuleType::NestedDeclarations:
93+
return createWrapper<CSSNestedDeclarations>(globalObject, WTFMove(rule));
9094
case StyleRuleType::Media:
9195
return createWrapper<CSSMediaRule>(globalObject, WTFMove(rule));
9296
case StyleRuleType::FontFace:

Source/WebCore/css/CSSGradientValue.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
#include "CSSPropertyParserConsumer+UnevaluatedCalc.h"
3232
#include "ColorInterpolationMethod.h"
3333
#include "Gradient.h"
34+
#include "StyleImage.h"
3435

3536
namespace WebCore {
3637

37-
class StyleImage;
38-
3938
namespace Style {
4039
class BuilderState;
4140
}

Source/WebCore/css/CSSGroupingRule.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "CSSGroupingRule.h"
3333

3434
#include "CSSParser.h"
35+
#include "CSSParserImpl.h"
3536
#include "CSSRuleList.h"
3637
#include "CSSStyleSheet.h"
3738
#include "StylePropertiesInlines.h"
@@ -69,13 +70,15 @@ ExceptionOr<unsigned> CSSGroupingRule::insertRule(const String& ruleString, unsi
6970
auto isNestedContext = hasStyleRuleAncestor() ? CSSParserEnum::IsNestedContext::Yes : CSSParserEnum::IsNestedContext::No;
7071
RefPtr<StyleRuleBase> newRule = CSSParser::parseRule(parserContext(), styleSheet ? &styleSheet->contents() : nullptr, ruleString, isNestedContext);
7172
if (!newRule) {
72-
// SyntaxError: Raised if the specified rule has a syntax error and is unparsable.
73-
return Exception { ExceptionCode::SyntaxError };
73+
newRule = CSSParserImpl::parseNestedDeclarations(parserContext(), ruleString);
74+
// SyntaxError raised if there is nothing valid to insert (rule or nested declarations).
75+
if (!newRule)
76+
return Exception { ExceptionCode::SyntaxError };
7477
}
7578

7679
if (newRule->isImportRule() || newRule->isNamespaceRule()) {
77-
// FIXME: an HierarchyRequestError should also be thrown for a @charset or a nested
78-
// @media rule. They are currently not getting parsed, resulting in a SyntaxError
80+
// FIXME: an HierarchyRequestError should also be thrown for a @charset.
81+
// They are currently not getting parsed, resulting in a SyntaxError
7982
// to get raised above.
8083

8184
// HierarchyRequestError: Raised if the rule cannot be inserted at the specified
@@ -84,8 +87,7 @@ ExceptionOr<unsigned> CSSGroupingRule::insertRule(const String& ruleString, unsi
8487
return Exception { ExceptionCode::HierarchyRequestError };
8588
}
8689

87-
// Nesting inside style rule only accepts style rule or group rule
88-
if (hasStyleRuleAncestor() && !newRule->isStyleRule() && !newRule->isGroupRule())
90+
if (hasStyleRuleAncestor() && !newRule->isStyleRule() && !newRule->isGroupRule() && !newRule->isNestedDeclarationsRule())
8991
return Exception { ExceptionCode::HierarchyRequestError };
9092

9193
CSSStyleSheet::RuleMutationScope mutationScope(this);

0 commit comments

Comments
 (0)