Skip to content

Conversation

@canova
Copy link
Member

@canova canova commented Nov 17, 2016

This PR adds serialization steps of CSSMediaRule and CSSFontFaceRule. I reverse-engineered the grammars and came up with these steps.
Serialization of these rules are also implemented with this approach in servo: servo/servo#14238

cc @Manishearth

<li>The string "<code>@media</code>" followed by a single SPACE (U+0020).</li>
<li>The result of performing <a>serialize a media query list<a> on rule's media query list.</li>
<li>A single SPACE (U+0020), followed by the string "{", i.e., LEFT CURLY BRACKET (U+007B), followed by a single SPACE (U+0020).</li>
<li>The result of performing <a>serialize a CSS rule</a> on the each rule in rule's CSSRules list.</li>
Copy link
Member

Choose a reason for hiding this comment

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

s/on the/on

There should be spaces between each rule I guess?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, added this too thanks.

@Manishearth
Copy link
Member

r? @annevk @zcorpan

Copy link
Contributor

@zcorpan zcorpan left a comment

Choose a reason for hiding this comment

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

Thank you! This is a great start.

Please also add yourself to the spec's Acknowledgments section.

<ol>
<li>The string "<code>@font-face {</code>" followed by a single SPACE (U+0020).</li>
<li>The string "<code>font-family:</code>" followed by a single SPACE (U+0020).</li>
<li>The result of performing <a>serialize a URL</a> on the rule’s font family name.</li>
Copy link
Contributor

Choose a reason for hiding this comment

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

serialize a string?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, fixed this as well.

<li>The string "<code>;</code>", i.e., SEMICOLON (U+003B).</li>
</ol>
</li>
<li>A single SPACE (U+0020), followed by the string "}", i.e., RIGHT CURLY BRACKET (U+007D).</li>
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the other descriptors?

Copy link
Member Author

Choose a reason for hiding this comment

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

They weren't implemented in servo yet(where I implement this serialization steps) and I forgot these. I added these too, thanks.

<ol>
<li>The string "<code>@media</code>" followed by a single SPACE (U+0020).</li>
<li>The result of performing <a>serialize a media query list<a> on rule's media query list.</li>
<li>A single SPACE (U+0020), followed by the string "{", i.e., LEFT CURLY BRACKET (U+007B), followed by a single SPACE (U+0020).</li>
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems browsers use a newline and then indent the child rules by two spaces...

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4682

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, fixed this thanks.

<dd>
The result of concatenating the following:
<ol>
<li>The string "<code>@font-face {</code>" followed by a single SPACE (U+0020).</li>
Copy link
Contributor

Choose a reason for hiding this comment

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

This matches Chromium and WebKit but Gecko and Edge use a newline. Gecko and Edge disagree on indentation though... So I guess this is OK.

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4683

Copy link
Member

Choose a reason for hiding this comment

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

Not having a newline also matches the CSSStyleRule serialization

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed.

@zcorpan zcorpan added the cssom-1 Current Work label Nov 22, 2016
<li>The string "<code>;</code>", i.e., SEMICOLON (U+003B).</li>
</ol>
</li>
<li>If rule's associated <code>unicode-range</code> descriptor is present, a single SPACE (U+0020), followed by the string "<code>unicode-range:</code>", followed by a single SPACE (U+0020), followed by the result of performing serialize a <unicode-rule>, followed by the string "<code>;</code>", i.e., SEMICOLON (U+003B).</li>
Copy link
Member Author

Choose a reason for hiding this comment

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

I wrote them as the result of performing serialize a <unicode-rule> because they aren't in exist in current spec. Should I make something different?

Copy link
Contributor

Choose a reason for hiding this comment

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

@tabatkins do you have advice on how to define serialization of <urange>?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have one yet, no, but I can write something up. I'd have to do some testing.

@Manishearth
Copy link
Member

Any updates?

@zcorpan
Copy link
Contributor

zcorpan commented Apr 21, 2017

Sorry for the delay here. I feel that we should probably merge this more or less as-is and file follow-up issues for remaining bits.

@zcorpan zcorpan merged commit 6cbb98d into w3c:master Jun 2, 2017
@canova canova deleted the serialization branch June 10, 2017 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cssom-1 Current Work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants