API Reference 0.3.24dart_web_toolkit_uiImage

Image class

A widget that displays the image at a given URL. The image can be in 'unclipped' mode (the default) or 'clipped' mode. In clipped mode, a viewport is overlaid on top of the image so that a subset of the image will be displayed. In unclipped mode, there is no viewport - the entire image will be visible. Whether an image is in clipped or unclipped mode depends on how the image is constructed, and how it is transformed after construction. Methods will operate differently depending on the mode that the image is in. These differences are detailed in the documentation for each method.

If an image transitions between clipped mode and unclipped mode, any {@link Element}-specific attributes added by the user (including style attributes, style names, and style modifiers), except for event listeners, will be lost.

CSS Style Rules

.gwt-Image
The outer element

Tranformations between clipped and unclipped state will result in a loss of any style names that were set/added; the only style names that are preserved are those that are mentioned in the static CSS style rules. Due to browser-specific HTML constructions needed to achieve the clipping effect, certain CSS attributes, such as padding and background, may not work as expected when an image is in clipped mode. These limitations can usually be easily worked around by encapsulating the image in a container widget that can itself be styled.

Example

{@example com.google.gwt.examples.ImageExample}

class Image extends Widget implements HasLoadHandlers, HasErrorHandlers,
 HasClickHandlers, HasDoubleClickHandlers, HasAllDragAndDropHandlers,
 HasAllGestureHandlers, HasAllMouseHandlers, HasAllTouchHandlers {

 /**
  * The attribute that is set when an image fires a native load or error event
  * before it is attached.
  * Moved to DomImpl.UNHANDLED_EVENT_ATTR
  */
 //static final String UNHANDLED_EVENT_ATTR = "dwtLastUnhandledEvent";

 /**
  * This map is used to store prefetched images. If a reference is not kept to
  * the prefetched image objects, they can get garbage collected, which
  * sometimes keeps them from getting fully fetched.
  */
 static Map<String, dart_html.Element> prefetchImages = new Map<String, dart_html.Element>();

 /**
  * Causes the browser to pre-fetch the image at a given URL.
  *
  * @param url the URL of the image to be prefetched
  */
 static void prefetch(String url) {
   dart_html.ImageElement img = new dart_html.ImageElement();
   img.src = url;
   prefetchImages[url] = img;
 }

 /**
  * Causes the browser to pre-fetch the image at a given URL.
  *
  * @param url the URL of the image to be prefetched
  */
 static void prefetchSafe(SafeUri url) {
   prefetch(url.asString());
 }

 /**
  * Creates a Image widget that wraps an existing &lt;img&gt; element.
  *
  * This element must already be attached to the document. If the element is
  * removed from the document, you must call
  * {@link RootPanel#detachNow(Widget)}.
  *
  * @param element the element to be wrapped
  */
 factory Image.wrap(dart_html.Element element) {
   // Assert that the element is attached.
   //assert Document.get().getBody().isOrHasChild(element);

   Image image = new Image.fromElement(element);

   // Mark it attached and remember it for cleanup.
   image.onAttach();
   RootPanel.detachOnWindowClose(image);

   return image;
 }

 _State _state;

 /**
  * This constructor may be used by subclasses to explicitly use an existing
  * element. This element must be an &lt;img&gt; element.
  *
  * @param element the element to be used
  */
 Image.fromElement(dart_html.ImageElement element) {
   setElement(element);
   changeState(new _UnclippedState(element:element));
 }

 /**
  * Creates an image with a specified URL. The load event will be fired once
  * the image at the given URL has been retrieved by the browser.
  *
  * @param url the URL of the image to be displayed
  */
 Image(String url) : this.fromSafeUri(UriUtils.unsafeCastFromUntrustedString(url));

 /**
  * Creates a clipped image with a specified URL and visibility rectangle. The
  * visibility rectangle is declared relative to the the rectangle which
  * encompasses the entire image, which has an upper-left vertex of (0,0). The
  * load event will be fired immediately after the object has been constructed
  * (i.e. potentially before the image has been loaded in the browser). Since
  * the width and height are specified explicitly by the user, this behavior
  * will not cause problems with retrieving the width and height of a clipped
  * image in a load event handler.
  *
  * @param url the URL of the image to be displayed
  * @param left the horizontal co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param top the vertical co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param width the width of the visibility rectangle
  * @param height the height of the visibility rectangle
  */
 Image.fromUriAndMeasure(String url, int left, int top, int width, int height) : this.fromSafeUriAndMeasure(UriUtils.unsafeCastFromUntrustedString(url), left, top, width, height);

 /**
  * Creates an image with a specified URL. The load event will be fired once
  * the image at the given URL has been retrieved by the browser.
  *
  * @param url the URL of the image to be displayed
  */
 Image.fromSafeUri(SafeUri url) {
   changeState(new _UnclippedState(image:this, url:url));
   //clearAndSetStyleName("dwt-Image");
 }

 /**
  * Creates a clipped image with a specified URL and visibility rectangle. The
  * visibility rectangle is declared relative to the the rectangle which
  * encompasses the entire image, which has an upper-left vertex of (0,0). The
  * load event will be fired immediately after the object has been constructed
  * (i.e. potentially before the image has been loaded in the browser). Since
  * the width and height are specified explicitly by the user, this behavior
  * will not cause problems with retrieving the width and height of a clipped
  * image in a load event handler.
  *
  * @param url the URL of the image to be displayed
  * @param left the horizontal co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param top the vertical co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param width the width of the visibility rectangle
  * @param height the height of the visibility rectangle
  */
 Image.fromSafeUriAndMeasure(SafeUri url, int left, int top, int width, int height) {
   changeState(new _ClippedState(this, url, left, top, width, height));
   //clearAndSetStyleName("dwt-Image");
 }

 /**
  * Creates an image whose size and content are defined by an ImageResource.
  * 
  * @param resource the ImageResource to be displayed
  */
 Image.fromImageResource(ImageResource resource) : this.clippedSafe(resource.url, resource.left, resource.top, resource.width, resource.height);
 
 /**
  * Creates a clipped image with a specified URL and visibility rectangle. The
  * visibility rectangle is declared relative to the the rectangle which
  * encompasses the entire image, which has an upper-left vertex of (0,0). The
  * load event will be fired immediately after the object has been constructed
  * (i.e. potentially before the image has been loaded in the browser). Since
  * the width and height are specified explicitly by the user, this behavior
  * will not cause problems with retrieving the width and height of a clipped
  * image in a load event handler.
  *
  * @param url the URL of the image to be displayed
  * @param left the horizontal co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param top the vertical co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param width the width of the visibility rectangle
  * @param height the height of the visibility rectangle
  */
 Image.clipped(String url, int left, int top, int width, int height) : this.clippedSafe(UriUtils.unsafeCastFromUntrustedString(url), left, top, width, height);

 /**
  * Creates a clipped image with a specified URL and visibility rectangle. The
  * visibility rectangle is declared relative to the the rectangle which
  * encompasses the entire image, which has an upper-left vertex of (0,0). The
  * load event will be fired immediately after the object has been constructed
  * (i.e. potentially before the image has been loaded in the browser). Since
  * the width and height are specified explicitly by the user, this behavior
  * will not cause problems with retrieving the width and height of a clipped
  * image in a load event handler.
  *
  * @param url the URL of the image to be displayed
  * @param left the horizontal co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param top the vertical co-ordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param width the width of the visibility rectangle
  * @param height the height of the visibility rectangle
  */
 Image.clippedSafe(SafeUri url, int left, int top, int width, int height) {
   changeState(new _ClippedState(this, url, left, top, width, height));
   clearAndSetStyleName("dwt-Image");
 }

 //***********************************
 // Implementation of HasClickHandlers
 //***********************************

 HandlerRegistration addClickHandler(ClickHandler handler) {
   return addHandler(handler, ClickEvent.TYPE);
 }

 HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) {
   return addHandler(handler, DoubleClickEvent.TYPE);
 }

 HandlerRegistration addDragEndHandler(DragEndHandler handler) {
   return addDomHandler(handler, DragEndEvent.TYPE);
 }

 HandlerRegistration addDragEnterHandler(DragEnterHandler handler) {
   return addDomHandler(handler, DragEnterEvent.TYPE);
 }

 HandlerRegistration addDragHandler(DragHandler handler) {
   return addDomHandler(handler, DragEvent.TYPE);
 }

 HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) {
   return addDomHandler(handler, DragLeaveEvent.TYPE);
 }

 HandlerRegistration addDragOverHandler(DragOverHandler handler) {
   return addDomHandler(handler, DragOverEvent.TYPE);
 }

 HandlerRegistration addDragStartHandler(DragStartHandler handler) {
   return addDomHandler(handler, DragStartEvent.TYPE);
 }

 HandlerRegistration addDropHandler(DropHandler handler) {
   return addDomHandler(handler, DropEvent.TYPE);
 }

 HandlerRegistration addErrorHandler(ErrorHandler handler) {
   return addHandler(handler, ErrorEvent.TYPE);
 }

 HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler) {
   return addDomHandler(handler, GestureChangeEvent.TYPE);
 }

 HandlerRegistration addGestureEndHandler(GestureEndHandler handler) {
   return addDomHandler(handler, GestureEndEvent.TYPE);
 }

 HandlerRegistration addGestureStartHandler(GestureStartHandler handler) {
   return addDomHandler(handler, GestureStartEvent.TYPE);
 }

 HandlerRegistration addLoadHandler(LoadHandler handler) {
   return addHandler(handler, LoadEvent.TYPE);
 }

 HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
   return addDomHandler(handler, MouseDownEvent.TYPE);
 }

 HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
   return addDomHandler(handler, MouseMoveEvent.TYPE);
 }

 HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
   return addDomHandler(handler, MouseOutEvent.TYPE);
 }

 HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
   return addDomHandler(handler, MouseOverEvent.TYPE);
 }

 HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
   return addDomHandler(handler, MouseUpEvent.TYPE);
 }

 HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) {
   return addDomHandler(handler, MouseWheelEvent.TYPE);
 }

 HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
   return addDomHandler(handler, TouchCancelEvent.TYPE);
 }

 HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
   return addDomHandler(handler, TouchEndEvent.TYPE);
 }

 HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
   return addDomHandler(handler, TouchMoveEvent.TYPE);
 }

 HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
   return addDomHandler(handler, TouchStartEvent.TYPE);
 }


 /**
  * Gets the alternate text for the image.
  *
  * @return the alternate text for the image
  */
 String getAltText() {
   return _state.getImageElement(this).alt;
 }

 /**
  * Sets the alternate text of the image for user agents that can't render the
  * image.
  *
  * @param altText the alternate text to set to
  */
 void setAltText(String altText) {
   _state.getImageElement(this).alt = altText;
 }

 /**
  * Gets the height of the image. When the image is in the unclipped state, the
  * height of the image is not known until the image has been loaded (i.e. load
  * event has been fired for the image).
  *
  * @return the height of the image, or 0 if the height is unknown
  */
 int getHeight() {
   return _state.getHeight(this);
 }

 /**
  * Gets the horizontal co-ordinate of the upper-left vertex of the image's
  * visibility rectangle. If the image is in the unclipped state, then the
  * visibility rectangle is assumed to be the rectangle which encompasses the
  * entire image, which has an upper-left vertex of (0,0).
  *
  * @return the horizontal co-ordinate of the upper-left vertex of the image's
  *         visibility rectangle
  */
 int getOriginLeft() {
   return _state.getOriginLeft();
 }

 /**
  * Gets the vertical co-ordinate of the upper-left vertex of the image's
  * visibility rectangle. If the image is in the unclipped state, then the
  * visibility rectangle is assumed to be the rectangle which encompasses the
  * entire image, which has an upper-left vertex of (0,0).
  *
  * @return the vertical co-ordinate of the upper-left vertex of the image's
  *         visibility rectangle
  */
 int getOriginTop() {
   return _state.getOriginTop();
 }

 /**
  * Gets the URL of the image. The URL that is returned is not necessarily the
  * URL that was passed in by the user. It may have been transformed to an
  * absolute URL.
  *
  * @return the image URL
  */
 String getUrl() {
   return _state.getUrl(this).asString();
 }

 /**
  * Sets the URL of the image to be displayed. If the image is in the clipped
  * state, a call to this method will cause a transition of the image to the
  * unclipped state. Regardless of whether or not the image is in the clipped
  * or unclipped state, a load event will be fired.
  *
  * @param url the image URL
  */
 void setSafeUrl(SafeUri url) {
   _state.setUrl(this, url);
 }

 /**
  * Sets the URL of the image to be displayed. If the image is in the clipped
  * state, a call to this method will cause a transition of the image to the
  * unclipped state. Regardless of whether or not the image is in the clipped
  * or unclipped state, a load event will be fired.
  *
  * @param url the image URL
  */
 void setUrl(String url) {
   setSafeUrl(UriUtils.unsafeCastFromUntrustedString(url));
 }

 /**
  * Gets the width of the image. When the image is in the unclipped state, the
  * width of the image is not known until the image has been loaded (i.e. load
  * event has been fired for the image).
  *
  * @return the width of the image, or 0 if the width is unknown
  */
 int getWidth() {
   return _state.getWidth(this);
 }

 void onBrowserEvent(dart_html.Event event) {
   // We have to clear the unhandled event before firing handlers because the
   // handlers could trigger onLoad, which would refire the event.
   if (Dom.eventGetType(event) == IEvent.ONLOAD) {
     clearUnhandledEvent();
     _state.onLoadEvent(this);
   }

   super.onBrowserEvent(event);
 }

 /**
  * Sets the url and the visibility rectangle for the image at the same time,
  * based on an ImageResource instance. A single load event will be fired if
  * either the incoming url or visiblity rectangle co-ordinates differ from the
  * image's current url or current visibility rectangle co-ordinates. If the
  * image is currently in the unclipped state, a call to this method will cause
  * a transition to the clipped state.
  *
  * @param resource the ImageResource to display
  */
//  void setResource(ImageResource resource) {
//    setUrlAndVisibleRect(resource.getSafeUri(), resource.getLeft(), resource.getTop(),
//        resource.getWidth(), resource.getHeight());
//  }

 /**
  * Sets the url and the visibility rectangle for the image at the same time. A
  * single load event will be fired if either the incoming url or visiblity
  * rectangle co-ordinates differ from the image's current url or current
  * visibility rectangle co-ordinates. If the image is currently in the
  * unclipped state, a call to this method will cause a transition to the
  * clipped state.
  *
  * @param url the image URL
  * @param left the horizontal coordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param top the vertical coordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param width the width of the visibility rectangle
  * @param height the height of the visibility rectangle
  */
 void setSafeUrlAndVisibleRect(SafeUri url, int left, int top, int width, int height) {
   _state.setUrlAndVisibleRect(this, url, left, top, width, height);
 }

 /**
  * Sets the url and the visibility rectangle for the image at the same time. A
  * single load event will be fired if either the incoming url or visiblity
  * rectangle co-ordinates differ from the image's current url or current
  * visibility rectangle co-ordinates. If the image is currently in the
  * unclipped state, a call to this method will cause a transition to the
  * clipped state.
  *
  * @param url the image URL
  * @param left the horizontal coordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param top the vertical coordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param width the width of the visibility rectangle
  * @param height the height of the visibility rectangle
  */
 void setUrlAndVisibleRect(String url, int left, int top, int width, int height) {
   setSafeUrlAndVisibleRect(UriUtils.unsafeCastFromUntrustedString(url), left, top, width, height);
 }

 /**
  * Sets the visibility rectangle of an image. The visibility rectangle is
  * declared relative to the the rectangle which encompasses the entire image,
  * which has an upper-left vertex of (0,0). Provided that any of the left,
  * top, width, and height parameters are different than the those values that
  * are currently set for the image, a load event will be fired. If the image
  * is in the unclipped state, a call to this method will cause a transition of
  * the image to the clipped state. This transition will cause a load event to
  * fire.
  *
  * @param left the horizontal coordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param top the vertical coordinate of the upper-left vertex of the
  *          visibility rectangle
  * @param width the width of the visibility rectangle
  * @param height the height of the visibility rectangle
  */
 void setVisibleRect(int left, int top, int width, int height) {
   _state.setVisibleRect(this, left, top, width, height);
 }

 void onLoad() {
   super.onLoad();

   // Issue 863: the state may need to fire a synthetic event if the native
   // onload event fired while the image was detached.
   _state.onLoad(this);
 }

 void changeState(_State newState) {
   _state = newState;
 }

 /**
  * Clear the unhandled event.
  */
 void clearUnhandledEvent() {
   if (_state != null) {
     _state.getImageElement(this).dataset[DomImpl.UNHANDLED_EVENT_ATTR] = "";
   }
 }
 
 /**
  * Sets the url and the visibility rectangle for the image at the same time,
  * based on an ImageResource instance. A single load event will be fired if
  * either the incoming url or visiblity rectangle co-ordinates differ from the
  * image's current url or current visibility rectangle co-ordinates. If the
  * image is currently in the unclipped state, a call to this method will cause
  * a transition to the clipped state.
  * 
  * @param resource the ImageResource to display
  */
 void setResource(ImageResource resource) {
   setUrlAndVisibleRect(resource.url.asString(), resource.left, resource.top, resource.width, resource.height);
 }
}

