Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions dotnet/src/webdriver/BiDi/Input/InputModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,5 @@ protected override void Initialize(IBiDi bidi, JsonSerializerOptions jsonSeriali
[JsonSerializable(typeof(SetFilesCommand))]
[JsonSerializable(typeof(SetFilesResult))]
[JsonSerializable(typeof(FileDialogEventArgs))]
[JsonSerializable(typeof(IEnumerable<IPointerSourceAction>))]
[JsonSerializable(typeof(IEnumerable<IKeySourceAction>))]
[JsonSerializable(typeof(IEnumerable<INoneSourceAction>))]
[JsonSerializable(typeof(IEnumerable<IWheelSourceAction>))]

internal partial class InputJsonSerializerContext : JsonSerializerContext;
176 changes: 0 additions & 176 deletions dotnet/src/webdriver/BiDi/Input/SequentialSourceActions.cs

This file was deleted.

93 changes: 39 additions & 54 deletions dotnet/src/webdriver/BiDi/Input/SourceActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,37 @@
// under the License.
// </copyright>

using System.Collections;
using System.Text.Json.Serialization;
using OpenQA.Selenium.BiDi.Json.Converters;
using OpenQA.Selenium.BiDi.Json.Converters.Enumerable;

namespace OpenQA.Selenium.BiDi.Input;

[JsonConverter(typeof(InputSourceActionsConverter))]
public abstract record SourceActions(string Id);

public interface ISourceAction;

public abstract record SourceActions<T>(string Id) : SourceActions(Id), IEnumerable<ISourceAction> where T : ISourceAction
{
public IList<ISourceAction> Actions { get; init; } = [];

public IEnumerator<ISourceAction> GetEnumerator() => Actions.GetEnumerator();
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
[JsonDerivedType(typeof(KeySourceActions), "key")]
[JsonDerivedType(typeof(PointerSourceActions), "pointer")]
[JsonDerivedType(typeof(WheelSourceActions), "wheel")]
[JsonDerivedType(typeof(NoneSourceActions), "none")]
public abstract record SourceActions;

IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator();
public abstract record SourceActions<TSourceAction>(string Id, IEnumerable<TSourceAction> Actions)
: SourceActions where TSourceAction : ISourceAction;

public void Add(ISourceAction action) => Actions.Add(action);
}
public interface ISourceAction;

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

public sealed record KeyActions(string Id) : SourceActions<IKeySourceAction>(Id)
public sealed record KeySourceActions(string Id, IEnumerable<IKeySourceAction> Actions)
: SourceActions<IKeySourceAction>(Id, Actions)
{
public KeyActions Type(string text)
// TODO move out as extension method
public KeySourceActions Type(string text) => this with
{
foreach (var character in text)
{
Add(new KeyDownAction(character));
Add(new KeyUpAction(character));
}

return this;
}
Actions = [.. Actions, .. text.SelectMany<char, IKeySourceAction>(c => [new KeyDownAction(c), new KeyUpAction(c)])]
};
}

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

public sealed record PointerActions(string Id) : SourceActions<IPointerSourceAction>(Id)
public sealed record PointerSourceActions(string Id, IEnumerable<IPointerSourceAction> Actions)
: SourceActions<IPointerSourceAction>(Id, Actions)
{
public PointerParameters? Options { get; init; }
public PointerParameters? Parameters { get; init; }
}

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

public sealed record WheelActions(string Id) : SourceActions<IWheelSourceAction>(Id);
public sealed record WheelSourceActions(string Id, IEnumerable<IWheelSourceAction> Actions)
: SourceActions<IWheelSourceAction>(Id, Actions);

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

public sealed record NoneActions(string Id) : SourceActions<INoneSourceAction>(Id);

public abstract record KeySourceAction : IKeySourceAction;
public sealed record NoneSourceActions(string Id, IEnumerable<INoneSourceAction> Actions)
: SourceActions<INoneSourceAction>(Id, Actions);

public sealed record KeyDownAction(char Value) : KeySourceAction;
public sealed record KeyDownAction(char Value) : IKeySourceAction;

public sealed record KeyUpAction(char Value) : KeySourceAction;
public sealed record KeyUpAction(char Value) : IKeySourceAction;

public abstract record PointerSourceAction : IPointerSourceAction;

public sealed record PointerDownAction(int Button) : PointerSourceAction, IPointerCommonProperties
public sealed record PointerDownAction(long Button) : IPointerSourceAction, IPointerCommonProperties
{
public int? Width { get; init; }
public int? Height { get; init; }
public long? Width { get; init; }
public long? Height { get; init; }
public double? Pressure { get; init; }
public double? TangentialPressure { get; init; }
public int? Twist { get; init; }
public long? Twist { get; init; }
public double? AltitudeAngle { get; init; }
public double? AzimuthAngle { get; init; }
}

public sealed record PointerUpAction(int Button) : PointerSourceAction;
public sealed record PointerUpAction(long Button) : IPointerSourceAction;

public sealed record PointerMoveAction(double X, double Y) : PointerSourceAction, IPointerCommonProperties
public sealed record PointerMoveAction(double X, double Y) : IPointerSourceAction, IPointerCommonProperties
{
public int? Duration { get; init; }
public long? Duration { get; init; }

public Origin? Origin { get; init; }

public int? Width { get; init; }
public int? Height { get; init; }
public long? Width { get; init; }
public long? Height { get; init; }
public double? Pressure { get; init; }
public double? TangentialPressure { get; init; }
public int? Twist { get; init; }
public long? Twist { get; init; }
public double? AltitudeAngle { get; init; }
public double? AzimuthAngle { get; init; }
}

public abstract record WheelSourceAction : IWheelSourceAction;

public sealed record WheelScrollAction(int X, int Y, int DeltaX, int DeltaY) : WheelSourceAction
public sealed record WheelScrollAction(long X, long Y, long DeltaX, long DeltaY) : IWheelSourceAction
{
public int? Duration { get; init; }
public long? Duration { get; init; }

public Origin? Origin { get; init; }
}

public abstract record NoneSourceAction : INoneSourceAction;

public sealed record PauseAction : ISourceAction, IKeySourceAction, IPointerSourceAction, IWheelSourceAction, INoneSourceAction
{
public long? Duration { get; init; }
Expand All @@ -152,15 +137,15 @@ public enum PointerType

public interface IPointerCommonProperties
{
public int? Width { get; init; }
public long? Width { get; init; }

public int? Height { get; init; }
public long? Height { get; init; }

public double? Pressure { get; init; }

public double? TangentialPressure { get; init; }

public int? Twist { get; init; }
public long? Twist { get; init; }

public double? AltitudeAngle { get; init; }

Expand Down
Loading
Loading