Sort & format in preparation for element wrapping patch.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2866 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/Image.java b/user/src/com/google/gwt/user/client/ui/Image.java
index e5942f1..0031214 100644
--- a/user/src/com/google/gwt/user/client/ui/Image.java
+++ b/user/src/com/google/gwt/user/client/ui/Image.java
@@ -1,12 +1,12 @@
/*
* Copyright 2007 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -34,19 +34,19 @@
* 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.
- *
+ *
* <p>
* 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.
* </p>
- *
+ *
* <h3>CSS Style Rules</h3>
* <ul class="css">
* <li>.gwt-Image { }</li>
* </ul>
- *
+ *
* 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
@@ -55,7 +55,7 @@
* 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.
- *
+ *
* <p>
* <h3>Example</h3>
* {@example com.google.gwt.examples.ImageExample}
@@ -65,6 +65,129 @@
SourcesLoadEvents, SourcesMouseEvents, SourcesMouseWheelEvents {
/**
+ * Implementation of behaviors associated with the clipped state of an image.
+ */
+ private static class ClippedState extends State {
+
+ private static final ClippedImageImpl impl = GWT.create(ClippedImageImpl.class);
+
+ private int height = 0;
+ private int left = 0;
+ private int top = 0;
+ private String url = null;
+ private int width = 0;
+
+ ClippedState(Image image, String url, int left, int top, int width,
+ int height) {
+ this.left = left;
+ this.top = top;
+ this.width = width;
+ this.height = height;
+ this.url = url;
+ image.replaceElement(impl.createStructure(url, left, top, width, height));
+ image.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONMOUSEWHEEL);
+ fireSyntheticLoadEvent(image);
+ }
+
+ @Override
+ public int getHeight(Image image) {
+ return height;
+ }
+
+ @Override
+ public int getOriginLeft() {
+ return left;
+ }
+
+ @Override
+ public int getOriginTop() {
+ return top;
+ }
+
+ @Override
+ public String getUrl(Image image) {
+ return url;
+ }
+
+ @Override
+ public int getWidth(Image image) {
+ return width;
+ }
+
+ @Override
+ public void setUrl(Image image, String url) {
+ image.changeState(new UnclippedState(image, url));
+ }
+
+ @Override
+ public void setUrlAndVisibleRect(Image image, String url, int left,
+ int top, int width, int height) {
+ if (!this.url.equals(url) || this.left != left || this.top != top
+ || this.width != width || this.height != height) {
+
+ this.url = url;
+ this.left = left;
+ this.top = top;
+ this.width = width;
+ this.height = height;
+
+ impl.adjust(image.getElement(), url, left, top, width, height);
+ fireSyntheticLoadEvent(image);
+ }
+ }
+
+ @Override
+ public void setVisibleRect(Image image, int left, int top, int width,
+ int height) {
+ /*
+ * In the event that the clipping rectangle has not changed, we want to
+ * skip all of the work required with a getImpl().adjust, and we do not
+ * want to fire a load event.
+ */
+ if (this.left != left || this.top != top || this.width != width
+ || this.height != height) {
+
+ this.left = left;
+ this.top = top;
+ this.width = width;
+ this.height = height;
+
+ impl.adjust(image.getElement(), url, left, top, width, height);
+ fireSyntheticLoadEvent(image);
+ }
+ }
+
+ /* This method is used only by unit tests */
+ @Override
+ protected String getStateName() {
+ return "clipped";
+ }
+
+ private void fireSyntheticLoadEvent(final Image image) {
+ /*
+ * We need to synthesize a load event, because the native events that are
+ * fired would correspond to the loading of clear.cache.gif, which is
+ * incorrect. A native event would not even fire in Internet Explorer,
+ * because the root element is a wrapper element around the <img> element.
+ * Since we are synthesizing a load event, we do not need to sink the
+ * onload event.
+ *
+ * We use a deferred command here to simulate the native version of the
+ * load event as closely as possible. In the native event case, it is
+ * unlikely that a second load event would occur while you are in the load
+ * event handler.
+ */
+ DeferredCommand.addCommand(new Command() {
+ public void execute() {
+ if (image.loadListeners != null) {
+ image.loadListeners.fireLoad(image);
+ }
+ }
+ });
+ }
+ }
+
+ /**
* Abstract class which is used to hold the state associated with an image
* object.
*/
@@ -160,129 +283,6 @@
}
/**
- * Implementation of behaviors associated with the clipped state of an image.
- */
- private static class ClippedState extends State {
-
- private static final ClippedImageImpl impl = GWT.create(ClippedImageImpl.class);
-
- private int left = 0;
- private int top = 0;
- private int width = 0;
- private int height = 0;
- private String url = null;
-
- ClippedState(Image image, String url, int left, int top, int width,
- int height) {
- this.left = left;
- this.top = top;
- this.width = width;
- this.height = height;
- this.url = url;
- image.replaceElement(impl.createStructure(url, left, top, width, height));
- image.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONMOUSEWHEEL);
- fireSyntheticLoadEvent(image);
- }
-
- private void fireSyntheticLoadEvent(final Image image) {
- /*
- * We need to synthesize a load event, because the native events that are
- * fired would correspond to the loading of clear.cache.gif, which is
- * incorrect. A native event would not even fire in Internet Explorer,
- * because the root element is a wrapper element around the <img> element.
- * Since we are synthesizing a load event, we do not need to sink the
- * onload event.
- *
- * We use a deferred command here to simulate the native version of the
- * load event as closely as possible. In the native event case, it is
- * unlikely that a second load event would occur while you are in the load
- * event handler.
- */
- DeferredCommand.addCommand(new Command() {
- public void execute() {
- if (image.loadListeners != null) {
- image.loadListeners.fireLoad(image);
- }
- }
- });
- }
-
- @Override
- public int getHeight(Image image) {
- return height;
- }
-
- @Override
- public int getOriginLeft() {
- return left;
- }
-
- @Override
- public int getOriginTop() {
- return top;
- }
-
- @Override
- public String getUrl(Image image) {
- return url;
- }
-
- @Override
- public int getWidth(Image image) {
- return width;
- }
-
- @Override
- public void setUrl(Image image, String url) {
- image.changeState(new UnclippedState(image, url));
- }
-
- @Override
- public void setUrlAndVisibleRect(Image image, String url, int left,
- int top, int width, int height) {
- if (!this.url.equals(url) || this.left != left || this.top != top
- || this.width != width || this.height != height) {
-
- this.url = url;
- this.left = left;
- this.top = top;
- this.width = width;
- this.height = height;
-
- impl.adjust(image.getElement(), url, left, top, width, height);
- fireSyntheticLoadEvent(image);
- }
- }
-
- @Override
- public void setVisibleRect(Image image, int left, int top, int width,
- int height) {
- /*
- * In the event that the clipping rectangle has not changed, we want to
- * skip all of the work required with a getImpl().adjust, and we do not
- * want to fire a load event.
- */
- if (this.left != left || this.top != top || this.width != width
- || this.height != height) {
-
- this.left = left;
- this.top = top;
- this.width = width;
- this.height = height;
-
- impl.adjust(image.getElement(), url, left, top, width, height);
- fireSyntheticLoadEvent(image);
- }
- }
-
- /* This method is used only by unit tests */
- @Override
- protected String getStateName() {
- return "clipped";
- }
- }
-
- /**
* 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.
@@ -291,7 +291,7 @@
/**
* Causes the browser to pre-fetch the image at a given URL.
- *
+ *
* @param url the URL of the image to be prefetched
*/
public static void prefetch(String url) {
@@ -318,7 +318,7 @@
/**
* 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
*/
public Image(String url) {
@@ -335,7 +335,7 @@
* 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
@@ -381,7 +381,7 @@
* 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
*/
public int getHeight() {
@@ -393,7 +393,7 @@
* 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
*/
@@ -406,7 +406,7 @@
* 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
*/
@@ -418,7 +418,7 @@
* 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
*/
public String getUrl() {
@@ -429,7 +429,7 @@
* 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
*/
public int getWidth() {
@@ -504,7 +504,7 @@
* 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
*/
public void setUrl(String url) {
@@ -518,7 +518,7 @@
* 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
@@ -541,7 +541,7 @@
* 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