Bug 104805 - Do not allow unitless values for CSS unprefixed perspective property
Summary: Do not allow unitless values for CSS unprefixed perspective property
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Martin Robinson
URL:
Keywords: InRadar, WebExposed, WPTImpact
Depends on: 104802
Blocks: 240341 93136
  Show dependency treegraph
 
Reported: 2012-12-12 05:50 PST by Alexis Menard (darktears)
Modified: 2022-11-13 02:55 PST (History)
22 users (show)

See Also:


Attachments
Patch (5.49 KB, patch)
2021-11-02 10:30 PDT, Martin Robinson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (6.34 KB, patch)
2021-11-02 10:58 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (114.44 KB, patch)
2021-11-03 02:23 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (120.17 KB, patch)
2021-11-05 08:16 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (13.20 KB, patch)
2022-05-12 06:52 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (10.99 KB, patch)
2022-05-12 07:32 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (11.69 KB, patch)
2022-05-12 10:59 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (11.87 KB, patch)
2022-05-12 11:14 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (18.24 KB, patch)
2022-05-13 01:06 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (18.14 KB, patch)
2022-05-13 02:22 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (19.89 KB, patch)
2022-05-13 04:53 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexis Menard (darktears) 2012-12-12 05:50:06 PST
Today -webkit-perspective accept valueless values which is not part of the CSS Transforms specification. We should keep the behavior for the old -webkit-perspective property but we should make the parsing stricter for the unprefixed version.
Comment 1 Eric Willigers 2018-10-25 23:33:43 PDT
Microsoft calculates use counts, and no usage of unitless numbers is reported on top sites.
https://developer.microsoft.com/en-us/microsoft-edge/platform/usage/css/perspective/
For comparison, see https://developer.microsoft.com/en-us/microsoft-edge/platform/usage/css/stroke-width/
Comment 2 Sam Sneddon [:gsnedders] 2021-04-22 06:34:04 PDT
wpt/quirks/unitless-length/excluded-properties-001.html covers this with the "Property perspective does not support quirky length" subtest; we're the only browser to fail this subtest.
Comment 3 Radar WebKit Bug Importer 2021-04-22 06:34:13 PDT
<rdar://problem/77016090>
Comment 4 Martin Robinson 2021-11-02 10:30:05 PDT
Created attachment 443104 [details]
Patch
Comment 5 Martin Robinson 2021-11-02 10:58:40 PDT
Created attachment 443110 [details]
Patch
Comment 6 Martin Robinson 2021-11-03 02:23:22 PDT
Created attachment 443183 [details]
Patch
Comment 7 Martin Robinson 2021-11-05 08:16:09 PDT
Created attachment 443395 [details]
Patch
Comment 8 EWS Watchlist 2021-11-05 08:16:57 PDT
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Comment 9 Martin Robinson 2021-11-05 10:17:36 PDT
Comment on attachment 443395 [details]
Patch

I think this is ready for review.
Comment 10 Myles C. Maxfield 2021-11-08 13:20:40 PST
This is a bit scary. Simon should be the one to review it.
Comment 11 Tim Nguyen (:ntim) 2022-05-11 08:02:50 PDT
Comment on attachment 443395 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=443395&action=review

This looks fine aside from my comments, though I'd like Oriol to look at it before giving r+, since he's done work to make sure such aliased properties get the correct computed style.

