示例#1
0
            protected override void ExecuteDefaultActionAtTarget(EventBase evt)
            {
                base.ExecuteDefaultActionAtTarget(evt);

                if (evt == null)
                {
                    return;
                }

                if (evt.eventTypeId == KeyDownEvent.TypeId())
                {
                    KeyDownEvent kde = evt as KeyDownEvent;

                    if (!parentTextField.isDelayed || (!multiline && ((kde?.keyCode == KeyCode.KeypadEnter) || (kde?.keyCode == KeyCode.Return))))
                    {
                        parentTextField.value = text;
                    }

                    if (multiline)
                    {
                        if (kde?.character == '\t' && kde.modifiers == EventModifiers.None)
                        {
                            kde?.StopPropagation();
                            kde?.PreventDefault();
                        }
                        else if (((kde?.character == 3) && (kde?.shiftKey == true)) ||  // KeyCode.KeypadEnter
                                 ((kde?.character == '\n') && (kde?.shiftKey == true))) // KeyCode.Return
                        {
                            parent.Focus();
                            evt.StopPropagation();
                            evt.PreventDefault();
                        }
                    }
                    else if ((kde?.character == 3) ||    // KeyCode.KeypadEnter
                             (kde?.character == '\n'))   // KeyCode.Return
                    {
                        parent.Focus();
                        evt.StopPropagation();
                        evt.PreventDefault();
                    }
                }
                else if (evt.eventTypeId == ExecuteCommandEvent.TypeId())
                {
                    ExecuteCommandEvent commandEvt = evt as ExecuteCommandEvent;
                    string cmdName = commandEvt.commandName;
                    if (!parentTextField.isDelayed && (cmdName == EventCommandNames.Paste || cmdName == EventCommandNames.Cut))
                    {
                        parentTextField.value = text;
                    }
                }
                // Prevent duplicated navigation events, since we're observing KeyDownEvents instead
                else if (evt.eventTypeId == NavigationSubmitEvent.TypeId() ||
                         evt.eventTypeId == NavigationCancelEvent.TypeId() ||
                         evt.eventTypeId == NavigationMoveEvent.TypeId())
                {
                    evt.StopPropagation();
                    evt.PreventDefault();
                }
            }
示例#2
0
        protected override void ExecuteDefaultActionAtTarget(EventBase evt)
        {
            base.ExecuteDefaultActionAtTarget(evt);

            if (evt is KeyDownEvent kde)
            {
                if (!isDelayed || (!multiline && ((kde?.keyCode == KeyCode.KeypadEnter) || (kde?.keyCode == KeyCode.Return))))
                {
                    value = text;
                }

                if (multiline)
                {
                    // For multiline text fields, make sure tab doesn't trigger a focus change.
                    if (hasFocus && (kde?.keyCode == KeyCode.Tab || kde?.character == '\t'))
                    {
                        evt.StopPropagation();
                        evt.PreventDefault();
                    }
                    else if (((kde?.character == 3) && (kde?.shiftKey == true)) ||  // KeyCode.KeypadEnter
                             ((kde?.character == '\n') && (kde?.shiftKey == true))) // KeyCode.Return
                    {
                        Focus();
                        evt.StopPropagation();
                        evt.PreventDefault();
                    }
                }
                else if ((kde?.character == 3) ||    // KeyCode.KeypadEnter
                         (kde?.character == '\n'))   // KeyCode.Return
                {
                    if (hasFocus)
                    {
                        Focus();
                    }
                    else
                    {
                        textInput.textElement.Focus();
                    }
                    evt.StopPropagation();
                    evt.PreventDefault();
                }
            }
            else if (evt is ExecuteCommandEvent commandEvt)
            {
                string cmdName = commandEvt.commandName;
                if (!isDelayed && (cmdName == EventCommandNames.Paste || cmdName == EventCommandNames.Cut))
                {
                    value = text;
                }
            }
            // Prevent duplicated navigation events, since we're observing KeyDownEvents instead
            else if (evt.eventTypeId == NavigationSubmitEvent.TypeId() ||
                     evt.eventTypeId == NavigationCancelEvent.TypeId() ||
                     evt.eventTypeId == NavigationMoveEvent.TypeId())
            {
                evt.StopPropagation();
                evt.PreventDefault();
            }
        }
示例#3
0
 internal void ProcessEvent(EventBase evt)
 {
     if (evt.imguiEvent != null && SendEventToIMGUI(evt) ||
         // Prevent navigation events since IMGUI already uses KeyDown events
         evt.eventTypeId == NavigationMoveEvent.TypeId() ||
         evt.eventTypeId == NavigationSubmitEvent.TypeId() ||
         evt.eventTypeId == NavigationCancelEvent.TypeId())
     {
         evt.StopPropagation();
         evt.PreventDefault();
     }
 }
示例#4
0
 private void SendEquivalentNavigationEventIfAny(IPanel panel)
 {
     if (character == '\n' || character == 3 || character == 10 || character == ' ')
     {
         using (var ne = NavigationSubmitEvent.GetPooled(NavigationDeviceType.Keyboard, modifiers))
         {
             ne.target = leafTarget;
             panel.visualTree.SendEvent(ne);
         }
     }
     else if (keyCode == KeyCode.Escape)
     {
         using (var ne = NavigationCancelEvent.GetPooled(NavigationDeviceType.Keyboard, modifiers))
         {
             ne.target = leafTarget;
             panel.visualTree.SendEvent(ne);
         }
     }
     // Important: wait for character \t instead of KeyCode.Tab, because we don't want to insert a
     // NavigationTabEvent between the two KeyDownEvents, in case some controls use \t to navigate.
     else if (character == '\t' && !ctrlKey && !altKey && !commandKey)
     {
         using (var ne = NavigationMoveEvent.GetPooled(
                    shiftKey ? NavigationMoveEvent.Direction.Previous : NavigationMoveEvent.Direction.Next,
                    NavigationDeviceType.Keyboard, modifiers))
         {
             ne.target = leafTarget;
             panel.visualTree.SendEvent(ne);
         }
     }
     else if (keyCode == KeyCode.RightArrow || keyCode == KeyCode.LeftArrow ||
              keyCode == KeyCode.UpArrow || keyCode == KeyCode.DownArrow)
     {
         var d = keyCode == KeyCode.RightArrow ? Vector2.right :
                 keyCode == KeyCode.LeftArrow ? Vector2.left :
                 keyCode == KeyCode.UpArrow ? Vector2.up :
                 Vector2.down;
         using (var ne = NavigationMoveEvent.GetPooled(d, NavigationDeviceType.Keyboard, modifiers))
         {
             ne.target = leafTarget;
             panel.visualTree.SendEvent(ne);
         }
     }
 }
示例#5
0
        private IEnumerator DoReplayEvents(IEnumerable <EventDebuggerEventRecord> eventBases, Action <int, int> refreshList)
        {
            var sortedEvents      = eventBases.OrderBy(e => e.timestamp).ToList();
            var sortedEventsCount = sortedEvents.Count;

            IEnumerator AwaitForNextEvent(int currentIndex)
            {
                if (currentIndex == sortedEvents.Count - 1)
                {
                    yield break;
                }

                var deltaTimestampMs = sortedEvents[currentIndex + 1].timestamp - sortedEvents[currentIndex].timestamp;

                var timeMs = 0.0f;

                while (timeMs < deltaTimestampMs)
                {
                    if (isPlaybackPaused)
                    {
                        yield return(null);
                    }
                    else
                    {
                        var time = Panel.TimeSinceStartupMs();
                        yield return(null);

                        var delta = Panel.TimeSinceStartupMs() - time;
                        timeMs += delta * playbackSpeed;
                    }
                }
            }

            for (var i = 0; i < sortedEventsCount; i++)
            {
                if (!isReplaying)
                {
                    break;
                }

                var eventBase = sortedEvents[i];
                var newEvent  = new Event
                {
                    button        = eventBase.button,
                    clickCount    = eventBase.clickCount,
                    modifiers     = eventBase.modifiers,
                    mousePosition = eventBase.mousePosition,
                };

                if (eventBase.eventTypeId == MouseMoveEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseMove;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseMove), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseDownEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseDown;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseUpEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseUp;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ContextClickEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.ContextClick;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ContextClick), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseEnterWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseEnterWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseEnterWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseLeaveWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseLeaveWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseLeaveWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == PointerMoveEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseMove;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseMove), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == PointerDownEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseDown;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == PointerUpEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseUp;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == WheelEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type  = EventType.ScrollWheel;
                    newEvent.delta = eventBase.delta;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ScrollWheel), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyDownEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyDown;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyUpEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyUp;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == NavigationMoveEvent.TypeId())
                {
                    panel.dispatcher.Dispatch(NavigationMoveEvent.GetPooled(eventBase.navigationDirection, eventBase.deviceType, eventBase.modifiers), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == NavigationSubmitEvent.TypeId())
                {
                    panel.dispatcher.Dispatch(NavigationSubmitEvent.GetPooled(eventBase.deviceType, eventBase.modifiers), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == NavigationCancelEvent.TypeId())
                {
                    panel.dispatcher.Dispatch(NavigationCancelEvent.GetPooled(eventBase.deviceType, eventBase.modifiers), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragUpdatedEvent.TypeId())
                {
                    newEvent.type = EventType.DragUpdated;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragUpdated), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragPerformEvent.TypeId())
                {
                    newEvent.type = EventType.DragPerform;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragPerform), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragExitedEvent.TypeId())
                {
                    newEvent.type = EventType.DragExited;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragExited), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ValidateCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ValidateCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ValidateCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ExecuteCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ExecuteCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ExecuteCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == IMGUIEvent.TypeId())
                {
                    Debug.Log("Skipped IMGUI event (" + eventBase.eventBaseName + "): " + eventBase);
                    var awaitSkipped = AwaitForNextEvent(i);
                    while (awaitSkipped.MoveNext())
                    {
                        yield return(null);
                    }
                    continue;
                }
                else
                {
                    Debug.Log("Skipped event (" + eventBase.eventBaseName + "): " + eventBase);
                    var awaitSkipped = AwaitForNextEvent(i);
                    while (awaitSkipped.MoveNext())
                    {
                        yield return(null);
                    }
                    continue;
                }

                refreshList?.Invoke(i, sortedEventsCount);

                Debug.Log($"Replayed event {eventBase.eventId.ToString()} ({eventBase.eventBaseName}): {newEvent}");
                var await = AwaitForNextEvent(i);
                while (await.MoveNext())
                {
                    yield return(null);
                }
            }

            isReplaying = false;
        }
示例#6
0
 void OnNavigationCancel(NavigationCancelEvent evt)
 {
     Invoke(KeyboardNavigationOperation.Cancel, evt);
 }