public void PostProcessInput_Should_Not_Be_Called_If_Cancelled()
        {
            bool notified = false;

            PreProcessInputEventHandler preProcess = (sender, ev) =>
            {
                ev.Cancel();
            };

            ProcessInputEventHandler postProcess = (sender, ev) =>
            {
                notified = true;
            };

            InputElement  element = new InputElement();
            TestEventArgs e       = new TestEventArgs(element);

            e.RoutedEvent = InputElement.RawEvent;

            InputManager.Current.PreProcessInput  += preProcess;
            InputManager.Current.PostProcessInput += postProcess;
            InputManager.Current.ProcessInput(e);
            InputManager.Current.PostProcessInput += postProcess;
            InputManager.Current.PreProcessInput  -= preProcess;

            Assert.IsFalse(notified);
        }
Exemple #2
0
        /// <summary>
        /// To prevent contaminating the system with test side effects
        /// (basically, to prevent our MockKeyboardDevice from listening and reacting to real
        /// keyboard input), we need to undo the damage done by the
        /// base KeyboardDevice's constructor where it subscribes to some events.
        /// By unsubscribing from these events we make sure our KeyboardDevice
        /// won't respond to real input and will be used solely to provide the
        /// desired state of the Shift, Alt and Ctrl modifier keys when asked for.
        /// </summary>
        private MockKeyboardDevice()
            : base(InputManager.Current)
        {
            // There's only one global input manager in the system
            InputManager inputManager = InputManager.Current;

            // First, unsubscribe our 3 handlers from the InputManager.

            // 1)
            // Undo the effect of the following line in the KeyboardDevice ctor:
            // this._inputManager.Value.PreProcessInput += new PreProcessInputEventHandler(this.PreProcessInput);
            PreProcessInputEventHandler preProcessInputHandler =
                GetDelegateForMethod <PreProcessInputEventHandler>(this, "PreProcessInput");

            inputManager.PreProcessInput -= preProcessInputHandler;

            // 2)
            // Undo the effect of the following line in the KeyboardDevice ctor:
            // this._inputManager.Value.PreNotifyInput += new NotifyInputEventHandler(this.PreNotifyInput);
            NotifyInputEventHandler preNotifyInputHandler =
                GetDelegateForMethod <NotifyInputEventHandler>(this, "PreNotifyInput");

            inputManager.PreNotifyInput -= preNotifyInputHandler;

            // 3)
            // Undo the effect of the following line in the KeyboardDevice ctor:
            // this._inputManager.Value.PostProcessInput += new ProcessInputEventHandler(this.PostProcessInput);
            ProcessInputEventHandler postProcessInputHandler =
                GetDelegateForMethod <ProcessInputEventHandler>(this, "PostProcessInput");

            inputManager.PostProcessInput -= postProcessInputHandler;

            // Now undo the damage done by creating a new TextServicesManager

            // this._TsfManager = new SecurityCriticalDataClass<TextServicesManager>(new TextServicesManager(inputManager));
            var textServicesManager = this.GetFieldValue("_TsfManager").GetFieldValue("_value");

            // this._inputManager.PreProcessInput += new PreProcessInputEventHandler(this.PreProcessInput);
            preProcessInputHandler        = GetDelegateForMethod <PreProcessInputEventHandler>(textServicesManager, "PreProcessInput");
            inputManager.PreProcessInput -= preProcessInputHandler;

            // this._inputManager.PostProcessInput += new ProcessInputEventHandler(this.PostProcessInput);
            postProcessInputHandler        = GetDelegateForMethod <ProcessInputEventHandler>(textServicesManager, "PostProcessInput");
            inputManager.PostProcessInput -= postProcessInputHandler;

            // And finally, revert the changes done by creating a new TextCompositionManager

            // this._textcompositionManager = new SecurityCriticalData<TextCompositionManager>(new TextCompositionManager(inputManager));
            var textCompositionManager = this.GetFieldValue("_textcompositionManager").GetFieldValue("_value");

            // this._inputManager.PreProcessInput += new PreProcessInputEventHandler(this.PreProcessInput);
            preProcessInputHandler        = GetDelegateForMethod <PreProcessInputEventHandler>(textCompositionManager, "PreProcessInput");
            inputManager.PreProcessInput -= preProcessInputHandler;

            // his._inputManager.PostProcessInput += new ProcessInputEventHandler(this.PostProcessInput);
            postProcessInputHandler        = GetDelegateForMethod <ProcessInputEventHandler>(textCompositionManager, "PostProcessInput");
            inputManager.PostProcessInput -= postProcessInputHandler;
        }
