コード例 #1
0
        public void ProcessInput_Should_Return_True_If_One_Event_Handled()
        {
            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);
                }
            };

            InputElement element = new InputElement();

            element.SetMutatedEventHandled = true;

            TestEventArgs e = new TestEventArgs(element);

            e.RoutedEvent = InputElement.RawEvent;

            InputManager.Current.PreProcessInput += preProcess;
            bool result = InputManager.Current.ProcessInput(e);

            InputManager.Current.PreProcessInput -= preProcess;

            // This goes against the documentation which says should return true if all events handled.
            Assert.IsTrue(element.RawEventRaised);
            Assert.IsTrue(element.MutatedEventRaised);
            Assert.IsTrue(result);
        }
コード例 #2
0
        public void ProcessInput_Should_Return_False_If_No_Events_Handled()
        {
            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);
                }
            };

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

            e.RoutedEvent = InputElement.RawEvent;

            InputManager.Current.PreProcessInput += preProcess;
            bool result = InputManager.Current.ProcessInput(e);

            InputManager.Current.PreProcessInput -= preProcess;

            Assert.IsFalse(result);
        }
コード例 #3
0
        public void PreProcess_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();
                }
                else 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.ProcessInput(e);
            InputManager.Current.PreProcessInput -= preProcess;

            Assert.IsTrue(calledWithMutated);
        }
コード例 #4
0
        public void Mutated_Event_Should_Still_Be_Raised_When_Raw_Event_Cancelled()
        {
            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();
                }
            };

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

            e.RoutedEvent = InputElement.RawEvent;

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

            Assert.IsFalse(element.RawEventRaised);
            Assert.IsTrue(element.MutatedEventRaised);
        }
コード例 #5
0
        /// <summary>
        ///     Pushes an input event onto the top of the staging area.
        /// </summary>
        /// <param name="input">
        ///     The input event to place on the staging area.  This may not
        ///     be null, and may not already exist in the staging area.
        /// </param>
        /// <param name="promote">
        ///     An existing staging area item to promote the state from.
        /// </param>
        /// <returns>
        ///     The staging area input item that wraps the specified input.
        /// </returns>
        public StagingAreaInputItem PushInput(InputEventArgs input,
                                              StagingAreaInputItem promote) // Note: this should be a bool, and always use the InputItem available on these args.
        {
            var item = new StagingAreaInputItem(input, promote);

            InputManager.CurrentInputManager._currentStagingStack.Push(item);

            return(item);
        }
コード例 #6
0
 private bool IsPointerButtonEventItem(StagingAreaInputItem stagingItem)
 {
     if (stagingItem == null)
     {
         return(false);
     }
     if (!(stagingItem.Input is MouseButtonEventArgs))
     {
         return(stagingItem.Input is StylusButtonEventArgs);
     }
     return(true);
 }
コード例 #7
0
        private static StagingAreaInputItem CreateStagingItem(TestEventArgs e)
        {
            ConstructorInfo c = typeof(StagingAreaInputItem).GetConstructor(
                BindingFlags.NonPublic | BindingFlags.Instance,
                null,
                new[] { typeof(bool) },
                null);
            StagingAreaInputItem result = (StagingAreaInputItem)c.Invoke(new object[] { false });
            FieldInfo            f      = typeof(StagingAreaInputItem).GetField("_input", BindingFlags.NonPublic | BindingFlags.Instance);

            f.SetValue(result, e);
            return(result);
        }
コード例 #8
0
 public StagingAreaInputItem PushInput(InputEventArgs input, StagingAreaInputItem promote)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public StagingAreaInputItem PushInput(StagingAreaInputItem input)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
 // Only we can make these.  Note that we cache and reuse instances.
 internal PreProcessInputEventArgs(StagingAreaInputItem input)
     : base(input) => this._canceled = false;
コード例 #11
0
        /// <summary>
        ///     Pushes an input event onto the top of the staging area.
        /// </summary>
        /// <param name="input">
        ///     The input event to place on the staging area.  This may not
        ///     be null, and may not already exist in the staging area.
        /// </param>
        /// <returns>
        ///     The specified staging area input item.
        /// </returns>
        public StagingAreaInputItem PushInput(StagingAreaInputItem input)
        {
            InputManager.CurrentInputManager._currentStagingStack.Push(input);

            return(input);
        }
コード例 #12
0
 // Only we can make these.
 internal ProcessInputEventArgs(StagingAreaInputItem input)
     : base(input)
 {
 }
コード例 #13
0
 private bool IsPointerButtonEventItem(StagingAreaInputItem stagingItem)
 {
     return(stagingItem != null && (stagingItem.Input as MouseButtonEventArgs != null || stagingItem.Input as StylusButtonEventArgs != null));
 }