private void LocalInit()
        {
            this.timestamp      = Panel.TimeSinceStartupMs();
            this.triggerEventId = 0uL;
            ulong expr_1C = EventBase.s_NextEventId;

            EventBase.s_NextEventId = expr_1C + 1uL;
            this.eventId            = expr_1C;
            this.propagation        = EventBase.EventPropagation.None;
            PropagationPaths expr_39 = this.m_Path;

            if (expr_39 != null)
            {
                expr_39.Release();
            }
            this.m_Path     = null;
            this.leafTarget = null;
            this.target     = null;
            this.skipElements.Clear();
            this.isPropagationStopped          = false;
            this.isImmediatePropagationStopped = false;
            this.isDefaultPrevented            = false;
            this.propagationPhase      = PropagationPhase.None;
            this.originalMousePosition = Vector2.zero;
            this.m_CurrentTarget       = null;
            this.dispatch                   = false;
            this.stopDispatch               = false;
            this.propagateToIMGUI           = true;
            this.dispatched                 = false;
            this.processed                  = false;
            this.processedByFocusController = false;
            this.imguiEventIsValid          = false;
            this.pooled      = false;
            this.eventLogger = null;
        }
Esempio n. 2
0
        void LogPropagationPathsInternal(EventBase evt, PropagationPaths paths)
        {
            var pathsCopy = paths == null ? new PropagationPaths() : new PropagationPaths(paths);

            AddPropagationPaths(evt, pathsCopy);
            UpdateModificationCount();
        }
Esempio n. 3
0
 public static void LogPropagationPaths(EventBase evt, PropagationPaths paths)
 {
     if (evt.log)
     {
         evt.eventLogger.LogPropagationPathsInternal(evt, paths);
     }
 }
Esempio n. 4
0
        void LocalInit()
        {
            timestamp = (long)(Time.realtimeSinceStartup * 1000.0f);

            propagation = EventPropagation.None;

            m_Path?.Release();
            m_Path     = null;
            leafTarget = null;
            target     = null;

            skipElements.Clear();

            isPropagationStopped          = false;
            isImmediatePropagationStopped = false;
            isDefaultPrevented            = false;

            propagationPhase = PropagationPhase.None;

            originalMousePosition = Vector2.zero;
            m_CurrentTarget       = null;

            dispatch         = false;
            stopDispatch     = false;
            propagateToIMGUI = true;

            dispatched        = false;
            imguiEventIsValid = false;
            pooled            = false;
        }
Esempio n. 5
0
        private void LogPropagationPathsInternal(EventBase evt, PropagationPaths paths)
        {
            PropagationPaths paths2 = (paths == null) ? new PropagationPaths() : new PropagationPaths(paths);

            this.AddPropagationPaths(evt, paths2);
            this.UpdateModificationCount();
        }
        public static void LogPropagationPaths(EventBase evt, PropagationPaths paths)
        {
#if UNITY_EDITOR
            if (evt.log)
            {
                evt.eventLogger.LogPropagationPathsInternal(evt, paths);
            }
#endif
        }
Esempio n. 7
0
        internal static PropagationPaths Copy(PropagationPaths paths)
        {
            PropagationPaths propagationPaths = PropagationPaths.s_Pool.Get();

            propagationPaths.trickleDownPath.AddRange(paths.trickleDownPath);
            propagationPaths.targetElements.AddRange(paths.targetElements);
            propagationPaths.bubbleUpPath.AddRange(paths.bubbleUpPath);
            return(propagationPaths);
        }
Esempio n. 8
0
        public static PropagationPaths Build(VisualElement elem, Type pathTypesRequested)
        {
            if (elem == null || pathTypesRequested == Type.None)
            {
                return(null);
            }

            PropagationPaths paths = s_Pool.Get();

            while (elem.hierarchy.parent != null)
            {
                if (elem.hierarchy.parent.enabledInHierarchy)
                {
                    if (elem.hierarchy.parent.isCompositeRoot)
                    {
                        // Callback for elem.hierarchy.parent must be called at the Target phase.
                        var item = new PropagationPathElement
                        {
                            m_VisualElement = elem.hierarchy.parent,
                            m_IsTarget      = true
                        };
                        paths.targetAndBubblePath.Add(item);
                    }
                    else
                    {
                        if ((pathTypesRequested & Type.TrickleDown) == Type.TrickleDown && elem.hierarchy.parent.HasTrickleDownHandlers())
                        {
                            paths.trickleDownPath.Add(elem.hierarchy.parent);
                        }

                        if ((pathTypesRequested & Type.BubbleUp) == Type.BubbleUp && elem.hierarchy.parent.HasBubbleUpHandlers())
                        {
                            var item = new PropagationPathElement
                            {
                                m_VisualElement = elem.hierarchy.parent,
                                m_IsTarget      = false
                            };
                            paths.targetAndBubblePath.Add(item);
                        }
                    }
                }
                elem = elem.hierarchy.parent;
            }
            return(paths);
        }
Esempio n. 9
0
        public static PropagationPaths Build(VisualElement elem, PropagationPaths.Type pathTypesRequested)
        {
            bool             flag = elem == null || pathTypesRequested == PropagationPaths.Type.None;
            PropagationPaths result;

            if (flag)
            {
                result = null;
            }
            else
            {
                PropagationPaths propagationPaths = PropagationPaths.s_Pool.Get();
                propagationPaths.targetElements.Add(elem);
                while (elem.hierarchy.parent != null)
                {
                    bool enabledInHierarchy = elem.hierarchy.parent.enabledInHierarchy;
                    if (enabledInHierarchy)
                    {
                        bool isCompositeRoot = elem.hierarchy.parent.isCompositeRoot;
                        if (isCompositeRoot)
                        {
                            propagationPaths.targetElements.Add(elem.hierarchy.parent);
                        }
                        else
                        {
                            bool flag2 = (pathTypesRequested & PropagationPaths.Type.TrickleDown) == PropagationPaths.Type.TrickleDown && elem.hierarchy.parent.HasTrickleDownHandlers();
                            if (flag2)
                            {
                                propagationPaths.trickleDownPath.Add(elem.hierarchy.parent);
                            }
                            bool flag3 = (pathTypesRequested & PropagationPaths.Type.BubbleUp) == PropagationPaths.Type.BubbleUp && elem.hierarchy.parent.HasBubbleUpHandlers();
                            if (flag3)
                            {
                                propagationPaths.bubbleUpPath.Add(elem.hierarchy.parent);
                            }
                        }
                    }
                    elem = elem.hierarchy.parent;
                }
                result = propagationPaths;
            }
            return(result);
        }
Esempio n. 10
0
        void AddPropagationPaths(EventBase evt, PropagationPaths paths)
        {
            if (m_Log)
            {
                var pathObject = new EventDebuggerPathTrace(panel, evt, paths);

                List <EventDebuggerPathTrace> list;
                if (m_EventPathObjects.ContainsKey(panel))
                {
                    list = m_EventPathObjects[panel];
                }
                else
                {
                    list = new List <EventDebuggerPathTrace>();
                    m_EventPathObjects.Add(panel, list);
                }
                list.Add(pathObject);
            }
        }
Esempio n. 11
0
        void AddPropagationPaths(EventBase evt, PropagationPaths paths)
        {
            if (suspended)
            {
                return;
            }

            if (m_Log)
            {
                var pathObject = new EventDebuggerPathTrace(panel, evt, paths);

                if (!m_EventPathObjects.TryGetValue(panel, out var list))
                {
                    list = new List <EventDebuggerPathTrace>();
                    m_EventPathObjects.Add(panel, list);
                }

                list.Add(pathObject);
            }
        }
Esempio n. 12
0
        private void AddPropagationPaths(EventBase evt, PropagationPaths paths)
        {
            bool log = this.m_Log;

            if (log)
            {
                EventDebuggerPathTrace item = new EventDebuggerPathTrace(this.panel, evt, paths);
                bool flag = this.m_EventPathObjects.ContainsKey(this.panel);
                List <EventDebuggerPathTrace> list;
                if (flag)
                {
                    list = this.m_EventPathObjects[this.panel];
                }
                else
                {
                    list = new List <EventDebuggerPathTrace>();
                    this.m_EventPathObjects.Add(this.panel, list);
                }
                list.Add(item);
            }
        }
Esempio n. 13
0
        void LocalInit()
        {
            timestamp = Panel.TimeSinceStartupMs();

            triggerEventId = 0;
            eventId        = s_NextEventId++;

            propagation = EventPropagation.None;

            m_Path?.Release();
            m_Path     = null;
            leafTarget = null;
            target     = null;

            skipElements.Clear();

            isPropagationStopped          = false;
            isImmediatePropagationStopped = false;
            isDefaultPrevented            = false;

            propagationPhase = PropagationPhase.None;

            originalMousePosition = Vector2.zero;
            m_CurrentTarget       = null;

            dispatch         = false;
            stopDispatch     = false;
            propagateToIMGUI = true;

            dispatched = false;
            processed  = false;
            processedByFocusController = false;
            imguiEventIsValid          = false;
            pooled = false;

#if UNITY_EDITOR
            eventLogger = null;
#endif
        }
