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