Ejemplo n.º 1
0
        void DispatchMouseEnterMouseLeave(VisualElement previousTopElementUnderMouse, VisualElement currentTopElementUnderMouse, Event triggerEvent)
        {
            if (previousTopElementUnderMouse == currentTopElementUnderMouse)
            {
                return;
            }

            // We want to find the common ancestor CA of previousTopElementUnderMouse and currentTopElementUnderMouse,
            // send MouseLeave events to elements between CA and previousTopElementUnderMouse
            // and send MouseEnter events to elements between CA and currentTopElementUnderMouse.

            int prevDepth = 0;
            var p         = previousTopElementUnderMouse;

            while (p != null)
            {
                prevDepth++;
                p = p.shadow.parent;
            }

            int currDepth = 0;
            var c         = currentTopElementUnderMouse;

            while (c != null)
            {
                currDepth++;
                c = c.shadow.parent;
            }

            p = previousTopElementUnderMouse;
            c = currentTopElementUnderMouse;

            while (prevDepth > currDepth)
            {
                using (var leaveEvent = MouseLeaveEvent.GetPooled(triggerEvent))
                {
                    leaveEvent.target = p;
                    DispatchEvent(leaveEvent, p.panel);
                }

                prevDepth--;
                p = p.shadow.parent;
            }

            // We want to send enter events after all the leave events.
            // We will store the elements being entered in this list.
            List <VisualElement> enteringElements = new List <VisualElement>(currDepth);

            while (currDepth > prevDepth)
            {
                enteringElements.Add(c);

                currDepth--;
                c = c.shadow.parent;
            }

            // Now p and c are at the same depth. Go up the tree until p == c.
            while (p != c)
            {
                using (var leaveEvent = MouseLeaveEvent.GetPooled(triggerEvent))
                {
                    leaveEvent.target = p;
                    DispatchEvent(leaveEvent, p.panel);
                }

                enteringElements.Add(c);

                p = p.shadow.parent;
                c = c.shadow.parent;
            }

            for (var i = enteringElements.Count - 1; i >= 0; i--)
            {
                using (var enterEvent = MouseEnterEvent.GetPooled(triggerEvent))
                {
                    enterEvent.target = enteringElements[i];
                    DispatchEvent(enterEvent, enteringElements[i].panel);
                }
            }
        }
Ejemplo n.º 2
0
 void DispatchMouseEnterMouseLeave(VisualElement previousTopElementUnderMouse, VisualElement currentTopElementUnderMouse, IMouseEvent triggerEvent)
 {
     DispatchEnterLeave(previousTopElementUnderMouse, currentTopElementUnderMouse, () => MouseEnterEvent.GetPooled(triggerEvent), () => MouseLeaveEvent.GetPooled(triggerEvent));
 }
 void DispatchMouseEnterMouseLeave(VisualElement previousTopElementUnderMouse, VisualElement currentTopElementUnderMouse, IMouseEvent triggerEvent)
 {
     if (triggerEvent != null)
     {
         DispatchEnterLeave(previousTopElementUnderMouse, currentTopElementUnderMouse, () => MouseEnterEvent.GetPooled(triggerEvent), () => MouseLeaveEvent.GetPooled(triggerEvent));
     }
     else
     {
         DispatchEnterLeave(previousTopElementUnderMouse, currentTopElementUnderMouse, () => MouseEnterEvent.GetPooled(m_LastMousePosition), () => MouseLeaveEvent.GetPooled(m_LastMousePosition));
     }
 }