Skip to content

Commit 5e0e402

Browse files
author
zhourenjian
committed
Implement Browser#execute
Replace StringBuffer usage in Link with String so StringBuffer is not in the dependency tree of Link. Link#initAccessible is ignored Tray is ignored in Display's dependency tree. Fix a bug that ShellFrameDND's half transparent layer is not disposed correctly.
1 parent 8e05be0 commit 5e0e402

File tree

7 files changed

+122
-30
lines changed

7 files changed

+122
-30
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.eclipse.swt.SWTError;
1515
import org.eclipse.swt.SWTException;
1616
import org.eclipse.swt.internal.browser.OS;
17+
import org.eclipse.swt.internal.xhtml.ContentWindow;
1718
import org.eclipse.swt.internal.xhtml.Element;
1819
import org.eclipse.swt.internal.xhtml.document;
1920
import org.eclipse.swt.widgets.Composite;
@@ -861,6 +862,14 @@ public boolean execute(String script) {
861862
if (pVarResult == null) return false;
862863
pVarResult.dispose();
863864
*/
865+
/**
866+
* @j2sNative
867+
* try {
868+
* this.browserHandle.contentWindow.eval (script);
869+
* } catch (e) {
870+
* return false;
871+
* }
872+
*/ { }
864873
return true;
865874
}
866875

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ public boolean dragBegan(DragEvent e) {
5959
e.startX = e.currentX;
6060
e.startY = e.currentY;
6161
Element[] frames = document.getElementsByTagName("IFRAME");
62-
if (frames.length != 0) {
62+
boolean needOverIFrameLayer = false;
63+
for (int i = 0; i < frames.length; i++) {
64+
if (frames[i].style.display != "none") {
65+
needOverIFrameLayer = true;
66+
break;
67+
}
68+
}
69+
if (needOverIFrameLayer) {
6370
overFrameHandle = document.createElement ("DIV");
6471
overFrameHandle.className = "over-iframe-layer";
6572
overFrameHandle.style.zIndex = window.currentTopZIndex;

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ public boolean dragBegan(DragEvent e) {
9494
this.frame.style.width = this.sourceWidth + "px";
9595
this.frame.style.height = this.sourceHeight + "px";
9696
Element[] frames = document.getElementsByTagName("IFRAME");
97-
if (frames.length != 0) {
97+
boolean needOverIFrameLayer = false;
98+
for (int i = 0; i < frames.length; i++) {
99+
if (frames[i].style.display != "none") {
100+
needOverIFrameLayer = true;
101+
break;
102+
}
103+
}
104+
if (needOverIFrameLayer) {
98105
overFrameHandle = document.createElement ("DIV");
99106
overFrameHandle.className = "over-iframe-layer";
100107
overFrameHandle.style.zIndex = window.currentTopZIndex;
@@ -245,7 +252,9 @@ public boolean dragEnded(DragEvent e) {
245252
return true;
246253
}
247254
private void clean() {
248-
this.frame.style.display = "none";
255+
if(this.frame != null) {
256+
this.frame.style.display = "none";
257+
}
249258
document.body.style.cursor = "auto";
250259
this.resize = null;
251260

@@ -254,6 +263,15 @@ private void clean() {
254263
overFrameHandle = null;
255264
}
256265
};
266+
267+
public void dispose() {
268+
clean();
269+
if (this.frame != null) {
270+
this.frame.parentNode.removeChild(this.frame);
271+
this.frame = null;
272+
}
273+
}
274+
257275
/**
258276
* To initialize bounds.
259277
*/

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Control.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,10 @@ public boolean isEnabled () {
13171317
*/
13181318
public boolean isFocusControl () {
13191319
checkWidget ();
1320+
Control focusControl = display.focusControl;
1321+
if (focusControl != null && !focusControl.isDisposed ()) {
1322+
return this == focusControl;
1323+
}
13201324
return hasFocus ();
13211325
}
13221326

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Decorations.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public class Decorations extends Canvas {
134134
private Element shellClose;
135135
Element titleBar;
136136
Element shellMenuBar;
137-
Element shellToolBar;
137+
Element shellToolBar;
138+
private ShellFrameDND shellFrameDND;
138139

139140
/**
140141
* Prevents uninitialized instances from being created outside the package.
@@ -602,7 +603,7 @@ public void run() {
602603
contentHandle = createCSSDiv(contentCSS);
603604
if (DragAndDrop.class != null) {
604605
DragAndDrop dnd = new DragAndDrop();
605-
dnd.addDragListener(new ShellFrameDND() {
606+
shellFrameDND = new ShellFrameDND() {
606607
protected int deltaWidth = 0;
607608
protected int deltaHeight = 0;
608609
public boolean isDraggable(HTMLEventWrapper e) {
@@ -635,9 +636,11 @@ public boolean updateShellBounds(int x, int y, int w, int h) {
635636
if (resized) {
636637
sendEvent(SWT.Resize);
637638
}
639+
bringToTop();
638640
return true;
639641
}
640-
});
642+
};
643+
dnd.addDragListener(shellFrameDND);
641644
dnd.bind(handle);
642645
}
643646
// contentHandle.onclick = new RunnableCompatibility(){
@@ -763,6 +766,12 @@ public void dispose () {
763766
shell.setFocus ();
764767
}
765768
}
769+
770+
if (shellFrameDND != null) {
771+
shellFrameDND.dispose();
772+
shellFrameDND = null;
773+
}
774+
766775
if ((this.style & SWT.TOOL) == 0)
767776
/**
768777
* @j2sNative

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Display.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
* @see #sleep
109109
* @see Device#dispose
110110
*
111+
* @j2sIgnoreImport org.eclipse.swt.widgets.Tray
111112
* @j2sSuffix
112113
// Only IE need to release the resources so that no memory is leaked
113114
if (window.attachEvent) {

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Link.java

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,16 @@ public void run() {
335335
}
336336
};
337337
for (int i = 0; i < anchors.length; i++) {
338-
anchors[i].href = "#";
338+
anchors[i].href = "javascript:void(0);";
339339
anchors[i].target = null;
340340
anchors[i].onclick = linkHandler;
341341
anchors[i].ondblclick = linkHandler;
342342
}
343343
}
344344

345+
/**
346+
* @j2sIgnore
347+
*/
345348
void initAccessible () {
346349
Accessible accessible = getAccessible ();
347350
accessible.addAccessibleListener (new AccessibleAdapter () {
@@ -456,8 +459,10 @@ String parse (String string, Object handle) {
456459
offsets = new Point [length / 4];
457460
ids = new String [length / 4];
458461
mnemonics = new int [length / 4 + 1];
459-
StringBuffer result = new StringBuffer ();
460-
StringBuffer result2 = new StringBuffer ();
462+
// StringBuffer result = new StringBuffer ();
463+
// StringBuffer result2 = new StringBuffer ();
464+
char[] result = new char[0];
465+
char[] result2 = new char[0];
461466
char [] buffer = new char [length];
462467
string.getChars (0, string.length (), buffer, 0);
463468
int index = 0, state = 0, linkIndex = 0;
@@ -508,21 +513,28 @@ String parse (String string, Object handle) {
508513
case 6:
509514
if (c == '>') {
510515
mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result, result2, handle);
511-
int offset = result.length ();
516+
// int offset = result.length ();
517+
int offset = result.length;
512518
Element anchor = null;
513519
if (handle != null) {
514520
anchor = document.createElement("A");
515521
el.appendChild(anchor);
516522
anchors[anchors.length] = anchor;
517523
}
518524
parseMnemonics (buffer, linkStart, endtagStart, result, result2, anchor);
519-
offsets [linkIndex] = new Point (offset, result.length () - 1);
525+
// offsets [linkIndex] = new Point (offset, result.length () - 1);
526+
offsets [linkIndex] = new Point (offset, result.length - 1);
520527
if (ids [linkIndex] == null) {
521528
ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart);
522529
}
523530
if (anchor != null) {
524-
anchor.href = ids[linkIndex];
525-
anchor.target = "_blank";
531+
if ("#".equals(ids[linkIndex])) {
532+
anchor.href = "javascript:void(0);";
533+
anchor.target = "_self";
534+
} else {
535+
anchor.href = ids[linkIndex];
536+
anchor.target = "_blank";
537+
}
526538
String title = ids[linkIndex];
527539
if (title != null && title.length() > 0 && !title.startsWith("#")) {
528540
anchor.title = ids[linkIndex];
@@ -599,31 +611,47 @@ String parse (String string, Object handle) {
599611
System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1);
600612
mnemonics = newMnemonics;
601613
}
602-
cachedText = result2.toString();
614+
// cachedText = result2.toString();
615+
/**
616+
* @j2sNative
617+
* this.cachedText = result2.join ('');
618+
*/ {}
603619
if (anchors != null && anchors.length > 0 && (hooks(SWT.Selection) || hooks(SWT.DefaultSelection))) {
604620
hookSelection();
605621
}
622+
/**
623+
* @j2sNative
624+
* return result.join ('');
625+
*/ {}
606626
return result.toString ();
607627
}
608628

609-
int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, StringBuffer result2, Object handle) {
629+
//int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, StringBuffer result2, Object handle) {
630+
int parseMnemonics (char[] buffer, int start, int end, char[] result, char[] result2, Object handle) {
610631
Element el = (Element) handle;
611632
int mnemonic = -1, index = start;
612-
int lastIndex = result.length();
633+
// int lastIndex = result.length();
634+
int lastIndex = result.length;
613635
while (index < end) {
614636
char c = buffer [index];
615-
result2.append(c);
637+
// result2.append(c);
638+
result2[result2.length] = c;
616639
if (c == '&') {
617640
if (index + 1 < end && buffer [index + 1] == '&') {
618-
result.append (c);
641+
// result.append (c);
642+
result[result.length] = c;
619643
index++;
620644
} else {
621-
mnemonic = result.length();
645+
// mnemonic = result.length();
646+
mnemonic = result.length;
622647
if (el != null) {
623648
if ((mnemonic > lastIndex) && (el != null)) {
624649
int len = mnemonic - lastIndex;
625650
char[] cs = new char[len];
626-
result.getChars(lastIndex, mnemonic, cs, 0);
651+
// result.getChars(lastIndex, mnemonic, cs, 0);
652+
for (int i = 0; i < cs.length; i++) {
653+
cs[i] = result[lastIndex + i];
654+
}
627655
String s = new String(cs, 0, len);
628656
el.appendChild(document.createTextNode(s));
629657
}
@@ -634,12 +662,14 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, Stri
634662
}
635663
}
636664
} else {
637-
result.append (c);
665+
// result.append (c);
666+
result[result.length] = c;
638667
}
639668
boolean lineBreak = false;
640669
if (c == '\r') {
641670
if (index + 1 < end && buffer [index + 1] == '\n') {
642-
result.append ('\n');
671+
// result.append ('\n');
672+
result[result.length] = '\n';
643673
index++;
644674
}
645675
lineBreak = true;
@@ -648,11 +678,15 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, Stri
648678
lineBreak = true;
649679
}
650680
if (lineBreak && el != null) {
651-
int idx = result.length();
681+
// int idx = result.length();
682+
int idx = result.length;
652683
if (idx > lastIndex) {
653684
int len = idx - lastIndex;
654685
char[] cs = new char[len];
655-
result.getChars(lastIndex, idx, cs, 0);
686+
// result.getChars(lastIndex, idx, cs, 0);
687+
for (int i = 0; i < cs.length; i++) {
688+
cs[i] = result[lastIndex + i];
689+
}
656690
String s = new String(cs, 0, len);
657691
el.appendChild(document.createTextNode(s));
658692
}
@@ -661,11 +695,15 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuffer result, Stri
661695
}
662696
index++;
663697
}
664-
int idx = result.length();
698+
// int idx = result.length();
699+
int idx = result.length;
665700
if (idx > lastIndex && el != null) {
666701
int len = idx - lastIndex;
667702
char[] cs = new char[len];
668-
result.getChars(lastIndex, idx, cs, 0);
703+
// result.getChars(lastIndex, idx, cs, 0);
704+
for (int i = 0; i < cs.length; i++) {
705+
cs[i] = result[lastIndex + i];
706+
}
669707
String s = new String(cs, 0, len);
670708
el.appendChild(document.createTextNode(s));
671709
}
@@ -833,10 +871,16 @@ public void setText (String string) {
833871

834872
void unhookSelection() {
835873
for (int i = 0; i < anchors.length; i++) {
836-
anchors[i].onclick = null;
837-
anchors[i].ondblclick = null;
838-
anchors[i].href = ids[i];
839-
anchors[i].target = "_blank";
874+
Element anchor = anchors[i];
875+
anchor.onclick = null;
876+
anchor.ondblclick = null;
877+
if ("#".equals(ids[i])) {
878+
anchor.href = "javascript:void(0);";
879+
anchor.target = "_self";
880+
} else {
881+
anchor.href = ids[i];
882+
anchor.target = "_blank";
883+
}
840884
}
841885
}
842886

0 commit comments

Comments
 (0)