Newer
Older
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using Newtonsoft.Json.Serialization;
using UnityEngine.EventSystems;
using static UnityEngine.EventSystems.PointerEventData;
Bjoern Esswein
committed
namespace bessw.Unity.WebView.ChromeDevTools.Protocol.Input
Bjoern Esswein
committed
#region dispatchMouseEvent
/// <summary>
/// Dispatches a mouse event to the page.
/// </summary>
public class dispatchMouseEvent: IDevtoolsCommand
Bjoern Esswein
committed
public dispatchMouseEvent(MouseEventType type, int x, int y)
Bjoern Esswein
committed
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)
Bjoern Esswein
committed
case InputButton.Left:
button = MouseButton.Left; break;
case InputButton.Right:
button = MouseButton.Right; break;
case InputButton.Middle:
button = MouseButton.Middle; break;
Bjoern Esswein
committed
clickCount = eventData.clickCount;
// TODO: delta compensate stream and texture scaling
deltaX = (int?)eventData.delta.x;
deltaY = (int?)eventData.delta.y;
}
Bjoern Esswein
committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/// <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; }
}
Bjoern Esswein
committed
public enum MouseEventType
{
MousePressed, MouseReleased, MouseMoved, MouseWheel
}
Bjoern Esswein
committed
public enum MouseButton
{
None, Left, Middle, Right, Back, Forward
}
Bjoern Esswein
committed
[Flags]
public enum MouseButtonFlags
{
None = 0, Left = 1, Right = 2, Middle = 4, Back = 8, Forward = 16
}
Bjoern Esswein
committed
public enum PointerType
{
Mouse, Pen
}
#endregion dispatchMouseEvent
Bjoern Esswein
committed
#region dispatchDragEvent
Bjoern Esswein
committed
/// <summary>
/// Cancels any active dragging in the page.
/// </summary>
public class cancelDragging : IDevtoolsCommand
{
Bjoern Esswein
committed
}
Bjoern Esswein
committed
/// <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; }
Bjoern Esswein
committed
}
Bjoern Esswein
committed
public enum DragEventType
{
dragEnter, dragOver, drop, dragCancel
}
Bjoern Esswein
committed
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; }
}
Bjoern Esswein
committed
[Flags]
public enum DragOperationsMask
{
Copy = 1, Link = 2, Move = 16
}
Bjoern Esswein
committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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