Class 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
    • 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 call super.onAddedToPage().
        Overrides:
        onAddedToPage in class DomNode
      • 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:
        setAttributeNS in class HtmlElement
        Parameters:
        namespaceURI - the URI that identifies an XML namespace
        qualifiedName - the qualified name (prefix:local) of the attribute
        value - the value of the attribute
        notifyAttributeChangeListeners - to notify the associated HtmlAttributeChangeListeners
        notifyMutationObservers - to notify MutationObservers or not
      • doOnLoad

        public void doOnLoad()

        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

        Executes this element's onload or onerror handler. 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 onload or onerror handler the first time it is invoked.

      • getSrcAttribute

        public final java.lang.String getSrcAttribute()
        Returns the value of the attribute src. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute src or an empty string if that attribute isn't defined
      • getSrc

        public java.lang.String getSrc()
        Returns the value of the src value.
        Returns:
        the value of the src value
      • getAltAttribute

        public final java.lang.String getAltAttribute()
        Returns the value of the attribute alt. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute alt or an empty string if that attribute isn't defined
      • getNameAttribute

        public final java.lang.String getNameAttribute()
        Returns the value of the attribute name. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute name or an empty string if that attribute isn't defined
      • getLongDescAttribute

        public final java.lang.String getLongDescAttribute()
        Returns the value of the attribute longdesc. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute longdesc or an empty string if that attribute isn't defined
      • getHeightAttribute

        public final java.lang.String getHeightAttribute()
        Returns the value of the attribute height. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute height or an empty string if that attribute isn't defined
      • getWidthAttribute

        public final java.lang.String getWidthAttribute()
        Returns the value of the attribute width. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute width or an empty string if that attribute isn't defined
      • getUseMapAttribute

        public final java.lang.String getUseMapAttribute()
        Returns the value of the attribute usemap. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute usemap or an empty string if that attribute isn't defined
      • getIsmapAttribute

        public final java.lang.String getIsmapAttribute()
        Returns the value of the attribute ismap. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute ismap or an empty string if that attribute isn't defined
      • getAlignAttribute

        public final java.lang.String getAlignAttribute()
        Returns the value of the attribute align. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute align or an empty string if that attribute isn't defined
      • getBorderAttribute

        public final java.lang.String getBorderAttribute()
        Returns the value of the attribute border. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute border or an empty string if that attribute isn't defined
      • getHspaceAttribute

        public final java.lang.String getHspaceAttribute()
        Returns the value of the attribute hspace. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute hspace or an empty string if that attribute isn't defined
      • getVspaceAttribute

        public final java.lang.String getVspaceAttribute()
        Returns the value of the attribute vspace. Refer to the HTML 4.01 documentation for details on the use of this attribute.
        Returns:
        the value of the attribute vspace or an empty string if that attribute isn't defined
      • getHeight

        public int getHeight()
                      throws java.io.IOException

        Returns 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 height property
      • getWidth

        public int getWidth()
                     throws java.io.IOException

        Returns 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 width property
      • 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 WebResponse for 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 downloadIfNeeded is true, 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:
        null if 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 click
        y - 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:
        click in class DomElement
        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.IOException
        Performs 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:
        doClickStateUpdate in class DomElement
        Parameters:
        shiftKey - true if SHIFT is pressed
        ctrlKey - true if 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.IOException
        Saves this image as the specified file.
        Parameters:
        file - the file to save to
        Throws:
        java.io.IOException - if an IO error occurs
      • onload

        public void onload()
      • isComplete

        public boolean isComplete()
        Returns:
        true if the image was successfully downloaded
      • isDisplayed

        public boolean isDisplayed()

        Returns true if 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 disabled, this method does not take this element's style into consideration!

        Overwritten to support the hidden attribute (html5).
        Overrides:
        isDisplayed in class HtmlElement
        Returns:
        true if the node is visible to the user, false otherwise
        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 between img and image.
        Returns:
        the original element qualified name
      • getLocalName

        public java.lang.String getLocalName()
        Specified by:
        getLocalName in interface org.w3c.dom.Node
        Overrides:
        getLocalName in class DomNamespaceNode
      • 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:
        fireEvent in class DomElement
        Parameters:
        event - the event to fire
        Returns:
        the execution result, or null if nothing is executed