@@ -12,9 +12,10 @@ var LibraryHTML5 = {
12
12
] ,
13
13
$JSEvents : {
14
14
15
- /* We do not depend on the exact initial values of falsey member fields - these fields can be populated on-demand
16
- to save code size.
15
+ /* We do not depend on the exact initial values of falsey member fields - these
16
+ fields can be populated on-demand to save code size.
17
17
(but still documented here to keep track of what is supposed to be present)
18
+
18
19
// pointers to structs malloc()ed to Emscripten HEAP for JS->C interop.
19
20
keyEvent: 0,
20
21
mouseEvent: 0,
@@ -28,42 +29,41 @@ var LibraryHTML5 = {
28
29
visibilityChangeEvent: 0,
29
30
touchEvent: 0,
30
31
31
- // When we transition from fullscreen to windowed mode, we remember here the element that was just in fullscreen mode
32
- // so that we can report information about that element in the event message.
32
+ // When we transition from fullscreen to windowed mode, we remember here the
33
+ // element that was just in fullscreen mode so that we can report
34
+ // information about that element in the event message.
33
35
previousFullscreenElement: null,
34
36
35
37
#if MIN_SAFARI_VERSION <= 80000 || MIN_CHROME_VERSION <= 21 // https://caniuse.com/#search=movementX
36
- // Remember the current mouse coordinates in case we need to emulate movementXY generation for browsers that don't support it.
38
+ // Remember the current mouse coordinates in case we need to emulate
39
+ // movementXY generation for browsers that don't support it.
37
40
// Some browsers (e.g. Safari 6.0.5) only give movementXY when Pointerlock is active.
38
41
previousScreenX: null,
39
42
previousScreenY: null,
40
43
#endif
41
44
42
- // When the C runtime exits via exit(), we unregister all event handlers added by this library to be nice and clean.
45
+ // When the C runtime exits via exit(), we unregister all event handlers
46
+ // added by this library to be nice and clean.
43
47
// Track in this field whether we have yet registered that __ATEXIT__ handler.
44
48
removeEventListenersRegistered: false,
45
49
46
50
#if HTML5_SUPPORT_DEFERRING_USER_SENSITIVE_REQUESTS
47
- // If we are in an event handler, specifies the event handler object from the eventHandlers array that is currently running.
51
+ // If we are in an event handler, specifies the event handler object from
52
+ // the eventHandlers array that is currently running.
48
53
currentEventHandler: null,
49
54
#endif
50
55
*/
51
56
52
- // If positive, we are currently executing in a JS event handler.
53
- // (this particular property must be initialized to zero, as we ++/-- it)
54
- inEventHandler : 0 ,
55
-
56
57
removeAllEventListeners ( ) {
57
- for ( var i = JSEvents . eventHandlers . length - 1 ; i >= 0 ; -- i ) {
58
- JSEvents . _removeHandler ( i ) ;
58
+ while ( JSEvents . eventHandlers . length ) {
59
+ JSEvents . _removeHandler ( JSEvents . eventHandlers . length - 1 ) ;
59
60
}
60
- JSEvents . eventHandlers = [ ] ;
61
61
#if HTML5_SUPPORT_DEFERRING_USER_SENSITIVE_REQUESTS
62
62
JSEvents . deferredCalls = [ ] ;
63
63
#endif
64
64
} ,
65
65
66
- #if ! MINIMAL_RUNTIME || EXIT_RUNTIME // In minimal runtime, there is no concept of the page running vs being closed, and hence __ATEXIT__ is not present
66
+ #if EXIT_RUNTIME
67
67
registerRemoveEventListeners ( ) {
68
68
if ( ! JSEvents . removeEventListenersRegistered ) {
69
69
__ATEXIT__ . push ( JSEvents . removeAllEventListeners ) ;
@@ -73,6 +73,10 @@ var LibraryHTML5 = {
73
73
#endif
74
74
75
75
#if HTML5_SUPPORT_DEFERRING_USER_SENSITIVE_REQUESTS
76
+ // If positive, we are currently executing in a JS event handler.
77
+ // (this particular property must be initialized to zero, as we ++/-- it)
78
+ inEventHandler : 0 ,
79
+
76
80
deferredCalls : [ ] ,
77
81
78
82
// Queues the given function call to occur the next time we enter an event handler.
@@ -170,29 +174,30 @@ var LibraryHTML5 = {
170
174
#endif
171
175
return { { { cDefs . EMSCRIPTEN_RESULT_UNKNOWN_TARGET } } } ;
172
176
}
173
- var jsEventHandler = function jsEventHandler ( event ) {
174
- #if HTML5_SUPPORT_DEFERRING_USER_SENSITIVE_REQUESTS
175
- // Increment nesting count for the event handler.
176
- ++ JSEvents . inEventHandler ;
177
- JSEvents . currentEventHandler = eventHandler ;
178
- // Process any old deferred calls the user has placed.
179
- JSEvents . runDeferredCalls ( ) ;
180
- #endif
181
- // Process the actual event, calls back to user C code handler.
182
- eventHandler . handlerFunc ( event ) ;
177
+ if ( eventHandler . callbackfunc ) {
183
178
#if HTML5_SUPPORT_DEFERRING_USER_SENSITIVE_REQUESTS
184
- // Process any new deferred calls that were placed right now from this event handler.
185
- JSEvents . runDeferredCalls ( ) ;
186
- // Out of event handler - restore nesting count.
187
- -- JSEvents . inEventHandler ;
179
+ eventHandler . eventListenerFunc = function ( event ) {
180
+ // Increment nesting count for the event handler.
181
+ ++ JSEvents . inEventHandler ;
182
+ JSEvents . currentEventHandler = eventHandler ;
183
+ // Process any old deferred calls the user has placed.
184
+ JSEvents . runDeferredCalls ( ) ;
185
+ // Process the actual event, calls back to user C code handler.
186
+ eventHandler . handlerFunc ( event ) ;
187
+ // Process any new deferred calls that were placed right now from this event handler.
188
+ JSEvents . runDeferredCalls ( ) ;
189
+ // Out of event handler - restore nesting count.
190
+ -- JSEvents . inEventHandler ;
191
+ } ;
192
+ #else
193
+ eventHandler . eventListenerFunc = eventHandler . handlerFunc ;
188
194
#endif
189
- } ;
190
195
191
- if ( eventHandler . callbackfunc ) {
192
- eventHandler . eventListenerFunc = jsEventHandler ;
193
- eventHandler . target . addEventListener ( eventHandler . eventTypeString , jsEventHandler , eventHandler . useCapture ) ;
196
+ eventHandler . target . addEventListener ( eventHandler . eventTypeString ,
197
+ eventHandler . eventListenerFunc ,
198
+ eventHandler . useCapture ) ;
194
199
JSEvents . eventHandlers . push ( eventHandler ) ;
195
- #if ! MINIMAL_RUNTIME // In minimal runtime, there is no concept of the page running vs being closed, and hence __ATEXIT__ is not present
200
+ #if EXIT_RUNTIME
196
201
JSEvents . registerRemoveEventListeners ( ) ;
197
202
#endif
198
203
} else {
@@ -678,7 +683,7 @@ var LibraryHTML5 = {
678
683
#if DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
679
684
target = findEventTarget ( target ) ;
680
685
#else
681
- if ( eventTypeString == "scroll" && ! target ) {
686
+ if ( eventTypeId == { { { cDefs . EMSCRIPTEN_EVENT_SCROLL } } } && ! target ) {
682
687
target = document ; // By default read scroll events on document rather than window.
683
688
} else {
684
689
target = findEventTarget ( target ) ;
@@ -778,27 +783,23 @@ var LibraryHTML5 = {
778
783
779
784
emscripten_set_blur_callback_on_thread__proxy : 'sync ',
780
785
emscripten_set_blur_callback_on_thread__deps : [ '$registerFocusEventCallback' ] ,
781
- emscripten_set_blur_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) => {
782
- return registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_BLUR } } } , "blur" , targetThread) ;
783
- } ,
786
+ emscripten_set_blur_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) =>
787
+ registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_BLUR } } } , "blur" , targetThread) ,
784
788
785
789
emscripten_set_focus_callback_on_thread__proxy : 'sync' ,
786
790
emscripten_set_focus_callback_on_thread__deps : [ '$registerFocusEventCallback' ] ,
787
- emscripten_set_focus_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) => {
788
- return registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_FOCUS } } } , "focus" , targetThread) ;
789
- } ,
791
+ emscripten_set_focus_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) =>
792
+ registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_FOCUS } } } , "focus" , targetThread) ,
790
793
791
794
emscripten_set_focusin_callback_on_thread__proxy : 'sync' ,
792
795
emscripten_set_focusin_callback_on_thread__deps : [ '$registerFocusEventCallback' ] ,
793
- emscripten_set_focusin_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) => {
794
- return registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_FOCUSIN } } } , "focusin" , targetThread) ;
795
- } ,
796
+ emscripten_set_focusin_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) =>
797
+ registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_FOCUSIN } } } , "focusin" , targetThread) ,
796
798
797
799
emscripten_set_focusout_callback_on_thread__proxy : 'sync' ,
798
800
emscripten_set_focusout_callback_on_thread__deps : [ '$registerFocusEventCallback' ] ,
799
- emscripten_set_focusout_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) => {
800
- return registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_FOCUSOUT } } } , "focusout" , targetThread) ;
801
- } ,
801
+ emscripten_set_focusout_callback_on_thread : ( target , userData , useCapture , callbackfunc , targetThread ) =>
802
+ registerFocusEventCallback ( target , userData , useCapture , callbackfunc , { { { cDefs . EMSCRIPTEN_EVENT_FOCUSOUT } } } , "focusout" , targetThread) ,
802
803
803
804
$fillDeviceOrientationEventData__deps : [ '$JSEvents' ] ,
804
805
$fillDeviceOrientationEventData : ( eventStruct , e , target ) => {
@@ -968,7 +969,7 @@ var LibraryHTML5 = {
968
969
if ( { { { makeDynCall ( 'iipp' , 'callbackfunc' ) } } } ( eventTypeId , orientationChangeEvent , userData ) ) e . preventDefault ( ) ;
969
970
} ;
970
971
971
- if ( eventTypeString == "orientationchange" && screen . mozOrientation !== undefined ) {
972
+ if ( eventTypeId == { { { cDefs . EMSCRIPTEN_EVENT_ORIENTATIONCHANGE } } } && screen . mozOrientation !== undefined ) {
972
973
eventTypeString = "mozorientationchange" ;
973
974
}
974
975
0 commit comments