Skip to content

Commit 0be6177

Browse files
hansohanso
authored andcommitted
several fixes
Menu issues with touch Frame closing doesn't work with touch JSHTMLHelper doesn't check for node having [0] element PT approx() should leave 0 as 0, not -0
1 parent adf91c0 commit 0be6177

File tree

8 files changed

+133
-37
lines changed

8 files changed

+133
-37
lines changed
1005 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/javajs/util/PT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ public static String getQuotedAttribute(String info, String name) {
372372
}
373373

374374
public static double approxD(double f, double n) {
375-
return Math.round (f * n) / n;
375+
f = Math.round (f * n) / n;
376+
return (f == 0 ? 0 : f);// removing -0 values
376377
}
377378

378379
/**
@@ -1772,7 +1773,8 @@ public static String formatF(float value, int width, int precision,
17721773
}
17731774

17741775
public static float approx(float f, int n) {
1775-
return Math.round (f * n) / n;
1776+
f = Math.round (f * n) / n;
1777+
return (f == 0 ? 0 : f);// removing -0 values
17761778
}
17771779

17781780
/**

sources/net.sf.j2s.java.core/src/swingjs/JSHTMLHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public String getText() {
7979
public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
8080
EventType type = null;
8181
JQueryObject node = JSUtil.jQuery.$(/** @j2sNative jQueryEvent.target ||*/ null).closest("a");
82-
String href = /** @j2sNative node && node[0].href || */
82+
String href = /** @j2sNative target.id && target.id.indexOf("Menu" < 0) && node && node[0] && node[0].href || */
8383
null;
8484
if (href == null)
8585
return JSComponentUI.HANDLED;

sources/net.sf.j2s.java.core/src/swingjs/jquery/j2sMenu.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ J2S.__makeMenu = function(){};
217217
// adds role=xxxx
218218
me.refresh("_openSubmenu",n);
219219
// adds mouse binding to role=menuitem
220-
ensureMouseSet(ui.menu, li);
220+
ensureMouseSet(ui.popupMenu, li);
221221
var v = me.element.find(".ui-j2smenu").not(t.parents(".ui-j2smenu"));
222222
doCmd("_hide", me, v);
223223
try {
@@ -287,6 +287,7 @@ J2S.__makeMenu = function(){};
287287
}
288288
break;
289289
case "collapseAll":
290+
return; // fails for Tracker touch
290291
if (me.closed || me.clickoutDisabled) {
291292
return;
292293
}
@@ -388,7 +389,7 @@ J2S.__makeMenu = function(){};
388389
$.widget("ui.j2smenu",{
389390
version:"1.9.2",
390391
defaultElement:"<ul>",
391-
delay:30,
392+
delay:300,
392393
options:{icons:{submenu:"ui-icon-carat-1-e"},
393394
menus:"ul",
394395
position:{my:"left top",at:"right top"},
@@ -406,8 +407,8 @@ $.widget("ui.j2smenu",{
406407

407408
this.closed = false;
408409

409-
if (typeof this.options.delay == "number")
410-
this.delay = this.options.delay;
410+
// if (typeof this.options.delay == "number")
411+
// this.delay = this.options.delay;
411412

412413
this.activeMenu=this.element,
413414
this.element.uniqueId().addClass("ui-j2smenu ui-widget ui-widget-content ui-corner-all")
@@ -632,9 +633,13 @@ var ensureMouseSet = function(menu, node) {
632633

633634
var setMouseMenuItem = function(menu, node) {
634635
J2S.unsetMouse(node);
636+
node._menu = menu;
637+
node.applet = menu._applet;
638+
while (!node.applet && menu.invoker.parent != null) {
639+
menu = menu.invoker.parent;
635640
node.applet = menu._applet;
641+
}
636642
node._frameViewer = menu.invoker.getFrameViewer$();
637-
node._menu = menu;
638643
J2S.setMouse(node, true);
639644
}
640645

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
282282
switch (/** @j2sNative jQueryEvent.type || */
283283
"") {
284284
case "click":
285+
case "pointerup":
286+
case "mouseup":
285287
frameCloserAction();
286288
return HANDLED;
287289
case "pointerout":

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSWindowUI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ protected void bindWindowEvents() {
219219
setJ2sMouseHandler();
220220
setDraggableEvents();
221221
addJQueryFocusCallbacks();
222+
// pointerup is more reliable than click
222223
if (closerNode != null)
223-
bindJQueryEvents(closerNode, "click mouseenter mouseout", SOME_MOUSE_EVENT);
224+
bindJQueryEvents(closerNode, "click pointerup pointerenter pointerout mouseup mouseenter mouseout", SOME_MOUSE_EVENT);
224225
}
225226

226227
protected void setDraggableEvents() {

sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// j2sApplet.js BH = Bob Hanson hansonr@stolaf.edu
22

3+
// BH 2023.11.01 adds pointerup, pointerdown, and pointermove to J2S.setMouse
4+
// BH 2023.11.01 allows null applet in J2S.setMouse (?? should it ever be null?)
35
// BH 2023.02.04 adds support for file load cancel
46
// BH 2023.01.10 j2sargs typo
57
// BH 2022.08.27 fix frame resizing for browsers reporting noninteger pageX, pageY
@@ -1741,11 +1743,11 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
17411743
J2S._haveMouse;
17421744
J2S._firstTouch; // three-position switch: undefined, true, false
17431745

1744-
J2S.$bind('body', 'mousedown mousemove mouseup', function(ev) {
1746+
J2S.$bind('body', 'pointerdown pointermove mousedown mousemove mouseup', function(ev) {
17451747
J2S._haveMouse = true;
17461748
});
17471749

1748-
J2S.$bind('body', 'mouseup touchend', function(ev) {
1750+
J2S.$bind('body', 'pointerup mouseup touchend', function(ev) {
17491751
mouseUp(null, ev);
17501752
return true;
17511753
});
@@ -1779,6 +1781,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
17791781
};
17801782

17811783
var mouseEnter = function(who, ev) {
1784+
if (who.applet == null)
1785+
return;
17821786
if (J2S._traceMouse)
17831787
J2S.traceMouse(who,"ENTER", ev);
17841788

@@ -1798,6 +1802,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
17981802

17991803
var mouseDown = function(who, ev) {
18001804

1805+
if (who.applet == null)
1806+
return;
18011807
if (J2S._traceMouse)
18021808
J2S.traceMouse(who,"DOWN", ev);
18031809

@@ -1838,6 +1844,9 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
18381844
// J2S.setWindowZIndex(who._frameViewer.top.ui.domNode,
18391845
// Integer.MAX_VALUE);
18401846
who.applet._processEvent(501, xym, ev, who._frameViewer); // MouseEvent.MOUSE_PRESSED
1847+
1848+
1849+
who.isDown = true;
18411850
}
18421851

18431852
return !!(ui || target);
@@ -1848,6 +1857,9 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
18481857
var mouseMove = function(who, ev) {
18491858
// ignore touchmove if J2S._haveMouse
18501859

1860+
if (who.applet == null)
1861+
return;
1862+
18511863
if (ev.type == "touchmove" &&
18521864
(J2S._firstTouch || J2S._haveMouse)) {
18531865
return;
@@ -1883,6 +1895,9 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
18831895
}
18841896

18851897
var mouseUp = function(who, ev) {
1898+
who.isDown = false;
1899+
if (who.applet == null)
1900+
return;
18861901
if (J2S._traceMouse)
18871902
J2S.traceMouse(who,"UP", ev);
18881903

@@ -1926,6 +1941,21 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
19261941
}
19271942

19281943
var mouseClick = function(who, ev) {
1944+
1945+
if (who.applet == null) {
1946+
who.isDown = false;
1947+
return;
1948+
}
1949+
1950+
if (who.isDown) {
1951+
// this may happen with a pointer. In this case
1952+
// we have to generate the down first.
1953+
ev.type = "pointerup";
1954+
mouseUp(who, ev);
1955+
ev.type = "click";
1956+
ev.originalEvent.xhandled = false;
1957+
}
1958+
19291959
if (J2S._traceMouse)
19301960
J2S.traceMouse(who,"CLICK", ev);
19311961

@@ -1945,6 +1975,9 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
19451975

19461976
var mouseWheel = function(who, ev) {
19471977

1978+
if (who.applet == null) {
1979+
return;
1980+
}
19481981
// Zoom
19491982
// not for wheel event, or action will not take place on handle and
19501983
// track
@@ -1979,6 +2012,9 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
19792012
}
19802013

19812014
var mouseLeave = function(who, ev) {
2015+
if (who.applet == null) {
2016+
return;
2017+
}
19822018
if (J2S._traceMouse)
19832019
J2S.traceMouse(who,"OUT", ev);
19842020

@@ -2019,22 +2055,22 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
20192055
// swingjs.api.J2SInterface
20202056

20212057

2022-
J2S.$bind(who, (J2S._haveMouse ? 'mousemove' : 'mousemove touchmove'),
2058+
J2S.$bind(who, (J2S._haveMouse ? 'mousemove pointermove' : 'pointermove mousemove touchmove'),
20232059
function(ev) { return mouseMove(who, ev) });
20242060

20252061
J2S.$bind(who, 'click', function(ev) { return mouseClick(who, ev) });
20262062

20272063
J2S.$bind(who, 'DOMMouseScroll mousewheel', function(ev) { return mouseWheel(who, ev) });
20282064

2029-
J2S.$bind(who, (J2S._haveMouse ? 'mousedown' : 'mousedown touchstart'),
2065+
J2S.$bind(who, (J2S._haveMouse ? 'mousedown pointerdown' : 'pointerdown mousedown touchstart'),
20302066
function(ev) { return mouseDown(who, ev) });
20312067

2032-
J2S.$bind(who, (J2S._haveMouse ? 'mouseup' : 'mouseup touchend'),
2068+
J2S.$bind(who, (J2S._haveMouse ? 'mouseup pointerup' : 'pointerup mouseup touchend'),
20332069
function(ev) { return mouseUp(who, ev) });
20342070

2035-
J2S.$bind(who, 'mouseenter', function(ev) { return mouseEnter(who, ev) });
2071+
J2S.$bind(who, 'pointerenter mouseenter', function(ev) { return mouseEnter(who, ev) });
20362072

2037-
J2S.$bind(who, 'mouseleave', function(ev) { return mouseLeave(who, ev) });
2073+
J2S.$bind(who, 'pointerout mouseleave', function(ev) { return mouseLeave(who, ev) });
20382074

20392075
// context menu is fired on mouse down, not up, and it's handled already
20402076
// anyway.
@@ -2047,7 +2083,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
20472083
J2S.$bind(who, 'mouseupoutjsmol',
20482084
function(evspecial, target, ev) { return mouseUpOut(who, ev) });
20492085

2050-
if (who.applet._is2D && !who.applet._isApp) {
2086+
if (who.applet && who.applet._is2D && !who.applet._isApp) {
20512087
J2S.$resize(function() {
20522088
if (!who.applet)
20532089
return;
@@ -2064,7 +2100,13 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
20642100
who.applet = null;
20652101
who._frameViewer = null;
20662102
J2S.$bind(who,
2067-
'mouseupoutjsmol click mousedown touchstart mousemove touchmove mouseup touchend DOMMouseScroll mousewheel contextmenu mouseleave mouseenter mousemoveoutjsmol',
2103+
'mouseupoutjsmol click touchoutjsmol pointerupoutjsmol '
2104+
+'mousedown pointerdown touchstart '
2105+
+'mousemove touchmove pointermove '
2106+
+'mouseup pointerup touchend '
2107+
+'DOMMouseScroll mousewheel contextmenu '
2108+
+'mouseleave mouseenter mousemoveoutjsmol '
2109+
+'pointerout pointerenter pointermoveoutjsmol ',
20682110
null);
20692111
J2S.setMouseOwner(null);
20702112
}
@@ -3080,14 +3122,15 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
30803122
$tag.unbind('touchmoveoutjsmol');
30813123
$tag.unbind('mouseupoutjsmol');
30823124
$tag.unbind('touchendoutjsmol');
3125+
$tag.unbind('pointeroutjsmol');
30833126
J2S._dmouseOwner = null;
30843127
tag.isDragging = false;
30853128
tag._isDragger = false;
30863129
if (isBind) {
3087-
$tag.bind('mousemoveoutjsmol touchmoveoutjsmol', function(ev) {
3130+
$tag.bind('mousemoveoutjsmol pointeroutjsmol touchmoveoutjsmol', function(ev) {
30883131
drag && drag(ev);
30893132
});
3090-
$tag.bind('mouseupoutjsmol touchendoutjsmol', function(ev) {
3133+
$tag.bind('mouseupoutjsmol pointeroutjsmol touchendoutjsmol', function(ev) {
30913134
up && up(ev);
30923135
});
30933136
}
@@ -3210,15 +3253,15 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
32103253
return ev;
32113254
}
32123255

3213-
$tag.bind('mousedown touchstart', function(ev) {
3256+
$tag.bind('pointerdown mousedown touchstart', function(ev) {
32143257
return down && down(fixTouch(ev));
32153258
});
32163259

3217-
$tag.bind('mousemove touchmove', function(ev) {
3260+
$tag.bind('pointermove mousemove touchmove', function(ev) {
32183261
return drag && drag(fixTouch(ev));
32193262
});
32203263

3221-
$tag.bind('mouseup touchend', function(ev) {
3264+
$tag.bind('pointerup mouseup touchend', function(ev) {
32223265
// touchend does not express a position, and we don't use it anyway
32233266
return up && up(ev);
32243267
});

0 commit comments

Comments
 (0)