private void OnPointerCapturedOut(PointerCaptureOutEvent evt) { // Whenever the pointer is captured by another element, like a text input, we should reset the drag state. if (!useDragEvents) { ClearDragAndDropUI(); } m_DragState = DragState.None; }
public void DispatchEvent(EventBase evt, IPanel panel) { IPointerEvent pointerEvent = evt as IPointerEvent; if (pointerEvent == null) { return; } IEventHandler targetOverride = panel.GetCapturingElement(pointerEvent.pointerId); if (targetOverride == null) { return; } // Release pointer capture if capture element is not in a panel. VisualElement captureVE = targetOverride as VisualElement; if (evt.eventTypeId != PointerCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { panel.ReleasePointer(pointerEvent.pointerId); return; } if (evt.target != null && evt.target != targetOverride) { return; } if (evt.eventTypeId != PointerCaptureEvent.TypeId() && evt.eventTypeId != PointerCaptureOutEvent.TypeId()) { panel.ProcessPointerCapture(pointerEvent.pointerId); } // Exclusive processing by capturing element. evt.dispatch = true; evt.target = targetOverride; evt.currentTarget = targetOverride; evt.propagationPhase = PropagationPhase.AtTarget; targetOverride.HandleEvent(evt); // Leave evt.target = originalCaptureElement for ExecuteDefaultAction() evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; evt.stopDispatch = true; evt.propagateToIMGUI = false; }
public void ProcessPointerCapture(int pointerId) { if (m_PointerCapture[pointerId] == m_PendingPointerCapture[pointerId]) { return; } if (m_PointerCapture[pointerId] != null) { using (var e = PointerCaptureOutEvent.GetPooled(m_PointerCapture[pointerId], m_PendingPointerCapture[pointerId], pointerId)) { m_PointerCapture[pointerId].SendEvent(e); } if (pointerId == PointerId.mousePointerId) { using (var e = MouseCaptureOutEvent.GetPooled(m_PointerCapture[pointerId], m_PendingPointerCapture[pointerId], pointerId)) { m_PointerCapture[pointerId].SendEvent(e); } } } if (m_PendingPointerCapture[pointerId] != null) { using (var e = PointerCaptureEvent.GetPooled(m_PendingPointerCapture[pointerId], m_PointerCapture[pointerId], pointerId)) { m_PendingPointerCapture[pointerId].SendEvent(e); } if (pointerId == PointerId.mousePointerId) { using (var e = MouseCaptureEvent.GetPooled(m_PendingPointerCapture[pointerId], m_PointerCapture[pointerId], pointerId)) { m_PendingPointerCapture[pointerId].SendEvent(e); } } } m_PointerCapture[pointerId] = m_PendingPointerCapture[pointerId]; }
public void ProcessPointerCapture(int pointerId) { bool flag = this.m_PointerCapture[pointerId] == this.m_PendingPointerCapture[pointerId]; if (!flag) { bool flag2 = this.m_PointerCapture[pointerId] != null; if (flag2) { using (PointerCaptureOutEvent pooled = PointerCaptureEventBase <PointerCaptureOutEvent> .GetPooled(this.m_PointerCapture[pointerId], this.m_PendingPointerCapture[pointerId], pointerId)) { this.m_PointerCapture[pointerId].SendEvent(pooled); } bool flag3 = pointerId == PointerId.mousePointerId; if (flag3) { using (MouseCaptureOutEvent pooled2 = PointerCaptureEventBase <MouseCaptureOutEvent> .GetPooled(this.m_PointerCapture[pointerId], this.m_PendingPointerCapture[pointerId], pointerId)) { this.m_PointerCapture[pointerId].SendEvent(pooled2); } } } bool flag4 = this.m_PendingPointerCapture[pointerId] != null; if (flag4) { using (PointerCaptureEvent pooled3 = PointerCaptureEventBase <PointerCaptureEvent> .GetPooled(this.m_PendingPointerCapture[pointerId], this.m_PointerCapture[pointerId], pointerId)) { this.m_PendingPointerCapture[pointerId].SendEvent(pooled3); } bool flag5 = pointerId == PointerId.mousePointerId; if (flag5) { using (MouseCaptureEvent pooled4 = PointerCaptureEventBase <MouseCaptureEvent> .GetPooled(this.m_PendingPointerCapture[pointerId], this.m_PointerCapture[pointerId], pointerId)) { this.m_PendingPointerCapture[pointerId].SendEvent(pooled4); } } } this.m_PointerCapture[pointerId] = this.m_PendingPointerCapture[pointerId]; } }
public void DispatchEvent(EventBase evt, IPanel panel) { IPointerEvent pointerEvent = evt as IPointerEvent; if (pointerEvent == null) { return; } IEventHandler targetOverride = panel.GetCapturingElement(pointerEvent.pointerId); if (targetOverride == null) { return; } // Release pointer capture if capture element is not in a panel. VisualElement captureVE = targetOverride as VisualElement; if (evt.eventTypeId != PointerCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { panel.ReleasePointer(pointerEvent.pointerId); return; } if (evt.target != null && evt.target != targetOverride) { 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; } if (evt.eventTypeId != PointerCaptureEvent.TypeId() && evt.eventTypeId != PointerCaptureOutEvent.TypeId()) { panel.ProcessPointerCapture(pointerEvent.pointerId); } // Case 1353921: this will enforce PointerEnter/Out events even during pointer capture. // According to the W3 standard (https://www.w3.org/TR/pointerevents3/#the-pointerout-event), these events // are *not* supposed to occur, but we have been sending MouseEnter/Out events during mouse capture // since the early days of UI Toolkit, and users have been relying on it. if (panel is BaseVisualElementPanel basePanel) { bool shouldRecomputeTopElementUnderPointer = (pointerEvent as IPointerEventInternal)?.recomputeTopElementUnderPointer ?? true; if (shouldRecomputeTopElementUnderPointer) { basePanel.RecomputeTopElementUnderPointer(pointerEvent.pointerId, pointerEvent.position, evt); } } // Exclusive processing by capturing element. evt.dispatch = true; evt.target = targetOverride; evt.currentTarget = targetOverride; evt.propagationPhase = PropagationPhase.AtTarget; evt.skipDisabledElements = false; targetOverride.HandleEvent(evt); // Leave evt.target = originalCaptureElement for ExecuteDefaultAction() evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; evt.stopDispatch = true; evt.propagateToIMGUI = false; }