public override void ExecuteDefaultActionAtTarget(EventBase evt) { base.ExecuteDefaultActionAtTarget(evt); if (keyboardOnScreen != null) { return; } var edition = textElement.edition; if (!edition.isReadOnly && evt.eventTypeId == PointerDownEvent.TypeId()) { // CaptureMouse is preventing WebGL from processing pointerDown event in // TextInputFieldBase during the Javascript event handler, preventing the // keyboard from being displayed. Disable the capture behavior for WebGL. textElement.CaptureMouse(); m_LastPointerDownTarget = evt.target as VisualElement; } else if (!edition.isReadOnly && evt.eventTypeId == PointerUpEvent.TypeId()) { textElement.ReleaseMouse(); if (m_LastPointerDownTarget == null || !m_LastPointerDownTarget.worldBound.Contains(((PointerUpEvent)evt).position)) { return; } m_LastPointerDownTarget = null; edition.UpdateText(editingUtilities.text); OpenTouchScreenKeyboard(); if (keyboardOnScreen != null) { PollTouchScreenKeyboard(); } // Scroll offset might need to be updated edition.UpdateScrollOffset?.Invoke(); evt.StopPropagation(); } }
public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e) { if (e.eventTypeId == PointerDownEvent.TypeId()) { if (focusController.GetFocusableParentForPointerEvent(e.target as Focusable, out var target)) { return(VisualElementFocusChangeTarget.GetPooled(target)); } } if (e.eventTypeId == NavigationMoveEvent.TypeId()) { switch (((NavigationMoveEvent)e).direction) { case NavigationMoveEvent.Direction.Left: return(Left); case NavigationMoveEvent.Direction.Up: return(Up); case NavigationMoveEvent.Direction.Right: return(Right); case NavigationMoveEvent.Direction.Down: return(Down); } } //TODO: make NavigationTabEvent public and use it here else if (e.eventTypeId == KeyDownEvent.TypeId()) { var kde = (KeyDownEvent)e; // Important: using KeyDownEvent.character for focus prevents a TextField bug. // IMGUI sends KeyDownEvent with keyCode != None, then it sends another one with character != '\0'. // If we use keyCode instead of character, TextField will receive focus on the first KeyDownEvent, // then text will become selected and, in the case of multiline, the KeyDownEvent with character = '\t' // will immediately overwrite the text with a single Tab string. if (kde.character == (char)25 || kde.character == '\t') { return(kde.shiftKey ? Previous : Next); } } return(FocusChangeDirection.none); }
public override void ExecuteDefaultActionAtTarget(EventBase evt) { base.ExecuteDefaultActionAtTarget(evt); if (!textInputField.isReadOnly && evt.eventTypeId == PointerDownEvent.TypeId() && editorEngine.keyboardOnScreen == null) { m_LastPointerDownTarget = evt.target as VisualElement; } else if (!textInputField.isReadOnly && evt.eventTypeId == PointerUpEvent.TypeId() && editorEngine.keyboardOnScreen == null) { var pointerUpEvent = evt as PointerUpEvent; if (m_LastPointerDownTarget == null || !m_LastPointerDownTarget.worldBound.Contains(pointerUpEvent.position)) { return; } textInputField.SyncTextEngine(); textInputField.UpdateText(editorEngine.text); editorEngine.keyboardOnScreen = TouchScreenKeyboard.Open(textInputField.text, TouchScreenKeyboardType.Default, true, // autocorrection editorEngine.multiline, textInputField.isPasswordField); #if UNITY_IOS || UNITY_ANDROID s_KeyboardOnScreen = editorEngine.keyboardOnScreen; #endif if (editorEngine.keyboardOnScreen != null) { PollTouchScreenKeyboard(); } // Scroll offset might need to be updated editorEngine.UpdateScrollOffset(); evt.StopPropagation(); } }
void UpdateEventbaseInfo(EventDebuggerEventRecord eventBase, IEventHandler focused, IEventHandler capture) { ClearEventbaseInfo(); if (eventBase == null) { return; } m_EventbaseInfo.text += "Focused element: " + EventDebugger.GetObjectDisplayName(focused) + "\n"; m_EventbaseInfo.text += "Capture element: " + EventDebugger.GetObjectDisplayName(capture) + "\n"; if (eventBase.eventTypeId == MouseMoveEvent.TypeId() || eventBase.eventTypeId == MouseOverEvent.TypeId() || eventBase.eventTypeId == MouseOutEvent.TypeId() || eventBase.eventTypeId == MouseDownEvent.TypeId() || eventBase.eventTypeId == MouseUpEvent.TypeId() || eventBase.eventTypeId == MouseEnterEvent.TypeId() || eventBase.eventTypeId == MouseLeaveEvent.TypeId() || eventBase.eventTypeId == DragEnterEvent.TypeId() || eventBase.eventTypeId == DragLeaveEvent.TypeId() || eventBase.eventTypeId == DragUpdatedEvent.TypeId() || eventBase.eventTypeId == DragPerformEvent.TypeId() || eventBase.eventTypeId == DragExitedEvent.TypeId() || eventBase.eventTypeId == ContextClickEvent.TypeId() || eventBase.eventTypeId == PointerMoveEvent.TypeId() || eventBase.eventTypeId == PointerOverEvent.TypeId() || eventBase.eventTypeId == PointerOutEvent.TypeId() || eventBase.eventTypeId == PointerDownEvent.TypeId() || eventBase.eventTypeId == PointerUpEvent.TypeId() || eventBase.eventTypeId == PointerCancelEvent.TypeId() || eventBase.eventTypeId == PointerStationaryEvent.TypeId() || eventBase.eventTypeId == PointerEnterEvent.TypeId() || eventBase.eventTypeId == PointerLeaveEvent.TypeId()) { m_EventbaseInfo.text += "Mouse position: " + eventBase.mousePosition + "\n"; m_EventbaseInfo.text += "Modifiers: " + eventBase.modifiers + "\n"; } if (eventBase.eventTypeId == KeyDownEvent.TypeId() || eventBase.eventTypeId == KeyUpEvent.TypeId()) { m_EventbaseInfo.text += "Modifiers: " + eventBase.modifiers + "\n"; } if (eventBase.eventTypeId == MouseDownEvent.TypeId() || eventBase.eventTypeId == MouseUpEvent.TypeId() || eventBase.eventTypeId == PointerDownEvent.TypeId() || eventBase.eventTypeId == PointerUpEvent.TypeId() || eventBase.eventTypeId == DragUpdatedEvent.TypeId() || eventBase.eventTypeId == DragPerformEvent.TypeId() || eventBase.eventTypeId == DragExitedEvent.TypeId()) { m_EventbaseInfo.text += "Button: " + (eventBase.button == 0 ? "Left" : eventBase.button == 1 ? "Middle" : "Right") + "\n"; m_EventbaseInfo.text += "Click count: " + eventBase.clickCount + "\n"; } if (eventBase.eventTypeId == MouseMoveEvent.TypeId() || eventBase.eventTypeId == MouseOverEvent.TypeId() || eventBase.eventTypeId == MouseOutEvent.TypeId() || eventBase.eventTypeId == MouseDownEvent.TypeId() || eventBase.eventTypeId == MouseUpEvent.TypeId() || eventBase.eventTypeId == MouseEnterEvent.TypeId() || eventBase.eventTypeId == MouseLeaveEvent.TypeId() || eventBase.eventTypeId == DragEnterEvent.TypeId() || eventBase.eventTypeId == DragLeaveEvent.TypeId() || eventBase.eventTypeId == DragUpdatedEvent.TypeId() || eventBase.eventTypeId == DragPerformEvent.TypeId() || eventBase.eventTypeId == DragExitedEvent.TypeId() || eventBase.eventTypeId == ContextClickEvent.TypeId() || eventBase.eventTypeId == WheelEvent.TypeId() || eventBase.eventTypeId == PointerMoveEvent.TypeId() || eventBase.eventTypeId == PointerOverEvent.TypeId() || eventBase.eventTypeId == PointerOutEvent.TypeId() || eventBase.eventTypeId == PointerDownEvent.TypeId() || eventBase.eventTypeId == PointerUpEvent.TypeId() || eventBase.eventTypeId == PointerCancelEvent.TypeId() || eventBase.eventTypeId == PointerStationaryEvent.TypeId() || eventBase.eventTypeId == PointerEnterEvent.TypeId() || eventBase.eventTypeId == PointerLeaveEvent.TypeId()) { m_EventbaseInfo.text += "Pressed buttons: " + eventBase.pressedButtons + "\n"; } if (eventBase.eventTypeId == WheelEvent.TypeId()) { m_EventbaseInfo.text += "Mouse delta: " + eventBase.delta + "\n"; } if (eventBase.eventTypeId == KeyDownEvent.TypeId() || eventBase.eventTypeId == KeyUpEvent.TypeId()) { if (char.IsControl(eventBase.character)) { m_EventbaseInfo.text += "Character: \\" + (byte)(eventBase.character) + "\n"; } else { m_EventbaseInfo.text += "Character: " + eventBase.character + "\n"; } m_EventbaseInfo.text += "Key code: " + eventBase.keyCode + "\n"; } if (eventBase.eventTypeId == ValidateCommandEvent.TypeId() || eventBase.eventTypeId == ExecuteCommandEvent.TypeId()) { m_EventbaseInfo.text += "Command: " + eventBase.commandName + "\n"; } }
internal void CommitElementUnderPointers(EventDispatcher dispatcher) { for (var i = 0; i < m_TopElementUnderPointer.Length; i++) { if (m_TopElementUnderPointer[i] == m_PendingTopElementUnderPointer[i]) { continue; } if (m_TriggerPointerEvent[i] == null && m_TriggerMouseEvent[i] == null) { using (new EventDispatcherGate(dispatcher)) { Vector2 position = PointerDeviceState.GetPointerPosition(i); PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position, i); if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position); } } } if (m_TriggerPointerEvent[i] != null) { if ((m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerMoveEvent.TypeId() || (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerDownEvent.TypeId() || (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerUpEvent.TypeId() || (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerCancelEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerPointerEvent[i], m_TriggerPointerEvent[i].position, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerPointerEvent[i], m_TriggerPointerEvent[i].position, i); } } m_TriggerPointerEvent[i] = null; } if (m_TriggerMouseEvent[i] != null) { if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseMoveEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseDownEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseUpEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == WheelEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); } } else if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseEnterWindowEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseLeaveWindowEvent.TypeId() ) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); } } } else if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == DragUpdatedEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == DragExitedEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <DragLeaveEvent, DragEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); } } m_TriggerMouseEvent[i] = null; } m_TopElementUnderPointer[i] = m_PendingTopElementUnderPointer[i]; } }
internal void CommitElementUnderPointers(EventDispatcher dispatcher) { for (var i = 0; i < m_TopElementUnderPointer.Length; i++) { var triggerPointerEvent = m_TriggerPointerEvent[i]; var previous = m_TopElementUnderPointer[i]; var current = m_PendingTopElementUnderPointer[i]; if (current == previous) { if (triggerPointerEvent != null) { var pos3d = triggerPointerEvent.position; m_PickingPointerPositions[i] = new Vector2(pos3d.x, pos3d.y); } else if (m_TriggerMouseEvent[i] != null) { m_PickingPointerPositions[i] = m_TriggerMouseEvent[i].mousePosition; } continue; } m_TopElementUnderPointer[i] = current; if (triggerPointerEvent == null && m_TriggerMouseEvent[i] == null) { using (new EventDispatcherGate(dispatcher)) { Vector2 position = PointerDeviceState.GetPointerPosition(i); PointerEventsHelper.SendOverOut(previous, current, null, position, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, null, position, i); m_PickingPointerPositions[i] = position; if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(previous, current, null, position); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, null, position); } } } if (triggerPointerEvent != null) { var pos3d = triggerPointerEvent.position; m_PickingPointerPositions[i] = new Vector2(pos3d.x, pos3d.y); var baseEvent = triggerPointerEvent as EventBase; if (baseEvent != null && ( baseEvent.eventTypeId == PointerMoveEvent.TypeId() || baseEvent.eventTypeId == PointerDownEvent.TypeId() || baseEvent.eventTypeId == PointerUpEvent.TypeId() || baseEvent.eventTypeId == PointerCancelEvent.TypeId())) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(previous, current, triggerPointerEvent, pos3d, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, triggerPointerEvent, pos3d, i); } } } m_TriggerPointerEvent[i] = null; var triggerMouseEvent = m_TriggerMouseEvent[i]; if (triggerMouseEvent != null) { Vector2 mousePos = triggerMouseEvent.mousePosition; m_PickingPointerPositions[i] = mousePos; var baseEvent = triggerMouseEvent as EventBase; if (baseEvent != null) { if (baseEvent.eventTypeId == MouseMoveEvent.TypeId() || baseEvent.eventTypeId == MouseDownEvent.TypeId() || baseEvent.eventTypeId == MouseUpEvent.TypeId() || baseEvent.eventTypeId == WheelEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, triggerMouseEvent, mousePos); } } else if (baseEvent.eventTypeId == MouseEnterWindowEvent.TypeId() || baseEvent.eventTypeId == MouseLeaveWindowEvent.TypeId() ) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(previous, current, null, mousePos, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, null, mousePos, i); if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, triggerMouseEvent, mousePos); } } } else if (baseEvent.eventTypeId == DragUpdatedEvent.TypeId() || baseEvent.eventTypeId == DragExitedEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(previous, current, null, mousePos, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, null, mousePos, i); MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <DragLeaveEvent, DragEnterEvent>( previous, current, triggerMouseEvent, mousePos); } } } m_TriggerMouseEvent[i] = null; } } }