Class Canvas

All Implemented Interfaces:
HasAllDragAndDropHandlers, HasAllFocusHandlers, HasAllGestureHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasAllTouchHandlers, HasBlurHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragEndHandlers, HasDragEnterHandlers, HasDragHandlers, HasDragLeaveHandlers, HasDragOverHandlers, HasDragStartHandlers, HasDropHandlers, HasFocusHandlers, HasGestureChangeHandlers, HasGestureEndHandlers, HasGestureStartHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasTouchCancelHandlers, HasTouchEndHandlers, HasTouchMoveHandlers, HasTouchStartHandlers, HasAttachHandlers, HasHandlers, EventListener, Focusable, HasEnabled, HasFocus, HasVisibility, IsWidget, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents

public class Canvas extends FocusWidget
A widget representing a <canvas> element. This widget may not be supported on all browsers.
  • Method Details

    • createIfSupported

      public static Canvas createIfSupported()
      Return a new Canvas if supported, and null otherwise.
      Returns:
      a new Canvas if supported, and null otherwise
    • wrap

      public static Canvas wrap(CanvasElement element)
      Wrap an existing canvas element. The element must already be attached to the document. If the element is removed from the document, you must call RootPanel.detachNow(Widget). Note: This method can return null if there is no support for canvas by the current browser.
      Parameters:
      element - the element to wrap
      Returns:
      the Canvas widget or null if canvas is not supported by the current browser.
    • isSupported

      public static boolean isSupported()
      Runtime check for whether the canvas element is supported in this browser.
      Returns:
      whether the canvas element is supported
    • getCanvasElement

      public CanvasElement getCanvasElement()
      Returns the attached Canvas Element.
      Returns:
      the Canvas Element
    • getContext

      public Context getContext(String contextId)
      Gets the rendering context that may be used to draw on this canvas.
      Parameters:
      contextId - the context id as a String
      Returns:
      the canvas rendering context
    • getContext2d

      public Context2d getContext2d()
      Returns a 2D rendering context. This is a convenience method, see getContext(String).
      Returns:
      a 2D canvas rendering context
    • getCoordinateSpaceHeight

      public int getCoordinateSpaceHeight()
      Gets the height of the internal canvas coordinate space.
      Returns:
      the height, in pixels
      See Also:
    • getCoordinateSpaceWidth

      public int getCoordinateSpaceWidth()
      Gets the width of the internal canvas coordinate space.
      Returns:
      the width, in pixels
      See Also:
    • setCoordinateSpaceHeight

      public void setCoordinateSpaceHeight(int height)
      Sets the height of the internal canvas coordinate space.
      Parameters:
      height - the height, in pixels
      See Also:
    • setCoordinateSpaceWidth

      public void setCoordinateSpaceWidth(int width)
      Sets the width of the internal canvas coordinate space.
      Parameters:
      width - the width, in pixels
      See Also:
    • toDataUrl

      public String toDataUrl()
      Returns a data URL for the current content of the canvas element.
      Returns:
      a data URL for the current content of this element.
    • toDataUrl

      public String toDataUrl(String type)
      Returns a data URL for the current content of the canvas element, with a specified type.
      Parameters:
      type - the type of the data url, e.g., image/jpeg or image/png.
      Returns:
      a data URL for the current content of this element with the specified type.