Skip to content

Commit

Permalink
Improved master patch for #770
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Apr 24, 2018
1 parent fc09a50 commit 698c963
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions js/input/BrowserEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define( function( require ) {
}

// Only add the wheel listeners directly on the elements, so it won't trigger outside
display.domElement.addEventListener( 'wheel', this.onwheel, false );
display.domElement.addEventListener( 'wheel', this.onwheel, BrowserEvents.getEventOptions( passiveEvents, true ) );
},

/**
Expand Down Expand Up @@ -75,7 +75,33 @@ define( function( require ) {
this.addOrRemoveListeners( display.domElement, false, passiveEvents );
}

display.domElement.removeEventListener( 'wheel', this.onwheel, false );
display.domElement.removeEventListener( 'wheel', this.onwheel, BrowserEvents.getEventOptions( passiveEvents, true ) );
},

/**
* Returns the value to provide as the 3rd parameter to addEventListener/removeEventListener.
* @private
*
* @param {boolean|null} passiveEvents
* @param {boolean} isMain - If false, it is used on the "document" for workarounds.
* @returns {Object|boolean}
*/
getEventOptions: function( passiveEvents, isMain ) {
var passDirectPassiveFlag = Features.passive && passiveEvents !== null;
if ( !passDirectPassiveFlag ) {
return false;
}
if ( isMain ) {
return {
useCapture: false,
passive: passiveEvents
};
}
else {
return {
passive: passiveEvents
};
}
},

/**
Expand Down Expand Up @@ -252,8 +278,6 @@ define( function( require ) {
// {Array.<string>}
var eventTypes = this.getNonWheelUsedTypes();

var passDirectPassiveFlag = Features.passive && passiveEvents !== null;

for ( var i = 0; i < eventTypes.length; i++ ) {
var type = eventTypes[ i ];

Expand All @@ -262,20 +286,15 @@ define( function( require ) {
if ( forWindow ) {
// Workaround for older browsers needed,
// see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners
var documentOptions = passDirectPassiveFlag ? { passive: passiveEvents } : false;
document[ method ]( type, noop, documentOptions );
document[ method ]( type, noop, BrowserEvents.getEventOptions( passiveEvents, false ) );
}

var callback = this[ 'on' + type ];
assert && assert( !!callback );

// Workaround for older browsers needed,
// see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners
var mainOptions = passDirectPassiveFlag ? {
useCapture: false,
passive: passiveEvents
} : false;
element[ method ]( type, callback, mainOptions );
element[ method ]( type, callback, BrowserEvents.getEventOptions( passiveEvents, true ) );
}
},

Expand Down

0 comments on commit 698c963

Please sign in to comment.