Exemplo n.º 1
0
        private static PropagationPaths BuildPropagationPath(VisualElement elem, PropagationPaths.Type pathTypesRequested)
        {
            if (elem == null || pathTypesRequested == PropagationPaths.Type.None)
            {
                return(null);
            }
            var ret = PropagationPathsPool.Acquire();

            while (elem.shadow.parent != null)
            {
                if (elem.shadow.parent.enabledInHierarchy)
                {
                    if ((pathTypesRequested & PropagationPaths.Type.Capture) == PropagationPaths.Type.Capture && elem.shadow.parent.HasCaptureHandlers())
                    {
                        ret.capturePath.Add(elem.shadow.parent);
                    }
                    if ((pathTypesRequested & PropagationPaths.Type.BubbleUp) == PropagationPaths.Type.BubbleUp && elem.shadow.parent.HasBubbleHandlers())
                    {
                        ret.bubblePath.Add(elem.shadow.parent);
                    }
                }
                elem = elem.shadow.parent;
            }
            return(ret);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private static void PropagateEvent(EventBase evt)
        {
            if (evt.dispatch)
            {
                // FIXME: signal this as an error
                return;
            }

            PropagationPaths.Type pathTypesRequested = (evt.capturable ? PropagationPaths.Type.Capture : PropagationPaths.Type.None);
            pathTypesRequested |= (evt.bubbles ? PropagationPaths.Type.BubbleUp : PropagationPaths.Type.None);

            using (var paths = BuildPropagationPath(evt.target as VisualElement, pathTypesRequested))
            {
                evt.dispatch = true;

                if (evt.capturable && paths != null && paths.capturePath.Count > 0)
                {
                    // Phase 1: Capture phase
                    // Propagate event from root to target.parent
                    evt.propagationPhase = PropagationPhase.Capture;

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

                        if (paths.capturePath[i] == evt.skipElement)
                        {
                            continue;
                        }

                        evt.currentTarget = paths.capturePath[i];
                        evt.currentTarget.HandleEvent(evt);
                    }
                }

                // Phase 2: Target
                // Call HandleEvent() even if propagation is stopped, for the default actions at target.
                if (evt.target != evt.skipElement)
                {
                    evt.propagationPhase = PropagationPhase.AtTarget;
                    evt.currentTarget    = evt.target;
                    evt.currentTarget.HandleEvent(evt);
                }

                // Phase 3: bubble Up phase
                // Propagate event from target parent up to root
                if (evt.bubbles && paths != null && paths.bubblePath.Count > 0)
                {
                    evt.propagationPhase = PropagationPhase.BubbleUp;

                    foreach (VisualElement ve in paths.bubblePath)
                    {
                        if (evt.isPropagationStopped)
                        {
                            break;
                        }

                        if (ve == evt.skipElement)
                        {
                            continue;
                        }

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

                evt.dispatch         = false;
                evt.propagationPhase = PropagationPhase.None;
                evt.currentTarget    = null;
            }
        }