Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
perspective calc() values aren't clipped to 0
https://bugs.webkit.org/show_bug.cgi?id=249151

Reviewed by Simon Fraser and Dean Jackson.

The "perspective" property is specified to only allow non-negative values,
see https://www.w3.org/TR/css-transforms-2/#perspective-property. However,
we don't clip values that are computed to less than 0, for instance using a
calc() expression. Instead, we deem them invalid internally and thus consider
as if "none" was provided, which has implications when blending. Indeed, when
interpolating between a valid value and "none", we use discrete interpolation.

We now correctly clip values below 0.

Note that the relevant WPT test still fails, because the test itself is not
valid. It is being addressed in a dedicated WPT PR and will be imported back
into WebKit yielding a PASS result. See web-platform-tests/wpt#37457.

* LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/the-stylepropertymap/properties/perspective-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/web-animations/responsive/perspective-expected.txt:
* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumePerspective):

Canonical link: https://commits.webkit.org/257779@main
  • Loading branch information
graouts committed Dec 13, 2022
1 parent 7e04c00 commit c1c0e7f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
Expand Up @@ -6,7 +6,7 @@ PASS Can set 'perspective' to CSS-wide keywords: revert
FAIL Can set 'perspective' to var() references: var(--A) assert_equals: expected 2 but got 1
PASS Can set 'perspective' to the 'none' keyword: none
PASS Can set 'perspective' to a length: 0px
FAIL Can set 'perspective' to a length: -3.14em assert_class_string: relative lengths must compute to a CSSUnitValue expected "[object CSSUnitValue]" but got "[object CSSKeywordValue]"
PASS Can set 'perspective' to a length: -3.14em
PASS Can set 'perspective' to a length: 3.14cm
FAIL Can set 'perspective' to a length: calc(0px + 0em) assert_equals: expected "px" but got "em"
PASS Setting 'perspective' to a percent throws TypeError
Expand Down
@@ -1,5 +1,5 @@

PASS perspective responsive to style changes
FAIL perspective clamped to 0px assert_equals: expected "0px" but got "100px"
FAIL perspective clamped to 0px assert_equals: expected "0px" but got "20px"
FAIL perspective responsive to inherited changes assert_equals: expected "80px" but got "none"

8 changes: 1 addition & 7 deletions Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Expand Up @@ -6569,13 +6569,7 @@ RefPtr<CSSValue> consumePerspective(CSSParserTokenRange& range, CSSParserMode cs
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);

if (auto parsedValue = consumeLength(range, cssParserMode, ValueRange::All)) {
if (!parsedValue->isNegative().value_or(false))
return parsedValue;
}

return nullptr;
return consumeLength(range, cssParserMode, ValueRange::NonNegative);
}

RefPtr<CSSValue> consumeScrollSnapAlign(CSSParserTokenRange& range)
Expand Down

0 comments on commit c1c0e7f

Please sign in to comment.