> Source/WebCore/css/CSSProperties.json:6568
>          "perspective": {
>              "codegen-properties": {
> -                "aliases": [
> -                    "-webkit-perspective"
> -                ],
> +                "conditional-converter": "Perspective"
> +            },
> +            "specification": {
> +                "category": "css-transforms",
> +                "url": "https://www.w3.org/TR/css-transforms-1/#transform-style-property"
> +            }
> +        },
> +        "-webkit-perspective": {

Please add the related-property field to both of these, this way they can share the computed style (which is behavior you'd have with alias)

perspective should have -webkit-perspective as related property and vice-versa

> Source/WebCore/css/parser/CSSPropertyParser.cpp:2435
> +    auto value = consumePerspective(range, cssParserMode);
> +    if (value)
> +        return value;

if (auto value = consumePerspective(range, cssParserMode))
  return value;
Comment 12 Tim Nguyen (:ntim) 2022-05-11 08:03:34 PDT
Oriol, could you take a look at this patch, especially regarding the gCS() stuff?
Comment 13 Oriol Brufau 2022-05-11 08:52:44 PDT
Comment on attachment 443395 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=443395&action=review

>> Source/WebCore/css/CSSProperties.json:6568
>> +        "-webkit-perspective": {
> 
> Please add the related-property field to both of these, this way they can share the computed style (which is behavior you'd have with alias)
> 
> perspective should have -webkit-perspective as related property and vice-versa

Yes, longhands sharing a computed style should have related-property so that revert and revert-layer work correctly.
Strange that css/css-cascade/all-prop-revert-layer.html didn't catch it in EWS, locally I get the failure.

However, sharing a computed style is a non-standard hack (except for logical and physical properties), so I would prefer not to add more instances of that unless necessary.

The spec provides 2 standard possibilities: https://www.w3.org/TR/css-cascade-5/#aliasing
The 1st one is an alias, the current behavior, but it's not suitable since the grammars are different. Then the other option is a legacy shorthand.

So you could make -webkit-perspective a shorthand of perspective. Just let the parser for -webkit-perspective accept unitless values, but add the units when expanding to perspective.

Being a shorthand it may not be necessary to handle it in CSSPropertyAnimation.cpp and WillChangeData.cpp, but not sure.
Comment 14 Martin Robinson 2022-05-12 06:52:27 PDT
Created attachment 459228 [details]
Patch
Comment 15 Martin Robinson 2022-05-12 06:53:48 PDT
Thanks for the reviews. I have uploaded a new version of this change that makes `-webkit-perspective` a shorthand for `perspective`. Though it does seem a little counter-intuitive, it seems to work well.
Comment 16 Oriol Brufau 2022-05-12 07:19:53 PDT
Comment on attachment 459228 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459228&action=review

> Source/WebCore/animation/CSSPropertyAnimation.cpp:3139
> +        new PerspectiveWrapper(CSSPropertyPerspective),

If CSSPropertyWebkitPerspective doesn't need to be handled here, you can avoid modifying this file.

> Source/WebCore/css/CSSProperties.json:6715
> +                "url": "https://www.w3.org/TR/css-transforms-1/#transform-style-property"

The link was already wrong, but I guess it should be https://www.w3.org/TR/css-transforms-2/#perspective-property

> Source/WebCore/css/parser/CSSPropertyParser.cpp:2469
>          return nullptr;

Nit: You may remove this since there is another "return null" just after the conditional.

> Source/WebCore/css/parser/CSSPropertyParser.cpp:2479
> +        return true;

Should check m_range.atEnd(). Otherwise:

CSS.supports("-webkit-perspective", "1px foo"); // true

> Source/WebCore/css/parser/CSSPropertyParser.cpp:2483
> +        if (perspective->value < 0)

Should check m_range.atEnd(). Otherwise:

CSS.supports("-webkit-perspective", "1 foo"); // true
Comment 17 Martin Robinson 2022-05-12 07:32:32 PDT
Created attachment 459232 [details]
Patch
Comment 18 Martin Robinson 2022-05-12 07:36:07 PDT
(In reply to Oriol Brufau from comment #16)
> Comment on attachment 459228 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=459228&action=review
> 
> > Source/WebCore/animation/CSSPropertyAnimation.cpp:3139
> > +        new PerspectiveWrapper(CSSPropertyPerspective),
> 
> If CSSPropertyWebkitPerspective doesn't need to be handled here, you can
> avoid modifying this file.

Sorry. This was an oversight. It should be fixed now as well as the left over code in WillChangeData.cpp.

> > Source/WebCore/css/CSSProperties.json:6715
> > +                "url": "https://www.w3.org/TR/css-transforms-1/#transform-style-property"
> 
> The link was already wrong, but I guess it should be
> https://www.w3.org/TR/css-transforms-2/#perspective-property

Fixed both links.

> 
> > Source/WebCore/css/parser/CSSPropertyParser.cpp:2469
> >          return nullptr;
> 
> Nit: You may remove this since there is another "return null" just after the
> conditional.

Fixed.

> > Source/WebCore/css/parser/CSSPropertyParser.cpp:2479
> > +        return true;
> 
> Should check m_range.atEnd(). Otherwise:
> 
> CSS.supports("-webkit-perspective", "1px foo"); // true
> 
> > Source/WebCore/css/parser/CSSPropertyParser.cpp:2483
> > +        if (perspective->value < 0)
> 
> Should check m_range.atEnd(). Otherwise:
> 
> CSS.supports("-webkit-perspective", "1 foo"); // true

Fixed both of these.
Comment 19 Oriol Brufau 2022-05-12 07:37:58 PDT
Comment on attachment 459232 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459232&action=review

Informal LGTM.

> Source/WebCore/css/parser/CSSPropertyParser.cpp:6594
> +    case CSSPropertyWebkitPerspective: {

Nit: the curly brackets are not needed.
Comment 20 Tim Nguyen (:ntim) 2022-05-12 08:23:28 PDT
Comment on attachment 459232 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459232&action=review

> Source/WebCore/css/CSSProperties.json:6715
> +                "url": " https://www.w3.org/TR/css-transforms-2/#perspective-property"
> +            }
> +        },
> +        "-webkit-perspective": {
> +            "codegen-properties": {
> +                "longhands": [ "perspective" ]
> +            },
> +            "specification": {
> +                "category": "css-transforms",
> +                "url": " https://www.w3.org/TR/css-transforms-2/#perspective-property"

nit: The urls have a bogus space before it

also for consistency with the rest of the file, could you give `"perspective"` its own line in the longhands field?
Comment 21 Tim Nguyen (:ntim) 2022-05-12 08:31:17 PDT
Comment on attachment 459232 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459232&action=review

> Source/WebCore/css/parser/CSSPropertyParser.cpp:2476
> +    if (RefPtr<CSSValue> value = consumePerspective(m_range, m_context.mode)) {

Does `auto value = ...` or `RefPtr value = ...`  work here?
Comment 22 Martin Robinson 2022-05-12 10:59:54 PDT
Created attachment 459242 [details]
Patch
Comment 23 Tim Nguyen (:ntim) 2022-05-12 11:09:34 PDT
Comment on attachment 459242 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459242&action=review

> Source/WebCore/css/CSSProperties.json:6718
>              }

Can you add a status field like this one: https://webkit-search.igalia.com/webkit/rev/0d5437dbaa7bdb52f60b64bc7dd5a39adee14e81/Source/WebCore/css/CSSProperties.json#5444-5446 mentioning the quirk?
Comment 24 Tim Nguyen (:ntim) 2022-05-12 11:10:34 PDT
The previous patch seems to suggest you need to rebaseline imported/w3c/web-platform-tests/css/cssom/getComputedStyle-detached-subtree.html
Comment 25 Martin Robinson 2022-05-12 11:14:20 PDT
Created attachment 459243 [details]
Patch
Comment 26 Martin Robinson 2022-05-12 11:18:49 PDT
(In reply to Tim Nguyen (:ntim) from comment #24)
> The previous patch seems to suggest you need to rebaseline
> imported/w3c/web-platform-tests/css/cssom/getComputedStyle-detached-subtree.
> html

I examined that test and I couldn't see any reason my change would modify those results. I uploaded a new version to see if the bots would fail on it again.

> Can you add a status field like this one:
> https://webkit-search.igalia.com/webkit/rev/
> 0d5437dbaa7bdb52f60b64bc7dd5a39adee14e81/Source/WebCore/css/CSSProperties.
> json#5444-5446 mentioning the quirk?

Sure. That's a good idea.
Comment 27 Tim Nguyen (:ntim) 2022-05-12 11:41:41 PDT
(In reply to Martin Robinson from comment #26)
> (In reply to Tim Nguyen (:ntim) from comment #24)
> > The previous patch seems to suggest you need to rebaseline
> > imported/w3c/web-platform-tests/css/cssom/getComputedStyle-detached-subtree.
> > html
> 
> I examined that test and I couldn't see any reason my change would modify
> those results. I uploaded a new version to see if the bots would fail on it
> again.

The length of the computed style changed with your patch. This often happens when removing/adding properties.

The asserts test specifically the length of the computed style to be 0: https://webkit-search.igalia.com/webkit/source/LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-detached-subtree-expected.txt#3

Unfortunately, since we fail it, the assert message depends on the number of properties exposed.
Comment 29 Oriol Brufau 2022-05-12 13:17:01 PDT
Turning an alias into a legacy shorthand shouldn't actually increase the length of the computed style, since shorthands are not supposed to be indexed. Filed bug 240356.
Comment 30 Martin Robinson 2022-05-13 01:06:27 PDT
Created attachment 459283 [details]
Patch
Comment 31 Tim Nguyen (:ntim) 2022-05-13 02:19:49 PDT
Comment on attachment 459283 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459283&action=review

> Source/WebCore/ChangeLog:12
> +        * css/CSSComputedStyleDeclaration.cpp:

I think this changelog is out-of-date (the animation change is not reflected)

> LayoutTests/ChangeLog:15
> +2022-05-13  Martin Robinson  <mrobinson@webkit.org>
> +
> +        Do not allow unitless values for CSS unprefixed perspective property
> +        https://bugs.webkit.org/show_bug.cgi?id=104805
> +
> +        Reviewed by NOBODY (OOPS!).
> +
> +
> +2022-05-12  Martin Robinson  <mrobinson@webkit.org>
> +
> +        Do not allow unitless values for CSS unprefixed perspective property
> +        https://bugs.webkit.org/show_bug.cgi?id=104805
> +        <rdar://problem/77016090>
> +
> +        Reviewed by Tim Nguyen.

Double changelog
Comment 32 Martin Robinson 2022-05-13 02:22:25 PDT
Created attachment 459284 [details]
Patch
Comment 33 Tim Nguyen (:ntim) 2022-05-13 04:47:04 PDT
The non platform-specific imported/w3c/web-platform-tests/css/cssom/getComputedStyle-detached-subtree-expected.txt needs updating for mac as well.
Comment 34 Martin Robinson 2022-05-13 04:53:22 PDT
Created attachment 459292 [details]
Patch
Comment 35 EWS 2022-05-16 01:15:55 PDT
Committed r294224 (250582@main): <https://commits.webkit.org/250582@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 459292 [details].