001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.client.ui.impl;
017:
018: import com.google.gwt.user.client.DOM;
019: import com.google.gwt.user.client.Element;
020: import com.google.gwt.core.client.GWT;
021:
022: /**
023: * Implements the clipped image as a IMG inside a custom tag because we can't
024: * use the IE PNG transparency filter on background-image images.
025: *
026: * Do not use this class - it is used for implementation only, and its methods
027: * may change in the future.
028: */
029: public class ClippedImageImplIE6 extends ClippedImageImpl {
030:
031: private static String moduleBaseUrlProtocol = GWT
032: .getHostPageBaseURL().startsWith("https") ? "https://"
033: : "http://";
034:
035: private static native void injectGlobalHandler() /*-{
036: $wnd.__gwt_transparentImgHandler = function (elem) {
037: elem.onerror = null;
038: @com.google.gwt.user.client.DOM::setImgSrc(Lcom/google/gwt/user/client/Element;Ljava/lang/String;)(elem, @com.google.gwt.core.client.GWT::getModuleBaseURL()() + "clear.cache.gif");
039: };
040: }-*/;
041:
042: public ClippedImageImplIE6() {
043: injectGlobalHandler();
044: }
045:
046: @Override
047: public void adjust(Element clipper, String url, int left, int top,
048: int width, int height) {
049:
050: DOM.setStyleAttribute(clipper, "width", width + "px");
051: DOM.setStyleAttribute(clipper, "height", height + "px");
052:
053: // Update the nested image's url.
054: Element img = DOM.getFirstChild(clipper);
055: DOM.setStyleAttribute(img, "filter",
056: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
057: + url + "',sizingMethod='crop')");
058: DOM.setStyleAttribute(img, "marginLeft", -left + "px");
059: DOM.setStyleAttribute(img, "marginTop", -top + "px");
060:
061: // AlphaImageLoader requires that we size the image explicitly.
062: // It really only needs to be enough to show the revealed portion.
063: int imgWidth = left + width;
064: int imgHeight = top + height;
065: DOM.setElementPropertyInt(img, "width", imgWidth);
066: DOM.setElementPropertyInt(img, "height", imgHeight);
067: }
068:
069: @Override
070: public String getHTML(String url, int left, int top, int width,
071: int height) {
072: String clipperStyle = "overflow: hidden; width: " + width
073: + "px; height: " + height + "px; padding: 0px; zoom: 1";
074:
075: String imgStyle = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
076: + url
077: + "',sizingMethod='crop'); margin-left: "
078: + -left
079: + "px; margin-top: " + -top + "px; border: none";
080:
081: /*
082: * We initially set the image URL to an invalid value to force onerror to be
083: * fired when this string is turned into a DOM structure. At this point, we
084: * can set the image src using DOM.setImgSrc, which is used to get around
085: * issue #282. The invalid image URL is either http:// or https://,
086: * depending on the module's base URL. We have to match the invalid image
087: * URL's protocol with that of the module's base URL's protocol due to issue
088: * #1200.
089: */
090: String clippedImgHtml = "<gwt:clipper style=\""
091: + clipperStyle
092: + "\"><img src='"
093: + moduleBaseUrlProtocol
094: + "' onerror='if(window.__gwt_transparentImgHandler)window.__gwt_transparentImgHandler(this);else this.src=\""
095: + GWT.getModuleBaseURL()
096: + "clear.cache.gif\"' style=\"" + imgStyle
097: + "\" width=" + (left + width) + " height="
098: + (top + height) + " border='0'></gwt:clipper>";
099:
100: return clippedImgHtml;
101: }
102: }
|