public class

Canvas

extends FocusWidget
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.FocusWidget
         ↳ com.google.gwt.canvas.client.Canvas

Class Overview

A widget representing a <canvas> element.

Experimental API: This API is still under development and is subject to change.

This widget may not be supported on all browsers.

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Methods
static Canvas createIfSupported()
Return a new Canvas if supported, and null otherwise.
CanvasElement getCanvasElement()
Returns the attached Canvas Element.
Context getContext(String contextId)
Gets the rendering context that may be used to draw on this canvas.
Context2d getContext2d()
Returns a 2D rendering context.
int getCoordinateSpaceHeight()
Gets the height of the internal canvas coordinate space.
int getCoordinateSpaceWidth()
Gets the width of the internal canvas coordinate space.
static boolean isSupported()
Runtime check for whether the canvas element is supported in this browser.
void setCoordinateSpaceHeight(int height)
Sets the height of the internal canvas coordinate space.
void setCoordinateSpaceWidth(int width)
Sets the width of the internal canvas coordinate space.
String toDataUrl()
Returns a data URL for the current content of the canvas element.
String toDataUrl(String type)
Returns a data URL for the current content of the canvas element, with a specified type.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.FocusWidget
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.dom.client.HasBlurHandlers
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.dom.client.HasDoubleClickHandlers
From interface com.google.gwt.event.dom.client.HasFocusHandlers
From interface com.google.gwt.event.dom.client.HasGestureChangeHandlers
From interface com.google.gwt.event.dom.client.HasGestureEndHandlers
From interface com.google.gwt.event.dom.client.HasGestureStartHandlers
From interface com.google.gwt.event.dom.client.HasKeyDownHandlers
From interface com.google.gwt.event.dom.client.HasKeyPressHandlers
From interface com.google.gwt.event.dom.client.HasKeyUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseDownHandlers
From interface com.google.gwt.event.dom.client.HasMouseMoveHandlers
From interface com.google.gwt.event.dom.client.HasMouseOutHandlers
From interface com.google.gwt.event.dom.client.HasMouseOverHandlers
From interface com.google.gwt.event.dom.client.HasMouseUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseWheelHandlers
From interface com.google.gwt.event.dom.client.HasTouchCancelHandlers
From interface com.google.gwt.event.dom.client.HasTouchEndHandlers
From interface com.google.gwt.event.dom.client.HasTouchMoveHandlers
From interface com.google.gwt.event.dom.client.HasTouchStartHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.Focusable
From interface com.google.gwt.user.client.ui.HasEnabled
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesClickEvents
From interface com.google.gwt.user.client.ui.SourcesFocusEvents
From interface com.google.gwt.user.client.ui.SourcesKeyboardEvents
From interface com.google.gwt.user.client.ui.SourcesMouseEvents

Public Methods

public static Canvas createIfSupported ()

Return a new Canvas if supported, and null otherwise.

Returns
  • a new Canvas if supported, and null otherwise

public CanvasElement getCanvasElement ()

Returns the attached Canvas Element.

Returns
  • the Canvas Element

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

public Context2d getContext2d ()

Returns a 2D rendering context. This is a convenience method, see getContext(String).

Returns
  • a 2D canvas rendering context

public int getCoordinateSpaceHeight ()

Gets the height of the internal canvas coordinate space.

Returns
  • the height, in pixels

public int getCoordinateSpaceWidth ()

Gets the width of the internal canvas coordinate space.

Returns
  • the width, in pixels

public static boolean isSupported ()

Runtime check for whether the canvas element is supported in this browser.

Returns
  • whether the canvas element is supported

public void setCoordinateSpaceHeight (int height)

Sets the height of the internal canvas coordinate space.

Parameters
height the height, in pixels

public void setCoordinateSpaceWidth (int width)

Sets the width of the internal canvas coordinate space.

Parameters
width the width, in pixels

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.

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.