Skip to content

Commit

Permalink
BrowserAccessibility 功能迭代 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
YanZhiwei authored Jul 29, 2024
1 parent f75ba35 commit f1baf3d
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 90 deletions.
35 changes: 19 additions & 16 deletions Mortise.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Browser", "Browser", "{F8E5
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.BrowserAccessibility", "src\Browser\Mortise.BrowserAccessibility\Mortise.BrowserAccessibility.csproj", "{C6D5A33A-1BC0-4868-B63A-D1416C868088}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.Platform", "src\Mortise.Platform\Mortise.Platform.csproj", "{5D4BD629-CD56-4261-88BF-031ED2F70E02}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.ChromiumAccessibility", "src\Browser\Mortise.ChromiumAccessibility\Mortise.ChromiumAccessibility.csproj", "{2CB367CC-3D83-4319-B9F2-00A9F7B006F7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.Platform.Windows", "src\Mortise.Platform.Windows\Mortise.Platform.Windows.csproj", "{97ED5FE4-3807-44DE-ADB6-B5841353AEBE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.Browser.Platform", "src\Browser\Mortise.Browser.Platform\Mortise.Browser.Platform.csproj", "{E9C2BAE6-BD3A-4C31-98BF-60E358FABA05}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.Platform.Linux", "src\Mortise.Platform.Linux\Mortise.Platform.Linux.csproj", "{4EF3D4AD-F7D0-4B6E-A9BF-C65FF4C95B06}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.Browser.Platform.Linux", "src\Browser\Mortise.Browser.Platform.Linux\Mortise.Browser.Platform.Linux.csproj", "{E9869ACA-E887-4864-B922-976A51BF032D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.ChromiumAccessibility", "src\Browser\Mortise.ChromiumAccessibility\Mortise.ChromiumAccessibility.csproj", "{2CB367CC-3D83-4319-B9F2-00A9F7B006F7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mortise.Browser.Platform.Windows", "src\Browser\Mortise.Browser.Platform.Windows\Mortise.Browser.Platform.Windows.csproj", "{E7CA1085-E006-411F-807D-1CE27FC912EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -82,22 +82,22 @@ Global
{C6D5A33A-1BC0-4868-B63A-D1416C868088}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6D5A33A-1BC0-4868-B63A-D1416C868088}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6D5A33A-1BC0-4868-B63A-D1416C868088}.Release|Any CPU.Build.0 = Release|Any CPU
{5D4BD629-CD56-4261-88BF-031ED2F70E02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D4BD629-CD56-4261-88BF-031ED2F70E02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D4BD629-CD56-4261-88BF-031ED2F70E02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D4BD629-CD56-4261-88BF-031ED2F70E02}.Release|Any CPU.Build.0 = Release|Any CPU
{97ED5FE4-3807-44DE-ADB6-B5841353AEBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97ED5FE4-3807-44DE-ADB6-B5841353AEBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97ED5FE4-3807-44DE-ADB6-B5841353AEBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97ED5FE4-3807-44DE-ADB6-B5841353AEBE}.Release|Any CPU.Build.0 = Release|Any CPU
{4EF3D4AD-F7D0-4B6E-A9BF-C65FF4C95B06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EF3D4AD-F7D0-4B6E-A9BF-C65FF4C95B06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EF3D4AD-F7D0-4B6E-A9BF-C65FF4C95B06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EF3D4AD-F7D0-4B6E-A9BF-C65FF4C95B06}.Release|Any CPU.Build.0 = Release|Any CPU
{2CB367CC-3D83-4319-B9F2-00A9F7B006F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CB367CC-3D83-4319-B9F2-00A9F7B006F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CB367CC-3D83-4319-B9F2-00A9F7B006F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CB367CC-3D83-4319-B9F2-00A9F7B006F7}.Release|Any CPU.Build.0 = Release|Any CPU
{E9C2BAE6-BD3A-4C31-98BF-60E358FABA05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9C2BAE6-BD3A-4C31-98BF-60E358FABA05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9C2BAE6-BD3A-4C31-98BF-60E358FABA05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9C2BAE6-BD3A-4C31-98BF-60E358FABA05}.Release|Any CPU.Build.0 = Release|Any CPU
{E9869ACA-E887-4864-B922-976A51BF032D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9869ACA-E887-4864-B922-976A51BF032D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9869ACA-E887-4864-B922-976A51BF032D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9869ACA-E887-4864-B922-976A51BF032D}.Release|Any CPU.Build.0 = Release|Any CPU
{E7CA1085-E006-411F-807D-1CE27FC912EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7CA1085-E006-411F-807D-1CE27FC912EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7CA1085-E006-411F-807D-1CE27FC912EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7CA1085-E006-411F-807D-1CE27FC912EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -109,6 +109,9 @@ Global
{0267B422-302F-4138-A5D2-7C5547766953} = {B524BD24-3F72-4EB9-A3ED-EFBD39D86211}
{C6D5A33A-1BC0-4868-B63A-D1416C868088} = {F8E5F417-1060-4972-8FEE-886F38D3D5A8}
{2CB367CC-3D83-4319-B9F2-00A9F7B006F7} = {F8E5F417-1060-4972-8FEE-886F38D3D5A8}
{E9C2BAE6-BD3A-4C31-98BF-60E358FABA05} = {F8E5F417-1060-4972-8FEE-886F38D3D5A8}
{E9869ACA-E887-4864-B922-976A51BF032D} = {F8E5F417-1060-4972-8FEE-886F38D3D5A8}
{E7CA1085-E006-411F-807D-1CE27FC912EC} = {F8E5F417-1060-4972-8FEE-886F38D3D5A8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B2EB6DC1-0698-48D8-AD43-BFE923CC54EB}
Expand Down
7 changes: 7 additions & 0 deletions src/Browser/Mortise.Browser.Platform.Linux/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Mortise.Browser.Platform.Linux
{
public class Class1
{

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\nuget.props"></Import>
<Import Project="..\..\common.props"></Import>
<Import Project="..\..\version.props"></Import>
<Import Project="..\..\..\nuget.props"></Import>
<Import Project="..\..\..\common.props"></Import>
<Import Project="..\..\..\version.props"></Import>
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Mortise.Platform\Mortise.Platform.csproj" />
<ProjectReference Include="..\Mortise.Browser.Platform\Mortise.Browser.Platform.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Diagnostics;
using System.Drawing;
using Mortise.Browser.Platform;
using Mortise.BrowserAccessibility.Models;
using Tenon.Infra.Windows.Win32;
using Process = System.Diagnostics.Process;

namespace Mortise.Platform.Windows;

public class WindowsSystemInteraction : ISystemInteraction
{
public IntPtr GetWindowHandle(Point point = default)
{
return Window.GetTop(point);
}

public Process? GetProcess(Point point = default)
{
var handle = Window.GetTop(point);
if (handle == IntPtr.Zero)
return null;
var processId = Window.GetProcessId(handle);
return Process.GetProcessById((int)processId);
}

public Point ScreenPointToWebPoint(Point screenPoint)
{
Debug.WriteLine($"ScreenPointToWebPoint:{screenPoint.ToString()}");
var displayDevice = DisplayMonitor.FromPoint(screenPoint);
Debug.WriteLine($"point:{screenPoint.ToString()}=>{displayDevice.ScaleX}");
//displayDevice.ScaleX = 2;
//displayDevice.ScaleY = 2;
if (displayDevice == null) return screenPoint;
var locationY = screenPoint.Y / displayDevice.ScaleY;
float locationX = screenPoint.X;
if (locationX < 0)
locationX = (locationX + displayDevice.VirtualResolution.Width) / displayDevice.ScaleX;
else if (locationX > displayDevice.VirtualResolution.Width)
locationX = (locationX - displayDevice.VirtualResolution.Width) / displayDevice.ScaleX;
return new Point((int)locationX, (int)locationY);
}

public Rectangle WebPointToScreenRectangle(Point screenPoint, DomRect domRect)
{
var domRectangle = new Rectangle(domRect.X, domRect.Y, domRect.Width, domRect.Height);

var displayDevice = DisplayMonitor.FromPoint(domRect.Location);
if (displayDevice == null) return domRectangle;
if (screenPoint is { X: >= 0, Y: >= 0 } && screenPoint.X < displayDevice.VirtualResolution.Width && screenPoint.Y < displayDevice.VirtualResolution.Height)
return domRectangle;
Debug.WriteLine($"displayDevice:{displayDevice.VirtualResolution.Width}");
if (screenPoint.X < 0)
domRectangle.X =
Convert.ToInt32(domRectangle.X * displayDevice.ScaleX - displayDevice.VirtualResolution.Width);
if (screenPoint.X > displayDevice.VirtualResolution.Width)
domRectangle.X =
Convert.ToInt32(domRectangle.X * displayDevice.ScaleX + displayDevice.VirtualResolution.Width);
domRectangle.Y = Convert.ToInt32(domRectangle.Y * displayDevice.ScaleY);
return domRectangle with { Width = domRect.Width, Height = domRect.Height };
}
}
26 changes: 26 additions & 0 deletions src/Browser/Mortise.Browser.Platform/ISystemInteraction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Mortise.BrowserAccessibility.Models;
using System.Diagnostics;
using System.Drawing;

namespace Mortise.Browser.Platform;

public interface ISystemInteraction
{
/// <summary>
/// 根据坐标获取窗口句柄
/// </summary>
/// <param name="point">Point</param>
/// <returns>窗口句柄</returns>
public IntPtr GetWindowHandle(Point point = default);

/// <summary>
/// 根据坐标获取对应进程
/// </summary>
/// <param name="point">Point</param>
/// <returns>Process</returns>
public Process? GetProcess(Point point = default);

public Point ScreenPointToWebPoint(Point screenPoint);

public Rectangle WebPointToScreenRectangle(Point screenPoint, DomRect domRect);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<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>
<ProjectReference Include="..\Mortise.BrowserAccessibility\Mortise.BrowserAccessibility.csproj" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions src/Browser/Mortise.BrowserAccessibility/CoordinateTransformer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Mortise.BrowserAccessibility;

public class CoordinateTransformer
{
public static CssPoint ScreenPointToCssPoint(CssPoint screenPoint, RenderOption renderOption)
{
var finalPoint = screenPoint;
finalPoint = finalPoint.Offset(
-(renderOption.WindowLeft + renderOption.PageRenderX),
-(renderOption.WindowTop + renderOption.PageRenderY)
);

finalPoint = finalPoint.ScaleInv(1);

return finalPoint;
}

private object GetPageRenderOffsetInfo(RenderOption renderOption)
{
throw new NotImplementedException();
}
}
23 changes: 23 additions & 0 deletions src/Browser/Mortise.BrowserAccessibility/CssPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Mortise.BrowserAccessibility;

public sealed class CssPoint
{
public CssPoint(int x, int y)
{
X = x;
Y = y;
}
public int X { get; private init; }
public int Y { get; private init; }

public CssPoint Offset(int offsetX, int offsetY)
{
return new CssPoint(X + offsetX, Y + offsetY);
// { X = X + offsetX, Y = Y + offsetY };
}

public CssPoint ScaleInv(int scale)
{
return new CssPoint(X / scale, Y / scale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IBrowserAccessibleContext
/// 获取RenderWidget矩形框
/// </summary>
/// <returns></returns>
public Rectangle GetRenderingBoundingRectangle();
public Rectangle GetPageRenderRectangle();

public void SetMaximize();

Expand Down
7 changes: 6 additions & 1 deletion src/Browser/Mortise.BrowserAccessibility/Models/DomRect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Mortise.BrowserAccessibility.Models;
using System.Drawing;

namespace Mortise.BrowserAccessibility.Models;

public sealed class DomRect
{
Expand All @@ -8,4 +10,7 @@ public sealed class DomRect
public int Height { get; set; }
public int FrameOffsetX { get; set; }
public int FrameOffsetY { get; set; }
public string TagName { get; set; }

public Point Location => new(X, Y);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Tenon.Serialization.Abstractions" Version="0.0.1-alpha-202407261457" />
<PackageReference Include="Tenon.Serialization.Json" Version="0.0.1-alpha-202407261457" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Mortise.Accessibility.Abstractions\Mortise.Accessibility.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Mortise.Accessibility.Abstractions" Version="0.0.1-alpha-202407271513" />
<PackageReference Include="Tenon.Serialization.Abstractions" Version="0.0.1-alpha-202407261457" />
<PackageReference Include="Tenon.Serialization.Json" Version="0.0.1-alpha-202407261457" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions src/Browser/Mortise.BrowserAccessibility/RenderOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mortise.BrowserAccessibility
{
public sealed class RenderOption
{
public int WindowLeft { get; set; }

public int WindowTop { get; set; }

public int WindowWidth { get; set; }

public int WindowHeight { get; set; }

public int Dpi { get; set; }

public int PageRenderWidth { get; set; }

public int PageRenderHeight { get; set; }

public int PageRenderX { get; set; }

public int PageRenderY { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Concurrent;
using System.Drawing;
using Mortise.Accessibility.Abstractions;
using Mortise.Browser.Platform;
using Mortise.BrowserAccessibility;
using Mortise.BrowserAccessibility.Options;
using Mortise.Platform;
using Tenon.Mapper.Abstractions;

namespace Mortise.ChromiumAccessibility;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Drawing;
using Mortise.Accessibility.Abstractions;
using Mortise.Browser.Platform;
using Mortise.BrowserAccessibility;
using Mortise.Platform;
using Tenon.Mapper.Abstractions;

namespace Mortise.ChromiumAccessibility;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Mortise.BrowserAccessibility;
using Mortise.Platform;
using Mortise.Browser.Platform;
using Mortise.BrowserAccessibility;

namespace Mortise.ChromiumAccessibility.Configurations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Mortise.Accessibility.Abstractions" Version="0.0.1-alpha-202407271513" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
Expand All @@ -29,8 +30,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Mortise.Accessibility.Abstractions\Mortise.Accessibility.Abstractions.csproj" />
<ProjectReference Include="..\..\Mortise.Platform\Mortise.Platform.csproj" />
<ProjectReference Include="..\Mortise.Browser.Platform\Mortise.Browser.Platform.csproj" />
<ProjectReference Include="..\Mortise.BrowserAccessibility\Mortise.BrowserAccessibility.csproj" />
</ItemGroup>

Expand Down
7 changes: 0 additions & 7 deletions src/Mortise.Platform.Linux/Class1.cs

This file was deleted.

Loading

0 comments on commit f1baf3d

Please sign in to comment.