-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增Mortise.BrowserAccessibility初步定义 (#18)
- Loading branch information
Showing
14 changed files
with
257 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Browser/Mortise.BrowserAccessibility/BrowserAccessible.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Drawing; | ||
using Mortise.Accessibility.Abstractions; | ||
|
||
namespace Mortise.BrowserAccessibility; | ||
|
||
public abstract class BrowserAccessible(IBrowserAccessibleContext context) : Accessible | ||
{ | ||
protected readonly IBrowserAccessibleContext Context = context ?? throw new ArgumentNullException(nameof(context)); | ||
protected BrowserDescriptor Descriptor { get; set; } | ||
public BrowserEngine Engine { get; protected set; } | ||
public abstract Task<IPageAccessibleAction> AttachTo(Point location, string process); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Browser/Mortise.BrowserAccessibility/BrowserDescriptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Mortise.Accessibility.Abstractions; | ||
|
||
namespace Mortise.BrowserAccessibility; | ||
|
||
public class BrowserDescriptor : IAccessibleDescriptor | ||
{ | ||
public string ExecutablePath { get; set; } | ||
public HashSet<string> Profiles { get; set; } | ||
public Version Version { get; set; } | ||
public BrowserEngine Engine { get; set; } | ||
public string[] SupportedProcessNames { get; set; } | ||
public string IdentityString { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Mortise.BrowserAccessibility; | ||
|
||
public enum BrowserEngine | ||
{ | ||
/// <summary> | ||
/// Trident. | ||
/// </summary> | ||
Trident, | ||
|
||
/// <summary> | ||
/// Gecko. | ||
/// </summary> | ||
Gecko, | ||
|
||
/// <summary> | ||
/// Webkit | ||
/// </summary> | ||
Webkit, | ||
|
||
/// <summary> | ||
/// Chromium | ||
/// </summary> | ||
Chromium | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Mortise.BrowserAccessibility; | ||
|
||
public class Frame | ||
{ | ||
private Frame? Parent { get; set; } | ||
public string Name { get; set; } | ||
public string Src { get; set; } | ||
public string Id { get; set; } | ||
|
||
public Stack<Frame> Child { get; set; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Browser/Mortise.BrowserAccessibility/IBrowserAccessibleAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Mortise.BrowserAccessibility; | ||
|
||
public interface IBrowserAccessibleAction | ||
{ | ||
public bool IsConnected { get; } | ||
public Process Process { get; } | ||
public string UniqueId { get; } | ||
public IBrowserAccessibleContext Context { get; } | ||
public Task<IPageAccessibleAction[]?> GetPagesAsync(); | ||
public Task<IPageAccessibleAction> NewPageAsync(); | ||
public Task<IPageAccessibleAction> GetActivePageAsync(); | ||
public Task<IPageAccessibleAction[]?> GetPagesByTitleAsync(string title); | ||
public Task<IPageAccessibleAction[]?> GetPagesByUrlAsync(string url); | ||
public Task CloseAsync(); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Browser/Mortise.BrowserAccessibility/IBrowserAccessibleContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
|
||
namespace Mortise.BrowserAccessibility; | ||
|
||
public interface IBrowserAccessibleContext | ||
{ | ||
public Process[] GetRunningProcess(); | ||
|
||
/// <summary> | ||
/// 获取矩形框 | ||
/// </summary> | ||
/// <returns></returns> | ||
public Rectangle GetBoundingRectangle(); | ||
|
||
/// <summary> | ||
/// 获取RenderWidget矩形框 | ||
/// </summary> | ||
/// <returns></returns> | ||
public Rectangle GetRenderingBoundingRectangle(); | ||
|
||
public void SetMaximize(); | ||
|
||
public void SetMinimize(); | ||
|
||
public BrowserDescriptor GetDescriptor(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Mortise.BrowserAccessibility; | ||
|
||
public interface IFunction | ||
{ | ||
public string Name { get; set; } | ||
|
||
public dynamic Parameter { get; set; } | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Browser/Mortise.BrowserAccessibility/IPageAccessibleAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Drawing; | ||
using Mortise.BrowserAccessibility.Options; | ||
|
||
namespace Mortise.BrowserAccessibility; | ||
|
||
public interface IPageAccessibleAction | ||
{ | ||
public bool IsActive { get; } | ||
|
||
public bool IsReady { get; } | ||
|
||
public string Url { get; } | ||
|
||
public string UniqueId { get; } | ||
|
||
public Task<string> GetTitleAsync(); | ||
|
||
public Task SetActivateAsync(); | ||
|
||
public Task GotoAsync(string url); | ||
|
||
public Task CloseAsync(); | ||
|
||
public Task<bool> GoBackAsync(); | ||
|
||
public Task<bool> GoForwardAsync(); | ||
|
||
public Task<bool> ReloadAsync(); | ||
|
||
public Task<bool> InjectScriptAsync(InjectScriptOptions options); | ||
|
||
public Task<bool> Ping(); | ||
|
||
public Task ElementFromPoint(Point location); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Browser/Mortise.BrowserAccessibility/Mortise.BrowserAccessibility.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\..\nuget.props"></Import> | ||
<Import Project="..\..\..\common.props"></Import> | ||
<Import Project="..\..\..\version.props"></Import> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Tenon.Serialization.Abstractions" Version="0.0.1-alpha-202406271301" /> | ||
<PackageReference Include="Tenon.Serialization.Json" Version="0.0.1-alpha-202406271301" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Mortise.Accessibility.Abstractions\Mortise.Accessibility.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
src/Browser/Mortise.BrowserAccessibility/Options/InjectScriptOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Mortise.BrowserAccessibility.Options; | ||
|
||
public class InjectScriptOptions | ||
{ | ||
public string Content { get; set; } | ||
public string Type { get; set; } = "text/javascript"; | ||
public required object Id { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Browser/Mortise.BrowserAccessibility/Options/LaunchOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Mortise.BrowserAccessibility.Options; | ||
|
||
public class LaunchOptions | ||
{ | ||
public bool Headless { get; set; } | ||
|
||
public string ExecutablePath { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace Mortise.BrowserAccessibility; | ||
|
||
public abstract class Request<TRes> | ||
{ | ||
public Response<TRes> Response { get; private set; } | ||
|
||
public TRes Result => Response.Result; | ||
|
||
protected virtual async Task OnBeforeRequestAsync() | ||
{ | ||
await Task.CompletedTask; | ||
} | ||
|
||
protected abstract Task<Response<TRes>> EvaluateAsync(IFunction function); | ||
|
||
protected abstract Task<Response<TRes>> ContinueEvaluateAsync(Frame iframe); | ||
|
||
public async Task ExecuteAsync(IFunction function) | ||
{ | ||
await OnBeforeRequestAsync(); | ||
var response = await EvaluateAsync(function); | ||
if (response.Ok) | ||
{ | ||
Response = response; | ||
return; | ||
} | ||
await OnContinueExecuteRequestAsync(response); | ||
} | ||
|
||
private async Task OnContinueExecuteRequestAsync(Response<TRes> response) | ||
{ | ||
var iframes = response.Frame.Child; | ||
foreach (var iframe in iframes) | ||
{ | ||
var iframeResponse = await ContinueEvaluateAsync(iframe); | ||
if (iframeResponse.Ok) | ||
{ | ||
Response = iframeResponse; | ||
break; | ||
} | ||
|
||
await OnContinueExecuteRequestAsync(iframeResponse); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Mortise.BrowserAccessibility; | ||
|
||
public class Response<TRes> | ||
{ | ||
public Frame? Frame { get; set; } | ||
|
||
public TRes? Result { get; set; } | ||
|
||
public bool Ok { get; set; } | ||
|
||
public bool IsNavigationRequest { get; set; } | ||
} |