private void ProcessEvent(EventBase evt, IPanel panel)
        {
            Event imguiEvent = evt.imguiEvent;
            bool  flag       = imguiEvent != null && imguiEvent.rawType == EventType.Used;

            using (new EventDispatcherGate(this))
            {
                evt.PreDispatch(panel);
                bool flag2 = !evt.stopDispatch && !evt.isPropagationStopped;
                if (flag2)
                {
                    this.ApplyDispatchingStrategies(evt, panel, flag);
                }
                bool flag3 = evt.path != null;
                if (flag3)
                {
                    foreach (VisualElement current in evt.path.targetElements)
                    {
                        evt.target = current;
                        EventDispatchUtilities.ExecuteDefaultAction(evt, panel);
                    }
                    evt.target = evt.leafTarget;
                }
                else
                {
                    EventDispatchUtilities.ExecuteDefaultAction(evt, panel);
                }
                this.m_DebuggerEventDispatchingStrategy.PostDispatch(evt, panel);
                evt.PostDispatch(panel);
                this.m_ClickDetector.ProcessEvent(evt);
                Debug.Assert(flag || evt.isPropagationStopped || imguiEvent == null || imguiEvent.rawType != EventType.Used, "Event is used but not stopped.");
            }
        }
示例#2
0
        static bool SendEventToIMGUIContainer(EventBase evt, BaseVisualElementPanel panel)
        {
            if (evt.imguiEvent == null)
            {
                return(false);
            }

            // Root IMGUI is the container that handles all the GUIView/DockArea logic for EditorWindows.
            var rootIMGUI = panel.rootIMGUIContainer;

            if (rootIMGUI == null)
            {
                return(false);
            }

            // If root IMGUI doesn't use event, send it to other IMGUIs down the line.
            if (evt.propagateToIMGUI ||
                evt.eventTypeId == DragExitedEvent.TypeId() ||
                evt.eventTypeId == MouseEnterWindowEvent.TypeId() ||
                evt.eventTypeId == MouseLeaveWindowEvent.TypeId())
            {
                evt.skipElements.Add(evt.target);
                EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
            }

            return(IsDone(evt));
        }
        private static bool SendEventToIMGUIContainer(EventBase evt, BaseVisualElementPanel panel)
        {
            bool flag = evt.imguiEvent == null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                IMGUIContainer rootIMGUIContainer = panel.rootIMGUIContainer;
                bool           flag2 = rootIMGUIContainer == null;
                if (flag2)
                {
                    result = false;
                }
                else
                {
                    bool flag3 = evt.propagateToIMGUI || evt.eventTypeId == EventBase <MouseEnterWindowEvent> .TypeId() || evt.eventTypeId == EventBase <MouseLeaveWindowEvent> .TypeId();

                    if (flag3)
                    {
                        evt.skipElements.Add(evt.target);
                        EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
                    }
                    result = MouseEventDispatchingStrategy.IsDone(evt);
                }
            }
            return(result);
        }
示例#4
0
        private static void SendEventToTarget(EventBase evt)
        {
            bool flag = evt.target != null;

            if (flag)
            {
                EventDispatchUtilities.PropagateEvent(evt);
            }
        }
        static bool SendEventToRegularTarget(EventBase evt, BaseVisualElementPanel panel)
        {
            if (!(evt.target is VisualElement ve))
                return false;

            if (ve.panel == panel)
                EventDispatchUtilities.PropagateEvent(evt);

            return IsDone(evt);
        }
