Skip to content

Use real constructors - #61

Merged
rakina merged 3 commits into
gh-pagesfrom
updates
Dec 10, 2018
Merged

rakina merged 3 commits into
gh-pagesfrom
updates

Conversation

@rakina

@rakina rakina commented Nov 8, 2018 •

Copy link
Copy Markdown
Member

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

@rakina
rakina requested a review from tabatkins November 8, 2018 15:15
Comment thread index.bs Resolved
Comment thread index.bs Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah I'm not sure about this too, it's to resolve #46. Do you have a better place and wording for it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, how are you planning on implementing this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed that into a note, does this cover your concern well @bzbarsky?

Comment thread index.bs Resolved
Comment thread index.bs Outdated
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}}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That changes the handling of initial charset rules, but I am unsure whether it does so in a good or bad way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Do you think the rest of this PR is ok to merge?

Comment thread index.bs Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants