Skip to content

Move style-related code out of the HTML parser #1959

Closed

Description

@jdm

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.

Activity

  1. jdm commented on Mar 21, 2014

    @jdm
    MemberAuthor

    @mbrubeck said he's on this.

  2. mbrubeck commented on Mar 25, 2014

    @mbrubeck
    Contributor

    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.

  3. mbrubeck commented on Mar 26, 2014

    @mbrubeck
    Contributor

    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.)

  4. added a commit that references this issue on Apr 14, 2014
  5. mbrubeck commented on Sep 16, 2014

    @mbrubeck
    Contributor

    #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.

  6. mbrubeck commented on Sep 16, 2014

    @mbrubeck
    Contributor

    Closing this as fixed; remaining work will be tracked in #976.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-content/domA-content/parsers

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions