-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-syntax][css-nesting] Design of @nest
rule
#10234
Comments
Thank you @LeaVerou.
I actually want the In JavaScript it is possible to write blocks without any condition. I use this very frequently to group bits of code in a larger section. This new at-rule could serve a similar purpose. Most authors will never use it but they could to organise and structure their code. Today we use either multiple rules with the same selector, or comments when we want to group lists of declarations. Neither is really good. This is our list of custom props when we start a new project : :root {
/* #region Colors */
--color-foreground: rgb(0 0 0);
--color-background: rgb(255 255 255);
--color-grey-40: rgb(108 112 108);
--color-warning: rgb(242 149 0);
--color-error: rgb(207 0 0);
/* #endregion Colors */
/* #region Typography */
--font-sans: "Helvetica Neue", sans-serif;
--font-serif: "Georgia", serif;
/* #endregion Typography */
/* #region Spacers */
--space-1--px: 1px;
--space-1--rem: 0.0625rem;
--space-8--px: 8px;
--space-8--rem: 0.5rem;
--space-16--px: 16px;
--space-16--rem: 1rem;
--space-32--px: 32px;
--space-32--rem: 2rem;
--space-48--px: 48px;
--space-48--rem: 3rem;
/* #endregion Spacers */
} We need to add comments before and after each group so that we can have folding regions in code editors. @tabatkins has also stated that they aren't attached to the name of this at-rule. Something that isn't tied to nesting would be nice. If on the other hand, this can all be implementation details, then I prefer that. |
Do we need the
To be clear, this issue blocks actually carrying out #8738. The more we mess around with the details here, the higher the risk that no change will happen at all. |
That was not the resolution at all. Please implement the |
@LeaVerou Oh. I thought the point of the resolution was to focus the discussion and hopefully converge on something. Unfortunately I can't make a move on
The specific changes we're discussing here can not necessarily be made later at all. It is sometimes very hard to understand the risk of changing CSSOM APIs. |
@andruud It's not with the "intent to break it again later". It's with the intent to keep
If later on we prefer to switch to something else but it's not compatible, then so be it, we can stay with The point is that there was consensus that |
As I said in my final comment in 8738, when considering any new feature, or additional complexity in an existing feature, it's worth paying attention to both the size of the affected audience and the size of the benefit that audience will receive. The existence of an So, the audience of people affected by any change here is very tiny, I'll argue, and that audience is composed of relatively skilled authors. (I think this audience can be reasonably summarized as "people who are writing CSS tooling".) Do any of these changes allow that audience to do something currently difficult or impossible? No, these are solely attempting to improve the consistency of how the OM is represented in certain aspects. Do they improve this audience's experience in a meaningful way? Arguable. While they improve the consistency in some ways (making the OM and/or the reserialized string more closely resemble the originally authored code), they reduce consistency in other ways (unusual serialization rules; edge cases that require restrictions on where rules can be moved around; widening of the possible types in certain attributes). For example, right now you can, in theory, take any of the objects in an MQ's Or take Or a parsed stylesheet will never have an Whatever we do, if it's "magic" in some way, it'll spawn corner cases like this. Magic like this can be justified, by sufficient benefit to a sufficient audience. I don't think that it qualifies on either metric in this case, however. In summary, we should just do the simplest possible thing, with the least amount of magic possible, because all of the suggested magic (beyond the initial parser magic) won't actually pay for itself. |
We could, it would just be a new syntax construct to define. Relying on the existing at-rule syntax just makes for a slightly simpler model. And since we don't anticipate authors actually writing this themselves, I don't think the length of the name actually matter in any meaningful way. |
We are trying to avoid a breaking change by shipping
Tab, nobody is disagreeing that I/E matters, we’re disagreeing on what the I is.
I have responded to this point in the OP:
Also, since we’re sharing anecdotes, I have crawled and modified the CSS OM dozens of times in my web dev career, none of which was while writing WPTs. I did not mention it earlier because as an anecdote, I didn’t think it was that relevant.
Again, the users of these tools are not a small audience.
I don’t see how this is different than defining what Actually, depending on how we define it root-level declarations could even solve all these use cases that require setting stuff on the document node.
Yes! Which again seems like a win and more broadly useful.
I’m not married to the details, but I was envisioning that these nodes would be merged automatically by the CSS OM, not during serialization. All the Web Platform’s OMs are full of these kinds of normalizations, so I don’t see what the problem is. |
The users of tools that crawl/modify the CSSOM only matter for this proposal insofar as those tools expose the CSSOM to them (or this proposal makes those tools work better, thus improving the experience of their users). Do you have examples of that?
Sure, we have to define what
How is this a meaningful win over
I don't think that's accurate to say. For example, in the following: <!DOCTYPE html>
<p>
<script>
var p = document.querySelector("p");
p.appendChild(new Text("foo"));
p.appendChild(new Text("bar"));
console.log(p.childNodes);
</script> You'll get two Text nodes, despite that being essentially identical to just having a single Text node with "foobar". Having nodes magically merge underneath you as a side-effect of doing something unrelated (like removing a rule that previously happened to separate two of them) is the sort of thing that causes bugs in author code very easily, since objects disappear, indexes change, etc. in an unpredictable manner. |
Yeah, sure.
That is not what I'm saying. I'm saying it's not always easy to prove that CSSOM changes won't break sites, even if you strongly believe it won't. But OK, if shipping |
If we have author facing syntax for this, I'd prefer it's not
Thank you! |
One question that would affect my opinion of whether the CSSOM questions here matter: what's the chance that at some point in the future we'll allow the nesting syntax inside the |
I am not sure I understood the whole conversation between mdubet and emilio about this in #8738, but intermixing list of declarations (or The first list of declarations in I did not understood why contents would need to be exposed by the public But accepting declarations in |
My understanding is that this is basically planned, and it's just a matter of resource allocation. Inline style nesting is a huge use case. Since it seems hard to get consensus on making this rule less author facing, could we explore going the other way? I.e. keeping is as author-facing, and trying to make it useful in some way. Some ideas:
Just brainstorming here. What would be some low hanging, easy-ish to implement functionality that could make this rule actually useful? Perhaps we should simply name it |
You really want authors to be able to see all the styles in the stylesheet, in the right order. If cssRules doesn't do that you need something else. |
Another thing to note, not sure how well this interacts with IIRC we either stash an implicit That is, what does:
desugar to now? What would desugar to with |
@emilio Nothing different for Exploring the use cases for a more general |
Oh, so the fact that the scope rule is inside the #a selector is completely lost already? That's a bit weird / unintuitive but ok I guess |
Maybe it's not what you meant, but it's not completely lost, it's in the implicit
I think that will be just fine.
I support this too. Although we could easily add a |
Ah, cool, It's added to the start of the scope, that seems fine then I agree. I don't mind calling it |
Yes, agree. |
So authors could (but likely won't) write : :root {
@group {
--color-a: pink;
@media screen { --color-a: red; }
--color-b: lime;
}
} Which would be equivalent to : :root {
@group {
--color-a: pink;
@media screen { --color-a: red; }
@group { --color-b: lime; }
}
} |
The thinking was to support this kind of usage. It would be nice though if we could come up with some actual useful functionality for these groups other than simple grouping. Are any of the things I mentioned here feasible? |
With WebKit's position now clarified, and after some feedback on the Blink Intent-to-Ship, it's pretty clear that this issue is in fact blocking #8738. |
This is a long-shot, not well thought-through - but is there a way for named-group declarations to be available as a form of name-spaced custom property. I don't think this would provide actual new functionality, but some syntax shortcuts for name-spacing and declaring a custom/standard property at the same time: .now {
--base-padding: 1em;
padding: var(--base-padding);
--color-primary: teal;
--color-secondary: hotPink;
}
.groups {
@group --base {
padding: 1em;
}
@group --color {
--primary: teal;
--secondary: hotPink;
}
.access {
margin: var(--base.padding);
border-color: var(--color.--primary);
}
} (Hope I'm not straying too far from the question at hand - but it seems like an otherwise-useful rule might help with WebKit's concerns?) |
The CSS Working Group just discussed
The full IRC log of that discussion<keithamus> emilio: Leah added this, I can introduce it a bit<keithamus> ... there still seems to be some disagreement on best path forward <astearns> could we resolve on @some-long-weird-name? <Rossen4> s/Leah/Lea/ <keithamus> lea: the gist is another issue we resolved to stop hosting decls coming after nested rules, with decls inside a rule coming after get hoisted to the top which results in strange conflict resolution <keithamus> lea: Tab proposed the @ rule which avoid this. There was push back as it only exists in the OM and has no purpose for authors, only exists to make spec editors lives easier <fantasai> s/in the OM/for the purpose of the OM/ <Rossen4> q <keithamus> ... there are some challenges to not introducing. One proposal to have the @nest rule but not serialize, so you only get plain decls. <keithamus> ... Tabs opposition is that CSSOM isn't used that much so whats the point <keithamus> ... another proposal to make a new object to represent the interleaved decls. <keithamus> ... Blink is strongly opposing not having the rule <keithamus> ... On the grounds that CSSOM is not used frequently <keithamus> ... also that syntax is pointless from author perspective <keithamus> ... what if we call it @group then extend it later with functionality? What if we can give this rule a purpose? <TabAtkins> q+ <kizu> +1 to "<@astearns> could we resolve on @some-long-weird-name?" <keithamus> ... my position is that I tend to agree with webkit. Against priority of constituencies. People will find some weird ways to use it <keithamus> ... I disagree with Tab's assertion that CSSOM is infrequently used. <keithamus> ... We do plan to eventually add nesting & author styles - extremely author facing. <emilio> q+ <keithamus> ... many devs modify css properties on the fly, indirectly or not. It's extremely author facing <keithamus> ... I worry if we can't reach consensus we're stuck with status quo - the hoisting behavior, which is worse than any solutions proposed <keithamus> ... I'd be happier with @nest vs hoisting <keithamus> ... even though I'm opposed <miriam> +1 current behavior is worse than any of the proposals <keithamus> Rossen4: we can bikeshed later on naming. Prefer path forward suggested by Alan with @some-long-weird-name and bikeshed later <Rossen4> ack fantasai <keithamus> fantasai: webkit is opposed to new @ rule for the purpose of making it easier to specify CSSOM. Only reason this rule is being proposed. We don't think that's good for authors <keithamus> ... flexible to what form the OM does take. <keithamus> ... we posted one that we think gives some useful interfaces for authors. If people don't like it we're flexible <keithamus> ... but one thing we're opposed to is this thing that gets parsed out <Rossen4> ack TabAtkins <keithamus> TabAtkins: lea's characterization of my position is incomplete. Creating things in the OM is vary rarely used. Crawling via .style or other - there's no meaningful difference. Creating an OM from scratch is only where you'd see the difference. That's incredibly rare to do. Only CSS tooling does it <keithamus> ... the set of authors we're effecting positively or negatively is minuscule, and these authors are advances. We don't want to give them bad stuff just because, but we trust them to navigate this <keithamus> ... webkit proposal give us genuinely worse tradeoffs. When you serialize you get something useful but insert rule or manip gets magical in a bad way, where insertrule might merge or insert before or after. Deleting rules has odd behavior as well <keithamus> ... two decls next to eachother need to be resolved. <keithamus> ... unexpected tree structure munging is difficult to work with as a user of the API <keithamus> ... bikeshed represents HTML structure of the doc with a well used XML library but it sucks for HTML. APIs are hard to predict and has inconsistent behavior with text nodes as you're moving around element nodes <keithamus> ... I used to have bugs in bikeshed due to this. I reimplemented the DOM and used the DOM wrapper just because DOM treats text and other nodes the same, a predictable behavior. <keithamus> ... similar using an @ rule of some kind means we don't do any weird magic with OM manip. <keithamus> ... We have consistent behavior, nothing weird needs to happen with add/remove. No cleanup <keithamus> ... simplifies impl and specs. Importantly it makes manipulation predictable for the author which is far more important to maintain <keithamus> ... if necessary we're fine with having a serialization rule which most of the time omits @ nest. Anything you parse in can always serialize back out without showing the rule. It just relies on adding one serialization quirk, which you'll never notice unless you're creating rules which couldn't be produced by the parser. <keithamus> ... in all other cases it'll be invisible. This is acceptable to us <keithamus> ... I think it's a bad idea to complicate the data model with magic. <Rossen4> ack emilio <keithamus> emilio: I wanted to say similar. What lea said implied the model consistent only helps browser/spec editors, I don't think that's true. Let's not overcomplicate the solution. <lea> q? <keithamus> ... having extra @ rule vs having to invent weird stuff... the trade-off is clear for me. <Rossen4> ack fantasai <Zakim> fantasai, you wanted to clarify that a bunch of what Tab objects to is not something we're requiring and to clarify that most of what Tab objects to is not something we're <Zakim> ... requiring <fantasai> https://github.com//issues/10234 <keithamus> fantasai: Tab is referring to this <fantasai> https://github.com//issues/10234#issuecomment-2116380146 <keithamus> fantasai: which is one proposal which we suggested as a possibility. We clearly said we're flexible how it's represented in the CSSOM <TabAtkins> q+ <emilio> q+ <keithamus> ... so the long spiel about merging, that's objectionable, we can drop it <keithamus> ... what we were proposing is that we introducing a CSS Nested Declaration object inherit from CSSStyleRule, it has accessors... when you use insertrule, and there happens to be an adjacent rule, you'd merge the declarations into that. <keithamus> ... if that's a problem we don't have to do that. <keithamus> ... the only thing we're stating is that it serializes without an at-rule. Consequence is not merging in CSSOM when you serailize and parse it back in 2 objects get merged together. <keithamus> ... we think this is acceptable vs a new at-rule to avoid it. <fantasai> "We would also be OK with alternative solutions that don't introduce an at-rule" <fantasai> idk how to get more explicit than that <keithamus> TabAtkins: if that's the constraint it would be good to express it. It seemed like it was requiring more magic. Serialization & reparsing.. I don't care too much about that, as long as tree manip doesn't do unpredictable magic <Rossen4> ack TabAtkins <keithamus> ... changing behavior of insert rule to allow declaration lists... currently it throws but the OM API is old. It's always unpredictable if things like this are compat issues. <keithamus> ... if it's purely a matter of producing some sort of object, call is CSSDeclarationList, and it serializes declarations, and you're ok with it changing structure when you roundtrip, I'm okay with that <Rossen4> ack emilio <keithamus> ... but all the magic proposed in thread was what I was objecting to <keithamus> emilio: I still prefer avoiding rounttripping. Apples proposal without the extra magic is basically @nest without saying @nest. <TabAtkins> Note again that "just doing an at-rule" also always serializes as bare declarations *as long as you haven't used OM manipulation to do something funky*. <keithamus> ... that's not amazing but that seems way better than the original tree-monkeying stuff <Rossen4> ack dbaron <TabAtkins> Or network packet delays can cause separate text nodes, I think, directly from the parser. <keithamus> dbaron: Wanted to point out the idea you get a different OM when you serialize and reparse is something we already have with HTML: emtpy text nodes or adjacent text nodes. DOM has an API to normalize these. <Rossen4> q? <dbaron> https://developer.mozilla.org/en-US/docs/Web/API/Node/normalize <keithamus> Rossen4: are we getting close? The original proposal in IRC seems to be landing okay? <Rossen4> ack fantasai <fantasai> PROPOSAL: <fantasai> 1. Introduce a CSSNestedDeclarations object inheriting from CSSRule and having a .style accessor, and use that to represent all the declaration lists in a CSSStyleRule. It serializes as a raw declaration list. <fantasai> 2. Extend .insertRule() to parse declarations (or, if Web-compat requires it, add .insertDeclarations()) <fantasai> 3. Open question about the first declaration block. <keithamus> fantasai: we should handle 3 as a follow up <emilio> q+ <keithamus> emilio: to be honest I still prefer a regular rule than bare decls, but this is a fine compromise if people are unwilling <Rossen4> ack emilio <fantasai> s/())/()) into a CSSNestedDeclarations object/ <keithamus> TabAtkins: I don't think first decl block is an open question. We still have weird magic behavior. The first block of stuff is definitely put in a stylerules.style not reflected in child rules <keithamus> fantasai: 100%. I think theres a question about if its also represented in CSS rules. <keithamus> emilio: I don't think putting it in 2 places is great <keithamus> TabAtkins: I don't think we can. If you delete the first block you'll be invoking magic behaviour <keithamus> ... we'll have to re-create at some point. Exactly the magical behavior I want to avoid <keithamus> emilio: that's true.. calling delete rule would be weird <keithamus> fantasai: if we do this authors can have a single consistent API for all of the contents of the style rule <keithamus> TabAtkins: If we were designing these from scratch I'd agree <keithamus> ... but with history, the only way to maintain it safely would be additional magic with delete rule. I want to avoid the tree magic as much as possible <keithamus> fantasai: can we open that conversation separately? <keithamus> TabAtkins: I can guarantee my position but the others, mild objections, but this is acceptable <keithamus> Rossen4: Can we summarise the compromise? <keithamus> TabAtkins: In the proposal <keithamus> Rossen4: all 3? <keithamus> fantasai: 3rd isn't really a thing <keithamus> Rossen4: any additional points or objections>? <keithamus> s/>?/? <fantasai> 1. Introduce a CSSNestedDeclarations object inheriting from CSSRule and having a .style accessor, and use that to represent all the declaration lists in a CSSStyleRule. It serializes as a raw declaration list. <keithamus> lea: can someone restate the proposal? <fantasai> 2. Extend .insertRule() to parse declarations (or, if Web-compat requires it, add .insertDeclarations()) <fantasai> s/())/()) into a CSSNestedDeclarations object/ <keithamus> lea: that seems great <keithamus> Rossen4: I'll call this resolved <fantasai> RESOLVED: 1. Introduce a CSSNestedDeclarations object inheriting from CSSRule and having a .style accessor, and use that to represent the declaration lists in a CSSStyleRule. It serializes as a raw declaration list. 2. Extend .insertRule() to parse declarations (or, if Web-compat requires, add .insertDeclarations()) into a CSSNestedDeclarations Object. 3. Open a new issue wrt the first declarations block. |
Possibly too late to change the design, but I just had an idea: What if we do introduce the rule, call it @group {
border-radius: if(style(--button-shape: pill), infinity, revert-group);
} |
The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516 [1] w3c/csswg-drafts#10234
The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516, 361600667 [1] w3c/csswg-drafts#10234
The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. [1] w3c/csswg-drafts#10234 Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516, 361600667 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5594117 Reviewed-by: Steinar H Gunderson <sesse@chromium.org> Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Cr-Commit-Position: refs/heads/main@{#1347266}
The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. [1] w3c/csswg-drafts#10234 Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516, 361600667 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5594117 Reviewed-by: Steinar H Gunderson <sesse@chromium.org> Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Cr-Commit-Position: refs/heads/main@{#1347266}
The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. [1] w3c/csswg-drafts#10234 Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516, 361600667 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5594117 Reviewed-by: Steinar H Gunderson <sesse@chromium.org> Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Cr-Commit-Position: refs/heads/main@{#1347266}
…tions behind a flag, a=testonly Automatic update from web-platform-tests [css-nesting] Implement CSSNestedDeclarations behind a flag The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. [1] w3c/csswg-drafts#10234 Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516, 361600667 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5594117 Reviewed-by: Steinar H Gunderson <sesse@chromium.org> Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Cr-Commit-Position: refs/heads/main@{#1347266} -- wpt-commits: b23720e948f2af9d5ddb01d94ca49fbd1c40382e wpt-pr: 47744
…tions behind a flag, a=testonly Automatic update from web-platform-tests [css-nesting] Implement CSSNestedDeclarations behind a flag The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. [1] w3c/csswg-drafts#10234 Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516, 361600667 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5594117 Reviewed-by: Steinar H Gunderson <sesse@chromium.org> Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Cr-Commit-Position: refs/heads/main@{#1347266} -- wpt-commits: b23720e948f2af9d5ddb01d94ca49fbd1c40382e wpt-pr: 47744
…tions behind a flag, a=testonly Automatic update from web-platform-tests [css-nesting] Implement CSSNestedDeclarations behind a flag The CSSWG recently resolved to change how "bare" declarations work when mixed with nested style rules. Previously, any declaration following a nested style rule would be "shifted up" to join the leading declarations, but as of the work leading up to Issue 10234 [1], such declarations now instead remain in place (wrapped in a CSSNestedDeclarations rule). This CL implements this rule, as well as the parser changes needed to produce those rules during ConsumeDeclarationList. The parsing behavior is similar to the behavior previously seen for emitting signalling/invisible rules (removed in CL:5593832), although naturally without any signalling, nor any invisibility. Per spec, CSSNestedDeclarations is a kind of style rule that matches exactly what its parent style rule matches, and with the same specificity behavior. This is different from the '&' pseudo-class, which uses the maximum specificity across its arguments, and can't match pseudo-elements. This CL implements this via an inner StyleRule, held by the CSSNestedDeclarations rule. This inner StyleRule can't be observed via CSSOM. It exists primarily to be able to bucket the rule normally on RuleSet. [1] w3c/csswg-drafts#10234 Change-Id: If9afe0cbb41e7de0acdd781ecfbf6884d677c6f8 Binary-Size: crbug.com/344608183 Bug: 343463516, 361600667 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5594117 Reviewed-by: Steinar H Gunderson <sesse@chromium.org> Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Cr-Commit-Position: refs/heads/main@{#1347266} -- wpt-commits: b23720e948f2af9d5ddb01d94ca49fbd1c40382e wpt-pr: 47744
…nd 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:
…nd 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:
…nd 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:
…nd 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:
https://bugs.webkit.org/show_bug.cgi?id=275365 rdar://130094168 Reviewed by NOBODY (OOPS!). w3c/csswg-drafts#10234 Before this CSSWG resolution, any 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 leading block of declarations. This patch implements the new resolved behavior so the order of interleaved declarations is respected during cascade. https://drafts.csswg.org/css-nesting/#the-cssnestrule This patch introduces a new StyleRuleNestedDeclarations class to be able to store a block of declarations in-between rules and fit with the already existing RuleData/RuleSet mechanism. Its CSSOM representation (CSSNestedDeclarations) is purposedly not serialized as a rule in the CSSOM but like a list of declarations. The CSSOM insertRule() functions (on CSSStyleRule/CSSGroupingRule) are modified to allow inserting block of declarations. w3c/csswg-drafts#10520 * 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:
https://bugs.webkit.org/show_bug.cgi?id=275365 rdar://130094168 Reviewed by Tim Nguyen. w3c/csswg-drafts#10234 Before this CSSWG resolution, any 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 leading block of declarations. This patch implements the new resolved behavior so the order of interleaved declarations is respected during cascade. https://drafts.csswg.org/css-nesting/#the-cssnestrule This patch introduces a new StyleRuleNestedDeclarations class to be able to store a block of declarations in-between rules and fit with the already existing RuleData/RuleSet mechanism. Its CSSOM representation (CSSNestedDeclarations) is purposedly not serialized as a rule in the CSSOM but like a list of declarations. The CSSOM insertRule() functions (on CSSStyleRule/CSSGroupingRule) are modified to allow inserting block of declarations. w3c/csswg-drafts#10520 * 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: Canonical link: https://commits.webkit.org/283188@main
Opening this as requested by @astearns
In #8738 we resolved to stop hoisting interleaved declarations and introduce an
@nest
rule that means "exactly the same thing as the parent" instead of wrapping in:is()
, which is how interleaved declarations will be represented in the CSS OM. Since we were not able to get consensus on the specifics, but we had consensus that any solution along these lines is better than the status quo, we agreed that Tab would spec whatever (commit here), and we'd discuss the details later, since fixing the specifics is more web compatible than changing the current behavior after even longer.Note
An interleaved declaration is a declaration that comes after one or more nested rules.
The issues around which we could not reach consensus were:
@nest
and it’s only introduced to represent interleaved declarations and rules, should they even be able to?@nest
rules are magically added around interleaved declarations should they also be removed during serialization?.cssText
)?@nest
rule? What if we simply use the existingCSSStyleDeclaration
object to represent interleaved rules? (proposed by @mdubet)setProperty()
work if we go with one of the designs that involve more magic?rule.style
?These are not orthogonal decisions: it seems clear that if
@nest
serializes to include an actual@nest {}
rule, that@nest
rule needs to also be valid author code. So essentially there are three possible designs:@nest
(proposed by @tabatkins, supported by @emilio @andruud @Loirooriol): The rule is automatically added around interleaved declarations, but there is no more magic besides that.@nest
(proposed by @LeaVerou, supported by @fantasai @astearns): The rule becomes a CSS OM detail, with no corresponding CSS syntax, and is removed on serialization (regardless of how serialization happens).@nest
, justCSSStyleDeclaration
in the CSSOM (proposed by @mdubet, supported by @LeaVerou @fantasai)..cssRules
will also return non-rules? Would.insertRule()
also acceptCSSStyleDeclaration
?For 2 and 3, there are also design variations based on the answer to 4 and 5 above.
My position:
@nest
or make it an internal detail. That said, there could conceivably be use cases for it. E.g. one of the problems with IACVT is that fallbacks are thrown away by the time the declaration becomes invalid. What if this was a way to preserve fallbacks?@nest
is functionally equivalent toCSSStyleDeclaration
and we should not be introducing new interfaces with philosophical purity being the only motivation (i.e. "but otherwise.cssRules
would be returning a non-rule?!?")setProperty()
on the base rule should just work, without them having to do tree walking to find the last nested rule. Like,setProperty()
is an incredibly common operation, and an API where calls tosetProperty()
have no effect are exactly the kind of dreadful APIs that make utility libraries proliferate.So I would propose a design that would minimize author exposure to all of this, and would just try to do what's reasonable when reading and modifying the CSS OM:
.cssRules
would containCSSStyleDeclaration
objects with interleaved declarationsinsertRule()
would acceptCSSStyleDeclaration
objectsCSSStyleDeclaration
objects would be merged.CSSStyleDeclaration
object cannot be at the start ofcssRules
. Inserting one should simply merge the declarations withrule.style
.Should
rule.style
be magic?One thing I'm ambivalent about is whether
rule.style
should be magic too.This would mean:
rule.style
returns the union of all interleaved declarations (we can introduce another property to only get the non-interleaved ones)rule.style.setProperty()
(and accessors) adds to the last interleavedCSSStyleDeclaration
(if any are present). The third argument is turned into a dictionary with apriority
property and another property (name TBD) to reverse this behavior and actually add it to the first block of declarations.Pros & Cons:
If we decide to avoid magic here, we can make the API more palatable by:
rule
property that returns aCSSStyleDeclaration
for the union ofrule.style
and interleaved declarationsrule.setProperty()
method that would add the property at the end of the last interleaved declaration.rule.style.setProperty()
would continue to do what it currently does. Same forremoveProperty()
,getPropertyValue()
etc.The text was updated successfully, but these errors were encountered: