Bug 231340

Summary: [CSS Cascade Layers] Update CSSOM to the spec
Product: WebKit Reporter: Simon Fraser (smfr) <simon.fraser>
Component: CSSAssignee: Antti Koivisto <koivisto>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, cdumez, darin, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, hi, joepeck, kondapallykalyan, macpherson, menard, pangle, ryuan.choi, sergio, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 235455    
Bug Blocks: 220779, 234012    
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
none
Patch none

Description Simon Fraser (smfr) 2021-10-06 16:58:01 PDT
Per CSS WG resolution:
https://github.com/w3c/csswg-drafts/issues/6576#issuecomment-937246847
Comment 1 Radar WebKit Bug Importer 2021-10-06 16:58:29 PDT
<rdar://problem/83958697>
Comment 2 Antti Koivisto 2021-12-08 05:20:20 PST
Created attachment 446350 [details]
Patch
Comment 3 Antti Koivisto 2021-12-08 06:09:32 PST
Created attachment 446353 [details]
Patch
Comment 4 Antti Koivisto 2021-12-08 06:39:42 PST
Created attachment 446357 [details]
Patch
Comment 5 EWS 2021-12-08 08:56:20 PST
Committed r286657 (244970@main): <https://commits.webkit.org/244970@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 446357 [details].
Comment 6 Darin Adler 2021-12-08 09:00:57 PST
Comment on attachment 446357 [details]
Patch

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

> Source/WebCore/inspector/InspectorStyleSheet.cpp:455
> +            auto layerName = downcast<CSSImportRule>(parentRule)->layerName();
> +            if (!layerName.isNull()) {

Hey Antti, when making a change like this, please consider the modern C++ way to keep this scoped like it was before:

    if (auto layerName = downcast<CSSImportRule>(parentRule)->layerName(); !layerName.isNull()) {

I think it works and makes the code better even though it can be a little hard to spot the code after the semicolon.
Comment 7 Patrick Angle 2021-12-08 09:12:38 PST
Comment on attachment 446357 [details]
Patch

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

> Source/WebCore/inspector/InspectorStyleSheet.cpp:481
> +            layerRulePayload->setText(downcast<CSSLayerBlockRule>(parentRule)->name());

The Inspector frontend expects an anonymous layer will not provide the optional `text` parameter. Since this has already landed I've opened Bug 234012 to track cleaning this up.
Comment 8 Antti Koivisto 2021-12-08 10:49:12 PST
> Hey Antti, when making a change like this, please consider the modern C++
> way to keep this scoped like it was before:
> 
>     if (auto layerName = downcast<CSSImportRule>(parentRule)->layerName();
> !layerName.isNull()) {
> 
> I think it works and makes the code better even though it can be a little
> hard to spot the code after the semicolon.

I did consider it and decided it reads better as two lines. There is no benefit from limiting the scope here.
Comment 9 Antti Koivisto 2021-12-08 10:54:52 PST
Comment on attachment 446357 [details]
Patch

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

>> Source/WebCore/inspector/InspectorStyleSheet.cpp:481
>> +            layerRulePayload->setText(downcast<CSSLayerBlockRule>(parentRule)->name());
> 
> The Inspector frontend expects an anonymous layer will not provide the optional `text` parameter. Since this has already landed I've opened Bug 234012 to track cleaning this up.

layerName() returns an empty string for anonymous layers. Maybe best to handle that in the frontend.
Comment 10 Antti Koivisto 2021-12-08 11:00:21 PST
> layerName() returns an empty string for anonymous layers. Maybe best to
> handle that in the frontend.

Or to be exact CSSLayerBlockRule::name() returns empty string for anonymous layer (and never a null string).

CSSImportRule::layerName() returns null string for no layer specified case and empty string for anonymous layer case.

CSSLayerStatementRule::nameList() returns a vector with at least one item and no empty or null strings.
Comment 11 Patrick Angle 2021-12-08 11:13:55 PST
> > layerName() returns an empty string for anonymous layers. Maybe best to
> > handle that in the frontend.
> 
> Or to be exact CSSLayerBlockRule::name() returns empty string for anonymous
> layer (and never a null string).
> 
> CSSImportRule::layerName() returns null string for no layer specified case
> and empty string for anonymous layer case.
> 
> CSSLayerStatementRule::nameList() returns a vector with at least one item
> and no empty or null strings.

Makes sense - given this I think I will go ahead and just teach the frontend how to handle an empty string here. Thanks for the clarification!