示例#6
0
        void ProcessEvent(EventBase evt, IPanel panel)
        {
            Event e = evt.imguiEvent;
            // Sometimes (in tests only?) we receive Used events. Protect our verification from this case.
            bool imguiEventIsInitiallyUsed = e != null && e.type == EventType.Used;

            using (new EventDispatcherGate(this))
            {
                evt.PreDispatch(panel);

                IMouseEvent         mouseEvent         = evt as IMouseEvent;
                IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal;
                if (mouseEvent != null && mouseEventInternal != null && mouseEventInternal.triggeredByOS)
                {
                    MousePositionTracker.SaveMousePosition(mouseEvent.mousePosition, panel);
                }

                foreach (var strategy in m_DispatchingStrategies)
                {
                    if (strategy.CanDispatchEvent(evt))
                    {
                        strategy.DispatchEvent(evt, panel);

                        Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.type != EventType.Used,
                                     "Unexpected condition: !evt.isPropagationStopped && evt.imguiEvent.type == EventType.Used.");

                        if (evt.stopDispatch || evt.isPropagationStopped)
                        {
                            break;
                        }
                    }
                }

                if (evt.path != null)
                {
                    foreach (var element in evt.path.targetElements)
                    {
                        evt.target = element;
                        EventDispatchUtilities.ExecuteDefaultAction(evt, panel);
                    }

                    evt.target = evt.leafTarget;
                }
                else
                {
                    EventDispatchUtilities.ExecuteDefaultAction(evt, panel);
                }

                evt.PostDispatch(panel);

                m_DebuggerEventDispatchingStrategy.PostDispatch(evt, panel);

                Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.type != EventType.Used, "Event is used but not stopped.");
            }
        }
        public void DispatchEvent(EventBase evt, IPanel panel)
        {
            bool flag = panel != null;

            if (flag)
            {
                EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
            }
            evt.propagateToIMGUI = false;
            evt.stopDispatch     = true;
        }
        static bool SendEventToRegularTarget(EventBase evt, BaseVisualElementPanel panel)
        {
            if (evt.target == null)
            {
                return(false);
            }

            EventDispatchUtilities.PropagateEvent(evt);

            return(IsDone(evt));
        }
示例#9
0
        void ProcessEvent(EventBase evt, IPanel panel)
        {
            Event e = evt.imguiEvent;
            // Sometimes (in tests only?) we receive Used events. Protect our verification from this case.
            bool imguiEventIsInitiallyUsed = e != null && e.rawType == EventType.Used;

            using (new EventDispatcherGate(this))
            {
                evt.PreDispatch(panel);

                foreach (var strategy in m_DispatchingStrategies)
                {
                    if (strategy.CanDispatchEvent(evt))
                    {
                        strategy.DispatchEvent(evt, panel);

                        Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.rawType != EventType.Used,
                                     "Unexpected condition: !evt.isPropagationStopped && evt.imguiEvent.rawType == EventType.Used.");

                        if (evt.stopDispatch || evt.isPropagationStopped)
                        {
                            break;
                        }
                    }
                }

                if (evt.path != null)
                {
                    foreach (var element in evt.path.targetElements)
                    {
                        evt.target = element;
                        EventDispatchUtilities.ExecuteDefaultAction(evt, panel);
                    }

                    // Reset target to leaf target
                    evt.target = evt.leafTarget;
                }
                else
                {
                    EventDispatchUtilities.ExecuteDefaultAction(evt, panel);
                }

                m_DebuggerEventDispatchingStrategy.PostDispatch(evt, panel);

                evt.PostDispatch(panel);

                m_ClickDetector.ProcessEvent(evt);

                Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.rawType != EventType.Used, "Event is used but not stopped.");
            }
        }
