| // <copyright file="InputModule.cs" company="Selenium Committers"> |
| // Licensed to the Software Freedom Conservancy (SFC) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The SFC licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // </copyright> |
| |
| using System.Text.Json.Serialization; |
| using static OpenQA.Selenium.BiDi.Input.InputJsonSerializerContext; |
| |
| namespace OpenQA.Selenium.BiDi.Input; |
| |
| internal sealed class InputModule : Module, IInputModule |
| { |
| private static readonly Command<PerformActionsParameters, PerformActionsResult> PerformActionsCommand = new( |
| "input.performActions", Default.PerformActionsParameters, Default.PerformActionsResult); |
| |
| private static readonly Command<ReleaseActionsParameters, ReleaseActionsResult> ReleaseActionsCommand = new( |
| "input.releaseActions", Default.ReleaseActionsParameters, Default.ReleaseActionsResult); |
| |
| private static readonly Command<SetFilesParameters, SetFilesResult> SetFilesCommand = new( |
| "input.setFiles", Default.SetFilesParameters, Default.SetFilesResult); |
| |
| private static readonly Event<FileDialogOpenedEventArgs, FileDialogInfo> FileDialogOpenedEvent = new( |
| "input.fileDialogOpened", |
| static (bidi, p) => new FileDialogOpenedEventArgs(bidi, p.Context, p.UserContext, p.Multiple, p.Element), |
| Default.FileDialogInfo); |
| |
| public async Task<PerformActionsResult> PerformActionsAsync(BrowsingContext.BrowsingContext context, IEnumerable<SourceActions> actions, PerformActionsOptions? options = null, CancellationToken cancellationToken = default) |
| { |
| var @params = new PerformActionsParameters(context, actions); |
| |
| return await ExecuteAsync(PerformActionsCommand, @params, options, cancellationToken).ConfigureAwait(false); |
| } |
| |
| public async Task<ReleaseActionsResult> ReleaseActionsAsync(BrowsingContext.BrowsingContext context, ReleaseActionsOptions? options = null, CancellationToken cancellationToken = default) |
| { |
| var @params = new ReleaseActionsParameters(context); |
| |
| return await ExecuteAsync(ReleaseActionsCommand, @params, options, cancellationToken).ConfigureAwait(false); |
| } |
| |
| public async Task<SetFilesResult> SetFilesAsync(BrowsingContext.BrowsingContext context, Script.ISharedReference element, IEnumerable<string> files, SetFilesOptions? options = null, CancellationToken cancellationToken = default) |
| { |
| var @params = new SetFilesParameters(context, element, files); |
| |
| return await ExecuteAsync(SetFilesCommand, @params, options, cancellationToken).ConfigureAwait(false); |
| } |
| |
| public async Task<Subscription> OnFileDialogOpenedAsync(Func<FileDialogOpenedEventArgs, Task> handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) |
| { |
| return await SubscribeAsync(FileDialogOpenedEvent, handler, options, cancellationToken).ConfigureAwait(false); |
| } |
| |
| public async Task<Subscription> OnFileDialogOpenedAsync(Action<FileDialogOpenedEventArgs> handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) |
| { |
| return await SubscribeAsync(FileDialogOpenedEvent, handler, options, cancellationToken).ConfigureAwait(false); |
| } |
| } |
| |
| [JsonSerializable(typeof(PerformActionsParameters))] |
| [JsonSerializable(typeof(PerformActionsResult))] |
| [JsonSerializable(typeof(ReleaseActionsParameters))] |
| [JsonSerializable(typeof(ReleaseActionsResult))] |
| [JsonSerializable(typeof(SetFilesParameters))] |
| [JsonSerializable(typeof(SetFilesResult))] |
| |
| [JsonSerializable(typeof(FileDialogInfo))] |
| |
| [JsonSourceGenerationOptions( |
| PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, |
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] |
| internal partial class InputJsonSerializerContext : JsonSerializerContext; |