Skip to content

Commit e4250eb

Browse files
author
zhourenjian
committed
Support Firefox's font-size changed events in Shell's title and menu bar
1 parent bb5100d commit e4250eb

File tree

8 files changed

+145
-28
lines changed

8 files changed

+145
-28
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.eclipse.swt.graphics.Point;
1818
import org.eclipse.swt.graphics.Rectangle;
1919
import org.eclipse.swt.internal.browser.OS;
20+
import org.eclipse.swt.internal.xhtml.Element;
2021
import org.eclipse.swt.internal.xhtml.document;
2122
import org.eclipse.swt.widgets.Decorations;
2223
import org.eclipse.swt.widgets.Monitor;
@@ -39,7 +40,13 @@ public ResizeHandler(Decorations shell, int status) {
3940
}
4041

4142
public void updateMinimized() {
42-
shell.setLocation(-1, shell.getMonitor().getClientArea().height - 26);
43+
Element tb = null;
44+
/**
45+
* @j2sNative
46+
* tb = this.shell.titleBar;
47+
*/ {}
48+
int h = ((shell.getStyle() & SWT.TITLE) != 0) ? OS.getContainerHeight(tb) : 0;
49+
shell.setLocation(-1, shell.getMonitor().getClientArea().height - h - 6);
4350
}
4451
public void updateMaximized() {
4552
Monitor monitor = shell.getMonitor();
@@ -55,7 +62,13 @@ public void updateMaximized() {
5562
width = document.body.parentNode.clientWidth;
5663
height = OS.getFixedBodyClientHeight();
5764
}
58-
int titleHeight = ((shell.getStyle() & SWT.TITLE) != 0) ? 20 : 0;
65+
//int titleHeight = ((shell.getStyle() & SWT.TITLE) != 0) ? 20 : 0;
66+
Element tb = null;
67+
/**
68+
* @j2sNative
69+
* tb = this.shell.titleBar;
70+
*/ {}
71+
int titleHeight = ((shell.getStyle() & SWT.TITLE) != 0) ? OS.getContainerHeight(tb) : 0;
5972
// FIXME: maximized size is not accurate
6073
//shell.setBounds(shell.computeTrim(0, 0, width + 4, height - titleHeight + 6));
6174
boolean isOptMaximized = false;
@@ -72,10 +85,17 @@ public void updateMaximized() {
7285
//shell.setBounds(shell.computeTrim(0, 0, width + 2, height - 18));
7386
}
7487
public void updateCentered() {
88+
Element tb = null;
89+
/**
90+
* @j2sNative
91+
* tb = this.shell.titleBar;
92+
*/ {}
93+
int h = ((shell.getStyle() & SWT.TITLE) != 0) ? OS.getContainerHeight(tb) : 0;
94+
7595
// Not used now
7696
Monitor monitor = shell.getMonitor();
7797
Point size = shell.getSize();
78-
int y = (monitor.getClientArea().height - size.y) / 2 - 20;
98+
int y = (monitor.getClientArea().height - size.y) / 2 - h;
7999
if (y < 0) {
80100
y = 0;
81101
}

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

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class Decorations extends Canvas {
120120
Control savedFocus;
121121
Button defaultButton, saveDefault;
122122
//int swFlags, hAccel, nAccel;
123-
boolean moved, resized, opened;
123+
boolean moved, resized, opened, maximized, minimized;
124124
//int oldX = OS.CW_USEDEFAULT, oldY = OS.CW_USEDEFAULT;
125125
//int oldWidth = OS.CW_USEDEFAULT, oldHeight = OS.CW_USEDEFAULT;
126126
Element contentHandle;
@@ -135,8 +135,8 @@ public class Decorations extends Canvas {
135135
private Element shellMin;
136136
private Element shellMax;
137137
private Element shellIcon;
138-
private Element titleBar;
139138
private Element shellClose;
139+
Element titleBar;
140140
Element shellMenuBar;
141141
Element shellToolBar;
142142

@@ -383,7 +383,8 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
383383
checkWidget ();
384384
if ((style & SWT.NO_TRIM) == 0) {
385385
if ((style & (SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX)) != 0) {
386-
height += 20;
386+
//height += 20;
387+
height += OS.getContainerHeight(titleBar);
387388
if (width < 105) {
388389
width = 105;
389390
}
@@ -718,16 +719,21 @@ void addModalLayer() {
718719
* TODO: Move this function into external *.js
719720
* @xj2sIgnore
720721
*/
721-
void exportHTMLSource() {
722+
void exportHTMLSource(boolean onlyContent) {
722723
final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
723724
// shell.setLayout(new FillLayout());
724725
shell.setText("Export HTML Source");
725-
String b = contentHandle.innerHTML; // always be "b" for "@j2sNative/Src"
726+
String c = null; // always be "b" for "@j2sNative/Src"
727+
if (onlyContent) {
728+
c = contentHandle.innerHTML;
729+
} else {
730+
c = handle.innerHTML;
731+
}
726732
//b.replaceAll("(<\\/?)(\\w+)(\\s|>)", "$0$1$2");
727733
if (OS.isIE)
728734
/**
729735
* @j2sNative
730-
b = b.replace (/(<\/?)(\w+)(\s|>)/ig, function ($0, $1, $2, $3) {
736+
c = c.replace (/(<\/?)(\w+)(\s|>)/ig, function ($0, $1, $2, $3) {
731737
return $1 + $2.toLowerCase () + $3;
732738
}).replace (/(style\s*=\s*")([^"]+)(")/ig, function ($0, $1, $2, $3) {
733739
if (!((/;$/).test ($2))) {
@@ -743,13 +749,13 @@ void exportHTMLSource() {
743749
*/ {} else
744750
/**
745751
* @j2sNative
746-
b = b.replace (/(style\s*=\s*")([^"]+)(")/ig, function ($0, $1, $2, $3) {
752+
c = c.replace (/(style\s*=\s*")([^"]+)(")/ig, function ($0, $1, $2, $3) {
747753
return "style=\"" + $2.replace (/(:|;)\s+/g, "$1") + "\"";
748754
});
749755
*/ {}
750756
/**
751757
* @j2sNative
752-
b = b.replace (/(\sclass\s*=\s*)"([^"]*)"(\s|>)/ig, function ($0, $1, $2, $3) {
758+
c = c.replace (/(\sclass\s*=\s*)"([^"]*)"(\s|>)/ig, function ($0, $1, $2, $3) {
753759
$2 = $2.replace (/\s\s+/g, ' ').replace (/^\s+/, '').replace (/\s+$/g, '');
754760
if ($2.length == 0) {
755761
if ($3 != ">") {
@@ -779,9 +785,23 @@ void exportHTMLSource() {
779785
gd.heightHint = 275;
780786
text.setLayoutData(gd);
781787
Rectangle rect = getClientArea();
782-
String html = "<div class=\"shell-content\" style=\"" + "width:"
783-
+ rect.width + "px;height:" + rect.height + "px;\">" + b
788+
String html = null;
789+
if (onlyContent) {
790+
html = "<div class=\"shell-content\" style=\"" + "width:"
791+
+ rect.width + "px;height:" + rect.height + "px;\">" + c
784792
+ "</div>";
793+
} else {
794+
String cssText = handle.style.cssText;
795+
if (cssText != null && cssText.trim().length() != 0)
796+
/**
797+
* @j2sNative
798+
* cssText = cssText.replace (/([;\s]*)(top|left|right|bottom)\s*:\s*[^;"']*([;"'])/i, "$3").replace (/([;\s]*)(top|left|right|bottom)\s*:\s*[^;"']*([;"'])/i, "$3");
799+
*/ {}
800+
html = "<div class=\"" + handle.className + "\"" +
801+
((cssText != null && cssText.trim().length() != 0) ?
802+
" style=\"" + cssText + "\"" : "") +
803+
">" + c + "</div>";
804+
}
785805
text.setText(html);
786806
new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR)
787807
.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -956,15 +976,17 @@ public Rectangle getClientArea () {
956976
int w = width;
957977
int h = height;
958978
if ((style & (SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX)) != 0) {
959-
h -= 20;
979+
//h -= 20;
980+
h -= OS.getContainerHeight(titleBar);
960981
w -= 8;
961982
h -= 8;
962983
if ((style & SWT.BORDER) != 0) {
963984
w -= 4;
964985
h -= 4;
965986
}
966987
if (OS.existedCSSClass(handle, "shell-menu-bar")) {
967-
h -= 21;
988+
//h -= 21;
989+
h -= 1 + OS.getContainerHeight(shellMenuBar);
968990
}
969991
}
970992
return new Rectangle(0, 0, w, h);
@@ -1146,7 +1168,7 @@ public boolean getMinimized () {
11461168
* return this.handle.style.display == "none";
11471169
* }
11481170
*/ {}
1149-
return false; // TODO
1171+
return this.minimized; // TODO
11501172
}
11511173

11521174
String getNameText () {
@@ -1169,7 +1191,11 @@ public Point getSize () {
11691191
return super.getSize ();
11701192
*/
11711193
Point size = super.getSize();
1172-
size.y += 26;
1194+
//size.y += 26;
1195+
size.y += 6;
1196+
if (titleBar != null) {
1197+
size.y += OS.getContainerHeight(titleBar);
1198+
}
11731199
return size;
11741200
}
11751201

@@ -1663,6 +1689,7 @@ public void setMaximized (boolean maximized) {
16631689
OS.UpdateWindow (handle);
16641690
}
16651691
*/
1692+
this.maximized = maximized;
16661693
String key = "shell-maximized";
16671694
Element b = document.body;
16681695
boolean isStrictMode = b.parentNode.clientHeight != 0;
@@ -1712,7 +1739,8 @@ public void setMaximized (boolean maximized) {
17121739
width = document.body.parentNode.clientWidth;
17131740
height = OS.getFixedBodyClientHeight();
17141741
}
1715-
int titleHeight = ((style & SWT.TITLE) != 0) ? 20 : 0;
1742+
//int titleHeight = ((style & SWT.TITLE) != 0) ? 20 : 0;
1743+
int titleHeight = ((style & SWT.TITLE) != 0) ? OS.getContainerHeight(titleBar) : 0;
17161744
boolean isOptMaximized = false;
17171745
/**
17181746
* @j2sNative
@@ -1871,6 +1899,13 @@ public void setMinimized (boolean minimized) {
18711899
OS.ShowWindow (handle, flags);
18721900
OS.UpdateWindow (handle);
18731901
*/
1902+
this.minimized = minimized;
1903+
if (this.minimized && !minimized) {
1904+
if (this.maximized) {
1905+
this.setMaximized(true);
1906+
return;
1907+
}
1908+
}
18741909
/**
18751910
* @j2sNative
18761911
* if (window["ShellManager"] != null && this.parent == null && minimized) {
@@ -1888,7 +1923,8 @@ public void setMinimized (boolean minimized) {
18881923
if (width < 200) {
18891924
width = 200;
18901925
}
1891-
setBounds(-1, getMonitor().clientHeight - 26, 120, 0);
1926+
//setBounds(-1, getMonitor().clientHeight - 26, 120, 0);
1927+
setBounds(-1, getMonitor().clientHeight - 6 - (titleBar != null ? OS.getContainerHeight(titleBar) : 0), 120, 0);
18921928
}
18931929
if (minimized) {
18941930
ResizeSystem.register(this, SWT.MIN);
@@ -2031,7 +2067,8 @@ void setSystemMenu () {
20312067
// */ {
20322068
shellIcon.onclick = new RunnableCompatibility() {
20332069
public void run() {
2034-
exportHTMLSource();
2070+
HTMLEvent e = (HTMLEvent)getEvent();
2071+
exportHTMLSource(e == null || !e.ctrlKey);
20352072
}
20362073
};
20372074
// }
@@ -2259,7 +2296,8 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
22592296
int h = 0;
22602297
if ((style & (SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX)) != 0) {
22612298
w = 113;
2262-
h = 28;
2299+
//h = 28;
2300+
h = 8 + OS.getContainerHeight(titleBar);
22632301
}
22642302
if ((style & SWT.BORDER) != 0) {
22652303
w += 2;
@@ -2279,16 +2317,27 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
22792317
contentHandle.style.width = width + "px";
22802318
} else if (titleBar != null) {
22812319
int dw = 8;
2282-
int dh = 28;
2320+
//int dh = 28;
2321+
int tbh = OS.getContainerHeight(titleBar);
2322+
int dh = 8 + tbh;
22832323
int dww = 8;
22842324
if ((style & SWT.BORDER) != 0) {
22852325
dw += 2;
22862326
dh += 3;
22872327
dww += 2;
22882328
}
22892329
if (OS.existedCSSClass(handle, "shell-menu-bar")) {
2290-
dh += 21;
2330+
shellMenuBar.style.top = (3 + tbh) + "px";
2331+
int mbh = OS.getContainerHeight(shellMenuBar);
2332+
if (mbh < 20) {
2333+
mbh = tbh - 2;
2334+
}
2335+
// dh += 21;
2336+
// tbh += 21;
2337+
dh += mbh + 1;
2338+
tbh += mbh + 1;
22912339
}
2340+
contentHandle.style.top = (3 + tbh) + "px";
22922341
contentHandle.style.height = ((height - dh >= 0) ? height - dh : 0) + "px";
22932342
contentHandle.style.width = ((width - dw) > 0 ? width - dw : 0) + "px";
22942343
titleBar.style.width = ((width - dww) > 0 ? width - dww : 0) + "px";

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,13 +4325,39 @@ static void updateAllShellLayouts() {
43254325
if (Displays != null) {
43264326
for (int i = 0; i < Displays.length; i++) {
43274327
if (Displays[i] != null && !Displays[i].isDisposed()) {
4328+
boolean isOptMaximized = false;
4329+
boolean existedMaximized = false;
4330+
/**
4331+
* @j2sNative
4332+
* isOptMaximized = window["ShellManager"] != null;
4333+
*/ {}
43284334
Shell[] shells = Displays[i].getShells();
43294335
for (int j = 0; j < shells.length; j++) {
43304336
Shell shell = shells[j];
43314337
if (shell != null && !shell.isDisposed()) {
4338+
if ((shell.style & (SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX)) != 0) {
4339+
Rectangle bounds = shell.getBounds();
4340+
if (isOptMaximized && shell.getMaximized() && shell.titleBar != null) {
4341+
shell.setMaximized(true);
4342+
existedMaximized = true;
4343+
continue;
4344+
} else {
4345+
shell.SetWindowPos(shell.handle, null, bounds.x, bounds.y,
4346+
bounds.width, bounds.height, 0);
4347+
}
4348+
}
43324349
shell.layout(true, true);
43334350
}
43344351
}
4352+
if (isOptMaximized && existedMaximized)
4353+
/**
4354+
* @j2sNative
4355+
* if (ShellManager.topbarContainerEl.style.display != "none") {
4356+
* ShellManager.returnTopMaximized ();
4357+
* ShellManager.updateTopMaximized ();
4358+
* }
4359+
*/
4360+
{ }
43354361
}
43364362
}
43374363
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
margin:0 2px 0 1px;
1818
padding:2px;
1919
height:13px;
20+
height:1.5em;
2021
}
2122
.menu-item-enable-image {
2223
height:18px;
@@ -250,6 +251,7 @@
250251
padding:4px 0;
251252
z-index:9;
252253
margin:1px 2px;
254+
min-height:16px;
253255
}
254256
.menu-bar-item {
255257
display:inline;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ void createHandle () {
379379
if ((style & SWT.BAR) != 0) {
380380
handle.className = "menu-bar";
381381
OS.addCSSClass(parent.handle, "shell-menu-bar");
382-
handle.style.top = "23px";
382+
int top = 3;
383+
if (parent.titleBar != null) {
384+
top = 3 + OS.getContainerHeight(parent.titleBar);
385+
}
386+
handle.style.top = top + "px";
383387
parent.handle.appendChild(handle);
384388
parent.shellMenuBar = handle;
385389
} else {

0 commit comments

Comments
 (0)