Class HtmlPage.DomHtmlAttributeChangeListenerImpl

  • All Implemented Interfaces:
    java.io.Serializable, DomChangeListener, HtmlAttributeChangeListener
    Enclosing class:
    HtmlPage

    private class HtmlPage.DomHtmlAttributeChangeListenerImpl
    extends java.lang.Object
    implements DomChangeListener, HtmlAttributeChangeListener

    Listens for changes anywhere in the document and evicts cached computed styles whenever something relevant changes. Note that the very lazy way of doing this (completely clearing the cache every time something happens) results in very meager performance gains. In order to get good (but still correct) performance, we need to be a little smarter.

    CSS 2.1 has the following selector types (where "SN" is shorthand for "the selected node"):

    1. Universal (i.e. "*"): Affected by the removal of SN from the document.
    2. Type (i.e. "div"): Affected by the removal of SN from the document.
    3. Descendant (i.e. "div span"): Affected by changes to SN or to any of its ancestors.
    4. Child (i.e. "div > span"): Affected by changes to SN or to its parent.
    5. Adjacent Sibling (i.e. "table + p"): Affected by changes to SN or its previous sibling.
    6. Attribute (i.e. "div.up, div[class~=up]"): Affected by changes to an attribute of SN.
    7. ID (i.e. "#header): Affected by changes to the id attribute of SN.
    8. Pseudo-Elements and Pseudo-Classes (i.e. "p:first-child"): Affected by changes to parent.

    Together, these rules dictate that the smart (but still lazy) way of removing elements from the computed style cache is as follows -- whenever a node changes in any way, the cache needs to be cleared of styles for nodes which:

    • are actually the same node as the node that changed
    • are siblings of the node that changed
    • are descendants of the node that changed

    Additionally, whenever a style node or a link node with rel=stylesheet is added or removed, all elements should be removed from the computed style cache.

    • Constructor Detail

      • DomHtmlAttributeChangeListenerImpl

        DomHtmlAttributeChangeListenerImpl()
    • Method Detail

      • nodeAdded

        public void nodeAdded​(DomChangeEvent event)
        Notification that a new node was added. Called after the node is added.
        Specified by:
        nodeAdded in interface DomChangeListener
        Parameters:
        event - the node addition event
      • nodeDeleted

        public void nodeDeleted​(DomChangeEvent event)
        Notification that a new node was deleted. Called after the node is deleted.
        Specified by:
        nodeDeleted in interface DomChangeListener
        Parameters:
        event - the node deletion event
      • nodeChanged

        private void nodeChanged​(DomNode changedNode,
                                 java.lang.String attribName)