示例#10
0
        void ProcessEvent(EventBase evt, IPanel panel)
        {
            Event e = evt.imguiEvent;
            // Sometimes (in tests only?) we receive Used events. Protect our verification from this case.
            bool imguiEventIsInitiallyUsed = e != null && e.rawType == EventType.Used;

            using (new EventDispatcherGate(this))
            {
                evt.PreDispatch(panel);

                if (!evt.stopDispatch && !evt.isPropagationStopped)
                {
                    ApplyDispatchingStrategies(evt, panel, imguiEventIsInitiallyUsed);
                }

                if (evt.path != null)
                {
                    foreach (var element in evt.path.targetElements)
                    {
                        if (element.panel == panel)
                        {
                            evt.target = element;
                            EventDispatchUtilities.ExecuteDefaultAction(evt);
                        }
                    }

                    // Reset target to leaf target
                    evt.target = evt.leafTarget;
                }
                else
                {
                    // If no propagation path, make sure EventDispatchUtilities.ExecuteDefaultAction has a target
                    if (evt.target == null && panel != null)
                    {
                        evt.target = panel.visualTree;
                    }
                    EventDispatchUtilities.ExecuteDefaultAction(evt);
                }

                m_DebuggerEventDispatchingStrategy.PostDispatch(evt, panel);

                evt.PostDispatch(panel);

                m_ClickDetector.ProcessEvent(evt);

                Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.rawType != EventType.Used, "Event is used but not stopped.");
            }
        }
        private static bool SendEventToRegularTarget(EventBase evt, BaseVisualElementPanel panel)
        {
            bool flag = evt.target == null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                EventDispatchUtilities.PropagateEvent(evt);
                result = MouseEventDispatchingStrategy.IsDone(evt);
            }
            return(result);
        }
        static bool SendEventToRegularTarget(EventBase evt, BaseVisualElementPanel panel)
        {
            if (evt.target == null)
            {
                return(false);
            }

            EventDispatchUtilities.PropagateEvent(evt);
            if (evt.target is IMGUIContainer)
            {
                evt.propagateToIMGUI = true;
                evt.skipElements.Add(evt.target);
            }

            return(IsDone(evt));
        }
        public void DispatchEvent(EventBase evt, IPanel panel)
        {
            bool flag = panel != null;

            if (flag)
            {
                Focusable leafFocusedElement = panel.focusController.GetLeafFocusedElement();
                bool      flag2 = leafFocusedElement != null;
                if (flag2)
                {
                    bool isIMGUIContainer = leafFocusedElement.isIMGUIContainer;
                    if (isIMGUIContainer)
                    {
                        IMGUIContainer iMGUIContainer = (IMGUIContainer)leafFocusedElement;
                        bool           flag3          = !evt.Skip(iMGUIContainer) && iMGUIContainer.SendEventToIMGUI(evt, true, true);
                        if (flag3)
                        {
                            evt.StopPropagation();
                            evt.PreventDefault();
                        }
                        bool flag4 = !evt.isPropagationStopped && evt.propagateToIMGUI;
                        if (flag4)
                        {
                            evt.skipElements.Add(iMGUIContainer);
                            EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
                        }
                    }
                    else
                    {
                        evt.target = panel.focusController.GetLeafFocusedElement();
                        EventDispatchUtilities.PropagateEvent(evt);
                        bool flag5 = !evt.isPropagationStopped && evt.propagateToIMGUI;
                        if (flag5)
                        {
                            EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
                        }
                    }
                }
                else
                {
                    EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
                }
            }
            evt.propagateToIMGUI = false;
            evt.stopDispatch     = true;
        }
