Class HtmlPage.DomHtmlAttributeChangeListenerImpl

java.lang.Object
org.htmlunit.html.HtmlPage.DomHtmlAttributeChangeListenerImpl
All Implemented Interfaces:
Serializable, DomChangeListener, HtmlAttributeChangeListener
Enclosing class:
HtmlPage

private class HtmlPage.DomHtmlAttributeChangeListenerImpl extends 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 Details

    • DomHtmlAttributeChangeListenerImpl

      DomHtmlAttributeChangeListenerImpl()
  • Method Details

    • 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
    • attributeAdded

      public void attributeAdded(HtmlAttributeChangeEvent event)
      Notification that a new attribute was added to the HtmlElement. Called after the attribute is added.
      Specified by:
      attributeAdded in interface HtmlAttributeChangeListener
      Parameters:
      event - the attribute change event
    • attributeRemoved

      public void attributeRemoved(HtmlAttributeChangeEvent event)
      Notification that an existing attribute has been removed from the HtmlElement. Called after the attribute is removed.
      Specified by:
      attributeRemoved in interface HtmlAttributeChangeListener
      Parameters:
      event - the attribute change event
    • attributeReplaced

      public void attributeReplaced(HtmlAttributeChangeEvent event)
      Notification that an attribute on the HtmlElement has been replaced. Called after the attribute is replaced.
      Specified by:
      attributeReplaced in interface HtmlAttributeChangeListener
      Parameters:
      event - the attribute change event
    • nodeChanged

      private void nodeChanged(DomNode changedNode, String attribName)