Skip to content
Snippets Groups Projects
Select Git revision
  • 0b1eaf92ab8741548793dadf4dda7280a422630d
  • main default
2 results

Input.cs

Blame
  • Input.cs 8.71 KiB
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;
    using System;
    using Newtonsoft.Json.Serialization;
    using UnityEngine.EventSystems;
    using static UnityEngine.EventSystems.PointerEventData;
    
    #nullable enable annotations
    namespace bessw.Unity.WebView.ChromeDevTools.Protocol.Input
    {
        #region dispatchMouseEvent
        /// <summary>
        /// Dispatches a mouse event to the page.
        /// </summary>
        public class dispatchMouseEvent: IDevtoolsCommand
        {
            public dispatchMouseEvent(MouseEventType type, int x, int y)
            {
                this.type = type;
                this.x = x;
                this.y = y;
            }
            public dispatchMouseEvent(MouseEventType type, int x, int y, PointerEventData eventData) : this(type, x, y)
            {
                switch (eventData.button)
                {
                    case InputButton.Left:
                        button = MouseButton.Left; break;
                    case InputButton.Right:
                        button = MouseButton.Right; break;
                    case InputButton.Middle:
                        button = MouseButton.Middle; break;
                }
                clickCount = eventData.clickCount;
                // TODO: delta compensate stream and texture scaling
                deltaX = (int?)eventData.delta.x;
                deltaY = (int?)eventData.delta.y;
            }
    
            /// <summary>
            /// Type of the mouse event.
            /// Allowed Values: mousePressed, mouseReleased, mouseMoved, mouseWheel
            /// </summary>
            [JsonConverter(typeof(StringEnumConverter), typeof(CamelCaseNamingStrategy))]
            public MouseEventType type { get; set; }
            /// <summary>
            /// X coordinate of the event relative to the main frame's viewport in CSS pixels.
            /// </summary>
            public int x { get; set; }
            /// <summary>
            /// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
            /// </summary>
            public int y { get; set; }
            /// <summary>
            /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public ModifierKeyFlags? modifiers { get; set; }
            /// <summary>
            /// Time at which the event occurred.
            /// TimeSinceEpoch UTC time in seconds, counted from January 1, 1970.
            /// </summary>
            [JsonConverter(typeof(UnixDateTimeConverter))]
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public DateTime? timestamp { get; set; }
            /// <summary>
            /// Allowed Values: none, left, middle, right, back, forward
            /// Mouse button (default: "none").
            /// </summary>
            [JsonConverter(typeof(StringEnumConverter), typeof(CamelCaseNamingStrategy))]
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public MouseButton? button { get; set; }
            /// <summary>
            /// A number indicating which buttons are pressed on the mouse when a mouse event is triggered. Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public MouseButtonFlags? buttons { get; set; }
            /// <summary>
            /// Number of times the mouse button was clicked (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? clickCount { get; set; }
            /// <summary>
            /// The normalized pressure, which has a range of [0,1] (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? force { get; set; }
            /// <summary>
            /// The normalized tangential pressure, which has a range of [-1,1] (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? tangentialPressure { get; set; }
            /// <summary>
            /// The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? tiltX { get; set; }
            /// <summary>
            /// The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? tiltY { get; set; }
            /// <summary>
            /// The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? twist { get; set; }
            /// <summary>
            /// X delta in CSS pixels for mouse wheel event (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? deltaX { get; set; }
            /// <summary>
            /// Y delta in CSS pixels for mouse wheel event (default: 0).
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public int? deltaY { get; set; }
            /// <summary>
            /// Pointer type (default: "mouse").
            /// Allowed Values: mouse, pen
            /// </summary>
            [JsonConverter(typeof(StringEnumConverter), typeof(CamelCaseNamingStrategy))]
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public PointerType? pointerType { get; set; }
        }
    
        public enum MouseEventType
        {
            MousePressed, MouseReleased, MouseMoved, MouseWheel
        }
    
        public enum MouseButton
        {
            None, Left, Middle, Right, Back, Forward
        }
    
        [Flags]
        public enum MouseButtonFlags
        {
            None = 0, Left = 1, Right = 2, Middle = 4, Back = 8, Forward = 16
        }
    
        public enum PointerType
        {
            Mouse, Pen
        }
        #endregion dispatchMouseEvent
    
        #region dispatchDragEvent
    
        /// <summary>
        /// Cancels any active dragging in the page.
        /// </summary>
        public class cancelDragging : IDevtoolsCommand
        {
    
        }
    
        /// <summary>
        /// Dispatches a drag event into the page.
        /// </summary>
        public class dispatchDragEvent : IDevtoolsCommand
        {
            /// <summary>
            /// Type of the drag event.
            /// Allowed Values: dragEnter, dragOver, drop, dragCancel
            /// </summary>
            [JsonConverter(typeof(StringEnumConverter), typeof(CamelCaseNamingStrategy))]
            public DragEventType type { get; set; }
            public int x { get; set; }
            public int y { get; set; }
            public DragData data { get; set; }
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public ModifierKeyFlags? modifiers { get; set; }
    
        }
    
        public enum DragEventType
        {
            dragEnter, dragOver, drop, dragCancel
        }
    
        public class DragData
        {
            public DragDataItem[] items { get; set; }
            /// <summary>
            /// List of filenames that should be included when dropping
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public string[]? files { get; set; }
            public DragOperationsMask dragOperationsMask { get; set; }
        }
    
        [Flags]
        public enum DragOperationsMask
        {
            Copy = 1, Link = 2, Move = 16
        }
    
        public class DragDataItem
        {
            /// <summary>
            /// Mime type of the dragged data.
            /// </summary>
            public string mimeType { get; set; } = "";
            /// <summary>
            /// Depending of the value of mimeType, it contains the dragged link, text, HTML markup or any other data.
            /// </summary>
            public string data { get; set; } = "";
            /// <summary>
            /// Title associated with a link. Only valid when mimeType == "text/uri-list".
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public string? title { get; set; } = null;
            /// <summary>
            /// Stores the base URL for the contained markup. Only valid when mimeType == "text/html".
            /// </summary>
            [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
            public string? baseURL { get; set; } = null;
        }
        #endregion dispatchDragEvent
    
        /// <summary>
        /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
        /// </summary>
        [Flags]
        public enum ModifierKeyFlags
        {
            None = 0, Alt = 1, Ctrl = 2, Meta_Command = 4, Shift = 8
        }
    }