internal static void PropagateToIMGUIContainer(VisualElement root, EventBase evt) { //We don't support IMGUIContainers in player if (evt.imguiEvent == null || root.elementPanel.contextType == ContextType.Player) { return; } // Send the event to the first IMGUIContainer that can handle it. if (root.isIMGUIContainer) { var imContainer = root as IMGUIContainer; if (evt.Skip(imContainer)) { // IMGUIContainer have no children. We can return without iterating the children list. return; } // Only permit switching the focus to another IMGUIContainer if the event target was not focusable. bool targetIsFocusable = (evt.target as Focusable)?.focusable ?? false; if (imContainer.SendEventToIMGUI(evt, !targetIsFocusable)) { evt.StopPropagation(); evt.PreventDefault(); } if (evt.imguiEvent.rawType == EventType.Used) { Debug.Assert(evt.isPropagationStopped); } } if (root.imguiContainerDescendantCount > 0) { using (ListPool <VisualElement> .Get(out var childrenToNotify)) { childrenToNotify.AddRange(root.hierarchy.children); foreach (var child in childrenToNotify) { // if child is no longer in the hierarchy (removed when notified another child. See issue 1413477) // , then ignore it. if (child.hierarchy.parent != root) { continue; } PropagateToIMGUIContainer(child, evt); if (evt.isPropagationStopped) { break; } } } } }
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; }
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 static void PropagateEvent(EventBase evt) { Debug.Assert(!evt.dispatch, "Event is being dispatched recursively."); evt.dispatch = true; bool flag = evt.path == null; if (flag) { CallbackEventHandler expr_36 = evt.target as CallbackEventHandler; if (expr_36 != null) { expr_36.HandleEventAtTargetPhase(evt); } } else { bool tricklesDown = evt.tricklesDown; if (tricklesDown) { evt.propagationPhase = PropagationPhase.TrickleDown; for (int i = evt.path.trickleDownPath.Count - 1; i >= 0; i--) { bool isPropagationStopped = evt.isPropagationStopped; if (isPropagationStopped) { break; } bool flag2 = evt.Skip(evt.path.trickleDownPath[i]); if (!flag2) { evt.currentTarget = evt.path.trickleDownPath[i]; evt.currentTarget.HandleEvent(evt); } } } evt.propagationPhase = PropagationPhase.AtTarget; foreach (VisualElement current in evt.path.targetElements) { bool flag3 = evt.Skip(current); if (!flag3) { evt.target = current; evt.currentTarget = evt.target; evt.currentTarget.HandleEvent(evt); } } evt.propagationPhase = PropagationPhase.DefaultActionAtTarget; foreach (VisualElement current2 in evt.path.targetElements) { bool flag4 = evt.Skip(current2); if (!flag4) { evt.target = current2; evt.currentTarget = evt.target; evt.currentTarget.HandleEvent(evt); } } evt.target = evt.leafTarget; bool bubbles = evt.bubbles; if (bubbles) { evt.propagationPhase = PropagationPhase.BubbleUp; foreach (VisualElement current3 in evt.path.bubbleUpPath) { bool flag5 = evt.Skip(current3); if (!flag5) { evt.currentTarget = current3; evt.currentTarget.HandleEvent(evt); } } } } evt.dispatch = false; evt.propagationPhase = PropagationPhase.None; evt.currentTarget = null; }
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; }