Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c45b6f9

Browse files
committed
Optimize for mobile web browsers
1 parent 73989b6 commit c45b6f9

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ResizeHandler(Decorations shell, int status) {
3838
this.status = status;
3939
}
4040

41-
private Rectangle getClientArea() {
41+
public Rectangle getClientArea() {
4242
int orientation = SWT.LEFT;
4343
int clientWidth = 0;
4444
int clientHeight = 0;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @author zhou renjian
2121
*
2222
* 2006-4-24
23+
* @j2sRequireImport org.eclipse.swt.internal.browser.OS
2324
* @j2sSuffix
2425
var $browserResizingHandle = null;
2526
$browserLayoutResize = function () {
@@ -33,6 +34,9 @@
3334
3435
if (document.addEventListener) {
3536
window.addEventListener('resize', $browserLayoutResize, true);
37+
if (O$.isMobile) {
38+
window.addEventListener('orientationchange', $browserLayoutResize, true);
39+
}
3640
} else if (document.attachEvent) {
3741
window.attachEvent('onresize', $browserLayoutResize);
3842
}

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.eclipse.swt.internal.xhtml.CSSStyle;
1919
import org.eclipse.swt.internal.xhtml.Element;
2020
import org.eclipse.swt.internal.xhtml.document;
21+
import org.eclipse.swt.internal.xhtml.window;
2122

2223
/**
2324
* @author zhou renjian
@@ -64,6 +65,11 @@ private OS() {
6465

6566
public static boolean isChrome30 = false;
6667

68+
public static boolean isMobile = false;
69+
70+
public static boolean isAndroid = false;
71+
72+
public static boolean isiOS = false;
6773

6874
/* Record Caps Lock status */
6975
public static boolean isCapsLockOn = false;
@@ -103,6 +109,31 @@ private OS() {
103109
os.isIE90 = os.isIE && dua.indexOf("MSIE 9.0")>=0;
104110
os.isIENeedPNGFix = os.isIE50 || os.isIE55 || os.isIE60;
105111
os.noReturnCallback = os.noReturnCallbackFunction;
112+
if (dua.match(/Android/i)
113+
|| dua.match(/webOS/i)
114+
|| dua.match(/iPhone/i)
115+
|| dua.match(/iPad/i)
116+
|| dua.match(/iPod/i)
117+
|| dua.match(/BlackBerry/i)
118+
|| dua.match(/Windows Phone/i)
119+
) {
120+
os.isMobile = true;
121+
} else {
122+
os.isMobile = false;
123+
}
124+
if (dua.match(/Android/i)) {
125+
os.isAndroid = true;
126+
} else {
127+
os.isAndroid = false;
128+
}
129+
if (dua.match(/iPhone/i)
130+
|| dua.match(/iPad/i)
131+
|| dua.match(/iPod/i)
132+
) {
133+
os.isiOS = true;
134+
} else {
135+
os.isiOS = false;
136+
}
106137
*/
107138
static {
108139

@@ -938,7 +969,11 @@ public static int getFixedBodyClientHeight() {
938969
Element p = b.parentNode;
939970
int bcHeight = b.clientHeight;
940971
int pcHeight = p.clientHeight;
941-
if (OS.isIE) { // && !OS.isOpera
972+
if (OS.isMobile) {
973+
int height = (pcHeight == p.offsetHeight
974+
&& pcHeight == p.scrollHeight) ? bcHeight : pcHeight;
975+
return Math.max(window.innerHeight, height);
976+
} else if (OS.isIE) { // && !OS.isOpera
942977
return (pcHeight == 0) ? bcHeight : pcHeight;
943978
} else if (OS.isFirefox || OS.isSafari) {
944979
return (pcHeight == p.offsetHeight

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/xhtml/window.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public class window {
1010
public static int clientWidth;
1111
public static int clientHeight;
1212

13+
public static int innerWidth; // IE9+
14+
public static int innerHeight; // IE9+
15+
1316
public static Screen screen;
1417
public static History history;
1518

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void createHandle() {
505505
if (OS.isChrome) {
506506
btnHandle.className += " " + btnHandle.className + "-chrome";
507507
} else if (OS.isSafari) {
508-
boolean isSafari4Plus = false;
508+
boolean isSafari4Plus = true;
509509
/**
510510
* @j2sNative
511511
* var ua = navigator.userAgent;
@@ -514,7 +514,7 @@ void createHandle() {
514514
* var verStr = ua.substring (verIdx + 8);
515515
* var verNumber = parseFloat (verStr);
516516
* isSafari4Plus = verNumber >= 4.0
517-
* }
517+
* } // Google Chrome browser on iOS or Android does not have version number
518518
*/ {}
519519
if (!isSafari4Plus) { // There is no need of CSS hack for Safari 4.0+
520520
btnHandle.className += " " + btnHandle.className + "-safari";

0 commit comments

Comments
 (0)