Skip to content

Commit 5516358

Browse files
Replace deprecated scroll-touch-events with input-event
1 parent 941b8cf commit 5516358

File tree

12 files changed

+711
-353
lines changed

12 files changed

+711
-353
lines changed

ElectronNET.API/BrowserWindow.cs

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -702,93 +702,6 @@ public event Action<string> OnAppCommand
702702

703703
private event Action<string> _appCommand;
704704

705-
/// <summary>
706-
/// Emitted when scroll wheel event phase has begun.
707-
/// </summary>
708-
public event Action OnScrollTouchBegin
709-
{
710-
add
711-
{
712-
if (_scrollTouchBegin == null)
713-
{
714-
BridgeConnector.Socket.On("browserWindow-scroll-touch-begin" + Id, () =>
715-
{
716-
_scrollTouchBegin();
717-
});
718-
719-
BridgeConnector.Socket.Emit("register-browserWindow-scroll-touch-begin", Id);
720-
}
721-
_scrollTouchBegin += value;
722-
}
723-
remove
724-
{
725-
_scrollTouchBegin -= value;
726-
727-
if (_scrollTouchBegin == null)
728-
BridgeConnector.Socket.Off("browserWindow-scroll-touch-begin" + Id);
729-
}
730-
}
731-
732-
private event Action _scrollTouchBegin;
733-
734-
/// <summary>
735-
/// Emitted when scroll wheel event phase has ended.
736-
/// </summary>
737-
public event Action OnScrollTouchEnd
738-
{
739-
add
740-
{
741-
if (_scrollTouchEnd == null)
742-
{
743-
BridgeConnector.Socket.On("browserWindow-scroll-touch-end" + Id, () =>
744-
{
745-
_scrollTouchEnd();
746-
});
747-
748-
BridgeConnector.Socket.Emit("register-browserWindow-scroll-touch-end", Id);
749-
}
750-
_scrollTouchEnd += value;
751-
}
752-
remove
753-
{
754-
_scrollTouchEnd -= value;
755-
756-
if (_scrollTouchEnd == null)
757-
BridgeConnector.Socket.Off("browserWindow-scroll-touch-end" + Id);
758-
}
759-
}
760-
761-
private event Action _scrollTouchEnd;
762-
763-
/// <summary>
764-
/// Emitted when scroll wheel event phase filed upon reaching the edge of element.
765-
/// </summary>
766-
public event Action OnScrollTouchEdge
767-
{
768-
add
769-
{
770-
if (_scrollTouchEdge == null)
771-
{
772-
BridgeConnector.Socket.On("browserWindow-scroll-touch-edge" + Id, () =>
773-
{
774-
_scrollTouchEdge();
775-
});
776-
777-
BridgeConnector.Socket.Emit("register-browserWindow-scroll-touch-edge", Id);
778-
}
779-
_scrollTouchEdge += value;
780-
}
781-
remove
782-
{
783-
_scrollTouchEdge -= value;
784-
785-
if (_scrollTouchEdge == null)
786-
BridgeConnector.Socket.Off("browserWindow-scroll-touch-edge" + Id);
787-
}
788-
}
789-
790-
private event Action _scrollTouchEdge;
791-
792705
/// <summary>
793706
/// Emitted on 3-finger swipe. Possible directions are up, right, down, left.
794707
/// </summary>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using ElectronNET.API.Entities;
5+
using Newtonsoft.Json;
6+
using Newtonsoft.Json.Linq;
7+
8+
namespace ElectronNET.API.Converter;
9+
10+
/// <summary>
11+
///
12+
/// </summary>
13+
public class ModifierTypeListConverter : JsonConverter<List<ModifierType>>
14+
{
15+
/// <summary>
16+
///
17+
/// </summary>
18+
/// <param name="reader"></param>
19+
/// <param name="objectType"></param>
20+
/// <param name="existingValue"></param>
21+
/// <param name="hasExistingValue"></param>
22+
/// <param name="serializer"></param>
23+
/// <returns></returns>
24+
public override List<ModifierType> ReadJson(JsonReader reader, Type objectType, List<ModifierType> existingValue, bool hasExistingValue, JsonSerializer serializer)
25+
{
26+
var token = JToken.Load(reader);
27+
28+
if (token.Type == JTokenType.Null)
29+
{
30+
return null;
31+
}
32+
33+
34+
return token.ToObject<List<string>>().Select(m => (ModifierType)Enum.Parse(typeof(ModifierType), m)).ToList();
35+
}
36+
37+
/// <summary>
38+
///
39+
/// </summary>
40+
/// <param name="writer"></param>
41+
/// <param name="value"></param>
42+
/// <param name="serializer"></param>
43+
public override void WriteJson(JsonWriter writer, List<ModifierType> value, JsonSerializer serializer)
44+
{
45+
writer.WriteStartArray();
46+
47+
foreach (var modifier in value)
48+
{
49+
writer.WriteValue(modifier.ToString());
50+
}
51+
52+
writer.WriteEndArray();
53+
}
54+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using Newtonsoft.Json.Converters;
2+
using System.Collections.Generic;
3+
using ElectronNET.API.Converter;
4+
using Newtonsoft.Json;
5+
6+
namespace ElectronNET.API.Entities
7+
{
8+
/// <summary>
9+
///
10+
/// </summary>
11+
public class InputEvent
12+
{
13+
/// <summary>
14+
/// Equivalent to KeyboardEvent.key.
15+
/// </summary>
16+
public string Key { get; set; } = "";
17+
18+
/// <summary>
19+
/// Equivalent to KeyboardEvent.code.
20+
/// </summary>
21+
public string Code { get; set; } = "";
22+
23+
/// <summary>
24+
/// Equivalent to KeyboardEvent.repeat.
25+
/// </summary>
26+
public bool IsAutoRepeat { get; set; } = false;
27+
28+
/// <summary>
29+
/// Equivalent to KeyboardEvent.isComposing.
30+
/// </summary>
31+
public bool IsComposing { get; set; } = false;
32+
33+
/// <summary>
34+
/// Equivalent to KeyboardEvent.shiftKey.
35+
/// </summary>
36+
public bool Shift { get; set; } = false;
37+
38+
/// <summary>
39+
/// Equivalent to KeyboardEvent.controlKey.
40+
/// </summary>
41+
public bool Control { get; set; } = false;
42+
43+
/// <summary>
44+
/// Equivalent to KeyboardEvent.altKey.
45+
/// </summary>
46+
public bool Alt { get; set; } = false;
47+
48+
/// <summary>
49+
/// Equivalent to KeyboardEvent.metaKey.
50+
/// </summary>
51+
public bool Meta { get; set; } = false;
52+
53+
/// <summary>
54+
/// Equivalent to KeyboardEvent.location.
55+
/// </summary>
56+
public int Location { get; set; } = 0;
57+
58+
/// <summary>
59+
/// An array of modifiers of the event, can be `shift`, `control`, `ctrl`, `alt`,
60+
/// `meta`, `command`, `cmd`, `isKeypad`, `isAutoRepeat`, `leftButtonDown`,
61+
/// `middleButtonDown`, `rightButtonDown`, `capsLock`, `numLock`, `left`, `right`
62+
/// </summary>
63+
[JsonConverter(typeof(ModifierTypeListConverter))]
64+
public List<ModifierType> Modifiers { get; set; }
65+
66+
/// <summary>
67+
/// Can be `undefined`, `mouseDown`, `mouseUp`, `mouseMove`, `mouseEnter`,
68+
/// `mouseLeave`, `contextMenu`, `mouseWheel`, `rawKeyDown`, `keyDown`, `keyUp`,
69+
/// `gestureScrollBegin`, `gestureScrollEnd`, `gestureScrollUpdate`,
70+
/// `gestureFlingStart`, `gestureFlingCancel`, `gesturePinchBegin`,
71+
/// `gesturePinchEnd`, `gesturePinchUpdate`, `gestureTapDown`, `gestureShowPress`,
72+
/// `gestureTap`, `gestureTapCancel`, `gestureShortPress`, `gestureLongPress`,
73+
/// `gestureLongTap`, `gestureTwoFingerTap`, `gestureTapUnconfirmed`,
74+
/// `gestureDoubleTap`, `touchStart`, `touchMove`, `touchEnd`, `touchCancel`,
75+
/// `touchScrollStarted`, `pointerDown`, `pointerUp`, `pointerMove`,
76+
/// `pointerRawUpdate`, `pointerCancel` or `pointerCausedUaAction`.
77+
/// </summary>
78+
[JsonConverter(typeof(StringEnumConverter))]
79+
public InputEventType Type { get; set; }
80+
}
81+
}

0 commit comments

Comments
 (0)