Skip to content

Commit

Permalink
Moving core alt input type listeners to BrowserEvents (always listeni…
Browse files Browse the repository at this point in the history
…ng, but conditionally dispatching based on whether accessible and the previous conditions). See #1445
  • Loading branch information
jonathanolson committed Oct 26, 2022
1 parent e462b48 commit 90143b5
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 213 deletions.
1 change: 1 addition & 0 deletions js/accessibility/pdom/PDOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const ELEMENTS_WITHOUT_CLOSING_TAG = [ INPUT_TAG ];

// valid DOM events that the display adds listeners to. For a list of scenery events that support pdom features
// see Input.PDOM_EVENT_TYPES
// NOTE: Update BrowserEvents if this is added to
const DOM_EVENTS = [ 'focusin', 'focusout', 'input', 'change', 'click', 'keydown', 'keyup' ];

// DOM events that must have been triggered from user input of some kind, and will trigger the
Expand Down
3 changes: 2 additions & 1 deletion js/input/BatchedDOMEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class BatchedDOMEventType extends EnumerationValue {
public static readonly TOUCH_TYPE = new BatchedDOMEventType();
public static readonly MOUSE_TYPE = new BatchedDOMEventType();
public static readonly WHEEL_TYPE = new BatchedDOMEventType();
public static readonly ALT_TYPE = new BatchedDOMEventType();

public static readonly enumeration = new Enumeration( BatchedDOMEventType, {
phetioDocumentation: 'The type of batched event'
Expand Down Expand Up @@ -83,7 +84,7 @@ export default class BatchedDOMEvent implements TPoolable {
callback.call( input, input.pointFromEvent( mouseEvent ), mouseEvent );
}
}
else if ( this.type === BatchedDOMEventType.WHEEL_TYPE ) {
else if ( this.type === BatchedDOMEventType.WHEEL_TYPE || this.type === BatchedDOMEventType.ALT_TYPE ) {
callback.call( input, domEvent );
}
else {
Expand Down
83 changes: 79 additions & 4 deletions js/input/BrowserEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import arrayRemove from '../../../phet-core/js/arrayRemove.js';
import platform from '../../../phet-core/js/platform.js';
import { BatchedDOMEventType, Display, Features, scenery } from '../imports.js';
import { BatchedDOMEventType, Display, Features, PDOMUtils, scenery } from '../imports.js';

// Sometimes we need to add a listener that does absolutely nothing
const noop = () => {};
Expand Down Expand Up @@ -191,6 +191,12 @@ const BrowserEvents = {
'wheel'
],

/**
* {Array.<string>} - Alternative input types
* @private
*/
altListenerTypes: PDOMUtils.DOM_EVENTS,

/**
* Returns all event types that will be listened to on this specific platform.
* @private
Expand All @@ -217,10 +223,9 @@ const BrowserEvents = {
eventTypes = this.touchListenerTypes.concat( this.mouseListenerTypes );
}

// eventTypes = eventTypes.concat( this.wheelListenerTypes );
eventTypes = eventTypes.concat( this.altListenerTypes );

assert && assert( !_.includes( eventTypes, 'keydown' ),
'Make sure not to preventDefault key events in the future.' );
// eventTypes = eventTypes.concat( this.wheelListenerTypes );

return eventTypes;
},
Expand Down Expand Up @@ -714,6 +719,76 @@ const BrowserEvents = {
// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.WHEEL_TYPE, 'wheel', false );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
},

onfocusin: function onfocusin( domEvent ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'focusin' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.ALT_TYPE, 'focusIn', true );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
},

onfocusout: function onfocusout( domEvent ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'focusout' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.ALT_TYPE, 'focusOut', true );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
},

oninput: function oninput( domEvent ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'input' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.ALT_TYPE, 'input', true );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
},

onchange: function onchange( domEvent ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'change' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.ALT_TYPE, 'change', true );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
},

onclick: function onclick( domEvent ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'click' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.ALT_TYPE, 'click', true );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
},

onkeydown: function onkeydown( domEvent ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'keydown' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.ALT_TYPE, 'keyDown', true );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
},

onkeyup: function onkeyup( domEvent ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'keyup' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEventType.ALT_TYPE, 'keyUp', true );

sceneryLog && sceneryLog.OnInput && sceneryLog.pop();
}
};
Expand Down
Loading

0 comments on commit 90143b5

Please sign in to comment.