Class HtmlPage.DomHtmlAttributeChangeListenerImpl
- java.lang.Object
-
- org.htmlunit.html.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"):
- Universal (i.e. "*"): Affected by the removal of SN from the document.
- Type (i.e. "div"): Affected by the removal of SN from the document.
- Descendant (i.e. "div span"): Affected by changes to SN or to any of its ancestors.
- Child (i.e. "div > span"): Affected by changes to SN or to its parent.
- Adjacent Sibling (i.e. "table + p"): Affected by changes to SN or its previous sibling.
- Attribute (i.e. "div.up, div[class~=up]"): Affected by changes to an attribute of SN.
- ID (i.e. "#header): Affected by changes to the
id
attribute of SN. - 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 alink
node withrel=stylesheet
is added or removed, all elements should be removed from the computed style cache.
-
-
Constructor Summary
Constructors Constructor Description DomHtmlAttributeChangeListenerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeAdded(HtmlAttributeChangeEvent event)
Notification that a new attribute was added to the HtmlElement.void
attributeRemoved(HtmlAttributeChangeEvent event)
Notification that an existing attribute has been removed from the HtmlElement.void
attributeReplaced(HtmlAttributeChangeEvent event)
Notification that an attribute on the HtmlElement has been replaced.void
nodeAdded(DomChangeEvent event)
Notification that a new node was added.private void
nodeChanged(DomNode changedNode, java.lang.String attribName)
void
nodeDeleted(DomChangeEvent event)
Notification that a new node was deleted.
-
-
-
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 interfaceDomChangeListener
- 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 interfaceDomChangeListener
- 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 interfaceHtmlAttributeChangeListener
- 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 interfaceHtmlAttributeChangeListener
- 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 interfaceHtmlAttributeChangeListener
- Parameters:
event
- the attribute change event
-
nodeChanged
private void nodeChanged(DomNode changedNode, java.lang.String attribName)
-
-