Skip to content

Commit 3c525d8

Browse files
authored
[dotnet] [bidi] Remove enumerable json converter for Input module (#17285)
1 parent 4a4c593 commit 3c525d8

File tree

5 files changed

+78
-323
lines changed

5 files changed

+78
-323
lines changed

dotnet/src/webdriver/BiDi/Input/InputModule.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,5 @@ protected override void Initialize(IBiDi bidi, JsonSerializerOptions jsonSeriali
7575
[JsonSerializable(typeof(SetFilesCommand))]
7676
[JsonSerializable(typeof(SetFilesResult))]
7777
[JsonSerializable(typeof(FileDialogEventArgs))]
78-
[JsonSerializable(typeof(IEnumerable<IPointerSourceAction>))]
79-
[JsonSerializable(typeof(IEnumerable<IKeySourceAction>))]
80-
[JsonSerializable(typeof(IEnumerable<INoneSourceAction>))]
81-
[JsonSerializable(typeof(IEnumerable<IWheelSourceAction>))]
8278

8379
internal partial class InputJsonSerializerContext : JsonSerializerContext;

dotnet/src/webdriver/BiDi/Input/SequentialSourceActions.cs

Lines changed: 0 additions & 176 deletions
This file was deleted.

dotnet/src/webdriver/BiDi/Input/SourceActions.cs

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,37 @@
1717
// under the License.
1818
// </copyright>
1919

20-
using System.Collections;
2120
using System.Text.Json.Serialization;
2221
using OpenQA.Selenium.BiDi.Json.Converters;
23-
using OpenQA.Selenium.BiDi.Json.Converters.Enumerable;
2422

2523
namespace OpenQA.Selenium.BiDi.Input;
2624

27-
[JsonConverter(typeof(InputSourceActionsConverter))]
28-
public abstract record SourceActions(string Id);
29-
30-
public interface ISourceAction;
31-
32-
public abstract record SourceActions<T>(string Id) : SourceActions(Id), IEnumerable<ISourceAction> where T : ISourceAction
33-
{
34-
public IList<ISourceAction> Actions { get; init; } = [];
35-
36-
public IEnumerator<ISourceAction> GetEnumerator() => Actions.GetEnumerator();
25+
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
26+
[JsonDerivedType(typeof(KeySourceActions), "key")]
27+
[JsonDerivedType(typeof(PointerSourceActions), "pointer")]
28+
[JsonDerivedType(typeof(WheelSourceActions), "wheel")]
29+
[JsonDerivedType(typeof(NoneSourceActions), "none")]
30+
public abstract record SourceActions;
3731

38-
IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator();
32+
public abstract record SourceActions<TSourceAction>(string Id, IEnumerable<TSourceAction> Actions)
33+
: SourceActions where TSourceAction : ISourceAction;
3934

40-
public void Add(ISourceAction action) => Actions.Add(action);
41-
}
35+
public interface ISourceAction;
4236

4337
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
4438
[JsonDerivedType(typeof(PauseAction), "pause")]
4539
[JsonDerivedType(typeof(KeyDownAction), "keyDown")]
4640
[JsonDerivedType(typeof(KeyUpAction), "keyUp")]
4741
public interface IKeySourceAction : ISourceAction;
4842

49-
public sealed record KeyActions(string Id) : SourceActions<IKeySourceAction>(Id)
43+
public sealed record KeySourceActions(string Id, IEnumerable<IKeySourceAction> Actions)
44+
: SourceActions<IKeySourceAction>(Id, Actions)
5045
{
51-
public KeyActions Type(string text)
46+
// TODO move out as extension method
47+
public KeySourceActions Type(string text) => this with
5248
{
53-
foreach (var character in text)
54-
{
55-
Add(new KeyDownAction(character));
56-
Add(new KeyUpAction(character));
57-
}
58-
59-
return this;
60-
}
49+
Actions = [.. Actions, .. text.SelectMany<char, IKeySourceAction>(c => [new KeyDownAction(c), new KeyUpAction(c)])]
50+
};
6151
}
6252

6353
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
@@ -67,71 +57,66 @@ public KeyActions Type(string text)
6757
[JsonDerivedType(typeof(PointerMoveAction), "pointerMove")]
6858
public interface IPointerSourceAction : ISourceAction;
6959

70-
public sealed record PointerActions(string Id) : SourceActions<IPointerSourceAction>(Id)
60+
public sealed record PointerSourceActions(string Id, IEnumerable<IPointerSourceAction> Actions)
61+
: SourceActions<IPointerSourceAction>(Id, Actions)
7162
{
72-
public PointerParameters? Options { get; init; }
63+
public PointerParameters? Parameters { get; init; }
7364
}
7465

7566
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
7667
[JsonDerivedType(typeof(PauseAction), "pause")]
7768
[JsonDerivedType(typeof(WheelScrollAction), "scroll")]
7869
public interface IWheelSourceAction : ISourceAction;
7970

80-
public sealed record WheelActions(string Id) : SourceActions<IWheelSourceAction>(Id);
71+
public sealed record WheelSourceActions(string Id, IEnumerable<IWheelSourceAction> Actions)
72+
: SourceActions<IWheelSourceAction>(Id, Actions);
8173

8274
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
8375
[JsonDerivedType(typeof(PauseAction), "pause")]
8476
public interface INoneSourceAction : ISourceAction;
8577

86-
public sealed record NoneActions(string Id) : SourceActions<INoneSourceAction>(Id);
87-
88-
public abstract record KeySourceAction : IKeySourceAction;
78+
public sealed record NoneSourceActions(string Id, IEnumerable<INoneSourceAction> Actions)
79+
: SourceActions<INoneSourceAction>(Id, Actions);
8980

90-
public sealed record KeyDownAction(char Value) : KeySourceAction;
81+
public sealed record KeyDownAction(char Value) : IKeySourceAction;
9182

92-
public sealed record KeyUpAction(char Value) : KeySourceAction;
83+
public sealed record KeyUpAction(char Value) : IKeySourceAction;
9384

94-
public abstract record PointerSourceAction : IPointerSourceAction;
95-
96-
public sealed record PointerDownAction(int Button) : PointerSourceAction, IPointerCommonProperties
85+
public sealed record PointerDownAction(long Button) : IPointerSourceAction, IPointerCommonProperties
9786
{
98-
public int? Width { get; init; }
99-
public int? Height { get; init; }
87+
public long? Width { get; init; }
88+
public long? Height { get; init; }
10089
public double? Pressure { get; init; }
10190
public double? TangentialPressure { get; init; }
102-
public int? Twist { get; init; }
91+
public long? Twist { get; init; }
10392
public double? AltitudeAngle { get; init; }
10493
public double? AzimuthAngle { get; init; }
10594
}
10695

107-
public sealed record PointerUpAction(int Button) : PointerSourceAction;
96+
public sealed record PointerUpAction(long Button) : IPointerSourceAction;
10897

109-
public sealed record PointerMoveAction(double X, double Y) : PointerSourceAction, IPointerCommonProperties
98+
public sealed record PointerMoveAction(double X, double Y) : IPointerSourceAction, IPointerCommonProperties
11099
{
111-
public int? Duration { get; init; }
100+
public long? Duration { get; init; }
112101

113102
public Origin? Origin { get; init; }
114103

115-
public int? Width { get; init; }
116-
public int? Height { get; init; }
104+
public long? Width { get; init; }
105+
public long? Height { get; init; }
117106
public double? Pressure { get; init; }
118107
public double? TangentialPressure { get; init; }
119-
public int? Twist { get; init; }
108+
public long? Twist { get; init; }
120109
public double? AltitudeAngle { get; init; }
121110
public double? AzimuthAngle { get; init; }
122111
}
123112

124-
public abstract record WheelSourceAction : IWheelSourceAction;
125-
126-
public sealed record WheelScrollAction(int X, int Y, int DeltaX, int DeltaY) : WheelSourceAction
113+
public sealed record WheelScrollAction(long X, long Y, long DeltaX, long DeltaY) : IWheelSourceAction
127114
{
128-
public int? Duration { get; init; }
115+
public long? Duration { get; init; }
129116

130117
public Origin? Origin { get; init; }
131118
}
132119

133-
public abstract record NoneSourceAction : INoneSourceAction;
134-
135120
public sealed record PauseAction : ISourceAction, IKeySourceAction, IPointerSourceAction, IWheelSourceAction, INoneSourceAction
136121
{
137122
public long? Duration { get; init; }
@@ -152,15 +137,15 @@ public enum PointerType
152137

153138
public interface IPointerCommonProperties
154139
{
155-
public int? Width { get; init; }
140+
public long? Width { get; init; }
156141

157-
public int? Height { get; init; }
142+
public long? Height { get; init; }
158143

159144
public double? Pressure { get; init; }
160145

161146
public double? TangentialPressure { get; init; }
162147

163-
public int? Twist { get; init; }
148+
public long? Twist { get; init; }
164149

165150
public double? AltitudeAngle { get; init; }
166151

0 commit comments

Comments
 (0)