Class HtmlImage
- java.lang.Object
-
- org.htmlunit.html.DomNode
-
- org.htmlunit.html.DomNamespaceNode
-
- org.htmlunit.html.DomElement
-
- org.htmlunit.html.HtmlElement
-
- org.htmlunit.html.HtmlImage
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.w3c.dom.Element,org.w3c.dom.Node
public class HtmlImage extends HtmlElement
Wrapper for the HTML element "img".- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.htmlunit.html.HtmlElement
HtmlElement.DisplayStyle
-
Nested classes/interfaces inherited from class org.htmlunit.html.DomElement
DomElement.ChildElementsIterator
-
Nested classes/interfaces inherited from class org.htmlunit.html.DomNode
DomNode.ChildIterator, DomNode.DescendantElementsIterator<T extends DomNode>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringTAG_NAMEThe HTML tag represented by this element.static java.lang.StringTAG_NAME2Another HTML tag represented by this element.-
Fields inherited from class org.htmlunit.html.HtmlElement
ATTRIBUTE_CHECKED, ATTRIBUTE_REQUIRED, TAB_INDEX_OUT_OF_BOUNDS
-
Fields inherited from class org.htmlunit.html.DomElement
ATTRIBUTE_NOT_DEFINED, ATTRIBUTE_VALUE_EMPTY, SRC_ATTRIBUTE
-
Fields inherited from class org.htmlunit.html.DomNode
PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED
-
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Pageclick()Simulates clicking this element at the position(0, 0).Pageclick(int x, int y)Simulates clicking this element at the specified position.protected booleandoClickStateUpdate(boolean shiftKey, boolean ctrlKey)Performs the click action on the enclosing A tag (if any).voiddoOnLoad()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.ScriptResultfireEvent(org.htmlunit.javascript.host.event.Event event)INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Fires the event on the element.java.lang.StringgetAlignAttribute()Returns the value of the attributealign.java.lang.StringgetAltAttribute()Returns the value of the attributealt.java.lang.StringgetBorderAttribute()Returns the value of the attributeborder.HtmlElement.DisplayStylegetDefaultStyleDisplay()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns the default display style.intgetHeight()Returns the image's actual height (not the image'sheight attribute).java.lang.StringgetHeightAttribute()Returns the value of the attributeheight.intgetHeightOrDefault()Returns the value same value as the js height property.java.lang.StringgetHspaceAttribute()Returns the value of the attributehspace.org.htmlunit.platform.image.ImageDatagetImageData()javax.imageio.ImageReadergetImageReader()Deprecated.as of version 2.70.0; usegetImageData()insteadjava.lang.StringgetIsmapAttribute()Returns the value of the attributeismap.java.lang.StringgetLocalName()java.lang.StringgetLongDescAttribute()Returns the value of the attributelongdesc.java.lang.StringgetNameAttribute()Returns the value of the attributename.java.lang.StringgetOriginalQualifiedName()Returns the original element qualified name, this is needed to differentiate betweenimgandimage.java.lang.StringgetSrc()Returns the value of thesrcvalue.java.lang.StringgetSrcAttribute()Returns the value of the attributesrc.java.lang.StringgetUseMapAttribute()Returns the value of the attributeusemap.java.lang.StringgetVspaceAttribute()Returns the value of the attributevspace.WebResponsegetWebResponse(boolean downloadIfNeeded)Returns theWebResponsefor the image contained by this image element.intgetWidth()Returns the image's actual width (not the image'swidth attribute).java.lang.StringgetWidthAttribute()Returns the value of the attributewidth.intgetWidthOrDefault()Returns the value same value as the js width property.booleanisComplete()booleanisDisplayed()Returnstrueif this node is displayed and can be visible to the user (ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).voidmarkAsCreatedByJavascript()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Marks this frame as created by javascript.protected voidonAddedToPage()Lifecycle method invoked whenever a node is added to a page.voidonload()voidprocessImportNode(org.htmlunit.javascript.host.dom.Document doc)INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Lifecycle method to support special processing for js method importNode.voidsaveAs(java.io.File file)Saves this image as the specified file.protected voidsetAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName, java.lang.String value, boolean notifyAttributeChangeListeners, boolean notifyMutationObservers)Sets the value of the attribute specified by namespace and qualified name.booleanwasCreatedByJavascript()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns true if this frame was created by javascript.-
Methods inherited from class org.htmlunit.html.HtmlElement
acceptChar, addHtmlAttributeChangeListener, appendChildIfNoneExists, checkChildHierarchy, cloneNode, detach, doType, doType, fireHtmlAttributeAdded, fireHtmlAttributeRemoved, fireHtmlAttributeReplaced, getCanonicalXPath, getElementsByAttribute, getEnclosingElement, getEnclosingForm, getEnclosingFormOrDie, getLangAttribute, getNodeName, getOnClickAttribute, getOnDblClickAttribute, getOneHtmlElementByAttribute, getOnKeyDownAttribute, getOnKeyPressAttribute, getOnKeyUpAttribute, getOnMouseDownAttribute, getOnMouseMoveAttribute, getOnMouseOutAttribute, getOnMouseOverAttribute, getOnMouseUpAttribute, getSrcAttributeNormalized, getTabIndex, getTextDirectionAttribute, getXmlLangAttribute, handles, hasEventHandlers, isAltPressed, isAttributeCaseSensitive, isCtrlPressed, isHidden, isOptional, isRequired, isRequiredSupported, isShiftPressed, isSubmittableByEnter, isValid, notifyAttributeChangeListeners, removeAttribute, removeChild, removeHtmlAttributeChangeListener, setAttributeNode, setRequired, type, type, type, type, typeDone
-
Methods inherited from class org.htmlunit.html.DomElement
blur, click, click, click, click, dblClick, dblClick, doClickFireChangeEvent, doClickFireClickEvent, fireEvent, focus, getAttribute, getAttributeDirect, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getAttributesMap, getChildElementCount, getChildElements, getElementsByTagName, getElementsByTagNameNS, getEventTargetElement, getFirstElementChild, getId, getLastElementChild, getNodeType, getSchemaTypeInfo, getStyleElement, getStyleElementCaseInSensitive, getStyleMap, getTagName, hasAttribute, hasAttributeNS, hasAttributes, isDisabledElementAndDisabled, isEmptyXmlTagExpanded, isMouseOver, isStateUpdateFirst, matches, mouseDown, mouseDown, mouseMove, mouseMove, mouseOut, mouseOut, mouseOver, mouseOver, mouseUp, mouseUp, preventDefault, printOpeningTagContentAsXml, printXml, propagateClickStateUpdateToParent, removeAttributeNode, removeAttributeNS, removeFocus, removeStyleAttribute, replaceStyleAttribute, rightClick, rightClick, setAttribute, setAttributeNodeNS, setAttributeNS, setDefaults, setId, setIdAttribute, setIdAttributeNode, setIdAttributeNS, setInnerHtml, setNodeValue, toString, writeStyleToElement
-
Methods inherited from class org.htmlunit.html.DomNamespaceNode
getLowercaseName, getNamespaceURI, getPrefix, getQualifiedName, setPrefix
-
Methods inherited from class org.htmlunit.html.DomNode
addCharacterDataChangeListener, addDomChangeListener, appendChild, asNormalizedText, asXml, basicRemove, closest, compareDocumentPosition, fireCharacterDataChanged, fireNodeAdded, fireNodeDeleted, getAncestors, getBaseURI, getByXPath, getByXPath, getChildNodes, getChildren, getDescendants, getDomElementDescendants, getEndColumnNumber, getEndLineNumber, getFeature, getFirstByXPath, getFirstByXPath, getFirstChild, getHtmlElementDescendants, getHtmlPageOrNull, getIndex, getLastChild, getNextElementSibling, getNextSibling, getNodeValue, getOwnerDocument, getPage, getParentNode, getPreviousElementSibling, getPreviousSibling, getReadyState, getScriptableObject, getSelectorList, getStartColumnNumber, getStartLineNumber, getTextContent, getUserData, getVisibleText, hasChildNodes, hasFeature, insertBefore, insertBefore, isAncestorOf, isAncestorOfAny, isAttachedToPage, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, mayBeDisplayed, normalize, notifyIncorrectness, onAddedToDocumentFragment, onAllChildrenAddedToPage, parseHtmlSnippet, printChildrenAsXml, querySelector, querySelectorAll, quietlyRemoveAndMoveChildrenTo, remove, removeAllChildren, removeCharacterDataChangeListener, removeChild, removeDomChangeListener, replace, replaceChild, setEndLocation, setParentNode, setReadyState, setScriptableObject, setStartLocation, setTextContent, setUserData
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.w3c.dom.Node
appendChild, compareDocumentPosition, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setPrefix, setTextContent, setUserData
-
-
-
-
Field Detail
-
TAG_NAME
public static final java.lang.String TAG_NAME
The HTML tag represented by this element.- See Also:
- Constant Field Values
-
TAG_NAME2
public static final java.lang.String TAG_NAME2
Another HTML tag represented by this element.- See Also:
- Constant Field Values
-
-
Method Detail
-
onAddedToPage
protected void onAddedToPage()
Lifecycle method invoked whenever a node is added to a page. Intended to be overridden by nodes which need to perform custom logic when they are added to a page. This method is recursive, so if you override it, please be sure to callsuper.onAddedToPage().- Overrides:
onAddedToPagein classDomNode
-
setAttributeNS
protected void setAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName, java.lang.String value, boolean notifyAttributeChangeListeners, boolean notifyMutationObservers)Sets the value of the attribute specified by namespace and qualified name.- Overrides:
setAttributeNSin classHtmlElement- Parameters:
namespaceURI- the URI that identifies an XML namespacequalifiedName- the qualified name (prefix:local) of the attributevalue- the value of the attributenotifyAttributeChangeListeners- to notify the associatedHtmlAttributeChangeListenersnotifyMutationObservers- to notifyMutationObservers or not
-
processImportNode
public void processImportNode(org.htmlunit.javascript.host.dom.Document doc)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Lifecycle method to support special processing for js method importNode.- Overrides:
processImportNodein classDomNamespaceNode- Parameters:
doc- the import target document- See Also:
Document.importNode( org.htmlunit.javascript.host.dom.Node, boolean),HtmlScript.processImportNode(org.htmlunit.javascript.host.dom.Document)
-
doOnLoad
public void doOnLoad()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Executes this element's
onloadoronerrorhandler. This method downloads the image if either of these handlers are present (prior to invoking the resulting handler), because applications sometimes use images to send information to the server and use these handlers to get notified when the information has been received by the server.See here and here for the discussion which lead up to this method.
This method may be called multiple times, but will only attempt to execute the
onloadoronerrorhandler the first time it is invoked.
-
getSrcAttribute
public final java.lang.String getSrcAttribute()
Returns the value of the attributesrc. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
srcor an empty string if that attribute isn't defined
-
getSrc
public java.lang.String getSrc()
Returns the value of thesrcvalue.- Returns:
- the value of the
srcvalue
-
getAltAttribute
public final java.lang.String getAltAttribute()
Returns the value of the attributealt. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
altor an empty string if that attribute isn't defined
-
getNameAttribute
public final java.lang.String getNameAttribute()
Returns the value of the attributename. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
nameor an empty string if that attribute isn't defined
-
getLongDescAttribute
public final java.lang.String getLongDescAttribute()
Returns the value of the attributelongdesc. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
longdescor an empty string if that attribute isn't defined
-
getHeightAttribute
public final java.lang.String getHeightAttribute()
Returns the value of the attributeheight. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
heightor an empty string if that attribute isn't defined
-
getWidthAttribute
public final java.lang.String getWidthAttribute()
Returns the value of the attributewidth. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
widthor an empty string if that attribute isn't defined
-
getUseMapAttribute
public final java.lang.String getUseMapAttribute()
Returns the value of the attributeusemap. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
usemapor an empty string if that attribute isn't defined
-
getIsmapAttribute
public final java.lang.String getIsmapAttribute()
Returns the value of the attributeismap. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
ismapor an empty string if that attribute isn't defined
-
getAlignAttribute
public final java.lang.String getAlignAttribute()
Returns the value of the attributealign. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
alignor an empty string if that attribute isn't defined
-
getBorderAttribute
public final java.lang.String getBorderAttribute()
Returns the value of the attributeborder. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
borderor an empty string if that attribute isn't defined
-
getHspaceAttribute
public final java.lang.String getHspaceAttribute()
Returns the value of the attributehspace. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
hspaceor an empty string if that attribute isn't defined
-
getVspaceAttribute
public final java.lang.String getVspaceAttribute()
Returns the value of the attributevspace. Refer to the HTML 4.01 documentation for details on the use of this attribute.- Returns:
- the value of the attribute
vspaceor an empty string if that attribute isn't defined
-
getHeight
public int getHeight() throws java.io.IOExceptionReturns the image's actual height (not the image's
height attribute).POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK
If the image has not already been downloaded, this method triggers a download and caches the image.
- Returns:
- the image's actual height
- Throws:
java.io.IOException- if an error occurs while downloading or reading the image
-
getHeightOrDefault
public int getHeightOrDefault()
Returns the value same value as the js height property.- Returns:
- the value of the
heightproperty
-
getWidth
public int getWidth() throws java.io.IOExceptionReturns the image's actual width (not the image's
width attribute).POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK
If the image has not already been downloaded, this method triggers a download and caches the image.
- Returns:
- the image's actual width
- Throws:
java.io.IOException- if an error occurs while downloading or reading the image
-
getWidthOrDefault
public int getWidthOrDefault()
Returns the value same value as the js width property.- Returns:
- the value of the
widthproperty
-
getImageReader
@Deprecated public javax.imageio.ImageReader getImageReader() throws java.io.IOExceptionDeprecated.as of version 2.70.0; usegetImageData()insteadReturns the
ImageReaderwhich can be used to read the image contained by this image element.POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK
If the image has not already been downloaded, this method triggers a download and caches the image.
- Returns:
- the
ImageReaderwhich can be used to read the image contained by this image element - Throws:
java.io.IOException- if an error occurs while downloading or reading the image
-
getImageData
public org.htmlunit.platform.image.ImageData getImageData() throws java.io.IOException- Throws:
java.io.IOException
-
getWebResponse
public WebResponse getWebResponse(boolean downloadIfNeeded) throws java.io.IOException
Returns the
WebResponsefor the image contained by this image element.POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK
If the image has not already been downloaded and
downloadIfNeededistrue, this method triggers a download and caches the image.- Parameters:
downloadIfNeeded- whether or not the image should be downloaded (if it hasn't already been downloaded)- Returns:
nullif no download should be performed and one hasn't already been triggered; otherwise, the response received when performing a request for the image referenced by this element- Throws:
java.io.IOException- if an error occurs while downloading the image
-
click
public Page click(int x, int y) throws java.io.IOException
Simulates clicking this element at the specified position. This only makes sense for an image map (currently only server side), where the position matters. This method returns the page contained by this image's window after the click, which may or may not be the same as the original page, depending on JavaScript event handlers, etc.- Parameters:
x- the x position of the clicky- the y position of the click- Returns:
- the page contained by this image's window after the click
- Throws:
java.io.IOException- if an IO error occurs
-
click
public Page click() throws java.io.IOException
Simulates clicking this element at the position(0, 0). This method returns the page contained by this image's window after the click, which may or may not be the same as the original page, depending on JavaScript event handlers, etc.- Overrides:
clickin classDomElement- Returns:
- the page contained by this image's window after the click
- Throws:
java.io.IOException- if an IO error occurs
-
doClickStateUpdate
protected boolean doClickStateUpdate(boolean shiftKey, boolean ctrlKey) throws java.io.IOExceptionPerforms the click action on the enclosing A tag (if any). This method implements the control state update part of the click action.The default implementation only calls doClickStateUpdate on parent's DomElement (if any). Subclasses requiring different behavior (like
HtmlSubmitInput) will override this method.- Overrides:
doClickStateUpdatein classDomElement- Parameters:
shiftKey-trueif SHIFT is pressedctrlKey-trueif CTRL is pressed- Returns:
- true if doClickFireEvent method has to be called later on (to signal, that the value was changed)
- Throws:
java.io.IOException- if an IO error occurred
-
saveAs
public void saveAs(java.io.File file) throws java.io.IOExceptionSaves this image as the specified file.- Parameters:
file- the file to save to- Throws:
java.io.IOException- if an IO error occurs
-
getDefaultStyleDisplay
public HtmlElement.DisplayStyle getDefaultStyleDisplay()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns the default display style.- Overrides:
getDefaultStyleDisplayin classHtmlElement- Returns:
- the default display style
-
onload
public void onload()
-
isComplete
public boolean isComplete()
- Returns:
- true if the image was successfully downloaded
-
isDisplayed
public boolean isDisplayed()
Returns
trueif this node is displayed and can be visible to the user (ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).NOTE: If CSS is
Overwritten to support the hidden attribute (html5).disabled, this method does not take this element's style into consideration!- Overrides:
isDisplayedin classHtmlElement- Returns:
trueif the node is visible to the user,falseotherwise- See Also:
- CSS2 Visibility,
CSS2 Display,
MSDN Documentation,
DomNode.mayBeDisplayed()
-
markAsCreatedByJavascript
public void markAsCreatedByJavascript()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Marks this frame as created by javascript. This is needed to handle some special IE behavior.
-
wasCreatedByJavascript
public boolean wasCreatedByJavascript()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns true if this frame was created by javascript. This is needed to handle some special IE behavior.- Returns:
- true or false
-
getOriginalQualifiedName
public java.lang.String getOriginalQualifiedName()
Returns the original element qualified name, this is needed to differentiate betweenimgandimage.- Returns:
- the original element qualified name
-
getLocalName
public java.lang.String getLocalName()
- Specified by:
getLocalNamein interfaceorg.w3c.dom.Node- Overrides:
getLocalNamein classDomNamespaceNode
-
fireEvent
public ScriptResult fireEvent(org.htmlunit.javascript.host.event.Event event)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Fires the event on the element. Nothing is done if JavaScript is disabled.- Overrides:
fireEventin classDomElement- Parameters:
event- the event to fire- Returns:
- the execution result, or
nullif nothing is executed
-
-