示例#14
0
        internal static void PropagateToIMGUIContainer(VisualElement root, EventBase evt)
        {
            bool flag = evt.imguiEvent == null || root.elementPanel.contextType == ContextType.Player;

            if (!flag)
            {
                bool isIMGUIContainer = root.isIMGUIContainer;
                if (isIMGUIContainer)
                {
                    IMGUIContainer iMGUIContainer = root as IMGUIContainer;
                    bool           flag2          = evt.Skip(iMGUIContainer);
                    if (flag2)
                    {
                        return;
                    }
                    Focusable expr_54 = evt.target as Focusable;
                    bool      flag3   = expr_54 != null && expr_54.focusable;
                    bool      flag4   = iMGUIContainer.SendEventToIMGUI(evt, !flag3, true);
                    if (flag4)
                    {
                        evt.StopPropagation();
                        evt.PreventDefault();
                    }
                    bool flag5 = evt.imguiEvent.rawType == EventType.Used;
                    if (flag5)
                    {
                        Debug.Assert(evt.isPropagationStopped);
                    }
                }
                bool flag6 = root.imguiContainerDescendantCount > 0;
                if (flag6)
                {
                    int childCount = root.hierarchy.childCount;
                    for (int i = 0; i < childCount; i++)
                    {
                        EventDispatchUtilities.PropagateToIMGUIContainer(root.hierarchy[i], evt);
                        bool isPropagationStopped = evt.isPropagationStopped;
                        if (isPropagationStopped)
                        {
                            break;
                        }
                    }
                }
            }
        }
        static bool SendEventToIMGUIContainer(EventBase evt, BaseVisualElementPanel panel)
        {
            if (evt.imguiEvent == null)
            {
                return(false);
            }

            // Root IMGUI is the container that handles all the GUIView/DockArea logic for EditorWindows.
            var rootIMGUI = panel.rootIMGUIContainer;

            if (rootIMGUI == null)
            {
                return(false);
            }

            // If root IMGUI doesn't use event, send it to other IMGUIs down the line.
            if (evt.propagateToIMGUI ||
                evt.eventTypeId == MouseEnterWindowEvent.TypeId() ||
                evt.eventTypeId == MouseLeaveWindowEvent.TypeId() ||
                evt.target == rootIMGUI
                )
            {
                evt.skipElements.Add(evt.target);
                EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
            }
            // If non-root element doesn't use event, send it to root IMGUI.
            // This is necessary for some behaviors like dropdown menus in IMGUI.
            // See case : https://fogbugz.unity3d.com/f/cases/1223087/
            else
            {
                evt.skipElements.Add(evt.target);
                if (!evt.Skip(rootIMGUI))
                {
                    // Only permit switching the focus to another IMGUIContainer if the event target was not focusable
                    // and was itself an IMGUIContainer
                    bool canAffectFocus = evt.target is Focusable f && !f.focusable && f.isIMGUIContainer;
                    rootIMGUI.SendEventToIMGUI(evt, canAffectFocus);
                }
            }

            return(IsDone(evt));
        }
        static bool SendEventToIMGUIContainer(EventBase evt, BaseVisualElementPanel panel)
        {
            if (evt.propagateToIMGUI ||
                evt.eventTypeId == MouseEnterWindowEvent.TypeId() ||
                evt.eventTypeId == MouseLeaveWindowEvent.TypeId()
                )
            {
                EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
            }
            else
            {
                // Send the events to the GUIView container so that it can process them.
                // This is necessary for some behaviors like dropdown menus in IMGUI.
                // See case : https://fogbugz.unity3d.com/f/cases/1223087/
                var topLevelIMGUI = panel.rootIMGUIContainer;
                if (topLevelIMGUI != null && !evt.Skip(topLevelIMGUI) && evt.imguiEvent != null)
                {
                    topLevelIMGUI.SendEventToIMGUI(evt, false);
                }
            }

            return(IsDone(evt));
        }
        public void DispatchEvent(EventBase evt, IPanel panel)
        {
            bool flag = evt.target != null;

            if (flag)
            {
                evt.propagateToIMGUI = (evt.target is IMGUIContainer);
                EventDispatchUtilities.PropagateEvent(evt);
            }
            else
            {
                bool flag2 = !evt.isPropagationStopped && panel != null;
                if (flag2)
                {
                    bool flag3 = evt.propagateToIMGUI || evt.eventTypeId == EventBase <MouseEnterWindowEvent> .TypeId() || evt.eventTypeId == EventBase <MouseLeaveWindowEvent> .TypeId();

                    if (flag3)
                    {
                        EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
                    }
                }
            }
            evt.stopDispatch = true;
        }