Exemple #3
0
        private void RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
        {
            processInputEventArgs.StagingItem.Input.MarkAsUserInitiated();

            try
            {
                // Invoke the handlers in reverse order so that handlers that
                // users add are invoked before handlers in the system.
                Delegate[] handlers = postProcessInput.GetInvocationList();
                for (int i = (handlers.Length - 1); i >= 0; i--)
                {
                    ProcessInputEventHandler handler = (ProcessInputEventHandler)handlers[i];
                    handler(this, processInputEventArgs);
                }
            }
            finally // we do this in a finally block in case of exceptions
            {
                processInputEventArgs.StagingItem.Input.ClearUserInitiated();
            }
        }
        public void PostProcess_Event_Should_Be_Called_With_Mutated_Event()
        {
            bool calledWithMutated = false;

            PreProcessInputEventHandler preProcess = (sender, ev) =>
            {
                if (ev.StagingItem.Input.RoutedEvent == InputElement.RawEvent)
                {
                    TestEventArgs mutated = new TestEventArgs(ev.StagingItem.Input.Device.Target);
                    mutated.RoutedEvent = InputElement.MutatedEvent;
                    StagingAreaInputItem stagingItem = CreateStagingItem(mutated);
                    ev.PushInput(stagingItem);
                    ev.Cancel();
                }
            };

            ProcessInputEventHandler postProcess = (sender, ev) =>
            {
                if (ev.StagingItem.Input.RoutedEvent == InputElement.MutatedEvent)
                {
                    calledWithMutated = true;
                }
            };

            InputElement  element = new InputElement();
            TestEventArgs e       = new TestEventArgs(element);

            e.RoutedEvent = InputElement.RawEvent;

            InputManager.Current.PreProcessInput  += preProcess;
            InputManager.Current.PostProcessInput += postProcess;
            InputManager.Current.ProcessInput(e);
            InputManager.Current.PostProcessInput += postProcess;
            InputManager.Current.PreProcessInput  -= preProcess;

            Assert.IsTrue(calledWithMutated);
        }
Exemple #5
0
        private void RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
        {
            processInputEventArgs.StagingItem.Input.MarkAsUserInitiated();

            try
            {
                // Invoke the handlers in reverse order so that handlers that
                // users add are invoked before handlers in the system.
                Delegate[] handlers = postProcessInput.GetInvocationList();
                for(int i = (handlers.Length - 1); i >= 0; i--)
                {
                    ProcessInputEventHandler handler = (ProcessInputEventHandler) handlers[i];
                    handler(this, processInputEventArgs);
                }
            }
            finally // we do this in a finally block in case of exceptions
            {
                processInputEventArgs.StagingItem.Input.ClearUserInitiated();
            }
        }
Exemple #6
0
        private object ProcessStagingArea(object frame)
        {
            bool flag1 = false;

            try
            {
label_21:
                if (this._stagingArea.Count > 0)
                {
                    this._currentStagingStack = this._stagingArea.Dequeue() as Stack;
                    do
                    {
                        StagingAreaInputItem stagingAreaInputItem = (StagingAreaInputItem)this._currentStagingStack.Pop();
                        bool flag2      = false;
                        int  deviceType = (int)stagingAreaInputItem.Input._inputDevice.DeviceType;
                        if (this.InputDeviceEvents[deviceType]._preProcessInput != null)
                        {
                            PreProcessInputEventArgs processInputEventArgs;
                            this.InputDeviceEvents[deviceType]._preProcessInput((object)this, processInputEventArgs = new PreProcessInputEventArgs(stagingAreaInputItem));
                            flag2 = processInputEventArgs._canceled;
                        }
                        if (!flag2)
                        {
                            NotifyInputEventHandler preNotifyInput = this.InputDeviceEvents[deviceType]._preNotifyInput;
                            if (preNotifyInput != null)
                            {
                                preNotifyInput((object)this, new NotifyInputEventArgs(stagingAreaInputItem));
                            }
                            InputEventArgs input1    = stagingAreaInputItem.Input;
                            UIElement      uiElement = input1._source as UIElement;
                            if (uiElement == null && input1._inputDevice != null)
                            {
                                uiElement = input1._inputDevice.Target;
                            }
                            uiElement?.RaiseEvent((RoutedEventArgs)input1);
                            NotifyInputEventHandler postNotifyInput = this.InputDeviceEvents[deviceType]._postNotifyInput;
                            if (postNotifyInput != null)
                            {
                                postNotifyInput((object)this, new NotifyInputEventArgs(stagingAreaInputItem));
                            }
                            ProcessInputEventHandler postProcessInput = this.InputDeviceEvents[deviceType]._postProcessInput;
                            if (postProcessInput != null)
                            {
                                postProcessInput((object)this, new ProcessInputEventArgs(stagingAreaInputItem));
                            }
                            if (stagingAreaInputItem.Input._routedEvent == InputManager.PreviewInputReportEvent && !stagingAreaInputItem.Input.Handled)
                            {
                                InputReportEventArgs input2 = (InputReportEventArgs)stagingAreaInputItem.Input;
                                InputReportEventArgs inputReportEventArgs = new InputReportEventArgs(input2.Device, input2.Report);
                                inputReportEventArgs.RoutedEvent = InputManager.InputReportEvent;
                                this._currentStagingStack.Push((object)new StagingAreaInputItem((InputEventArgs)inputReportEventArgs, stagingAreaInputItem));
                            }
                            if (input1.Handled)
                            {
                                flag1 = true;
                            }
                        }
                    }while (this._currentStagingStack.Count > 0);
                    goto label_21;
                }
            }
            finally
            {
                if (this._stagingArea.Count > 0)
                {
                    this.Dispatcher.BeginInvoke(this._continueProcessingStagingAreaCallback, (object)this.Dispatcher.CurrentFrame);
                }
                this._frameStagingArea.Remove(frame);
            }
            return((object)flag1);
        }