public void DispatchEvent(EventBase evt, IPanel panel) { EventBehavior captureBehavior = EventBehavior.None; if (MouseCaptureController.mouseCapture == null) { return; } // Release mouse capture if capture element is not in a panel. VisualElement captureVE = MouseCaptureController.mouseCapture as VisualElement; if (evt.eventTypeId != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { MouseCaptureController.ReleaseMouse(); return; } if (panel != null && captureVE != null && captureVE.panel.contextType != panel.contextType) { return; } IMouseEvent mouseEvent = evt as IMouseEvent; if (mouseEvent != null && (evt.target == null || evt.target == MouseCaptureController.mouseCapture)) { // Exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; captureBehavior |= EventBehavior.IsSentExclusivelyToCapturingElement; } else if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; } if (evt.eventTypeId == MouseEnterWindowEvent.TypeId() || evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == WheelEvent.TypeId()) { captureBehavior = EventBehavior.None; } if ((captureBehavior & EventBehavior.IsCapturable) == EventBehavior.IsCapturable) { BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel; if (mouseEvent != null && basePanel != null) { bool shouldRecomputeTopElementUnderMouse = true; if ((IMouseEventInternal)mouseEvent != null) { shouldRecomputeTopElementUnderMouse = ((IMouseEventInternal)mouseEvent).recomputeTopElementUnderMouse; } VisualElement elementUnderMouse = shouldRecomputeTopElementUnderMouse ? basePanel.Pick(mouseEvent.mousePosition) : basePanel.topElementUnderMouse; basePanel.SetElementUnderMouse(elementUnderMouse, evt); } IEventHandler originalCaptureElement = MouseCaptureController.mouseCapture; evt.dispatch = true; evt.target = MouseCaptureController.mouseCapture; evt.currentTarget = MouseCaptureController.mouseCapture; evt.propagationPhase = PropagationPhase.AtTarget; MouseCaptureController.mouseCapture.HandleEvent(evt); // Do further processing with a target computed the usual way. // However, if mouseEventWasCaptured, the only thing remaining to do is ExecuteDefaultAction, // which should be done with mouseCapture as the target. if ((captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) != EventBehavior.IsSentExclusivelyToCapturingElement) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElements.Add(originalCaptureElement); evt.stopDispatch = (captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) == EventBehavior.IsSentExclusivelyToCapturingElement; evt.propagateToIMGUI = false; } }
public void DispatchEvent(EventBase evt, IPanel panel) { EventBehavior captureBehavior = EventBehavior.None; IEventHandler capturingElement = panel?.GetCapturingElement(PointerId.mousePointerId); if (capturingElement == null) { return; } // Release mouse capture if capture element is not in a panel. VisualElement captureVE = capturingElement as VisualElement; if (evt.eventTypeId != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { captureVE.ReleaseMouse(); return; } if (panel != null && captureVE != null && captureVE.panel.contextType != panel.contextType) { return; } IMouseEvent mouseEvent = evt as IMouseEvent; if (mouseEvent != null && (evt.target == null || evt.target == capturingElement)) { // Exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; captureBehavior |= EventBehavior.IsSentExclusivelyToCapturingElement; } else if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; } if (evt.eventTypeId == MouseEnterWindowEvent.TypeId() || evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == WheelEvent.TypeId()) { captureBehavior = EventBehavior.None; } if ((captureBehavior & EventBehavior.IsCapturable) == EventBehavior.IsCapturable) { BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel; if (mouseEvent != null && basePanel != null) { bool shouldRecomputeTopElementUnderMouse = (mouseEvent as IMouseEventInternal)?.recomputeTopElementUnderMouse ?? true; if (shouldRecomputeTopElementUnderMouse) { basePanel.RecomputeTopElementUnderPointer(mouseEvent.mousePosition, evt); } } evt.dispatch = true; evt.target = capturingElement; evt.currentTarget = capturingElement; (capturingElement as CallbackEventHandler)?.HandleEventAtTargetPhase(evt); // Do further processing with a target computed the usual way. // However, if IsSentExclusivelyToCapturingElement, the only thing remaining to do is ExecuteDefaultAction, // which should be done with mouseCapture as the target. if ((captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) != EventBehavior.IsSentExclusivelyToCapturingElement) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElements.Add(capturingElement); evt.stopDispatch = (captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) == EventBehavior.IsSentExclusivelyToCapturingElement; if (evt.target is IMGUIContainer) { evt.propagateToIMGUI = true; evt.skipElements.Add(evt.target); } else { evt.propagateToIMGUI = false; } } }
public void DispatchEvent(EventBase evt, IPanel panel) { EventBehavior captureBehavior = EventBehavior.None; IEventHandler capturingElement = panel?.GetCapturingElement(PointerId.mousePointerId); if (capturingElement == null) { return; } // Release mouse capture if capture element is not in a panel. VisualElement captureVE = capturingElement as VisualElement; if (evt.eventTypeId != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { captureVE.ReleaseMouse(); return; } // Case 1342115: mouse position is in local panel coordinates; sending event to a target from a different // panel will lead to a wrong position, so we don't allow it. Note that in general the mouse-down-move-up // sequence still works properly because the OS captures the mouse on the starting EditorWindow. if (panel != null && captureVE != null && captureVE.panel != panel) { return; } IMouseEvent mouseEvent = evt as IMouseEvent; if (mouseEvent != null && (evt.target == null || evt.target == capturingElement)) { // Exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; captureBehavior |= EventBehavior.IsSentExclusivelyToCapturingElement; } else if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. captureBehavior = EventBehavior.IsCapturable; } if (evt.eventTypeId == MouseEnterWindowEvent.TypeId() || evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == WheelEvent.TypeId()) { captureBehavior = EventBehavior.None; } if ((captureBehavior & EventBehavior.IsCapturable) == EventBehavior.IsCapturable) { BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel; if (mouseEvent != null && basePanel != null) { bool shouldRecomputeTopElementUnderMouse = (mouseEvent as IMouseEventInternal)?.recomputeTopElementUnderMouse ?? true; if (shouldRecomputeTopElementUnderMouse) { basePanel.RecomputeTopElementUnderPointer(PointerId.mousePointerId, mouseEvent.mousePosition, evt); } } evt.dispatch = true; evt.target = capturingElement; var skipDisabledElements = evt.skipDisabledElements; evt.skipDisabledElements = false; (capturingElement as CallbackEventHandler)?.HandleEventAtTargetPhase(evt); // Do further processing with a target computed the usual way. // However, if IsSentExclusivelyToCapturingElement, the only thing remaining to do is ExecuteDefaultAction, // which should be done with mouseCapture as the target. if ((captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) != EventBehavior.IsSentExclusivelyToCapturingElement) { evt.target = null; evt.skipDisabledElements = skipDisabledElements; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElements.Add(capturingElement); evt.stopDispatch = (captureBehavior & EventBehavior.IsSentExclusivelyToCapturingElement) == EventBehavior.IsSentExclusivelyToCapturingElement; if (evt.target is IMGUIContainer) { evt.propagateToIMGUI = true; evt.skipElements.Add(evt.target); } else { evt.propagateToIMGUI = false; } } }