KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > impl > ClippedImageImplIE6


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.ui.impl;
17
18 import com.google.gwt.user.client.DOM;
19 import com.google.gwt.user.client.Element;
20
21 /**
22  * Implements the clipped image as a IMG inside a custom tag because we can't
23  * use the IE PNG transparency filter on background-image images.
24  *
25  * Do not use this class - it is used for implementation only, and its methods
26  * may change in the future.
27  */

28 public class ClippedImageImplIE6 extends ClippedImageImpl {
29   
30   private static native void injectGlobalHandler() /*-{
31     $wnd.__gwt_transparentImgHandler = function (elem) {
32       elem.onerror = null;
33       @com.google.gwt.user.client.DOM::setImgSrc(Lcom/google/gwt/user/client/Element;Ljava/lang/String;)(elem, "clear.cache.gif");
34     };
35   }-*/
;
36   
37   public ClippedImageImplIE6() {
38     injectGlobalHandler();
39   }
40
41   public void adjust(Element clipper, String JavaDoc url, int left, int top, int width,
42       int height) {
43
44     DOM.setStyleAttribute(clipper, "width", width + "px");
45     DOM.setStyleAttribute(clipper, "height", height + "px");
46
47     // Update the nested image's url.
48
Element img = DOM.getFirstChild(clipper);
49     DOM.setStyleAttribute(img, "filter",
50         "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url
51             + "',sizingMethod='crop')");
52     DOM.setStyleAttribute(img, "marginLeft", -left + "px");
53     DOM.setStyleAttribute(img, "marginTop", -top + "px");
54
55     // AlphaImageLoader requires that we size the image explicitly.
56
// It really only needs to be enough to show the revealed portion.
57
int imgWidth = left + width;
58     int imgHeight = top + height;
59     DOM.setElementPropertyInt(img, "width", imgWidth);
60     DOM.setElementPropertyInt(img, "height", imgHeight);
61   }
62
63   public String JavaDoc getHTML(String JavaDoc url, int left, int top, int width, int height) {
64     String JavaDoc clipperStyle = "overflow: hidden; width: " + width + "px; height: "
65         + height + "px; padding: 0px";
66
67     String JavaDoc imgStyle =
68         "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
69         + url + "',sizingMethod='crop'); margin-left: "
70         + -left + "px; margin-top: " + -top + "px; border: none";
71
72     String JavaDoc clippedImgHtml = "<gwt:clipper style=\""
73         + clipperStyle
74         + "\"><img SRC='about:blank' onerror='if(window.__gwt_transparentImgHandler)window.__gwt_transparentImgHandler(this);else this.src=\"clear.cache.gif\"' style=\""
75         + imgStyle + "\" width=" + (left + width) + " height=" + (top + height)
76         + " border='0'></gwt:clipper>";
77
78     return clippedImgHtml;
79   }
80 }
81
Popular Tags