void _updateDevices( PointerEvent targetEvent = null, _UpdatedDeviceHandler handleUpdatedDevice = null) { D.assert(handleUpdatedDevice != null); D.assert(result: !_duringBuildPhase); D.assert(result: !_duringDeviceUpdate); var mouseWasConnected = mouseIsConnected; _MouseState targetState = null; if (targetEvent != null) { targetState = _mouseStates.getOrDefault(key: targetEvent.device); if (targetState == null) { targetState = new _MouseState(initialEvent: targetEvent); _mouseStates[key : targetState.device] = targetState; } else { D.assert(!(targetEvent is PointerAddedEvent)); targetState.latestEvent = targetEvent; if (targetEvent is PointerRemovedEvent) { _mouseStates.Remove(key: targetEvent.device); } } } D.assert(targetState == null == (targetEvent == null)); D.assert(() => { _duringDeviceUpdate = true; return(true); }); var dirtyStates = targetEvent == null ? (IEnumerable <_MouseState>)_mouseStates.Values : new List <_MouseState> { targetState }; foreach (var dirtyState in dirtyStates) { var nextAnnotations = _findAnnotations(state: dirtyState); var lastAnnotations = dirtyState.replaceAnnotations(value: nextAnnotations); handleUpdatedDevice(mouseState: dirtyState, previousAnnotations: lastAnnotations); } D.assert(() => { _duringDeviceUpdate = false; return(true); }); if (mouseWasConnected != mouseIsConnected) { notifyListeners(); } }
void _updateDevices( PointerEvent targetEvent = null, _UpdatedDeviceHandler handleUpdatedDevice = null) { D.assert(handleUpdatedDevice != null); D.assert(!_duringBuildPhase); D.assert(!_duringDeviceUpdate); bool mouseWasConnected = mouseIsConnected; _MouseState targetState = null; if (targetEvent != null) { targetState = _mouseStates.getOrDefault(targetEvent.device); if (targetState == null) { targetState = new _MouseState(initialEvent: targetEvent); _mouseStates[targetState.device] = targetState; } else { D.assert(!(targetEvent is PointerAddedEvent)); targetState.latestEvent = targetEvent; if (targetEvent is PointerRemovedEvent) { _mouseStates.Remove(targetEvent.device); } } } D.assert((targetState == null) == (targetEvent == null)); D.assert(() => { _duringDeviceUpdate = true; return(true); }); IEnumerable <_MouseState> dirtyStates = targetEvent == null ? (IEnumerable <_MouseState>)_mouseStates.Values : new List <_MouseState> { targetState }; foreach (_MouseState dirtyState in dirtyStates) { HashSet <MouseTrackerAnnotation> nextAnnotations = _findAnnotations(dirtyState); HashSet <MouseTrackerAnnotation> lastAnnotations = dirtyState.replaceAnnotations(nextAnnotations); handleUpdatedDevice(dirtyState, lastAnnotations); } D.assert(() => { _duringDeviceUpdate = false; return(true); }); if (mouseWasConnected != mouseIsConnected) { notifyListeners(); } }