Repository navigation
Conversation
| The user agent must include all style sheets in the {{DocumentOrShadowRoot}}'s | ||
| [=adopted stylesheets=] inside its <a>document or shadow root CSS style sheets</a>. The [=adopted stylesheets=] are ordered after all the other style sheets (i.e. those derived from {{DocumentOrShadowRoot/styleSheets}}). | ||
|
|
||
| If a {{DocumentOrShadowRoot}} is moved into a different {{Document}}, its [=adopted stylesheets=] are also moved along with it, retaining the same set of style sheets. |
There was a problem hiding this comment.
This statement is unclear to me. Is this a statement of fact that follows from another part of the spec, and is trying to summarize things in an easy to understand way? If so, I am having a hard time understanding it. Or is this trying to impose a normative implementation requirement? If so, I'm unsure what parts of the code would need to be modified to make this true.
There was a problem hiding this comment.
Hmm yeah I'm not sure about this too, it's to resolve #46. Do you have a better place and wording for it?
There was a problem hiding this comment.
Well, how are you planning on implementing this?
There was a problem hiding this comment.
On the implementation side, it's just automatically carried over along with the DocumentOrShadowRoot since it's the same object, and the CSSStyleSheet objects are not changed in any way, the base URLs stay the same, the @imports are not re-resolved, etc.
Maybe we should modify "adopt a node" spec as well?
There was a problem hiding this comment.
I see. I think it's automatic in the spec too. I would turn it into a non-normative note, and rephrase it to be clearer with something like
<p class="note">
Because the [=adopted stylesheets=] are a property of the {{DocumentOrShadowRoot}}, they move along with the {{ShadowRoot}} if it gets [=adopted=] into a different {{Document}}, e.g. when adopting its [=shadow host=].
</p>I guess I'm still not sure what @bzbarsky was concerned about in #46 though, so maybe he can chime in.
There was a problem hiding this comment.
Changed that into a note, does this cover your concern well @bzbarsky?
| 1. Let <var>sheet</var> be the stylesheet on which this function is called on. | ||
| 2. If <var>sheet’s</var> [=constructed flag=] is not set, or <var>sheet's</var> [=disallow modification flag=] is set, throw a "{{NotAllowedError}}" {{DOMException}}. | ||
| 3. Set <var>sheet’s</var> CSS rules to an empty list, and set <var>sheet's</var> [=disallow modification flag=]. | ||
| 4. <a spec=css-syntax-3>Parse a stylesheet</a> from {{text}}. |
There was a problem hiding this comment.
It looks like this doesn't return a list of rules; instead it returns a stylesheet of some sort. (But probably not the same as a CSSOM stylesheet?) This will probably need to be refactored eventually, but that's more of a @tabatkins issue. It doesn't need to block this, but we may want to file a tracking issue for this.
There was a problem hiding this comment.
Looks like there's https://drafts.csswg.org/css-syntax-3/#parse-list-of-rules, used that now.
There was a problem hiding this comment.
That changes the handling of initial charset rules, but I am unsure whether it does so in a good or bad way.
There was a problem hiding this comment.
That @charset handling is just so that other rules that check for "is this the first rule in the stylesheet?" don't fail because of a charset indicator.
That said, you bring up a good point - I should make the parsing algorithms optionally just allow themselves to be parsed in a forced utf-8, and then we should force that here. No reason to support other charsets; that's a legacy thing.
The other difference is whether <!-- and --> are ignored during parsing or not. This is another very legacy thing, to support commenting out the contents of style blocks to hide them from browsers that didn't understand CSS and thus treated style as an unknown element. This is also irrelevant for modern times, and so it's fine to not support it.
So all in all, I'm fine with switching to this algorithm.
There was a problem hiding this comment.
and then we should force that here
I'm not following. The input here is a DOMString, not bytes. What does it mean to parse that "as utf-8"? Are we expecting people to pass in strings or bytes here? Is there value in having this function take USVString, or do we not have a CSS parsing algorithm that takes a Unicode string as input? If we're supposed to be passing bytes, we should make that explicit by making this a ByteString, but I expect that's not what people actually want here.
There was a problem hiding this comment.
Does the tokenize take a stream of codepoints or scalar values?
Treating DOMString as a stream of codepoints is doable. But if you want scalar values, and I suspect you do, USVString is probably a better fit.
There was a problem hiding this comment.
Just codepoints, tho I suspect I did actually mean scalar values. (Back when I wrote this I don't think we were making the distinction clearly in DOM.) The fact that you can't use an escape to produce a surrogate suggests that I'm assuming no lone surrogates would show up in the input stream either.
There was a problem hiding this comment.
I don't really understand the conversation, but I take that it's OK to use the "parse list of rules" because the charset and comments thing are legacy and OK to not be supported?
There was a problem hiding this comment.
Yes. There might be a little detail I need to fix up in Syntax to handle (filed as w3c/csswg-drafts#3307), but that either won't need you to do anything, or will just require a small addition that I'll ping you about.
There was a problem hiding this comment.
Cool! Do you think the rest of this PR is ok to merge?
For #46, #56, #57, and #58. If there's still some unresolved discussion on those threads and this change is invalid, please ignore.
cc @domenic @bzbarsky (somehow I can't add any of you to the "Reviewers" list...)
Preview | Diff