Skip to content

Commit

Permalink
Adding userGestureEmitter for phetsims/vibe#32 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jul 26, 2018
1 parent 698c963 commit 81fcd1a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
18 changes: 10 additions & 8 deletions js/accessibility/AccessibleInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ define( function( require ) {

/**
* Constructor for AccessibleInstance, uses an initialize method for pooling.
*
*
* @param {AccessibleInstance|null} parent - parent of this instance, null if root of AccessibleInstance tree
* @param {Display} display
* @param {Trail} trail - trail to the node for this AccessibleInstance
* @param {Trail} trail - trail to the node for this AccessibleInstance
* @constructor
* @mixes Poolable
*/
Expand All @@ -38,7 +38,7 @@ define( function( require ) {

/**
* Initializes an AccessibleInstance, implements construction for pooling.
*
*
* @param {AccessibleInstance|null} parent - null if this AccessibleInstance is root of AccessibleInstance tree
* @param {Display} display
* @param {Trail} trail - trail to node for this AccessibleInstance
Expand Down Expand Up @@ -78,6 +78,8 @@ define( function( require ) {
var self = this;
document.body.addEventListener( 'keydown', function( event ) {

scenery.Display.userGestureEmitter.emit();

// if an accessible node was being interacted with a mouse, or had focus when sim is made inactive, this node
// should receive focus upon resuming keyboard navigation
if ( self.display.pointerFocus || self.display.activeNode ) {
Expand Down Expand Up @@ -142,7 +144,7 @@ define( function( require ) {

/**
* Add a subtree of AccessibleInstances to this AccessibleInstance.
*
*
* Consider the following example:
*
* We have a node structure:
Expand Down Expand Up @@ -268,7 +270,7 @@ define( function( require ) {
scenery.Display.focus = null;
}
}

// Edge has a bug where removing the hidden attribute on an ancestor doesn't add elements back to the navigation
// order. As a workaround, forcing the browser to redraw the PDOM seems to fix the issue. Forced redraw method
// recommended by https://stackoverflow.com/questions/8840580/force-dom-redraw-refresh-on-chrome-mac, also see
Expand All @@ -284,7 +286,7 @@ define( function( require ) {
* creating a comparison function between two accessible instances. The function walks along the trails
* of the children, looking for specified accessible orders that would determine the ordering for the two
* AccessibleInstances.
*
*
* @public (scenery-internal)
*/
sortChildren: function() {
Expand Down Expand Up @@ -412,7 +414,7 @@ define( function( require ) {

/**
* Recursive disposal, to make eligible for garbage collection.
*
*
* @public (scenery-internal)
*/
dispose: function() {
Expand Down Expand Up @@ -466,7 +468,7 @@ define( function( require ) {

/**
* For debugging purposes, inspect the tree of AccessibleInstances from the root.
*
*
* @public (scenery-internal)
*/
auditRoot: function() {
Expand Down
7 changes: 7 additions & 0 deletions js/display/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ define( function( require ) {

var AccessibilityUtil = require( 'SCENERY/accessibility/AccessibilityUtil' );
var Dimension2 = require( 'DOT/Dimension2' );
var Emitter = require( 'AXON/Emitter' );
var Events = require( 'AXON/Events' );
var extend = require( 'PHET_CORE/extend' );
var inherit = require( 'PHET_CORE/inherit' );
Expand Down Expand Up @@ -2009,5 +2010,11 @@ define( function( require ) {
}
};

// @public {Emitter} - Fires when we detect an input event that would be considered a "user gesture" by Chrome, so
// that we can trigger browser actions that are only allowed as a result.
// See https://github.com/phetsims/scenery/issues/802 and https://github.com/phetsims/vibe/issues/32 for more
// information.
Display.userGestureEmitter = new Emitter();

return Display;
} );
12 changes: 12 additions & 0 deletions js/input/BrowserEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ define( function( require ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'pointerdown' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

if ( domEvent.pointerType === 'mouse' ) {
scenery.Display.userGestureEmitter.emit();
}

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEvent.POINTER_TYPE, 'pointerDown', false );

Expand All @@ -347,6 +351,8 @@ define( function( require ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'pointerup' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

scenery.Display.userGestureEmitter.emit();

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

Expand Down Expand Up @@ -539,6 +545,8 @@ define( function( require ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'touchend' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

scenery.Display.userGestureEmitter.emit();

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

Expand Down Expand Up @@ -587,6 +595,8 @@ define( function( require ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'mousedown' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

scenery.Display.userGestureEmitter.emit();

// NOTE: Will be called without a proper 'this' reference. Do NOT rely on it here.
BrowserEvents.batchWindowEvent( domEvent, BatchedDOMEvent.MOUSE_TYPE, 'mouseDown', false );

Expand All @@ -603,6 +613,8 @@ define( function( require ) {
sceneryLog && sceneryLog.OnInput && sceneryLog.OnInput( 'mouseup' );
sceneryLog && sceneryLog.OnInput && sceneryLog.push();

scenery.Display.userGestureEmitter.emit();

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

Expand Down

0 comments on commit 81fcd1a

Please sign in to comment.