using System; using System.Collections.Generic; namespace UnityEngine.Experimental.UIElements { // Token: 0x02000316 RID: 790 internal class EventDispatcher : IDispatcher { // Token: 0x17000B61 RID: 2913 // (get) Token: 0x06003227 RID: 12839 RVA: 0x0004A98C File Offset: 0x00048B8C // (set) Token: 0x06003228 RID: 12840 RVA: 0x0004A9A8 File Offset: 0x00048BA8 public IEventHandler capture { get; set; } // Token: 0x06003229 RID: 12841 RVA: 0x0004A9B4 File Offset: 0x00048BB4 public void ReleaseCapture(IEventHandler handler) { Debug.Assert(handler == this.capture, "Element releasing capture does not have capture"); this.capture = null; } // Token: 0x0600322A RID: 12842 RVA: 0x0004A9D4 File Offset: 0x00048BD4 public void RemoveCapture() { if (this.capture != null) { this.capture.OnLostCapture(); } this.capture = null; } // Token: 0x0600322B RID: 12843 RVA: 0x0004A9F8 File Offset: 0x00048BF8 public void TakeCapture(IEventHandler handler) { if (this.capture != handler) { if (GUIUtility.hotControl != 0) { Debug.Log("Should not be capturing when there is a hotcontrol"); } else { this.RemoveCapture(); this.capture = handler; } } } // Token: 0x17000B62 RID: 2914 // (get) Token: 0x0600322C RID: 12844 RVA: 0x0004AA34 File Offset: 0x00048C34 // (set) Token: 0x0600322D RID: 12845 RVA: 0x0004AA50 File Offset: 0x00048C50 private VisualElement elementUnderMouse { get { return this.m_ElementUnderMouse; } set { if (this.m_ElementUnderMouse != value) { if (this.m_ElementUnderMouse != null) { this.m_ElementUnderMouse.pseudoStates = this.m_ElementUnderMouse.pseudoStates & ~PseudoStates.Hover; } this.m_ElementUnderMouse = value; if (this.m_ElementUnderMouse != null) { this.m_ElementUnderMouse.pseudoStates = this.m_ElementUnderMouse.pseudoStates | PseudoStates.Hover; } } } } // Token: 0x0600322E RID: 12846 RVA: 0x0004AAC4 File Offset: 0x00048CC4 public EventPropagation DispatchEvent(Event e, BaseVisualElementPanel panel) { EventPropagation eventPropagation; if (e.type == EventType.Repaint) { Debug.Log("Repaint should be handled by Panel before Dispatcher"); eventPropagation = EventPropagation.Continue; } else { bool flag = false; if (this.capture != null && this.capture.panel == null) { Debug.Log(string.Format("Capture has no panel, forcing removal (capture={0} eventType={1})", this.capture, e.type)); this.RemoveCapture(); } if (this.capture != null) { if (this.capture.panel.contextType != panel.contextType) { return EventPropagation.Continue; } VisualElement visualElement = this.capture as VisualElement; if (visualElement != null) { e.mousePosition = visualElement.GlobalToBound(e.mousePosition); } else { IManipulator manipulator = this.capture as IManipulator; if (manipulator != null) { e.mousePosition = manipulator.target.GlobalToBound(e.mousePosition); } } flag = true; if (this.capture.HandleEvent(e, this.capture as VisualElement) == EventPropagation.Stop) { return EventPropagation.Stop; } } if (e.isKey) { flag = true; if (panel.focusedElement != null) { if (this.PropagateEvent(panel.focusedElement, e) == EventPropagation.Stop) { return EventPropagation.Stop; } } else if (this.SendEventToIMGUIContainers(panel.visualTree, e, panel.focusedElement) == EventPropagation.Stop) { return EventPropagation.Stop; } } else if (e.isMouse || e.isScrollWheel || e.type == EventType.DragUpdated || e.type == EventType.DragPerform || e.type == EventType.DragExited) { if (e.type == EventType.MouseLeaveWindow) { this.elementUnderMouse = null; } else { this.elementUnderMouse = panel.Pick(e.mousePosition); } if (e.type == EventType.MouseDown && this.elementUnderMouse != null && this.elementUnderMouse.enabled) { this.SetFocusedElement(panel, this.elementUnderMouse); } if (this.elementUnderMouse != null) { flag = true; if (this.PropagateEvent(this.elementUnderMouse, e) == EventPropagation.Stop) { return EventPropagation.Stop; } } if (e.type == EventType.MouseEnterWindow || e.type == EventType.MouseLeaveWindow) { flag = true; if (this.SendEventToIMGUIContainers(panel.visualTree, e, null) == EventPropagation.Stop) { return EventPropagation.Stop; } } } if (e.type == EventType.ExecuteCommand || e.type == EventType.ValidateCommand) { flag = true; if (panel.focusedElement != null && this.PropagateEvent(panel.focusedElement, e) == EventPropagation.Stop) { return EventPropagation.Stop; } if (this.SendEventToIMGUIContainers(panel.visualTree, e, panel.focusedElement) == EventPropagation.Stop) { return EventPropagation.Stop; } } if (e.type == EventType.Used) { flag = true; if (this.SendEventToIMGUIContainers(panel.visualTree, e, null) == EventPropagation.Stop) { return EventPropagation.Stop; } } if (!flag) { if (this.SendEventToIMGUIContainers(panel.visualTree, e, null) == EventPropagation.Stop) { return EventPropagation.Stop; } } eventPropagation = EventPropagation.Continue; } return eventPropagation; } // Token: 0x0600322F RID: 12847 RVA: 0x0004AE04 File Offset: 0x00049004 private EventPropagation SendEventToIMGUIContainers(VisualElement root, Event evt, VisualElement skipElement) { IMGUIContainer imguicontainer = root as IMGUIContainer; EventPropagation eventPropagation; if (imguicontainer != null && imguicontainer != skipElement) { if (imguicontainer.HandleEvent(evt, imguicontainer) == EventPropagation.Stop) { eventPropagation = EventPropagation.Stop; } else { eventPropagation = EventPropagation.Continue; } } else { VisualContainer visualContainer = root as VisualContainer; if (visualContainer != null) { for (int i = 0; i < visualContainer.childrenCount; i++) { if (this.SendEventToIMGUIContainers(visualContainer.GetChildAt(i), evt, skipElement) == EventPropagation.Stop) { return EventPropagation.Stop; } } } eventPropagation = EventPropagation.Continue; } return eventPropagation; } // Token: 0x06003230 RID: 12848 RVA: 0x0004AE90 File Offset: 0x00049090 private EventPropagation PropagateEvent(VisualElement target, Event evt) { List list = this.BuildPropagationPath(target); Vector2 mousePosition = evt.mousePosition; for (int i = 0; i < list.Count; i++) { VisualElement visualElement = list[i]; if (visualElement.enabled) { evt.mousePosition = visualElement.GlobalToBound(mousePosition); List.Enumerator manipulatorsInternal = visualElement.GetManipulatorsInternal(); while (manipulatorsInternal.MoveNext()) { IManipulator manipulator = manipulatorsInternal.Current; if (manipulator.phaseInterest == EventPhase.Capture && manipulator.HandleEvent(evt, target) == EventPropagation.Stop) { return EventPropagation.Stop; } } if (visualElement.phaseInterest != EventPhase.Capture || visualElement.HandleEvent(evt, target) != EventPropagation.Stop) { goto IL_A2; } return EventPropagation.Stop; } IL_A2:; } if (target.enabled) { evt.mousePosition = target.GlobalToBound(mousePosition); List.Enumerator enumerator = target.GetManipulatorsInternal(); while (enumerator.MoveNext()) { IManipulator manipulator2 = enumerator.Current; if (manipulator2.phaseInterest == EventPhase.Capture && manipulator2.HandleEvent(evt, target) == EventPropagation.Stop) { return EventPropagation.Stop; } } if (target.HandleEvent(evt, target) == EventPropagation.Stop) { return EventPropagation.Stop; } enumerator = target.GetManipulatorsInternal(); while (enumerator.MoveNext()) { IManipulator manipulator3 = enumerator.Current; if (manipulator3.phaseInterest == EventPhase.BubbleUp && manipulator3.HandleEvent(evt, target) == EventPropagation.Stop) { return EventPropagation.Stop; } } } for (int j = list.Count - 1; j >= 0; j--) { VisualElement visualElement2 = list[j]; if (visualElement2.enabled) { evt.mousePosition = visualElement2.GlobalToBound(mousePosition); if (visualElement2.phaseInterest == EventPhase.BubbleUp && visualElement2.HandleEvent(evt, target) == EventPropagation.Stop) { return EventPropagation.Stop; } List.Enumerator manipulatorsInternal2 = visualElement2.GetManipulatorsInternal(); while (manipulatorsInternal2.MoveNext()) { IManipulator manipulator4 = manipulatorsInternal2.Current; if (manipulator4.phaseInterest == EventPhase.BubbleUp && manipulator4.HandleEvent(evt, target) == EventPropagation.Stop) { return EventPropagation.Stop; } } } } return EventPropagation.Continue; } // Token: 0x06003231 RID: 12849 RVA: 0x0004B0CC File Offset: 0x000492CC private void SetFocusedElement(BaseVisualElementPanel panel, VisualElement element) { if (panel.focusedElement != element) { if (panel.focusedElement != null) { panel.focusedElement.pseudoStates = panel.focusedElement.pseudoStates & ~PseudoStates.Focus; panel.focusedElement.OnLostKeyboardFocus(); } panel.focusedElement = element; if (element != null) { element.pseudoStates |= PseudoStates.Focus; } } } // Token: 0x06003232 RID: 12850 RVA: 0x0004B13C File Offset: 0x0004933C private List BuildPropagationPath(VisualElement elem) { List list = new List(); List list2; if (elem == null) { list2 = list; } else { while (elem.parent != null) { list.Insert(0, elem.parent); elem = elem.parent; } list2 = list; } return list2; } // Token: 0x04000A24 RID: 2596 private VisualElement m_ElementUnderMouse; } }