Skip to content

Commit 46a3601

Browse files
author
zhourenjian
committed
Remove on* related codes.
Fixed memory leak on IE Remove unnecessary codes
1 parent b29897e commit 46a3601

40 files changed

+392
-492
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/browser/OS.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.eclipse.swt.SWT;
1515
import org.eclipse.swt.graphics.Image;
1616
import org.eclipse.swt.graphics.Point;
17+
import org.eclipse.swt.internal.dnd.HTMLEventWrapper;
1718
import org.eclipse.swt.internal.xhtml.CSSStyle;
1819
import org.eclipse.swt.internal.xhtml.Element;
1920
import org.eclipse.swt.internal.xhtml.document;
@@ -59,6 +60,8 @@ private OS() {
5960

6061
/* Record Caps Lock status */
6162
public static boolean isCapsLockOn = false;
63+
64+
public static Object noReturnCallback;
6265

6366
/**
6467
* @j2sNative
@@ -82,6 +85,7 @@ private OS() {
8285
os.isIE70 = os.isIE && dav.indexOf("MSIE 7.0")>=0;
8386
os.isIE80 = os.isIE && dav.indexOf("MSIE 8.0")>=0;
8487
os.isIENeedPNGFix = os.isIE50 || os.isIE55 || os.isIE60;
88+
os.noReturnCallback = os.noReturnCallbackFunction;
8589
*/
8690
static {
8791

@@ -91,22 +95,6 @@ public static void destroyHandle(Object handle) {
9195
return ;
9296
}
9397
Element el = (Element) handle;
94-
el.onblur = null;
95-
el.onchange = null;
96-
el.onclick = null;
97-
el.oncontextmenu = null;
98-
el.ondblclick = null;
99-
el.onfocus = null;
100-
el.onkeydown = null;
101-
el.onkeypress = null;
102-
el.onkeyup = null;
103-
el.onmousedown = null;
104-
el.onmousemove = null;
105-
el.onmouseout = null;
106-
el.onmouseover = null;
107-
el.onmouseup = null;
108-
el.onselectchange = null;
109-
el.onselectstart = null;
11098
if (el.parentNode != null) {
11199
try {
112100
el.parentNode.removeChild (el);
@@ -212,6 +200,7 @@ private static void initGC() {
212200
if (gcContainer == null) {
213201
Element gc = document.createElement("DIV");
214202
gc.style.display = "none";
203+
gc.id = "gc";
215204
document.body.appendChild(gc);
216205
gcContainer = gc;
217206
}
@@ -220,14 +209,17 @@ private static void initGC() {
220209

221210
public static void dispose() {
222211
if (blockContainer != null) {
212+
deepClearChildren(blockContainer);
223213
destroyHandle(blockContainer);
224214
blockContainer = null;
225215
}
226216
if (lineContainer != null) {
217+
deepClearChildren(lineContainer);
227218
destroyHandle(lineContainer);
228219
lineContainer = null;
229220
}
230221
if (invisibleContainer != null) {
222+
deepClearChildren(invisibleContainer);
231223
destroyHandle(invisibleContainer);
232224
invisibleContainer = null;
233225
}
@@ -238,12 +230,14 @@ public static void dispose() {
238230
* for (var p in c) {
239231
* try {
240232
* c[p] = null;
233+
* delete c[p];
241234
* } catch (e) {}
242235
* }
243236
*/ { c.toString(); }
244237
}
245238
if (gcContainer != null) {
246239
gcContainer.parentNode.removeChild(gcContainer);
240+
gcContainer = null;
247241
}
248242
}
249243

@@ -335,7 +329,7 @@ public static String insertText(Object el, String text) {
335329
} else {
336330
c = s.split (/\r\n|\r|\n/g);
337331
}
338-
*/ {}
332+
*/ { lines = new String[0]; }
339333
for (int i = 0; i < lines.length; i++) {
340334
if (i > 0) {
341335
handle.appendChild (document.createElement ("BR"));
@@ -975,7 +969,7 @@ public static Point getImageSize(Image image) {
975969
/**
976970
* @j2sNative
977971
* img = O$.imageCaches[image.url];
978-
*/ {}
972+
*/ { imageCaches.toString(); }
979973
if (img == null) {
980974
img = new org.eclipse.swt.internal.xhtml.Image ();
981975
img.src = image.url;
@@ -1086,10 +1080,22 @@ public static boolean isInputCharacter(int keyCode, boolean shiftKey, boolean al
10861080
* @j2sNative
10871081
* if (O$.isMozilla || O$.isFirefox) {
10881082
* handle.style.MozUserSelect = enabled ? "all" : "none";
1083+
* } else if (typeof handle.style.KhtmlUserSelect != "undefined") {
1084+
* handle.style.KhtmlUserSelect = "none";
10891085
* } else if (typeof handle.onselectstart != "undefined") {
1090-
* handle.onselectstart = enabled ? null : function () { return false; };
1086+
* handle.onselectstart = enabled ? null : O$.noReturnCallbackFunction;
1087+
* return O$.noReturnCallbackFunction;
10911088
* }
1089+
* return null;
10921090
*/
1093-
public static void setTextSelection(Element handle, boolean enabled) {
1091+
public static Object setTextSelection(Element handle, boolean enabled) {
1092+
return null;
1093+
}
1094+
1095+
static boolean noReturnCallbackFunction(Object e) {
1096+
HTMLEventWrapper evt = new HTMLEventWrapper (e);
1097+
evt.preventDefault ();
1098+
evt.stopPropagation ();
1099+
return false;
10941100
}
10951101
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/DNDUtils.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public static boolean onselectstart(Object e) {
6969
public static boolean onmousemove(Object e, DragAndDrop oThis) {
7070
HTMLEventWrapper evt = new HTMLEventWrapper(e);
7171
if (!evt.leftButtonHold) {
72-
//oThis.element.onmouseup (e); /* reset */
7372
if (oThis.status != 0) {
7473
DragEvent dndEvt = new DragEvent (evt, oThis.element,
7574
oThis.startX, oThis.startY);
@@ -98,15 +97,26 @@ public static boolean onmousedown(Object e, DragAndDrop oThis) {
9897
if (!oThis.checkDraggable (evt)) {
9998
return true;
10099
}
101-
document.onselectstart = DNDUtils.onselectstart;
102-
//evt.target.onselectstart = DNDUtils.onselectstart;
103-
Clazz.addEvent(evt.target, "selectstart", DNDUtils.onselectstart);
100+
if (oThis.hSelectStart == null) {
101+
oThis.hSelectStart = DNDUtils.onselectstart;
102+
Clazz.addEvent(document.class, "selectstart", oThis.hSelectStart);
103+
Clazz.addEvent(evt.target, "selectstart", oThis.hSelectStart);
104+
}
104105

105106
oThis.startX = evt.x;
106107
oThis.startY = evt.y;
107-
document.onmousemove = DNDUtils.bindFunctionWith (DNDUtils.onmousemove, oThis);
108-
document.onkeyup = DNDUtils.bindFunctionWith (DNDUtils.onkeyup, oThis);
109-
document.onmouseup = DNDUtils.bindFunctionWith (DNDUtils.onmouseup, oThis); //oThis.element.onmouseup;
108+
if (oThis.hMouseMove == null) {
109+
oThis.hMouseMove = DNDUtils.bindFunctionWith (DNDUtils.onmousemove, oThis);
110+
Clazz.addEvent(document.class, "mousemove", oThis.hMouseMove);
111+
}
112+
if (oThis.hKeyUp == null) {
113+
oThis.hKeyUp = DNDUtils.bindFunctionWith (DNDUtils.onkeyup, oThis);
114+
Clazz.addEvent(document.class, "keyup", oThis.hKeyUp);
115+
}
116+
if (oThis.hMouseUp == null) {
117+
oThis.hMouseUp = DNDUtils.bindFunctionWith (DNDUtils.onmouseup, oThis);
118+
Clazz.addEvent(document.class, "mouseup", oThis.hMouseUp);
119+
}
110120
boolean isOpera = false;
111121
/**
112122
* @j2sNative

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/DragAndDrop.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,46 @@ public class DragAndDrop {
2626
int startX = 0;
2727
int startY = 0;
2828
private DragListener[] listeners = new DragListener[0];
29-
private Object hDND;
29+
30+
Object hSelectStart;
31+
Object hMouseDown;
32+
Object hMouseUp;
33+
Object hMouseMove;
34+
Object hKeyUp;
3035

3136
protected void reset() {
3237
status = 0;
33-
document.onmousemove = null;
34-
document.onmouseup = null;
35-
document.onselectstart = null;
36-
document.onkeyup = null;
37-
if (this.element != null) {
38-
//this.element.onselectstart = null;
39-
Clazz.removeEvent(element, "selectstart", DNDUtils.onselectstart);
38+
if (hMouseMove != null) {
39+
Clazz.removeEvent(document.class, "mousemove", hMouseMove);
40+
hMouseMove = null;
41+
}
42+
if (hMouseUp != null) {
43+
Clazz.removeEvent(document.class, "mouseup", hMouseUp);
44+
hMouseUp = null;
45+
}
46+
if (hKeyUp != null) {
47+
Clazz.removeEvent(document.class, "keyup", hKeyUp);
48+
hKeyUp = null;
49+
}
50+
if (this.element != null && hSelectStart != null) {
51+
Clazz.removeEvent(element, "selectstart", hSelectStart);
52+
}
53+
if (hSelectStart != null) {
54+
Clazz.removeEvent(document.class, "selectstart", hSelectStart);
55+
hSelectStart = null;
4056
}
4157
}
4258
public void bind(Element el) {
4359
this.element = el;
44-
hDND = DNDUtils.bindFunctionWith (DNDUtils.onmousedown, this);
45-
// el.onmousedown = ;
46-
Clazz.addEvent(el, "mousedown", hDND);
47-
//el.onmouseup = DNDUtils.bindFunctionWith (DNDUtils.onmouseup, this);
60+
if (hMouseDown == null) {
61+
hMouseDown = DNDUtils.bindFunctionWith (DNDUtils.onmousedown, this);
62+
Clazz.addEvent(el, "mousedown", hMouseDown);
63+
}
4864
}
4965
public void unbind() {
50-
if (hDND != null) {
51-
Clazz.removeEvent(element, "mouseover", hDND);
52-
hDND = null;
66+
if (hMouseDown != null) {
67+
Clazz.removeEvent(element, "mouseover", hMouseDown);
68+
hMouseDown = null;
5369
}
5470
element = null;
5571
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/SashDND.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class SashDND implements DragListener {
3030
protected Element thumb;
3131
protected boolean isHorizontal;
3232
private Element overFrameHandle;
33+
Object hSelectStart;
34+
3335
public boolean dragBegan(DragEvent e) {
3436
thumb = document.createElement ("DIV");
3537
String cssName = e.sourceElement.className;
@@ -46,8 +48,10 @@ public boolean dragBegan(DragEvent e) {
4648
thumb.style.top = e.sourceElement.style.top;
4749
thumb.style.width = e.sourceElement.style.width;
4850
thumb.style.height = e.sourceElement.style.height;
49-
//thumb.onselectstart = DNDUtils.onselectstart;
50-
Clazz.addEvent(thumb, "selectstart", DNDUtils.onselectstart);
51+
if (hSelectStart == null) {
52+
hSelectStart = DNDUtils.onselectstart;
53+
Clazz.addEvent(thumb, "selectstart", hSelectStart);
54+
}
5155
if (e.sourceElement.nextSibling != null) {
5256
e.sourceElement.parentNode.insertBefore (thumb,
5357
e.sourceElement.nextSibling);
@@ -91,7 +95,10 @@ public boolean dragEnded(DragEvent e) {
9195
protected void clean() {
9296
thumb.style.display = "none";
9397
document.body.style.cursor = "auto";
94-
Clazz.removeEvent(thumb, "selectstart", DNDUtils.onselectstart);
98+
if (hSelectStart != null) {
99+
Clazz.removeEvent(thumb, "selectstart", hSelectStart);
100+
hSelectStart = null;
101+
}
95102
//thumb.parentNode.removeChild(thumb);
96103
OS.destroyHandle(thumb);
97104
if (overFrameHandle != null) {

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/dnd/TableColumnDND.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
public class TableColumnDND extends DragAdapter {
2828
protected int sourceX = 0;
2929
protected Element thumb;
30+
Object hSelectStart;
31+
3032
public boolean dragBegan(DragEvent e) {
3133
thumb = document.createElement ("DIV");
3234
String cssName = e.sourceElement.className;
@@ -38,8 +40,10 @@ public boolean dragBegan(DragEvent e) {
3840
thumb.style.top = e.sourceElement.style.top;
3941
thumb.style.width = e.sourceElement.style.width;
4042
thumb.style.height = e.sourceElement.style.height;
41-
//thumb.onselectstart = DNDUtils.onselectstart;
42-
Clazz.addEvent(thumb, "selectstart", DNDUtils.onselectstart);
43+
if (hSelectStart == null) {
44+
hSelectStart = DNDUtils.onselectstart;
45+
Clazz.addEvent(thumb, "selectstart", hSelectStart);
46+
}
4347
if (e.sourceElement.nextSibling != null) {
4448
e.sourceElement.parentNode.insertBefore (thumb,
4549
e.sourceElement.nextSibling);
@@ -65,7 +69,10 @@ public boolean dragEnded(DragEvent e) {
6569

6670
protected void clean() {
6771
thumb.style.display = "none";
68-
Clazz.removeEvent(thumb, "selectstart", DNDUtils.onselectstart);
72+
if (hSelectStart != null) {
73+
Clazz.removeEvent(thumb, "selectstart", hSelectStart);
74+
hSelectStart = null;
75+
}
6976
document.body.style.cursor = "auto";
7077
//thumb.parentNode.removeChild(thumb);
7178
OS.destroyHandle(thumb);

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/package.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ $WTC$$.trackCSS = function (clazzName) {
4949
var links = head.getElementsByTagName ("LINK");
5050
for (var i = 0; i < links.length; i++) {
5151
if (links[i].id == "c$$." + name) {
52-
head.removeChild (links[i]);
52+
if (window["O$"] != null && O$.destroyHandle != null) {
53+
O$.destroyHandle (links[i]);
54+
} else {
55+
head.removeChild (links[i]);
56+
}
5357
break;
5458
}
5559
}
@@ -82,7 +86,11 @@ $WTC$$.removeTesting = function (clazzName) {
8286
if (els[i].className == cssClassName) {
8387
var el = els[i];
8488
if (el.parentNode != null) {
85-
el.parentNode.removeChild (el);
89+
if (window["O$"] != null && O$.destroyHandle != null) {
90+
O$.destroyHandle (el);
91+
} else {
92+
el.parentNode.removeChild (el);
93+
}
8694
}
8795
for (var j = i; j < els.length - 1; j++) {
8896
els[j] = els[j + 1];
@@ -104,7 +112,11 @@ $WTC$$.globalChecking = function () {
104112
$WTC$$.cssLoaded (el.className);
105113
window.clearTimeout ($WTC$$.timeouts[el.className]);
106114
if (el.parentNode != null) {
107-
el.parentNode.removeChild (el);
115+
if (window["O$"] != null && O$.destroyHandle != null) {
116+
O$.destroyHandle (el);
117+
} else {
118+
el.parentNode.removeChild (el);
119+
}
108120
}
109121
for (var j = i; j < els.length - 1; j++) {
110122
els[j] = els[j + 1];

0 commit comments

Comments
 (0)