My favorites | Sign in
Google
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright 2008 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.user.client.ui.impl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Image;

/**
* Implements the clipped image as a IMG inside a custom tag because we can't
* use the IE PNG transparency filter on background-image images.
*
* Do not use this class - it is used for implementation only, and its methods
* may change in the future.
*/
public class ClippedImageImplIE6 extends ClippedImageImpl {

private static String moduleBaseUrlProtocol =
GWT.getHostPageBaseURL().startsWith("https") ? "https://" : "http://";

private static native void injectGlobalHandler() /*-{
$wnd.__gwt_transparentImgHandler = function (elem) {
elem.onerror = null;
@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");
};
}-*/;

public ClippedImageImplIE6() {
injectGlobalHandler();
}

@Override
public void adjust(Element clipper, String url, int left, int top, int width,
int height) {

clipper.getStyle().setPropertyPx("width", width);
clipper.getStyle().setPropertyPx("height", height);

// Update the nested image's url.
Element img = clipper.getFirstChildElement();
img.getStyle().setProperty("filter",
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url
+ "',sizingMethod='crop')");
img.getStyle().setPropertyPx("marginLeft", -left);
img.getStyle().setPropertyPx("marginTop", -top);

// AlphaImageLoader requires that we size the image explicitly.
// It really only needs to be enough to show the revealed portion.
int imgWidth = left + width;
int imgHeight = top + height;
img.setPropertyInt("width", imgWidth);
img.setPropertyInt("height", imgHeight);
}

@Override
public Element createStructure(String url, int left, int top, int width,
int height) {
// We need to explicitly sink ONLOAD on the child image element, because it
// can't be fired on the clipper.
Element clipper = super.createStructure(url, left, top, width, height);
Element img = clipper.getFirstChildElement();
Event.sinkEvents(img, Event.ONLOAD);
return clipper;
}

public void fireSyntheticLoadEvent(final Image image) {
// This is the same as the superclass' implementation, except that it
// explicitly checks for the 'clipper' element, and dispatches the event
// on the img (you can't dispatch events on the clipper).
DeferredCommand.addCommand(new Command() {
public void execute() {
NativeEvent evt = Document.get().createLoadEvent();
Element clipper = image.getElement();
Element img = clipper.getFirstChildElement();
img.dispatchEvent(evt);
}
});
}

@Override
public String getHTML(String url, int left, int top, int width, int height) {
String clipperStyle = "overflow: hidden; width: " + width + "px; height: "
+ height + "px; padding: 0px; zoom: 1";

String imgStyle = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
+ url
+ "',sizingMethod='crop'); margin-left: "
+ -left
+ "px; margin-top: " + -top + "px; border: none";

/*
* We initially set the image URL to an invalid value to force onerror to be
* fired when this string is turned into a DOM structure. At this point, we
* can set the image src using DOM.setImgSrc, which is used to get around
* issue #282. The invalid image URL is either http:// or https://,
* depending on the module's base URL. We have to match the invalid image
* URL's protocol with that of the module's base URL's protocol due to issue
* #1200.
*/
String clippedImgHtml = "<gwt:clipper style=\""
+ clipperStyle
+ "\"><img src='"
+ moduleBaseUrlProtocol
+ "' onerror='if(window.__gwt_transparentImgHandler)window.__gwt_transparentImgHandler(this);else this.src=\"" + GWT.getModuleBaseURL() + "clear.cache.gif\"' style=\""
+ imgStyle + "\" width=" + (left + width) + " height=" + (top + height)
+ " border='0'></gwt:clipper>";

return clippedImgHtml;
}
}
Show details Hide details

Change log

r4659 by j...@google.com on Feb 06, 2009   Diff
Merging releases/1.6 into trunk.
svn merge -r4511:4604 https://google-web-
toolkit.googlecode.com/svn/releases/1.6 .
svn merge -r4605:4657 https://google-web-
toolkit.googlecode.com/svn/releases/1.6 .
Go to: 
Project members, sign in to write a code review

Older revisions

r3351 by sco...@google.com on Jul 30, 2008   Diff
Merging releases/1.5 into trunk

svn merge -r3205:3230 https://google-
web-toolkit.googlecode.com/svn/release
s/1.5 .
...
r1379 by gwt.team.knorton on Aug 24, 2007   Diff
Updated to Java1.5 constructs.

Review by: jlabanca, ajr

r1337 by gwt.team.jgw on Aug 17, 2007   Diff
Fixes ImageBundle layout on IE6 in
standards mode.

Issue: 1156
Patch by: reinierz
...
All revisions of this file

File info

Size: 5113 bytes, 128 lines

File properties

svn:mime-type
text/x-java
svn:eol-style
native