Skip to content

Commit

Permalink
👾 We have implemented serveral unimplemented interfaces previously fo…
Browse files Browse the repository at this point in the history
…r the Formium class, and it's now possible to provide custom handlers for these interfaces.
  • Loading branch information
XuanchenLin committed Feb 14, 2025
1 parent 5758ae4 commit 4cfbf8c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,12 @@ private void ShowContextMenu(CefRunContextMenuCallback callback, Point point, Li

var scaleFactor = WebViewHost.GetScaleFactor();

if (scaleFactor > 1.25f) scaleFactor = 1.25f;

var contextMenu = new AnimatedContextMenuStrip()
{
Renderer = new ContextMenuStripRenderer(ColorMode == WebViewColorMode.Dark),
Font = new Font("Segoe UI", 10.25f * scaleFactor, FontStyle.Regular, GraphicsUnit.Point, 0),
//Font = new Font("Microsoft Yahei", 10.25f, FontStyle.Regular, GraphicsUnit.Point, 0),
};

ToolStripDropDownClosedEventHandler? closeHandler = null;
Expand Down
50 changes: 31 additions & 19 deletions src/WinFormium/Sources/Formium/Formium.BrowserClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,100 +9,112 @@ public partial class Formium
/// <summary>
/// Return the handler for audio rendering events.
/// </summary>
public AudioHandler? AudioHandler { get; set; }
public IAudioHandler? AudioHandler
{
get => WebViewHost.AudioHandler;
set
{
WebViewHost.AudioHandler = value;
}
}

/// <summary>
/// Return the handler for dialogs.
/// </summary>
public DialogHandler? DialogHandler { get; set; }
public IDialogHandler? DialogHandler
{
get => WebViewHost.DialogHandler;
set => WebViewHost.DialogHandler = value;
}


/// <summary>
/// Return the handler for browser display state events.
/// </summary>
public DisplayHandler? DisplayHandler { get; set; } // <--- this is the one of internal handlers
public IDisplayHandler? DisplayHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for download events.
/// </summary>
public DownloadHandler? DownloadHandler { get; set; }
public IDownloadHandler? DownloadHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for drag events.
/// </summary>
public DragHandler? DragHandler { get; set; } // <--- this is the one of internal handlers
public IDragHandler? DragHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for find result events.
/// </summary>
public FindHandler? FindHandler { get; set; }
public IFindHandler? FindHandler { get => WebViewHost.FindHandler; set => WebViewHost.FindHandler = value; }

/// <summary>
/// Return the handler for focus events.
/// </summary>
public FocusHandler? FocusHandler { get; set; } // <--- this is the one of internal handlers
public IFocusHandler? FocusHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for events related to CefFrame lifespan. This method will be called once during CefBrowser creation and the result will be cached for performance reasons.
/// </summary>
public FrameHandler? FrameHandler { get; set; }
public IFrameHandler? FrameHandler { get => WebViewHost.FrameHandler; set => WebViewHost.FrameHandler = value; }

/// <summary>
/// Return the handler for JavaScript dialogs.
/// </summary>
public JSDialogHandler? JSDialogHandler { get; set; }
public IJSDialogHandler? JSDialogHandler { get => WebViewHost.JSDialogHandler; set => WebViewHost.JSDialogHandler = value; }

/// <summary>
/// Return the handler for keyboard events.
/// </summary>
public KeyboardHandler? KeyboardHandler { get; set; } // <--- this is the one of internal handlers
public IKeyboardHandler? KeyboardHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for browser life span events.
/// </summary>
public LifeSpanHandler? LifeSpanHandler { get; set; } // <--- this is the one of internal handlers
public ILifeSpanHandler? LifeSpanHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for browser load status events.
/// </summary>
public LoadHandler? LoadHandler { get; set; } // <--- this is the one of internal handlers
public ILoadHandler? LoadHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for printing on Linux.
/// </summary>
public PrintHandler? PrintHandler { get; set; }
public IPrintHandler? PrintHandler { get => WebViewHost.PrintHandler; set => WebViewHost.PrintHandler = value; }

/// <summary>
/// Return the handler for off-screen rendering events.
/// </summary>
public RenderHandler? RenderHandler { get; set; }
public IRenderHandler? RenderHandler { get; set; }

/// <summary>
/// Return the handler for browser request events.
/// </summary>
public RequestHandler? RequestHandler { get; set; } // <--- this is the one of internal handlers
public IRequestHandler? RequestHandler { get; set; } // <--- this is the one of internal handlers

/// <summary>
/// Return the handler for permission requests.
/// </summary>
public PermissionHandler? PermissionHandler { get; set; }
public IPermissionHandler? PermissionHandler { get => WebViewHost.PermissionHandler; set => WebViewHost.PermissionHandler = value; }

/// <summary>
/// Return the handler for context menus. If no handler is provided the default implementation will be used.
/// </summary>
public ContextMenuHandler? ContextMenuHandler { get; set; } // <--- this is the one of internal handlers
public IContextMenuHandler? ContextMenuHandler { get; set; } // <--- this is the one of internal handlers

internal void OnBrowserClientCreatedCore()
{
WebViewHost.AudioHandler = AudioHandler;
WebViewHost.ContextMenuHandler = ContextMenuHandler;
WebViewHost.DialogHandler = DialogHandler;
WebViewHost.DownloadHandler = this;
WebViewHost.FindHandler = FindHandler;
WebViewHost.FrameHandler = FrameHandler;
WebViewHost.JSDialogHandler = JSDialogHandler;
WebViewHost.PrintHandler = PrintHandler;
WebViewHost.PermissionHandler = PermissionHandler;

WebViewHost.ContextMenuHandler = ContextMenuHandler;
WebViewHost.DownloadHandler = this;
WebViewHost.LifeSpanHandler = this;
WebViewHost.LoadHandler = this;
WebViewHost.RequestHandler = this;
Expand Down
4 changes: 2 additions & 2 deletions src/WinFormium/Sources/Formium/Formium.Members.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ internal void HostWindowCreatedCore(Form target)

System.Diagnostics.Debug.WriteLine("[LIFECYCLE] -> WindowCreated");

ModifySystemMenu();

_splashScreen = new SplashScreen(target, PaintSplashScreen);

target.Controls.Add(_splashScreen);

_splashScreen.Visible = EnableSplashScreen;

ModifySystemMenu();

ShowSplash();

target.Activate();
Expand Down
2 changes: 1 addition & 1 deletion src/WinFormium/Sources/Formium/Formium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract partial class Formium
public bool AllowFullScreen { get => CurrentFormStyle.AllowFullScreen; set => CurrentFormStyle.AllowFullScreen = value; }


public bool EnableSplashScreen { get; set; } = true;
public bool EnableSplashScreen { get; set;} = true;

/// <summary>
/// Gets or sets the size of the form.
Expand Down
18 changes: 9 additions & 9 deletions src/WinFormium/WinFormium.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
<PackageReference Include="SharpGen.Runtime" Version="2.0.0-beta.13" />
<PackageReference Include="SharpGen.Runtime.COM" Version="2.0.0-beta.13" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp" Version="3.116.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
<PackageReference Include="Vanara.PInvoke.SHCore" Version="3.4.16" />
<PackageReference Include="Vanara.PInvoke.User32" Version="3.4.16" />
<PackageReference Include="Vanara.PInvoke.Gdi32" Version="3.4.16" />
<PackageReference Include="Vanara.PInvoke.DwmApi" Version="3.4.16" />
<PackageReference Include="Vanara.PInvoke.UxTheme" Version="3.4.16" />
<PackageReference Include="System.Text.Json" Version="9.0.2" />
<PackageReference Include="Vanara.PInvoke.SHCore" Version="4.0.5" />
<PackageReference Include="Vanara.PInvoke.User32" Version="4.0.5" />
<PackageReference Include="Vanara.PInvoke.Gdi32" Version="4.0.5" />
<PackageReference Include="Vanara.PInvoke.DwmApi" Version="4.0.5" />
<PackageReference Include="Vanara.PInvoke.UxTheme" Version="4.0.5" />
<PackageReference Include="Vortice.Direct2D1" Version="2.4.2" />
<PackageReference Include="Vortice.Direct3D11" Version="2.4.2" />
<PackageReference Include="Vortice.DirectComposition" Version="2.4.2" />
Expand Down

0 comments on commit 4cfbf8c

Please sign in to comment.