示例#18
0
        void ProcessEvent(EventBase evt, [NotNull] IPanel panel)
        {
            Event e = evt.imguiEvent;
            // Sometimes (in tests only?) we receive Used events. Protect our verification from this case.
            bool imguiEventIsInitiallyUsed = e != null && e.rawType == EventType.Used;

            using (new EventDispatcherGate(this))
            {
                evt.PreDispatch(panel);

                if (!evt.stopDispatch && !evt.isPropagationStopped)
                {
                    ApplyDispatchingStrategies(evt, panel, imguiEventIsInitiallyUsed);
                }

                // Last chance to build a path. Some dispatching strategies (e.g. PointerCaptureDispatchingStrategy)
                // don't call PropagateEvents but still need to call ExecuteDefaultActions on composite roots.
                var path = evt.path;
                if (path == null && evt.bubblesOrTricklesDown && evt.leafTarget is VisualElement leafTarget)
                {
                    path     = PropagationPaths.Build(leafTarget, evt);
                    evt.path = path;
                    EventDebugger.LogPropagationPaths(evt, path);
                }

                if (path != null)
                {
                    foreach (var element in path.targetElements)
                    {
                        if (element.panel == panel)
                        {
                            evt.target = element;
                            EventDispatchUtilities.ExecuteDefaultAction(evt);
                        }
                    }

                    // Reset target to leaf target
                    evt.target = evt.leafTarget;
                }
                else
                {
                    // If no propagation path, make sure EventDispatchUtilities.ExecuteDefaultAction has a target
                    if (!(evt.target is VisualElement target))
                    {
                        evt.target = target = panel.visualTree;
                    }

                    if (target.panel == panel)
                    {
                        EventDispatchUtilities.ExecuteDefaultAction(evt);
                    }
                }

                m_DebuggerEventDispatchingStrategy.PostDispatch(evt, panel);

                evt.PostDispatch(panel);

                m_ClickDetector.ProcessEvent(evt);

                Debug.Assert(imguiEventIsInitiallyUsed || evt.isPropagationStopped || e == null || e.rawType != EventType.Used, "Event is used but not stopped.");
            }
        }
示例#19
0
        public virtual void DispatchEvent(EventBase evt, IPanel panel)
        {
            IMouseEvent mouseEvent = evt as IMouseEvent;

            // FIXME: we should not change hover state when capture is true.
            // However, when doing drag and drop, drop target should be highlighted.

            // TODO when EditorWindow is docked MouseLeaveWindow is not always sent
            // this is a problem in itself but it could leave some elements as "hover"

            BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel;

            if (basePanel != null && (evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == DragExitedEvent.TypeId()))
            {
                basePanel.SetElementUnderMouse(null, evt);
            }
            else
            {
                // update element under mouse and fire necessary events
                if (basePanel != null)
                {
                    bool shouldRecomputeTopElementUnderMouse = true;
                    if ((IMouseEventInternal)mouseEvent != null)
                    {
                        shouldRecomputeTopElementUnderMouse =
                            ((IMouseEventInternal)mouseEvent).recomputeTopElementUnderMouse;
                    }

                    VisualElement elementUnderMouse = shouldRecomputeTopElementUnderMouse ?
                                                      basePanel.Pick(mouseEvent.mousePosition) :
                                                      basePanel.topElementUnderMouse;

                    if (evt.target == null)
                    {
                        evt.target = elementUnderMouse;
                    }

                    // Because events are queued, we can set the element under mouse
                    // right now, instead of waiting after the PropagateEvent() as we
                    // did before.
                    basePanel.SetElementUnderMouse(elementUnderMouse, evt);
                }

                if (evt.target != null)
                {
                    evt.propagateToIMGUI = false;
                    EventDispatchUtilities.PropagateEvent(evt);
                }
            }

            if (!evt.isPropagationStopped && panel != null)
            {
                if (evt.propagateToIMGUI ||
                    evt.eventTypeId == MouseEnterWindowEvent.TypeId() ||
                    evt.eventTypeId == MouseLeaveWindowEvent.TypeId()
                    )
                {
                    EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
                }
            }

            evt.stopDispatch = true;
        }