-
Notifications
You must be signed in to change notification settings - Fork 375
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
"::slotted" pseudo elements #331
Comments
I recently did a search through the Basic Web Components project looking for where we currently use ::content. We concur with Polymer: the only cases where we currently use ::content are trying to style the direct children of an insertion point. Regarding the name of this selector, it seems that the term "slotted" here is being used as a synonym for "assigned". For consistency with the use of "assigned" in the spec, and with existing API members such as getAssignedNodes(), perhaps this selector could be called ::assigned. That would reduce the number of terms and concepts a developer needs to learn here. |
@JanMiksovsky . Thank you! That's exactly the information I'd like to see. Regarding the name of this selector, I'm afraid that In this example,
|
Yeah, if we're making this pseudo element flatten slot elements' assigned node lists, then we should probably refrain from using the term "assigned". Also, someone pointed out that "assigned" might sound too generic while "slotted" sounds a lot more related to slot elements. |
We don't need to wait for #308 (comment). The following (tentative) definition could be enough:
|
Let me confirm: For Shadow DOM V0, the following pattern is often used: The In the proposed If @hayatoito's comment above is adopted, the Obviously if an author wants to style (I was a bit confused by the name, btw) |
Let me clarify the definition:
Does it make sense? |
Thanks, it is clearer now. Another question: Do we allow E.g. In shadow's style: ::slotted { color: green; }
::slotted(*) { color: blue; } where in this HTML: <div>
:shadow-root
<slot name="blue"></slot>
<slot></slot>
<div slot="blue">This text should be in blue.</div>
<div>(1)Is this color blue?</div>
(2)Is this color green?
</div> |
In my opinion, |
In a general rule, you cannot select text nodes with CSS selector, even with |
|
Ops. I meant a "compound selector" here, instead of a "simple selector". The motivation is to disallow "combinator" being used. Thus, the definition should be:
e.g. I expect that this does not increase the difficulty of the implementation, however, this gives us much flexibility. :) |
How do you target pseudo elements of the slotted element? ::slotted(div.foo::before) or ::slotted(div.foo)::before ? |
Good question. I've never thought this case. :)
This did not work, as intended, IMO. We might not want to support this because a pseudo element, which "::before" matches, is not a member of a distributed nodes of SLOT. This should not match.
How to support this kind of consecutive pseudo elements is up to each pseudo element. In this case, it's up to "::slotted" pseudo element. In a general rule, selectors have a limitation about what can be followed after a pseudo element. I'd like "::slotted" be valid only when it is the last item in a selector, as of now. |
On Tue, Jan 12, 2016 at 2:53 AM, Hayato Ito [email protected] Rune where the shadow tree for is: list:shadow <style> ::slotted(item)::before { content: attr(label) ":" } </style> /list:shadowFwiw, this currently works with ::content in Blink using "::content Also, this is quite similar to :host and :host-context. They happen to be
Rune Lillesveen |
Yeah, I do not have a strong opinion on this as long as the support cost do not get increased. AFAIR, the selector spec said that a selector can not have multiple pseudo elements being used at the same time, but it looks this limitation was removed from the editor's draft. Regarding with @tabatkins, |
I think there is no significant contentious bits about @tabatkins, could you update the CSS Scoping? Is the current rough definition good enough to spec it in the CSS Scoping? |
"::slotted" is used to style a distributed node directly, having a more power. e.g. slot::slotted(div.red) {
color: red;
}
slot::slotted(div.green) {
color: green;
} The following might be roughly equivalent to style a slot::slotted(*) {
color: green;
} |
Fair. |
Does a distributed node get all rules from each slot that it went through applied? Let's say an element X is assigned to a slot A, and the slot A is assigned to another slot B. So the X's final slot is B. Now, let's say both A's shadow DOM and B's shadow DOM have Should the rule in A's shadow DOM be applied to X? Or would it be ignored and only the rule in B's shadow DOM is applied? |
Yes, that's an intended behavior. A distributed node gets all rules from each slot.
I am no sure which is desired behavior, each slot or only final slot. I do not recall it being discussed. |
https://bugs.webkit.org/show_bug.cgi?id=149441 <rdar://problem/22731987> Reviewed by Andreas Kling. Source/WebCore: Based on latest in WICG/webcomponents#331 * css/CSSGrammar.y.in: Parse ::slotted. * css/CSSParser.cpp: (WebCore::CSSParser::detectFunctionTypeToken): * css/CSSParserValues.cpp: (WebCore::CSSParserSelector::parsePseudoElementCueFunctionSelector): (WebCore::CSSParserSelector::parsePseudoElementSlottedFunctionSelector): Tokenize ::slotted. (WebCore::CSSParserSelector::parsePseudoClassAndCompatibilityElementSelector): * css/CSSParserValues.h: * css/CSSSelector.cpp: (WebCore::CSSSelector::pseudoId): * css/CSSSelector.h: * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::matchAuthorRules): (WebCore::ElementRuleCollector::matchHostPseudoClassRules): (WebCore::ElementRuleCollector::matchSlottedPseudoElementRules): Match ::slotted selector. (WebCore::ElementRuleCollector::collectSlottedPseudoElementRulesForSlot): Collect ::slotted rules that may apply to an element in a slot. (WebCore::ElementRuleCollector::matchUserRules): (WebCore::ElementRuleCollector::matchUARules): (WebCore::findSlottedPseudoElementSelector): (WebCore::ElementRuleCollector::ruleMatches): * css/ElementRuleCollector.h: * css/RuleSet.cpp: (WebCore::RuleSet::addRule): Collect ::slotted rules. (WebCore::RuleSet::shrinkToFit): * css/RuleSet.h: (WebCore::RuleSet::hostPseudoClassRules): (WebCore::RuleSet::slottedPseudoElementRules): (WebCore::RuleSet::focusPseudoClassRules): (WebCore::RuleSet::universalRules): * css/SelectorChecker.cpp: (WebCore::SelectorChecker::checkOne): * style/StyleSharingResolver.cpp: (WebCore::Style::SharingResolver::resolve): Disable style sharing for children of shadow host. They may be affected by the shadow tree style which is not considered in style sharing checks. LayoutTests: * fast/shadow-dom/css-scoping-shadow-slotted-rule.html: Enable the test, fix it and update it to the current spec. * fast/shadow-dom/slotted-pseudo-element-css-text-expected.txt: Added. * fast/shadow-dom/slotted-pseudo-element-css-text.html: Added. Add parsing/cssText test based on a Blink test. There are a few failures due to * not roundtripping and the parser being too lenient with pseudo elements. * platform/mac/TestExpectations: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@197165 268f45cc-cd09-0410-ab3c-d52691b4dbfc
https://bugs.webkit.org/show_bug.cgi?id=154765 <rdar://problem/24870995> Reviewed by Ryosuke Niwa. Source/WebCore: See WICG/webcomponents#331 (comment) Test: fast/shadow-dom/css-scoping-shadow-slotted-nested.html * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::matchSlottedPseudoElementRules): Collect ::slotted rules from all the nested shadow trees instead of just the host's. LayoutTests: * fast/shadow-dom/css-scoping-shadow-slotted-nested-expected.html: Added. * fast/shadow-dom/css-scoping-shadow-slotted-nested.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@197316 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Here's the example for @rniwa <div id="host">
:shadow-root
<style>::slotted(span) { color: green; background-color: yellow; }</style>
<div id="host2">
:shadow-root
<style>::slotted(span) { color: red; }</style>
<slot name="slot2"></slot>
<slot name="slot1" slot="slot2"></slot>
</div>
<span slot="slot1">Hello, Shadow DOM</span>
</div> In current Blink's implementation, first |
Just a note. We still use our broken cascade order from v0 in Blink, so we shouldn't trust the current order from Blink in general right? |
Yeah, we just implemented that behavior in http://trac.webkit.org/changeset/197316. |
@TakayoshiKochi |
I'm contacting @tabatkins to get the spec updated. |
All done, and reply sent to the list. https://lists.w3.org/Archives/Public/www-style/2016Apr/0239.html Please review! |
Oh yeah, I haven't yet defined pseudo-element handling. Which do y'all prefer:
I don't have a strong opinion either way. |
I think I'd prefer ::slotted(.foo)::before because it's similar to how you add ::before/::after on hosts. Blink currently supports ::before/::after on hosts using :host(.foo)::before not :host(.foo::before) :host-context(.foo::before) would be strange also. |
Right, that's because :host() always represents the host element; it just uses the argument to query the tree to see if it should match or not. Putting ::before inside the argument wouldn't make any sense - you dont' want to check if an ancestor has a ::before pseudo-element. ::slotted, on the other hand, uses its argument to decide which of its assigned slotables it's supposed to represent. As such, it makes a little more sense to have ::before inside. (At least, it makes as much sense as using doing something like I don't have a problem with I'll also note that if you're drawing parallels between |
It seems weird though since it addresses a box inside |
Thank you, @tabatkins ! I reviewed quickly. Here are my comments:
Since the actual logic, "Which elements generate a box?", should be explained by the concept of the flat tree , I'm wondering how to state it simply in css scoping. The current Shadow DOM spec has the followings in the section of Flat trees:
I think we should upstream these sentences to CSS scoping. I guess these sentences need to be refined somehow to match the css scoping world. DOM Standard does not need a flat tree. I think only css scoping is a client of a flat tree. Thus, eventually, we need to upstream a flat tree to CSS. 3.1. Shadow DOM Selection Model
This can be:
Yeah, multiple shadow trees are removed. 3.1.1. Shadow Hosts in a Shadow Tree
This can be:
because multiple shadow trees are removed. 3.1.2. Slots and Slotted Elements in a Shadow Tree
I think we can remove these sentences. If we use the flat tree in the previous section, we do not need to mention a slot here as a special case. 3.2.2. Selecting Slot-Assigned Content: the ::slotted() pseudo-element
"::slotted()" represents "distributed nodes", instead of "assigned nodes". I think you can refer this as the definition of "distributed". |
In 3.2.2, ::slotted( <compound-selector>? )
We haven't discussed this in this issue before, and when I implemented in Blink I made the |
@annevk @TakayoshiKochi Yeah, I can make the argument mandatory. @hayatoito Thanks for the review! I hadn't caught that multiple shadow roots were removed; I'll fix. For the rest of your comments, I will (a) rephrase the explanatory part to be clearer that I'm not trying to redefine anything from DOM, just provide some framing for everything else in the spec (so people don't have to go read and understand DOM just to understand what I'm talking about), and (b) pull in all the flattening/distributing stuff so you can remove it from Shadow DOM. Between DOM and CSS Scoping, it looks like nearly all of Shadow DOM is getting eaten by other specs, so we should be able to remove most or all of it soon! |
I've finished all the edits; they ended up necessitating a larger reorg/rewrite than I'd expected! Scoping now defines the flattened tree, too. |
Closing this issue because the behavior is largely defined in the CSS scoping spec. We can file a new issue to track the remaining issues if there are any. |
Stop closing this issue, people won't suddenly forget they need this. |
?? |
Yes, ::slotted is supported everywhere, but ::slotted still doesn't allow to styling child nodes, which make them completely useless for anyone who care about UI.. Perhaps there's a way i don't know? But i sure as hell search for it!! If not, what is the purpose of a container who can't style it's content? |
That should be tracked in a new issue, not in this old issue about |
What a disappointing arbitrary limitation. Let the browser-makers solve performance issues and write the spec to be ideal. WEAK! |
@Lonniebiz I’m not sure this is as arbitrary as it seems at first. If I’ve understood right, the performance cost stems from a mathematical truth rather than browser implementation details. (Correct me if I’m mistaken.) |
Let's define the behavior of
::slotted
(a tentative name).I am aware that CSS Scoping should define it, but let's have a rough consensus here.
I remember that I had discussion, maybe in www-style?, that we should make
::content
take only a simple selector, instead of a selector. Polymer guys told us that styling a direct child of an insertion point is the only use case of::content
in Polymer.e.g.
::content(div)
That should be interpreted as
::content > div
in the previous syntax.We no longer support a selector as its argument, like
::content(div p)
We might want to make
::slotted
have this restriction because this makes the implementation simpler.See also #308 (comment) because the definition of
::slotted
will depend on those incoming changes.The text was updated successfully, but these errors were encountered: