You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Move style-related code out of the HTML parser #1959
The create_element and complete_style hooks are kind of hacky. The code to handle dynamic CSS additions via link and style elements really belongs in Element::bind_to_tree_impl, where it can be shared automatically by both the parser and regular DOM manipulation. #1957 adds code for inline style elements which is very close to the definition of complete_style; we should finish the job. In addition, we can use this to fix the longstanding inefficiency where CSS stylesheets discovered while parsing bounce through the content task before being passed to layout.
We can't do this entirely within Element::bind_to_tree_impl because it's called too early during parsing of inline style elements (before the text content has been appended). We may need to add hooks that are called when text nodes are inserted/modified/removed in a style element.
Notes from talking to jdm on IRC: For <link rel="stylesheet"> we will need the Page to store a reference to the resource channel while parse_html is running. When a <link> has attributes set that cause a stylesheet load, it can notify the Page, which can notify the channel if it exists. At the end of parse_html we will destroy the channel, signalling to listeners that we are done loading resources discovered during parsing. If a <link rel="stylesheet"> is later added dynamically, the same stylesheet-loading code will run but the channel will no longer exist since we are no longer parsing.
(We could apply the same changes to the similar code that handles <script> and <iframe> elements.)
#3352 moves <link rel=stylesheet> parsing out of the HTML parser, but we still need to handle dynamic changes to attributes on the <link> element, as discussed in the previous comment.
Activity
jdm commentedon Mar 21, 2014
@mbrubeck said he's on this.
mbrubeck commentedon Mar 25, 2014
We can't do this entirely within
Element::bind_to_tree_implbecause it's called too early during parsing of inlinestyleelements (before the text content has been appended). We may need to add hooks that are called when text nodes are inserted/modified/removed in astyleelement.mbrubeck commentedon Mar 26, 2014
Notes from talking to jdm on IRC: For
<link rel="stylesheet">we will need the Page to store a reference to the resource channel whileparse_htmlis running. When a<link>has attributes set that cause a stylesheet load, it can notify the Page, which can notify the channel if it exists. At the end ofparse_htmlwe will destroy the channel, signalling to listeners that we are done loading resources discovered during parsing. If a<link rel="stylesheet">is later added dynamically, the same stylesheet-loading code will run but the channel will no longer exist since we are no longer parsing.(We could apply the same changes to the similar code that handles
<script>and<iframe>elements.)auto merge of #1984 : mbrubeck/servo/1959-parser-style, r=jdm
mbrubeck commentedon Sep 16, 2014
#3352 moves
<link rel=stylesheet>parsing out of the HTML parser, but we still need to handle dynamic changes to attributes on the<link>element, as discussed in the previous comment.mbrubeck commentedon Sep 16, 2014
Closing this as fixed; remaining work will be tracked in #976.