client/js/foundation/eventmanager/eventmanager.coffee in rsence-pre-3.0.0.8 vs client/js/foundation/eventmanager/eventmanager.coffee in rsence-pre-3.0.0.9

- old
+ new

@@ -338,10 +338,13 @@ if !( typeof _eventOptions == 'object' ) @warn( "EventManager##{_warnMethodName} => Invalid eventOptions: ", _eventOptions ) return false return true # + # Queue of items to check for focus, because it's fairly slow directly: + _topmostQueue: [] + # # Converts eventOptions into a list of enabled event names _setEventOptions: (_ctrl,_eventOptions,_warnMethodName)-> _warnMethodName = '[unknown]' unless _warnMethodName _viewId = _ctrl.viewId _eventsOn = [] @@ -375,13 +378,11 @@ @_listeners.byId[_viewId] = _eventsOn if _ctrl.enabled @_listeners.enabled.unshift( _viewId ) unless ~@_listeners.enabled.indexOf(_viewId) _elem = ELEM.get( _ctrl.elemId ) [ x, y ] = @status.crsr - _matchIds = @_findTopmostEnabled( HPoint.new( x, y ), 'contains', null ) - if ~_matchIds.indexOf( _viewId ) - @changeActiveControl( _ctrl ) + @_topmostQueue.push( [ HPoint.new( x, y ), _ctrl ] ) # # Releases bindings done by #_setEventOptions _unsetEventOptions: (_ctrl,_warnMethodName)-> _warnMethodName = '[unknown]' unless _warnMethodName _viewId = _ctrl.viewId @@ -394,11 +395,10 @@ _value.splice(_viewIdx,1) if ~_viewIdx if _key == 'rectHover' _intersectHoverIdx = @_listeners._rectHoverIntersectMode.indexOf( _viewId ) if ~_intersectHoverIdx @_listeners._rectHoverIntersectMode.splice( _intersectHoverIdx, 1 ) - _wasFocused = false _elem = ELEM.get( _ctrl.elemId ) for _statusItem in [ 'dragged', 'selected', 'hovered', 'active', 'focused', 'enabled' ] _viewIdx = @_listeners[_statusItem].indexOf(_viewId) if ~_viewIdx if _statusItem == 'dragged' @@ -409,11 +409,10 @@ _ctrl.endHover( null ) else if _statusItem == 'active' _ctrl._lostActiveStatus( null ) else if _statusItem == 'focused' @blur( _ctrl ) - _wasFocused = true else if _statusItem == 'enabled' _ctrl.setEnabled( false ) if _ctrl.enabled _viewIdx = @_listeners[_statusItem].indexOf(_viewId) if ~_viewIdx @_listeners[_statusItem].splice(_viewIdx,1) @@ -734,12 +733,21 @@ return null if _active.length == 0 _prevActive = @_views[_active[0]] if _active.length != 1 @warn "Danger, too many active items: #{JSON.stringify(_active)}" for _viewId in _active.slice() + if _viewId == null + console.warn('encountered null viewId in active listeners!') + _idx = _active.indexOf( _viewId ) + while ~_idx + _idx = _active.indexOf( _viewId ) + _active.splice( _idx, 1 ) + continue continue if _newActive != null and _viewId == _newActive.viewId _ctrl = @_views[_viewId] + if _ctrl.isDead and !@isProduction + console.warn('trying to deactivate dead control!') _ctrl.active = false _idx = _active.indexOf( _viewId ) _dragIdx = _dragged.indexOf(_viewId) if ~_dragIdx _dragged.splice( _dragIdx, 1 ) @@ -1114,29 +1122,25 @@ # Traverses down the parent hierarchy searching for a parent object # that responds true to _methodName. If _ctrl is undefined, use # a special default rule of auto-selecting the active control and # checking all of its siblings before traversing. defaultKey: (_methodName,_ctrl)-> - if _ctrl? - return true if _ctrl[_methodName]? and _ctrl[_methodName]() - else # first special rules, check same - return null unless @_listeners.active - _ctrl = @_views[@_listeners.active[0]] - return true if _ctrl[_methodName]? and _ctrl[_methodName]() - _stop = null - for _viewId in _ctrl.parent.views - continue if _ctrl.viewId == _viewId - _ctrl = @_views[_viewId] - if _ctrl[_methodName]? - _stopStatus = _ctrl[_methodName]() - if _stopStatus == false or _stopStatus == true - _stop = _stopStatus unless _stop - if _stop != null - return _stop - if _ctrl.parent? - return true if @defaultKey(_methodName,_ctrl.parent) - return null + return true if _ctrl? and _ctrl[_methodName]? and _ctrl[_methodName]() == true + return null unless @_listeners.active + _ctrl = @_views[@_listeners.active[0]] + return true if _ctrl[_methodName]? and _ctrl[_methodName]() == true + _stop = null + for _viewId in _ctrl.parent.views + continue if _ctrl.viewId == _viewId + _ctrl = @_views[_viewId] + if _ctrl[_methodName]? + _stopStatus = _ctrl[_methodName]() + if _stopStatus == false or _stopStatus == true + _stop = _stopStatus unless _stop + return _stop if _stop != null + return true if _ctrl.parent? and @defaultKey(_methodName,_ctrl.parent) == true + null # # Handles the keyDown event keyDown: (e)-> @_modifiers(e) _keyCode = @translateKeyCodes( e.keyCode ) @@ -1217,24 +1221,38 @@ @status.metaKeyDown isCmdKeyDown: -> @warn('EventManager#isCmdKeyDown is deprecated, use #status.cmdKeyDown instead') @status.altKeyDown # - # Debug output - # idle: -> - # console.log( 'focused: ', - # JSON.stringify(@_listeners.focused),'active:', - # JSON.stringify(@_listeners.active),'dragged:', - # JSON.stringify(@_listeners.dragged),'hovered:', - # JSON.stringify(@_listeners.hovered) ) + idle: -> + if @_topmostQueue.length + _items = [] + _lastPoint = false + for i in [0..(@_topmostQueue.length-1)] + [ _point, _ctrl ] = @_topmostQueue.shift() + _lastPoint = _point + continue if _ctrl.isDead + continue unless _ctrl.enabled + _items.push( _ctrl ) + _matchIds = @_findTopmostEnabled( _lastPoint, 'contains', null ) + for _ctrl in _items + _viewId = _ctrl.viewId + if ~_matchIds.indexOf( _viewId ) + @changeActiveControl( _ctrl ) + # Debug output + # console.log( 'focused: ', + # JSON.stringify(@_listeners.focused),'active:', + # JSON.stringify(@_listeners.active),'dragged:', + # JSON.stringify(@_listeners.dragged),'hovered:', + # JSON.stringify(@_listeners.hovered) ) # # Cleans up structures die: -> @stop() @base() LOAD( -> - window.EventManager = EventManagerApp.new( 500, 'EventManager' ) + window.EventManager = EventManagerApp.new( 40, 'EventManager' ) # Alias: window.EVENT = EventManager EventManager.start() )