Extends

UiObject > Widget > Image

Implements

HasAllTouchHandlers, HasAllMouseHandlers, HasAllGestureHandlers, HasAllDragAndDropHandlers, HasDoubleClickHandlers, HasClickHandlers, HasErrorHandlers, HasLoadHandlers

Static Properties

Map<String, Element> prefetchImages #

The attribute that is set when an image fires a native load or error event before it is attached. Moved to DomImpl.UNHANDLEDEVENTATTR

This map is used to store prefetched images. If a reference is not kept to the prefetched image objects, they can get garbage collected, which sometimes keeps them from getting fully fetched.

static Map<String, dart_html.Element> prefetchImages = new Map<String, dart_html.Element>()

Static Methods

void prefetch(String url) #

Causes the browser to pre-fetch the image at a given URL.

@param url the URL of the image to be prefetched

static void prefetch(String url) {
 dart_html.ImageElement img = new dart_html.ImageElement();
 img.src = url;
 prefetchImages[url] = img;
}

void prefetchSafe(SafeUri url) #

Causes the browser to pre-fetch the image at a given URL.

@param url the URL of the image to be prefetched

static void prefetchSafe(SafeUri url) {
 prefetch(url.asString());
}

Constructors

new Image(String url) #

Creates an image with a specified URL. The load event will be fired once the image at the given URL has been retrieved by the browser.

@param url the URL of the image to be displayed

Image(String url) : this.fromSafeUri(UriUtils.unsafeCastFromUntrustedString(url));

new Image.clipped(String url, int left, int top, int width, int height) #

Creates a clipped image with a specified URL and visibility rectangle. The visibility rectangle is declared relative to the the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0). The load event will be fired immediately after the object has been constructed (i.e. potentially before the image has been loaded in the browser). Since the width and height are specified explicitly by the user, this behavior will not cause problems with retrieving the width and height of a clipped image in a load event handler.

@param url the URL of the image to be displayed @param left the horizontal co-ordinate of the upper-left vertex of the

     visibility rectangle

@param top the vertical co-ordinate of the upper-left vertex of the

     visibility rectangle

@param width the width of the visibility rectangle @param height the height of the visibility rectangle

Image.clipped(String url, int left, int top, int width, int height) : this.clippedSafe(UriUtils.unsafeCastFromUntrustedString(url), left, top, width, height);

new Image.clippedSafe(SafeUri url, int left, int top, int width, int height) #

Creates a clipped image with a specified URL and visibility rectangle. The visibility rectangle is declared relative to the the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0). The load event will be fired immediately after the object has been constructed (i.e. potentially before the image has been loaded in the browser). Since the width and height are specified explicitly by the user, this behavior will not cause problems with retrieving the width and height of a clipped image in a load event handler.

@param url the URL of the image to be displayed @param left the horizontal co-ordinate of the upper-left vertex of the

     visibility rectangle

@param top the vertical co-ordinate of the upper-left vertex of the

     visibility rectangle

@param width the width of the visibility rectangle @param height the height of the visibility rectangle

Image.clippedSafe(SafeUri url, int left, int top, int width, int height) {
 changeState(new _ClippedState(this, url, left, top, width, height));
 clearAndSetStyleName("dwt-Image");
}

new Image.fromElement(ImageElement element) #

This constructor may be used by subclasses to explicitly use an existing element. This element must be an <img> element.

@param element the element to be used

Image.fromElement(dart_html.ImageElement element) {
 setElement(element);
 changeState(new _UnclippedState(element:element));
}

new Image.fromImageResource(ImageResource resource) #

Creates an image whose size and content are defined by an ImageResource.

@param resource the ImageResource to be displayed

Image.fromImageResource(ImageResource resource) : this.clippedSafe(resource.url, resource.left, resource.top, resource.width, resource.height);

new Image.fromSafeUri(SafeUri url) #

Creates an image with a specified URL. The load event will be fired once the image at the given URL has been retrieved by the browser.

@param url the URL of the image to be displayed

Image.fromSafeUri(SafeUri url) {
 changeState(new _UnclippedState(image:this, url:url));
 //clearAndSetStyleName("dwt-Image");
}

new Image.fromSafeUriAndMeasure(SafeUri url, int left, int top, int width, int height) #

Creates a clipped image with a specified URL and visibility rectangle. The visibility rectangle is declared relative to the the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0). The load event will be fired immediately after the object has been constructed (i.e. potentially before the image has been loaded in the browser). Since the width and height are specified explicitly by the user, this behavior will not cause problems with retrieving the width and height of a clipped image in a load event handler.

@param url the URL of the image to be displayed @param left the horizontal co-ordinate of the upper-left vertex of the

     visibility rectangle

@param top the vertical co-ordinate of the upper-left vertex of the

     visibility rectangle

@param width the width of the visibility rectangle @param height the height of the visibility rectangle

Image.fromSafeUriAndMeasure(SafeUri url, int left, int top, int width, int height) {
 changeState(new _ClippedState(this, url, left, top, width, height));
 //clearAndSetStyleName("dwt-Image");
}

new Image.fromUriAndMeasure(String url, int left, int top, int width, int height) #

Creates a clipped image with a specified URL and visibility rectangle. The visibility rectangle is declared relative to the the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0). The load event will be fired immediately after the object has been constructed (i.e. potentially before the image has been loaded in the browser). Since the width and height are specified explicitly by the user, this behavior will not cause problems with retrieving the width and height of a clipped image in a load event handler.

@param url the URL of the image to be displayed @param left the horizontal co-ordinate of the upper-left vertex of the

     visibility rectangle

@param top the vertical co-ordinate of the upper-left vertex of the

     visibility rectangle

@param width the width of the visibility rectangle @param height the height of the visibility rectangle

Image.fromUriAndMeasure(String url, int left, int top, int width, int height) : this.fromSafeUriAndMeasure(UriUtils.unsafeCastFromUntrustedString(url), left, top, width, height);

factory Image.wrap(Element element) #

Creates a Image widget that wraps an existing <img> element.

This element must already be attached to the document. If the element is removed from the document, you must call {@link RootPanel#detachNow(Widget)}.

@param element the element to be wrapped

factory Image.wrap(dart_html.Element element) {
 // Assert that the element is attached.
 //assert Document.get().getBody().isOrHasChild(element);

 Image image = new Image.fromElement(element);

 // Mark it attached and remember it for cleanup.
 image.onAttach();
 RootPanel.detachOnWindowClose(image);

 return image;
}

Properties

int eventsToSink #

inherited from Widget

A set og events that should be sunk when the widget is attached to the DOM. (We delay the sinking of events to improve startup performance.) When the widget is attached, this is set is empty

Package protected to allow Composite to see it.

int eventsToSink = 0

String get title #

inherited from UiObject

Gets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.

@return the object's title

String get title => getElement().title;

void set title(String value) #

inherited from UiObject

Sets the element's title.

void set title(String value) {
 getElement().title = value;
}

bool get visible #

inherited from UiObject

Determines whether or not this object is visible. Note that this does not necessarily take into account whether or not the receiver's parent is visible, or even if it is attached to the Document. The default implementation of this trait in UIObject is based on the value of a dom element's style object's display attribute.

@return <code>true</code> if the object is visible

bool get visible => isVisible(getElement());

void set visible(bool visible) #

inherited from UiObject

Sets whether this object is visible.

@param visible <code>true</code> to show the object, <code>false</code> to

     hide it
void set visible(bool visible) {
 setVisible(getElement(), visible);
}

Methods

HandlerRegistration addAttachHandler(AttachEventHandler handler) #

inherited from Widget

Adds an AttachEvent handler.

@param handler the handler @return the handler registration

HandlerRegistration addAttachHandler(AttachEventHandler handler) {
 return addHandler(handler, AttachEvent.TYPE);
}

HandlerRegistration addBitlessDomHandler(EventHandler handler, DomEventType type) #

inherited from Widget

For <a href= "http://code.google.com/p/google-web-toolkit/wiki/UnderstandingMemoryLeaks"

browsers which do not leak</a>, adds a native event handler to the widget.

Note that, unlike the {@link #addDomHandler(EventHandler, com.google.gwt.event.dom.client.DomEvent.Type)} implementation, there is no need to attach the widget to the DOM in order to cause the event handlers to be attached.

@param <H> the type of handler to add @param type the event key @param handler the handler @return {@link HandlerRegistration} used to remove the handler

HandlerRegistration addBitlessDomHandler(EventHandler handler, DomEventType type) {
 assert (handler != null);; // : "handler must not be null";
 assert (type != null); // : "type must not be null";
 sinkBitlessEvent(type.eventName);
 return ensureHandlers().addHandler(type, handler);
}

HandlerRegistration addClickHandler(ClickHandler handler) #

Adds a {@link ClickEvent} handler.

@param handler the click handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasClickHandlers
HandlerRegistration addClickHandler(ClickHandler handler) {
 return addHandler(handler, ClickEvent.TYPE);
}

HandlerRegistration addDomHandler(EventHandler handler, DomEventType type) #

inherited from Widget

Adds a native event handler to the widget and sinks the corresponding native event. If you do not want to sink the native event, use the generic addHandler method instead.

@param <H> the type of handler to add @param type the event key @param handler the handler @return {@link HandlerRegistration} used to remove the handler

HandlerRegistration addDomHandler(EventHandler handler, DomEventType type) {
 assert (handler != null); // : "handler must not be null";
 assert (type != null); // : "type must not be null";
 int typeInt = IEvent.getTypeInt(type.eventName);
 if (typeInt == -1) {
   sinkBitlessEvent(type.eventName);
 } else {
   sinkEvents(typeInt);
 }
 return ensureHandlers().addHandler(type, handler);
}

HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) #

Adds a {@link DoubleClickEvent} handler.

@param handler the double click handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDoubleClickHandlers
HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) {
 return addHandler(handler, DoubleClickEvent.TYPE);
}

HandlerRegistration addDragEndHandler(DragEndHandler handler) #

Adds a {@link DragEndEvent} handler.

@param handler the drag end handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDragEndHandlers
HandlerRegistration addDragEndHandler(DragEndHandler handler) {
 return addDomHandler(handler, DragEndEvent.TYPE);
}

HandlerRegistration addDragEnterHandler(DragEnterHandler handler) #

Adds a {@link DragEnterEvent} handler.

@param handler the drag end handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDragEnterHandlers
HandlerRegistration addDragEnterHandler(DragEnterHandler handler) {
 return addDomHandler(handler, DragEnterEvent.TYPE);
}

HandlerRegistration addDragHandler(DragHandler handler) #

Adds a {@link DragEvent} handler.

@param handler the drag handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDragHandlers
HandlerRegistration addDragHandler(DragHandler handler) {
 return addDomHandler(handler, DragEvent.TYPE);
}

HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) #

Adds a {@link DragLeaveEvent} handler.

@param handler the drag leave handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDragLeaveHandlers
HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) {
 return addDomHandler(handler, DragLeaveEvent.TYPE);
}

HandlerRegistration addDragOverHandler(DragOverHandler handler) #

Adds a {@link DragOverEvent} handler.

@param handler the drag over handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDragOverHandlers
HandlerRegistration addDragOverHandler(DragOverHandler handler) {
 return addDomHandler(handler, DragOverEvent.TYPE);
}

HandlerRegistration addDragStartHandler(DragStartHandler handler) #

Adds a {@link DragStartEvent} handler.

@param handler the drag start handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDragStartHandlers
HandlerRegistration addDragStartHandler(DragStartHandler handler) {
 return addDomHandler(handler, DragStartEvent.TYPE);
}

HandlerRegistration addDropHandler(DropHandler handler) #

Adds a {@link DropEvent} handler.

@param handler the drop handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasDropHandlers
HandlerRegistration addDropHandler(DropHandler handler) {
 return addDomHandler(handler, DropEvent.TYPE);
}

HandlerRegistration addErrorHandler(ErrorHandler handler) #

Adds an {@link ErrorEvent} handler.

@param handler the error handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasErrorHandlers
HandlerRegistration addErrorHandler(ErrorHandler handler) {
 return addHandler(handler, ErrorEvent.TYPE);
}

HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler) #

HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler) {
 return addDomHandler(handler, GestureChangeEvent.TYPE);
}

HandlerRegistration addGestureEndHandler(GestureEndHandler handler) #

HandlerRegistration addGestureEndHandler(GestureEndHandler handler) {
 return addDomHandler(handler, GestureEndEvent.TYPE);
}

HandlerRegistration addGestureStartHandler(GestureStartHandler handler) #

HandlerRegistration addGestureStartHandler(GestureStartHandler handler) {
 return addDomHandler(handler, GestureStartEvent.TYPE);
}

HandlerRegistration addHandler(EventHandler handler, EventType<EventHandler> type) #

inherited from Widget

Adds this handler to the widget.

@param <H> the type of handler to add @param type the event type @param handler the handler @return {@link HandlerRegistration} used to remove the handler

HandlerRegistration addHandler(EventHandler handler, EventType<EventHandler> type) {
 return ensureHandlers().addHandler(type, handler);
}

HandlerRegistration addLoadHandler(LoadHandler handler) #

Adds a {@link LoadEvent} handler.

@param handler the load handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasLoadHandlers
HandlerRegistration addLoadHandler(LoadHandler handler) {
 return addHandler(handler, LoadEvent.TYPE);
}

HandlerRegistration addMouseDownHandler(MouseDownHandler handler) #

Adds a {@link MouseDownEvent} handler.

@param handler the mouse down handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasMouseDownHandlers
HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
 return addDomHandler(handler, MouseDownEvent.TYPE);
}

HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) #

Adds a {@link MouseMoveEvent} handler.

@param handler the mouse move handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasMouseMoveHandlers
HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
 return addDomHandler(handler, MouseMoveEvent.TYPE);
}

HandlerRegistration addMouseOutHandler(MouseOutHandler handler) #

Adds a {@link MouseOutEvent} handler.

@param handler the mouse out handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasMouseOutHandlers
HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
 return addDomHandler(handler, MouseOutEvent.TYPE);
}

HandlerRegistration addMouseOverHandler(MouseOverHandler handler) #

Adds a {@link MouseOverEvent} handler.

@param handler the mouse over handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasMouseOverHandlers
HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
 return addDomHandler(handler, MouseOverEvent.TYPE);
}

HandlerRegistration addMouseUpHandler(MouseUpHandler handler) #

Adds a {@link MouseUpEvent} handler.

@param handler the mouse up handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasMouseUpHandlers
HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
 return addDomHandler(handler, MouseUpEvent.TYPE);
}

HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) #

Adds a {@link MouseWheelEvent} handler.

@param handler the mouse wheel handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasMouseWheelHandlers
HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) {
 return addDomHandler(handler, MouseWheelEvent.TYPE);
}

void addStyleDependentName(String styleSuffix) #

inherited from UiObject

Adds a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:

getStylePrimaryName() + '-' + styleSuffix

@param styleSuffix the suffix of the dependent style to be added. @see #setStylePrimaryName(String) @see #removeStyleDependentName(String) @see #setStyleDependentName(String, boolean) @see #addStyleName(String)

void addStyleDependentName(String styleSuffix) {
 setStyleDependentName(styleSuffix, true);
}

void addStyleName(String style) #

inherited from UiObject

Adds a secondary or dependent style name to this object. A secondary style name is an additional style name that is, in HTML/CSS terms, included as a space-separated token in the value of the CSS <code>class</code> attribute for this object's root element.

The most important use for this method is to add a special kind of secondary style name called a dependent style name. To add a dependent style name, use {@link #addStyleDependentName(String)}, which will prefix the 'style' argument with the result of {@link #k()} (followed by a '-'). For example, suppose the primary style name is gwt-TextBox. If the following method is called as obj.setReadOnly(true):

public void setReadOnly(boolean readOnly) {
  isReadOnlyMode = readOnly;

// Create a dependent style name. String readOnlyStyle = "readonly";

if (readOnly) {

addStyleDependentName(readOnlyStyle);

} else {

removeStyleDependentName(readOnlyStyle);

} }</pre>

then both of the CSS style rules below will be applied:

// This rule is based on the primary style name and is always active. .gwt-TextBox { font-size: 12pt; }

// This rule is based on a dependent style name that is only active // when the widget has called addStyleName(getStylePrimaryName() + // "-readonly"). .gwt-TextBox-readonly { background-color: lightgrey; border: none; }</pre>

The code can also be simplified with {@link #setStyleDependentName(String, boolean)}:

public void setReadOnly(boolean readOnly) {
  isReadOnlyMode = readOnly;
  setStyleDependentName("readonly", readOnly);
}

Dependent style names are powerful because they are automatically updated whenever the primary style name changes. Continuing with the example above, if the primary style name changed due to the following call:

setStylePrimaryName("my-TextThingy");

then the object would be re-associated with following style rules, removing those that were shown above.

.my-TextThingy {
  font-size: 20pt;
}

.my-TextThingy-readonly { background-color: red; border: 2px solid yellow; }</pre>

Secondary style names that are not dependent style names are not automatically updated when the primary style name changes.

@param style the secondary style name to be added @see UIObject @see #removeStyleName(String)

void addStyleName(String style) {
 setStyleName(style, true);
}

HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) #

Adds a {@link TouchCancelEvent} handler.

@param handler the touch cancel handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasTouchCancelHandlers
HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
 return addDomHandler(handler, TouchCancelEvent.TYPE);
}

HandlerRegistration addTouchEndHandler(TouchEndHandler handler) #

Adds a {@link TouchEndEvent} handler.

@param handler the touch end handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasTouchEndHandlers
HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
 return addDomHandler(handler, TouchEndEvent.TYPE);
}

HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) #

Adds a {@link TouchMoveEvent} handler.

@param handler the touch move handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasTouchMoveHandlers
HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
 return addDomHandler(handler, TouchMoveEvent.TYPE);
}

HandlerRegistration addTouchStartHandler(TouchStartHandler handler) #

Adds a {@link TouchStartEvent} handler.

@param handler the touch start handler @return {@link HandlerRegistration} used to remove this handler

docs inherited from HasTouchStartHandlers
HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
 return addDomHandler(handler, TouchStartEvent.TYPE);
}

Widget asWidget() #

inherited from Widget

Returns the Widget aspect of the receiver.

Widget asWidget() {
 return this;
}

void changeState(_State newState) #

void changeState(_State newState) {
 _state = newState;
}

void clearAndSetStyleName(String style) #

inherited from UiObject

Clears all of the object's style names and sets it to the given style. You should normally use {@link #setStylePrimaryName(String)} unless you wish to explicitly remove all existing styles.

@param style the new style name @see #setStylePrimaryName(String)

void clearAndSetStyleName(String style) {
 setElementStyleName(getStyleElement(), style);
}

void clearUnhandledEvent() #

Clear the unhandled event.

void clearUnhandledEvent() {
 if (_state != null) {
   _state.getImageElement(this).dataset[DomImpl.UNHANDLED_EVENT_ATTR] = "";
 }
}

EventBus createEventBus() #

inherited from Widget

Creates the SimpleEventBus used by this Widget. You can override this method to create a custom EventBus.

@return the EventBus you want to use.

EventBus createEventBus() {
 return new SimpleEventBus();
}

void delegateEvent(Widget target, DwtEvent event) #

inherited from Widget

Fires an event on a child widget. Used to delegate the handling of an event from one widget to another.

@param event the event @param target fire the event on the given target

void delegateEvent(Widget target, DwtEvent event) {
 target.fireEvent(event);
}

void doAttachChildren() #

inherited from Widget

