Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[@Property] Handle unit cycles correctly
https://bugs.webkit.org/show_bug.cgi?id=247212 rdar://101974818 Reviewed by Simon Fraser. https://drafts.css-houdini.org/css-properties-values-api/#dependency-cycles A registered custom property with <length> syntax may use units that depend on another property. This can create a cycle: div { --my-font-size: 10em; font-size: var(--my-font-size); } This makes both properties invalid and has to be handled similarly to cycles between custom properties. The patch also contains some general cleanups to the custom property resolution code. * LayoutTests/TestExpectations: * LayoutTests/css-custom-properties-api/crash.html: * LayoutTests/css-custom-properties-api/cycles.html: * LayoutTests/css-custom-properties-api/inherits.html: Update expected results to match the current spec (and Blink). Registered typed custom properties behave like 'unset' when invalid. * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/unit-cycles-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/var-reference-registered-properties-cycles-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-substitution-variable-declaration-expected.txt: * Source/WebCore/css/CSSVariableReferenceValue.cpp: (WebCore::CSSVariableReferenceValue::resolveVariableFallback): (WebCore::CSSVariableReferenceValue::resolveVariableReference): (WebCore::CSSVariableReferenceValue::resolveTokenRange): (WebCore::CSSVariableReferenceValue::resolveVariableReferences const): (WebCore::resolveVariableFallback): Deleted. (WebCore::resolveVariableReference): Deleted. (WebCore::resolveTokenRange): Deleted. Turn static functions into private members. * Source/WebCore/css/CSSVariableReferenceValue.h: * Source/WebCore/css/parser/CSSParser.cpp: (WebCore::CSSParser::parseValueWithVariableReferences): Factor into two separate functions. (WebCore::CSSParser::parseCustomPropertyValueWithVariableReferences): Detect unit cycles and mark the associated normal property being part of a cycle. * Source/WebCore/css/parser/CSSParser.h: * Source/WebCore/style/PropertyCascade.h: (WebCore::Style::PropertyCascade::customProperty const): Return a reference instead of a copy. * Source/WebCore/style/StyleBuilder.cpp: (WebCore::Style::Builder::applyNonHighPriorityProperties): Move custom property resolution after all other properties. Any dependent custom properties will be already resolved by properties using them. This will just resolve the unused ones. (WebCore::Style::Builder::applyPropertiesImpl): (WebCore::Style::Builder::applyCustomProperty): Remove the looping over the link match enum values. Custom properties are not legal is :visited and we anyway keep only one version in RenderStyle. Return invalid or unset value based on property registration status. (WebCore::Style::Builder::applyProperty): 'unset' behaves differently if the property is registered as inherited or not. (WebCore::Style::Builder::resolveVariableReferences): Check for unit cycle. (WebCore::Style::Builder::resolveCustomPropertyValueWithVariableReferences): (WebCore::Style::Builder::resolveValue): Deleted. (WebCore::Style::Builder::resolvedVariableValue): Deleted. * Source/WebCore/style/StyleBuilder.h: * Source/WebCore/style/StyleBuilderState.h: (WebCore::Style::BuilderState::inProgressProperties const): (WebCore::Style::BuilderState::inUnitCycleProperties): Canonical link: https://commits.webkit.org/258357@main
- Loading branch information
Showing
15 changed files
with
171 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 20 additions & 14 deletions
34
...ts/imported/w3c/web-platform-tests/css/css-properties-values-api/unit-cycles-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
|
||
FAIL Non-font-dependent variables can be used in font-size assert_equals: expected "42px" but got "16px" | ||
FAIL Lengths with em units may not be referenced from font-size assert_equals: expected "" but got "32px" | ||
FAIL Lengths with ex units may not be referenced from font-size assert_equals: expected "" but got "14.359375px" | ||
FAIL Lengths with ch units may not be referenced from font-size assert_equals: expected "" but got "16px" | ||
FAIL Lengths with rem units may be referenced from font-size on non-root element assert_equals: expected "32px" but got "16px" | ||
FAIL Lengths with rem units may not be referenced from font-size on root element assert_equals: expected "" but got "32px" | ||
PASS Non-font-dependent variables can be used in font-size | ||
PASS Lengths with em units may not be referenced from font-size | ||
PASS Lengths with ex units may not be referenced from font-size | ||
PASS Lengths with ch units may not be referenced from font-size | ||
PASS Lengths with lh units may not be referenced from font-size | ||
PASS Lengths with rem units may be referenced from font-size on non-root element | ||
FAIL Lengths with rem units may not be referenced from font-size on root element assert_equals: expected "16px" but got "32px" | ||
PASS Lengths with lh units may not be referenced from line-height | ||
PASS Fallback may not use font-relative units | ||
PASS Fallback may not use line-height-relative units | ||
PASS Fallback not triggered while inside em unit cycle | ||
PASS Fallback not triggered while inside ex unit cycle | ||
PASS Fallback not triggered while inside ch unit cycle | ||
PASS Fallback not triggered while inside rem unit cycle on root element | ||
FAIL Lengths with em units are detected via var references assert_equals: expected "" but got "160px" | ||
FAIL Lengths with ex units are detected via var references assert_equals: expected "" but got "71.796875px" | ||
FAIL Lengths with ch units are detected via var references assert_equals: expected "" but got "80px" | ||
FAIL Lengths with rem units are detected via var references assert_equals: expected "" but got "160px" | ||
FAIL Inherited lengths with em units may be used assert_equals: expected "64px" but got "16px" | ||
FAIL Inherited lengths with ex units may be used assert_equals: expected "28.71875px" but got "16px" | ||
FAIL Inherited lengths with ch units may be used assert_equals: expected "32px" but got "16px" | ||
FAIL Fallback not triggered while inside rem unit cycle on root element assert_equals: expected "16px" but got "32px" | ||
PASS Fallback not triggered while inside lh unit cycle | ||
PASS Lengths with em units are detected via var references | ||
PASS Lengths with ex units are detected via var references | ||
PASS Lengths with ch units are detected via var references | ||
FAIL Lengths with rem units are detected via var references assert_equals: expected "16px" but got "160px" | ||
PASS Lengths with lh units are detected via var references | ||
PASS Inherited lengths with em units may be used | ||
PASS Inherited lengths with ex units may be used | ||
PASS Inherited lengths with ch units may be used | ||
PASS Inherited lengths with lh units may be used | ||
|
8 changes: 4 additions & 4 deletions
8
...sts/css/css-properties-values-api/var-reference-registered-properties-cycles-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
FAIL A var() cycle between two registered properties is handled correctly. assert_equals: expected "1px" but got "" | ||
FAIL A var() cycle between a registered properties and an unregistered property is handled correctly. assert_equals: expected "1px" but got "" | ||
PASS A var() cycle between two registered properties is handled correctly. | ||
PASS A var() cycle between a registered properties and an unregistered property is handled correctly. | ||
PASS A var() cycle between a two unregistered properties is handled correctly. | ||
FAIL A var() cycle between a syntax:'*' property and an unregistered property is handled correctly. assert_equals: expected "" but got "circle" | ||
FAIL Custom properties with universal syntax become guaranteed-invalid when invalid at computed-value time assert_equals: expected "" but got "foo" | ||
PASS A var() cycle between a syntax:'*' property and an unregistered property is handled correctly. | ||
PASS Custom properties with universal syntax become guaranteed-invalid when invalid at computed-value time | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.