Module org.htmlunit

Class HTMLCanvasElement

java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class HTMLCanvasElement extends HTMLElement
The JavaScript object HTMLCanvasElement.
Author:
Ahmed Ashour, Ronald Brill, Frank Danek
See Also:
  • Constructor Details

    • HTMLCanvasElement

      public HTMLCanvasElement()
  • Method Details

    • jsConstructor

      public void jsConstructor()
      JavaScript constructor.
      Overrides:
      jsConstructor in class HTMLElement
    • getWidth

      public int getWidth()
      Returns the width property.
      Returns:
      the width property
    • setWidth

      public void setWidth(int width)
      Sets the width property.
      Parameters:
      width - the width property value
    • getHeight

      public int getHeight()
      Returns the height property.
      Returns:
      the height property
    • setHeight

      public void setHeight(int height)
      Sets the height property.
      Parameters:
      height - the height property value
    • resetBitmap

      public void resetBitmap()
      Resets the bitmap after the width or height attribute was set (also to the current value). Like the browsers, the bitmap is cleared and the drawing state of the context is reset.

      Chrome and Edge reset the origin-clean flag also; there is no cross-origin content left. Firefox keeps the flag. Resetting the flag without clearing the bitmap would make the old (cross-origin) content readable again, therefore both are done here.

    • getContext

      public HtmlUnitScriptable getContext(String contextId)
      Gets the context.
      Parameters:
      contextId - the context id
      Returns:
      an object that exposes an API for drawing on the canvas, or null if the given context ID is not supported
    • isOriginClean

      public boolean isOriginClean()
      Returns the origin-clean flag of the canvas. The flag is set to false if cross-origin data (e.g. an image of another origin) is drawn into the canvas; the content of such a canvas can't be read back by script.
      Returns:
      the origin-clean flag
      See Also:
    • setOriginCleanFalse

      public void setOriginCleanFalse()
      Sets the origin-clean flag of the canvas to false (cross-origin data was drawn into the canvas). Depending on the browser, setting the size of the canvas resets the flag (see resetBitmap()).
    • toDataURL

      public String toDataURL(Object type)
      Gets the data: URL representation of the canvas element. Here we return an empty image.
      Parameters:
      type - the type (optional)
      Returns:
      the data URL