If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call {@link #onAttach()} for each of its child widgets.

@see #onAttach()

void doAttachChildren() {
}

void doDetachChildren() #

inherited from Widget

If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call {@link #onDetach()} for each of its child widgets.

@see #onDetach()

void doDetachChildren() {
}

EventBus ensureHandlers() #

inherited from Widget

Ensures the existence of the event bus.

@return the EventBus.

EventBus ensureHandlers() {
 return _eventBus == null ? _eventBus = createEventBus() : _eventBus;
}

double extractLengthValue(String s) #

inherited from UiObject

Intended to be used to pull the value out of a CSS length. If the value is "auto" or "inherit", 0 will be returned.

@param s The CSS length string to extract @return The leading numeric portion of <code>s</code>, or 0 if "auto" or

    "inherit" are passed in.
double extractLengthValue(String s) {
 if (s == "auto" || s == "inherit" || s == "") {
   return 0.0;
 } else {
   // numberRegex divides the string into a leading numeric portion
   // followed by an arbitrary portion.
   if(numberRegex.hasMatch(s)) {
     // Extract the leading numeric portion of string
     s = numberRegex.firstMatch(s)[0];
   }
   return double.parse(s);
 }
}

void fireEvent(DwtEvent event) #

inherited from Widget

Fires the given event to the handlers listening to the event's type.

Any exceptions thrown by handlers will be bundled into a UmbrellaException and then re-thrown after all handlers have completed. An exception thrown by a handler will not prevent other handlers from executing.

@param event the event

void fireEvent(DwtEvent event) {
//    if (_eventBus != null) {
//      _eventBus.fireEvent(event);
//    }
 if (_eventBus != null) {
   // If it not live we should revive it.
   if (!event.isLive()) {
     event.revive();
   }
   Object oldSource = event.getSource();
   event.overrideSource(getElement());
   try {

     // May throw an UmbrellaException.
     _eventBus.fireEventFromSource(event, getElement());
   } on UmbrellaException catch (e) {
     throw new UmbrellaException(e.causes);
   } finally {
     if (oldSource == null) {
       // This was my event, so I should kill it now that I'm done.
       event.kill();
     } else {
       // Restoring the source for the next handler to use.
       event.overrideSource(oldSource);
     }
   }
 }
}

int getAbsoluteLeft() #

inherited from UiObject

Gets the object's absolute left position in pixels, as measured from the browser window's client area.

@return the object's absolute left position

int getAbsoluteLeft() {
 return Dom.getAbsoluteLeft(getElement());
}

int getAbsoluteTop() #

inherited from UiObject

Gets the object's absolute top position in pixels, as measured from the browser window's client area.

@return the object's absolute top position

int getAbsoluteTop() {
 return Dom.getAbsoluteTop(getElement());
}

String getAltText() #

Gets the alternate text for the image.

@return the alternate text for the image

String getAltText() {
 return _state.getImageElement(this).alt;
}

Element getElement() #

inherited from UiObject

Gets this object's browser element.

dart_html.Element getElement() {
 assert (_element != null); // : MISSING_ELEMENT_ERROR;
 return _element;
}

EventBus getEventBus() #

inherited from Widget

Return EventBus.

EventBus getEventBus() {
 return _eventBus;
}

int getHeight() #

Gets the height of the image. When the image is in the unclipped state, the height of the image is not known until the image has been loaded (i.e. load event has been fired for the image).

@return the height of the image, or 0 if the height is unknown

int getHeight() {
 return _state.getHeight(this);
}

Object getLayoutData() #

inherited from Widget

Gets the panel-defined layout data associated with this widget.

@return the widget's layout data @see #setLayoutData

Object getLayoutData() {
 return _layoutData;
}

int getOffsetHeight() #

inherited from UiObject

Gets the object's offset height in pixels. This is the total height of the object, including decorations such as border and padding, but not margin.

@return the object's offset height

int getOffsetHeight() {
 return getElement().offset.height; // Dom.getElementPropertyInt(getElement(), "offsetHeight");
}

int getOffsetWidth() #

inherited from UiObject

Gets the object's offset width in pixels. This is the total width of the object, including decorations such as border and padding, but not margin.

@return the object's offset width

int getOffsetWidth() {
 return getElement().offset.width; // Dom.getElementPropertyInt(getElement(), "offsetWidth");
}

int getOriginLeft() #

Gets the horizontal co-ordinate of the upper-left vertex of the image's visibility rectangle. If the image is in the unclipped state, then the visibility rectangle is assumed to be the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0).

@return the horizontal co-ordinate of the upper-left vertex of the image's

    visibility rectangle
int getOriginLeft() {
 return _state.getOriginLeft();
}

int getOriginTop() #

Gets the vertical co-ordinate of the upper-left vertex of the image's visibility rectangle. If the image is in the unclipped state, then the visibility rectangle is assumed to be the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0).

@return the vertical co-ordinate of the upper-left vertex of the image's

    visibility rectangle
int getOriginTop() {
 return _state.getOriginTop();
}

Widget getParent() #

inherited from Widget

Gets this widget's parent panel.

@return the widget's parent panel

Widget getParent() {
 return _parent;
}

Element getStyleElement() #

inherited from UiObject

Template method that returns the element to which style names will be applied. By default it returns the root element, but this method may be overridden to apply styles to a child element.

@return the element to which style names will be applied

dart_html.Element getStyleElement() {
 return getElement();
}

String getStyleName() #

inherited from UiObject

Gets all of the object's style names, as a space-separated list. If you wish to retrieve only the primary style name, call {@link #getStylePrimaryName()}.

@return the objects's space-separated style names @see #getStylePrimaryName()

String getStyleName() {
 return getElementStyleName(getStyleElement());
}

String getStylePrimaryName() #

inherited from UiObject

Gets the primary style name associated with the object.

@return the object's primary style name @see #setStyleName(String) @see #addStyleName(String) @see #removeStyleName(String)

String getStylePrimaryName() {
 return getElementStylePrimaryName(getStyleElement());
}

String getUrl() #

Gets the URL of the image. The URL that is returned is not necessarily the URL that was passed in by the user. It may have been transformed to an absolute URL.

@return the image URL

String getUrl() {
 return _state.getUrl(this).asString();
}

int getWidth() #

Gets the width of the image. When the image is in the unclipped state, the width of the image is not known until the image has been loaded (i.e. load event has been fired for the image).

@return the width of the image, or 0 if the width is unknown

int getWidth() {
 return _state.getWidth(this);
}

bool isAttached() #

inherited from Widget

Returns whether or not the receiver is attached to the {@link com.google.gwt.dom.client.Document Document}'s {@link com.google.gwt.dom.client.BodyElement BodyElement}.

@return true if attached, false otherwise

bool isAttached() {
 return _attached;
}

bool isOrWasAttached() #

inherited from Widget

Has this widget ever been attached?

@return true if this widget ever been attached to the DOM, false otherwise

bool isOrWasAttached() {
 return eventsToSink == -1;
}

void onAttach() #

inherited from Widget

This method is called when a widget is attached to the browser's document. To receive notification after a Widget has been added to the document, override the {@link #onLoad} method or use {@link #addAttachHandler}.

It is strongly recommended that you override {@link #onLoad()} or {@link #doAttachChildren()} instead of this method to avoid inconsistencies between logical and physical attachment states.

Subclasses that override this method must call super.onAttach() to ensure that the Widget has been attached to its underlying Element.

@throws IllegalStateException if this widget is already attached @see #onLoad() @see #doAttachChildren()

void onAttach() {
 if (isAttached()) {
   throw new Exception("Should only call onAttach when the widget is detached from the browser's document");
 }

 _attached = true;

 // Event hookup code
 Dom.setEventListener(getElement(), this);
 int bitsToAdd = eventsToSink;
 eventsToSink = -1;
 if (bitsToAdd > 0) {
   sinkEvents(bitsToAdd);
 }
 doAttachChildren();

 // onLoad() gets called only *after* all of the children are attached and
 // the attached flag is set. This allows widgets to be notified when they
 // are fully attached, and panels when all of their children are attached.
 onLoad();
 AttachEvent.fire(this, true);
}

void onBrowserEvent(Event event) #

Fired whenever a browser event is received.

@param event the event received

TODO

docs inherited from Widget
void onBrowserEvent(dart_html.Event event) {
 // We have to clear the unhandled event before firing handlers because the
 // handlers could trigger onLoad, which would refire the event.
 if (Dom.eventGetType(event) == IEvent.ONLOAD) {
   clearUnhandledEvent();
   _state.onLoadEvent(this);
 }

 super.onBrowserEvent(event);
}

void onDetach() #

inherited from Widget

This method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the {@link #onUnload} method or use {@link #addAttachHandler}.

It is strongly recommended that you override {@link #onUnload()} or {@link #doDetachChildren()} instead of this method to avoid inconsistencies between logical and physical attachment states.

Subclasses that override this method must call super.onDetach() to ensure that the Widget has been detached from the underlying Element. Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects.

@throws IllegalStateException if this widget is already detached @see #onUnload() @see #doDetachChildren()

void onDetach() {
 if (!isAttached()) {
   throw new Exception("Should only call onDetach when the widget is attached to the browser's document");
 }

 try {
   // onUnload() gets called *before* everything else (the opposite of
   // onLoad()).
   onUnload();
   AttachEvent.fire(this, false);
 } finally {
   // Put this in a finally, just in case onUnload throws an exception.
   try {
     doDetachChildren();
   } finally {
     // Put this in a finally, in case doDetachChildren throws an exception.
     Dom.setEventListener(getElement(), null);
     _attached = false;
   }
 }
}

void onLoad() #

This method is called immediately after a widget becomes attached to the browser's document.

docs inherited from Widget
void onLoad() {
 super.onLoad();

 // Issue 863: the state may need to fire a synthetic event if the native
 // onload event fired while the image was detached.
 _state.onLoad(this);
}

void onUnload() #

inherited from Widget

This method is called immediately before a widget will be detached from the browser's document.

void onUnload() {
}

void removeFromParent() #

inherited from Widget

Removes this widget from its parent widget, if one exists.

If it has no parent, this method does nothing. If it is a "root" widget (meaning it's been added to the detach list via {@link RootPanel#detachOnWindowClose(Widget)}), it will be removed from the detached immediately. This makes it possible for Composites and Panels to adopt root widgets.

@throws IllegalStateException if this widget's parent does not support

      removal (e.g. {@link Composite})
void removeFromParent() {
 if (_parent == null) {
   // If the widget had no parent, check to see if it was in the detach list
   // and remove it if necessary.
   if (RootPanel.isInDetachList(this)) {
     RootPanel.detachNow(this);
   }
 } else if (_parent is HasWidgets) {
   (_parent as HasWidgets).remove(this);
 } else if (_parent != null) {
   throw new Exception("This widget's parent does not implement HasWidgets");
 }
}

void removeStyleDependentName(String styleSuffix) #

inherited from UiObject

Removes a dependent style name by specifying the style name's suffix.

@param styleSuffix the suffix of the dependent style to be removed @see #setStylePrimaryName(Element, String) @see #addStyleDependentName(String) @see #setStyleDependentName(String, boolean)

void removeStyleDependentName(String styleSuffix) {
 setStyleDependentName(styleSuffix, false);
}

void removeStyleName(String style) #

inherited from UiObject

Removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.

@param style the secondary style name to be removed @see #addStyleName(String) @see #setStyleName(String, boolean)

void removeStyleName(String style) {
 setStyleName(style, false);
}

void replaceElement(Element elem) #

inherited from Widget

Replaces this object's browser element.

This method exists only to support a specific use-case in Image, and should not be used by other classes.

@param elem the object's new element

void replaceElement(dart_html.Element elem) {
 if (isAttached()) {
   // Remove old event listener to avoid leaking. onDetach will not do this
   // for us, because it is only called when the widget itself is detached
   // from the document.
   Dom.setEventListener(getElement(), null);
 }

 super.replaceElement(elem);

 if (isAttached()) {
   // Hook the event listener back up on the new element. onAttach will not
   // do this for us, because it is only called when the widget itself is
   // attached to the document.
   Dom.setEventListener(getElement(), this);
 }
}

void setAltText(String altText) #

Sets the alternate text of the image for user agents that can't render the image.

@param altText the alternate text to set to

void setAltText(String altText) {
 _state.getImageElement(this).alt = altText;
}

void setElement(Element elem) #

inherited from UiObject

Sets this object's browser element. UIObject subclasses must call this method before attempting to call any other methods, and it may only be called once.

@param elem the object's element

void setElement(dart_html.Element elem) {
 assert (_element == null);
 this._element = elem;
}

void setHeight(String height) #

inherited from UiObject

Sets the object's height. This height does not include decorations such as border, margin, and padding.

@param height the object's new height, in CSS units (e.g. "10px", "1em")

void setHeight(String height) {
 // This exists to deal with an inconsistency in IE's implementation where
 // it won't accept negative numbers in length measurements
 assert (extractLengthValue(height.trim().toLowerCase()) >= 0); // : "CSS heights should not be negative";
 Dom.setStyleAttribute(getElement(), "height", height);
}

void setLayoutData(Object value) #

inherited from Widget

Sets the panel-defined layout data associated with this widget. Only the panel that currently contains a widget should ever set this value. It serves as a place to store layout bookkeeping data associated with a widget.

@param layoutData the widget's layout data

void setLayoutData(Object value) {
 this._layoutData = value;
}

void setParent(Widget parent) #

inherited from Widget

Sets this widget's parent. This method should only be called by {@link Panel} and {@link Composite}.

@param parent the widget's new parent @throws IllegalStateException if <code>parent</code> is non-null and the

      widget already has a parent
void setParent(Widget parent) {
 Widget oldParent = this._parent;
 if (parent == null) {
   try {
     if (oldParent != null && oldParent.isAttached()) {
       onDetach();
       assert (!isAttached()); // : "Failure of " + this.getClass().getName() + " to call super.onDetach()";
     }
   } finally {
     // Put this in a finally in case onDetach throws an exception.
     this._parent = null;
   }
 } else {
   if (oldParent != null) {
     throw new Exception("Cannot set a new parent without first clearing the old parent");
   }
   this._parent = parent;
   if (parent.isAttached()) {
     onAttach();
     assert (isAttached()); // : "Failure of " + this.getClass().getName() + " to call super.onAttach()";
   }
 }
}

void setPixelSize(int width, int height) #

inherited from UiObject

Sets the object's size, in pixels, not including decorations such as border, margin, and padding.

@param width the object's new width, in pixels @param height the object's new height, in pixels

void setPixelSize(int width, int height) {
 if (width >= 0) {
   setWidth(width.toString() + "px");
 }
 if (height >= 0) {
   setHeight(height.toString() + "px");
 }
}

void setResource(ImageResource resource) #

Sets the url and the visibility rectangle for the image at the same time, based on an ImageResource instance. A single load event will be fired if either the incoming url or visiblity rectangle co-ordinates differ from the image's current url or current visibility rectangle co-ordinates. If the image is currently in the unclipped state, a call to this method will cause a transition to the clipped state.

@param resource the ImageResource to display

void setResource(ImageResource resource) {
 setUrlAndVisibleRect(resource.url.asString(), resource.left, resource.top, resource.width, resource.height);
}

void setSafeUrl(SafeUri url) #

Sets the URL of the image to be displayed. If the image is in the clipped state, a call to this method will cause a transition of the image to the unclipped state. Regardless of whether or not the image is in the clipped or unclipped state, a load event will be fired.

@param url the image URL

void setSafeUrl(SafeUri url) {
 _state.setUrl(this, url);
}

void setSafeUrlAndVisibleRect(SafeUri url, int left, int top, int width, int height) #

Sets the url and the visibility rectangle for the image at the same time, based on an ImageResource instance. A single load event will be fired if either the incoming url or visiblity rectangle co-ordinates differ from the image's current url or current visibility rectangle co-ordinates. If the image is currently in the unclipped state, a call to this method will cause a transition to the clipped state.

@param resource the ImageResource to display

Sets the url and the visibility rectangle for the image at the same time. A single load event will be fired if either the incoming url or visiblity rectangle co-ordinates differ from the image's current url or current visibility rectangle co-ordinates. If the image is currently in the unclipped state, a call to this method will cause a transition to the clipped state.

@param url the image URL @param left the horizontal coordinate of the upper-left vertex of the

     visibility rectangle

@param top the vertical coordinate of the upper-left vertex of the

     visibility rectangle

@param width the width of the visibility rectangle @param height the height of the visibility rectangle

void setSafeUrlAndVisibleRect(SafeUri url, int left, int top, int width, int height) {
 _state.setUrlAndVisibleRect(this, url, left, top, width, height);
}

void setSize(String width, String height) #

inherited from UiObject

Sets the object's size. This size does not include decorations such as border, margin, and padding.

@param width the object's new width, in CSS units (e.g. "10px", "1em") @param height the object's new height, in CSS units (e.g. "10px", "1em")

void setSize(String width, String height) {
 setWidth(width);
 setHeight(height);
}

void setStyleDependentName(String styleSuffix, bool add) #

inherited from UiObject

Adds or removes a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:

getStylePrimaryName() + '-' + styleSuffix

@param styleSuffix the suffix of the dependent style to be added or removed @param add <code>true</code> to add the given style, <code>false</code> to

     remove it

@see #setStylePrimaryName(Element, String) @see #addStyleDependentName(String) @see #setStyleName(String, boolean) @see #removeStyleDependentName(String)

void setStyleDependentName(String styleSuffix, bool add) {
 setStyleName(getStylePrimaryName() + '-' + styleSuffix, add);
}

void setStyleName(String style, bool add) #

inherited from UiObject

Adds or removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.

@param style the style name to be added or removed @param add <code>true</code> to add the given style, <code>false</code> to

     remove it

@see #addStyleName(String) @see #removeStyleName(String)

void setStyleName(String style, bool add) {
 manageElementStyleName(getStyleElement(), style, add);
}

void setStylePrimaryName(String style) #

inherited from UiObject

Sets the object's primary style name and updates all dependent style names.

@param style the new primary style name @see #addStyleName(String) @see #removeStyleName(String)

void setStylePrimaryName(String style) {
 setElementStylePrimaryName(getStyleElement(), style);
}

void setUrl(String url) #

Sets the URL of the image to be displayed. If the image is in the clipped state, a call to this method will cause a transition of the image to the unclipped state. Regardless of whether or not the image is in the clipped or unclipped state, a load event will be fired.

@param url the image URL

void setUrl(String url) {
 setSafeUrl(UriUtils.unsafeCastFromUntrustedString(url));
}

void setUrlAndVisibleRect(String url, int left, int top, int width, int height) #

Sets the url and the visibility rectangle for the image at the same time. A single load event will be fired if either the incoming url or visiblity rectangle co-ordinates differ from the image's current url or current visibility rectangle co-ordinates. If the image is currently in the unclipped state, a call to this method will cause a transition to the clipped state.

@param url the image URL @param left the horizontal coordinate of the upper-left vertex of the

     visibility rectangle

@param top the vertical coordinate of the upper-left vertex of the

     visibility rectangle

@param width the width of the visibility rectangle @param height the height of the visibility rectangle

void setUrlAndVisibleRect(String url, int left, int top, int width, int height) {
 setSafeUrlAndVisibleRect(UriUtils.unsafeCastFromUntrustedString(url), left, top, width, height);
}

void setVisibleRect(int left, int top, int width, int height) #

Sets the visibility rectangle of an image. The visibility rectangle is declared relative to the the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0). Provided that any of the left, top, width, and height parameters are different than the those values that are currently set for the image, a load event will be fired. If the image is in the unclipped state, a call to this method will cause a transition of the image to the clipped state. This transition will cause a load event to fire.

@param left the horizontal coordinate of the upper-left vertex of the

     visibility rectangle

@param top the vertical coordinate of the upper-left vertex of the

     visibility rectangle

@param width the width of the visibility rectangle @param height the height of the visibility rectangle

void setVisibleRect(int left, int top, int width, int height) {
 _state.setVisibleRect(this, left, top, width, height);
}

void setWidth(String width) #

inherited from UiObject

Sets the object's width. This width does not include decorations such as border, margin, and padding.

@param width the object's new width, in CSS units (e.g. "10px", "1em")

void setWidth(String width) {
 // This exists to deal with an inconsistency in IE's implementation where
 // it won't accept negative numbers in length measurements
 assert (extractLengthValue(width.trim().toLowerCase()) >= 0); // : "CSS widths should not be negative";
 Dom.setStyleAttribute(getElement(), "width", width);
}

void sinkBitlessEvent(String eventTypeName) #

inherited from UiObject

Sinks a named event. Note that only {@link Widget widgets} may actually receive events, but can receive events from all objects contained within them.

@param eventTypeName name of the event to sink on this element @see com.google.gwt.user.client.Event

void sinkBitlessEvent(String eventTypeName) {
 Dom.sinkBitlessEvent(getElement(), eventTypeName);
}

void sinkEvents(int eventBitsToAdd) #

inherited from Widget

Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement. Subclasses wishing to customize sinkEvents can preserve this deferred sink behavior by putting their implementation behind a check of <code>isOrWasAttached()</code>:

{@literal @}Override
public void sinkEvents(int eventBitsToAdd) {
  if (isOrWasAttached()) {
    /{@literal *} customized sink code goes here {@literal *}/
  } else {
    super.sinkEvents(eventBitsToAdd);
 }
} 
void sinkEvents(int eventBitsToAdd) {
 if (isOrWasAttached()) {
   super.sinkEvents(eventsToSink);
 } else {
   eventsToSink |= eventBitsToAdd;
 }
}

String toString() #

inherited from UiObject

This method is overridden so that any object can be viewed in the debugger as an HTML snippet.

@return a string representation of the object

String toString() {
 if (_element == null) {
   return "(null handle)";
 }
 return getElement().toString();
}

void unsinkEvents(int eventBitsToRemove) #

inherited from UiObject

Removes a set of events from this object's event list.

@param eventBitsToRemove a bitfield representing the set of events to be

     removed from this element's event set

@see #sinkEvents @see com.google.gwt.user.client.Event

void unsinkEvents(int eventBitsToRemove) {
 Dom.sinkEvents(getElement(), Dom.getEventsSunk(getElement()) & (~eventBitsToRemove));
}