Files
KJD/TEMUKJD/Helper/LifeSpanHandlerLocal.cs
T
2026-07-05 22:53:54 +08:00

89 lines
2.7 KiB
C#

using CefSharp;
using CefSharp.WinForms;
using TemuKJD.ToolForms;
using NaiBa.CefHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TemuKJD.Helper
{
public enum PopWindowType
{
NewWindow,
SelfWindow,
NewTitleWindow,
}
public class PopData
{
public string Url { get; set; }
}
public class LifeSpanHandlerLocal : ILifeSpanHandler
{
private PopWindowType popWindowType = PopWindowType.NewWindow;
public event EventHandler<PopData> OnPop;
public ChromiumWebBrowser parent;
public LifeSpanHandlerLocal()
{
}
public LifeSpanHandlerLocal(PopWindowType _popWindowType)
{
popWindowType = _popWindowType;
}
public bool DoClose(IWebBrowser browserControl, IBrowser browser)
{
return false;
}
public void OnAfterCreated(IWebBrowser chromiumWebBrowser, IBrowser browser)
{
if (!browser.IsDisposed && browser.IsPopup)
{
//GlobalFormConfig.MainFormInstance.InvokeOnUiThreadIfRequired(() =>
//{
// // 修改窗体左上角的图标
// IntPtr handle = browser.GetHost().GetWindowHandle();
// PInvokeHelper.SendMessage(handle, 0x80, IntPtr.Zero, NaiBaGlobalConfig.SoftwareConfig.LogoIcon.Handle);
//});
}
}
public void OnBeforeClose(IWebBrowser browserControl, IBrowser browser)
{
}
public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
if (popWindowType == PopWindowType.NewWindow)
{
PopData p = new PopData() { Url = targetUrl };
if (OnPop != null)
OnPop(this, p);
newBrowser = null;
return true;
}
else if (popWindowType == PopWindowType.NewTitleWindow && popupFeatures.IsPopup)
{
PopData p = new PopData() { Url = targetUrl };
if (OnPop != null)
OnPop(this, p);
newBrowser = null;
return true;
}
else
{
// 不打开新的 tab
browser.MainFrame.LoadUrl(targetUrl);
newBrowser = null;
return true;
}
}
}
}