Esempio n. 14
0
        public static PropagationPaths Build(VisualElement elem, EventBase evt)
        {
            PropagationPaths paths = s_Pool.Get();
            var eventCategory      = evt.eventCategory;

            // Skip element if it has no event callbacks, default action, or default action at target
            if (elem.HasEventCallbacksOrDefaultActions(eventCategory))
            {
                paths.targetElements.Add(elem);
            }

            // Go through the entire hierarchy. Don't bother checking elem.HasParentEventCallbacks because
            // 1. It too goes through the entire parent hierarchy, and
            // 2. It would require dirtying the parent categories when we set isCompositeRoot, so more overhead
            for (var ve = elem.nextParentWithEventCallback; ve != null; ve = ve.nextParentWithEventCallback)
            {
                if (ve.isCompositeRoot && !evt.ignoreCompositeRoots)
                {
                    // Callback for elem must be called at the Target phase. Skip if no callback.
                    if (ve.HasEventCallbacksOrDefaultActions(eventCategory))
                    {
                        paths.targetElements.Add(ve);
                    }
                }
                else if (ve.HasEventCallbacks(eventCategory))
                {
                    if (evt.tricklesDown && ve.HasTrickleDownHandlers())
                    {
                        paths.trickleDownPath.Add(ve);
                    }
                    if (evt.bubbles && ve.HasBubbleUpHandlers())
                    {
                        paths.bubbleUpPath.Add(ve);
                    }
                }
            }
            return(paths);
        }
Esempio n. 15
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.");
            }
        }
 public EventDebuggerPathTrace(IPanel panel, EventBase evt, PropagationPaths paths) : base(panel, evt, -1L, null)
 {
     this.< paths > k__BackingField = paths;
 }
Esempio n. 17
0
 public PropagationPaths(PropagationPaths paths)
 {
     trickleDownPath     = new List <VisualElement>(paths.trickleDownPath);
     targetAndBubblePath = new List <PropagationPathElement>(paths.targetAndBubblePath);
 }
        private static void HandleEventAcrossPropagationPath(EventBase evt)
        {
            // Build and store propagation path
            var leafTarget = (VisualElement)evt.leafTarget;
            var path       = PropagationPaths.Build(leafTarget, evt);

            evt.path = path;
            EventDebugger.LogPropagationPaths(evt, path);

            var panel = leafTarget.panel;

            // Phase 1: TrickleDown phase
            // Propagate event from root to target.parent
            if (evt.tricklesDown)
            {
                evt.propagationPhase = PropagationPhase.TrickleDown;

                for (int i = path.trickleDownPath.Count - 1; i >= 0; i--)
                {
                    if (evt.isPropagationStopped)
                    {
                        break;
                    }

                    var element = path.trickleDownPath[i];
                    if (evt.Skip(element) || element.panel != panel)
                    {
                        continue;
                    }

                    evt.currentTarget = element;
                    evt.currentTarget.HandleEvent(evt);
                }
            }

            // Phase 2: Target / DefaultActionAtTarget
            // Propagate event from target parent up to root for the target phase

            // Call HandleEvent() even if propagation is stopped, for the default actions at target.
            evt.propagationPhase = PropagationPhase.AtTarget;
            foreach (var element in path.targetElements)
            {
                if (evt.Skip(element) || element.panel != panel)
                {
                    continue;
                }

                evt.target        = element;
                evt.currentTarget = evt.target;
                evt.currentTarget.HandleEvent(evt);
            }

            // Call ExecuteDefaultActionAtTarget
            evt.propagationPhase = PropagationPhase.DefaultActionAtTarget;
            foreach (var element in path.targetElements)
            {
                if (evt.Skip(element) || element.panel != panel)
                {
                    continue;
                }

                evt.target        = element;
                evt.currentTarget = evt.target;
                evt.currentTarget.HandleEvent(evt);
            }

            // Reset target to original target
            evt.target = evt.leafTarget;

            // Phase 3: bubble up phase
            // Propagate event from target parent up to root
            if (evt.bubbles)
            {
                evt.propagationPhase = PropagationPhase.BubbleUp;

                foreach (var element in path.bubbleUpPath)
                {
                    if (evt.Skip(element) || element.panel != panel)
                    {
                        continue;
                    }

                    evt.currentTarget = element;
                    evt.currentTarget.HandleEvent(evt);
                }
            }

            evt.propagationPhase = PropagationPhase.None;
            evt.currentTarget    = null;
        }
Esempio n. 19
0
 public PropagationPaths(PropagationPaths paths)
 {
     this.trickleDownPath = new List <VisualElement>(paths.trickleDownPath);
     this.targetElements  = new List <VisualElement>(paths.targetElements);
     this.bubbleUpPath    = new List <VisualElement>(paths.bubbleUpPath);
 }