1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

Added custom popup windows to the TabbedBrowser2 demo

This commit is contained in:
Salvador Diaz Fau 2020-12-17 16:28:38 +01:00
parent 8f88a31440
commit 28958bf7b6
9 changed files with 523 additions and 64 deletions

View File

@ -41,8 +41,8 @@ program TabbedBrowser2;
uses
{$IFDEF DELPHI16_UP}
WinApi.Windows,
Vcl.Forms,
WinApi.Windows,
{$ELSE}
Forms,
Windows,
@ -50,7 +50,8 @@ uses
uCEFApplication,
uMainForm in 'uMainForm.pas' {MainForm},
uBrowserFrame in 'uBrowserFrame.pas' {BrowserFrame: TFrame},
uBrowserTab in 'uBrowserTab.pas';
uBrowserTab in 'uBrowserTab.pas',
uChildForm in 'uChildForm.pas' {ChildForm};
{$R *.res}

View File

@ -135,6 +135,10 @@
<DesignClass>TFrame</DesignClass>
</DCCReference>
<DCCReference Include="uBrowserTab.pas"/>
<DCCReference Include="uChildForm.pas">
<Form>ChildForm</Form>
<FormType>dfm</FormType>
</DCCReference>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>

View File

@ -95,6 +95,8 @@ type
FOnBrowserDestroyed : TNotifyEvent;
FOnBrowserTitleChange : TBrowserTitleEvent;
function CreateClientHandler(var windowInfo : TCefWindowInfo; var client : ICefClient; const targetFrameName : string; const popupFeatures : TCefPopupFeatures) : boolean;
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
@ -116,6 +118,9 @@ implementation
{$R *.dfm}
uses
uBrowserTab;
constructor TBrowserFrame.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
@ -181,8 +186,7 @@ begin
Chromium1.LoadURL(URLCbx.Text);
end;
procedure TBrowserFrame.Chromium1AfterCreated(Sender: TObject;
const browser: ICefBrowser);
procedure TBrowserFrame.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
end;
@ -193,41 +197,71 @@ begin
end;
procedure TBrowserFrame.Chromium1AddressChange( Sender : TObject;
const browser: ICefBrowser; const frame: ICefFrame; const url: ustring);
const browser : ICefBrowser;
const frame : ICefFrame;
const url : ustring);
begin
if (URLCbx.Items.IndexOf(url) < 0) then URLCbx.Items.Add(url);
URLCbx.Text := url;
end;
procedure TBrowserFrame.Chromium1BeforeClose(Sender: TObject;
const browser: ICefBrowser);
procedure TBrowserFrame.Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
begin
if assigned(FOnBrowserDestroyed) then FOnBrowserDestroyed(self);
end;
procedure TBrowserFrame.Chromium1BeforePopup( Sender : TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; const popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue;
var noJavascriptAccess, Result: Boolean);
const browser : ICefBrowser;
const frame : ICefFrame;
const targetUrl : ustring;
const targetFrameName : ustring;
targetDisposition : TCefWindowOpenDisposition;
userGesture : Boolean;
const popupFeatures : TCefPopupFeatures;
var windowInfo : TCefWindowInfo;
var client : ICefClient;
var settings : TCefBrowserSettings;
var extra_info : ICefDictionaryValue;
var noJavascriptAccess : Boolean;
var Result : Boolean);
begin
case targetDisposition of
WOD_NEW_FOREGROUND_TAB,
WOD_NEW_BACKGROUND_TAB,
WOD_NEW_WINDOW : Result := True; // For simplicity, this demo blocks new tabs and new windows.
WOD_NEW_POPUP : Result := not(CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures));
else Result := False;
end;
end;
procedure TBrowserFrame.Chromium1OpenUrlFromTab( Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;
const targetUrl : ustring;
targetDisposition : TCefWindowOpenDisposition;
userGesture : Boolean;
out Result : Boolean);
begin
// For simplicity, this demo blocks all popup windows and new tabs
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
end;
procedure TBrowserFrame.Chromium1Close( Sender : TObject;
const browser: ICefBrowser; var aAction: TCefCloseBrowserAction);
const browser : ICefBrowser;
var aAction : TCefCloseBrowserAction);
begin
PostMessage(Handle, CEF_DESTROY, 0, 0);
aAction := cbaDelay;
end;
procedure TBrowserFrame.Chromium1LoadError( Sender : TObject;
const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer;
const errorText, failedUrl: ustring);
const browser : ICefBrowser;
const frame : ICefFrame;
errorCode : Integer;
const errorText : ustring;
const failedUrl : ustring);
var
TempString : string;
begin
@ -242,7 +276,10 @@ begin
end;
procedure TBrowserFrame.Chromium1LoadingStateChange( Sender : TObject;
const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
const browser : ICefBrowser;
isLoading : Boolean;
canGoBack : Boolean;
canGoForward : Boolean);
begin
BackBtn.Enabled := canGoBack;
ForwardBtn.Enabled := canGoForward;
@ -259,23 +296,16 @@ begin
end;
end;
procedure TBrowserFrame.Chromium1OpenUrlFromTab(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
out Result: Boolean);
begin
// For simplicity, this demo blocks all popup windows and new tabs
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
end;
procedure TBrowserFrame.Chromium1StatusMessage( Sender : TObject;
const browser: ICefBrowser; const value: ustring);
const browser : ICefBrowser;
const value : ustring);
begin
StatusBar1.Panels[0].Text := value;
end;
procedure TBrowserFrame.Chromium1TitleChange( Sender : TObject;
const browser: ICefBrowser; const title: ustring);
const browser : ICefBrowser;
const title : ustring);
begin
if not(assigned(FOnBrowserTitleChange)) then exit;
@ -296,6 +326,16 @@ begin
CEFWindowParent1.Free;
end;
function TBrowserFrame.CreateClientHandler(var windowInfo : TCefWindowInfo;
var client : ICefClient;
const targetFrameName : string;
const popupFeatures : TCefPopupFeatures) : boolean;
begin
Result := assigned(Parent) and
(Parent is TBrowserTab) and
TBrowserTab(Parent).CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures);
end;
end.

View File

@ -49,7 +49,7 @@ uses
Windows, Classes, Messages, ComCtrls, Controls,
Forms,
{$ENDIF}
uBrowserFrame;
uCEFInterfaces, uCEFTypes, uBrowserFrame;
type
TBrowserTab = class(TTabSheet)
@ -73,6 +73,7 @@ type
procedure CloseBrowser;
procedure ShowBrowser;
procedure HideBrowser;
function CreateClientHandler(var windowInfo : TCefWindowInfo; var client : ICefClient; const targetFrameName : string; const popupFeatures : TCefPopupFeatures) : boolean;
property TabID : cardinal read FTabID;
end;
@ -161,4 +162,17 @@ begin
Caption := aTitle;
end;
function TBrowserTab.CreateClientHandler(var windowInfo : TCefWindowInfo;
var client : ICefClient;
const targetFrameName : string;
const popupFeatures : TCefPopupFeatures) : boolean;
var
TempForm : TCustomForm;
begin
TempForm := ParentForm;
Result := (TempForm <> nil) and
(TempForm is TMainForm) and
TMainForm(TempForm).CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures);
end;
end.

View File

@ -0,0 +1,37 @@
object ChildForm: TChildForm
Left = 0
Top = 0
Caption = 'Popup'
ClientHeight = 256
ClientWidth = 352
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnClose = FormClose
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object CEFWindowParent1: TCEFWindowParent
Left = 0
Top = 0
Width = 352
Height = 256
Align = alClient
TabOrder = 0
end
object Chromium1: TChromium
OnTitleChange = Chromium1TitleChange
OnBeforePopup = Chromium1BeforePopup
OnBeforeClose = Chromium1BeforeClose
OnClose = Chromium1Close
Left = 24
Top = 56
end
end

View File

@ -0,0 +1,257 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2020 Salvador Diaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uChildForm;
{$I cef.inc}
interface
uses
{$IFDEF DELPHI16_UP}
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
System.SyncObjs, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
Vcl.ExtCtrls,
{$ELSE}
Windows, Messages, SysUtils, Variants, Classes, SyncObjs,
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
{$ENDIF}
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFWindowParent, uCEFWinControl,
uCEFChromiumCore;
type
TChildForm = class(TForm)
Chromium1: TChromium;
CEFWindowParent1: TCEFWindowParent;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Chromium1BeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean);
procedure Chromium1TitleChange(Sender: TObject; const browser: ICefBrowser; const title: ustring);
procedure Chromium1Close(Sender: TObject; const browser: ICefBrowser; var aAction : TCefCloseBrowserAction);
procedure Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
protected
FCanClose : boolean;
FClosing : boolean;
FClientInitialized : boolean;
FPopupFeatures : TCefPopupFeatures;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
public
procedure AfterConstruction; override;
function CreateClientHandler(var windowInfo : TCefWindowInfo; var client : ICefClient; const targetFrameName : string; const popupFeatures : TCefPopupFeatures) : boolean;
procedure ApplyPopupFeatures;
property ClientInitialized : boolean read FClientInitialized;
property Closing : boolean read FClosing;
end;
implementation
{$R *.dfm}
uses
{$IFDEF DELPHI16_UP}
System.Math,
{$ELSE}
Math,
{$ENDIF}
uCEFMiscFunctions, uCEFApplication, uMainForm;
// Destruction steps
// =================
// 1. FormCloseQuery sets CanClose to FALSE calls TChromium.CloseBrowser which triggers the TChromium.OnClose event.
// 2. TChromium.OnClose sends a CEFBROWSER_DESTROY message to destroy CEFWindowParent1 in the main thread, which triggers the TChromium.OnBeforeClose event.
// 3. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
procedure TChildForm.AfterConstruction;
begin
inherited AfterConstruction;
CreateHandle;
CEFWindowParent1.CreateHandle;
end;
function TChildForm.CreateClientHandler(var windowInfo : TCefWindowInfo;
var client : ICefClient;
const targetFrameName : string;
const popupFeatures : TCefPopupFeatures) : boolean;
var
TempRect : TRect;
begin
if CEFWindowParent1.HandleAllocated and
Chromium1.CreateClientHandler(client, False) then
begin
Result := True;
FClientInitialized := True;
FPopupFeatures := popupFeatures;
TempRect := CEFWindowParent1.ClientRect;
if (FPopupFeatures.widthset <> 0) then TempRect.Right := max(FPopupFeatures.width, 100);
if (FPopupFeatures.heightset <> 0) then TempRect.Bottom := max(FPopupFeatures.height, 100);
WindowInfoAsChild(windowInfo, CEFWindowParent1.Handle, TempRect, '');
end
else
Result := False;
end;
procedure TChildForm.ApplyPopupFeatures;
begin
if (FPopupFeatures.xset <> 0) then Chromium1.SetFormLeftTo(FPopupFeatures.x);
if (FPopupFeatures.yset <> 0) then Chromium1.SetFormTopTo(FPopupFeatures.y);
if (FPopupFeatures.widthset <> 0) then Chromium1.ResizeFormWidthTo(FPopupFeatures.width);
if (FPopupFeatures.heightset <> 0) then Chromium1.ResizeFormHeightTo(FPopupFeatures.height);
end;
procedure TChildForm.Chromium1BeforeClose(Sender: TObject; const browser: ICefBrowser);
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TChildForm.Chromium1BeforePopup(Sender : TObject;
const browser : ICefBrowser;
const frame : ICefFrame;
const targetUrl : ustring;
const targetFrameName : ustring;
targetDisposition : TCefWindowOpenDisposition;
userGesture : Boolean;
const popupFeatures : TCefPopupFeatures;
var windowInfo : TCefWindowInfo;
var client : ICefClient;
var settings : TCefBrowserSettings;
var extra_info : ICefDictionaryValue;
var noJavascriptAccess : Boolean;
var Result : Boolean);
begin
case targetDisposition of
WOD_NEW_FOREGROUND_TAB,
WOD_NEW_BACKGROUND_TAB,
WOD_NEW_WINDOW : Result := True; // For simplicity, this demo blocks new tabs and new windows.
WOD_NEW_POPUP : Result := not(TMainForm(Owner).CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures));
else Result := False;
end;
end;
procedure TChildForm.Chromium1Close(Sender: TObject; const browser: ICefBrowser; var aAction : TCefCloseBrowserAction);
begin
PostMessage(Handle, CEF_DESTROY, 0, 0);
aAction := cbaDelay;
end;
procedure TChildForm.Chromium1TitleChange(Sender: TObject; const browser: ICefBrowser; const title: ustring);
begin
Caption := title;
end;
procedure TChildForm.WMMove(var aMessage : TWMMove);
begin
inherited;
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
end;
procedure TChildForm.WMMoving(var aMessage : TMessage);
begin
inherited;
if (Chromium1 <> nil) then Chromium1.NotifyMoveOrResizeStarted;
end;
procedure TChildForm.WMEnterMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := True;
end;
procedure TChildForm.WMExitMenuLoop(var aMessage: TMessage);
begin
inherited;
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
end;
procedure TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TChildForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := FCanClose;
if not(FClosing) then
begin
FClosing := True;
Visible := False;
Chromium1.CloseBrowser(True);
end;
end;
procedure TChildForm.FormCreate(Sender: TObject);
begin
FCanClose := False;
FClosing := False;
FClientInitialized := False;
end;
procedure TChildForm.FormDestroy(Sender: TObject);
begin
if FClientInitialized and TMainForm(Owner).HandleAllocated then
PostMessage(TMainForm(Owner).Handle, CEF_CHILDDESTROYED, 0, 0);
end;
procedure TChildForm.BrowserDestroyMsg(var aMessage : TMessage);
begin
CEFWindowParent1.Free;
end;
end.

View File

@ -14,6 +14,7 @@ object MainForm: TMainForm
Position = poScreenCenter
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13

View File

@ -43,19 +43,19 @@ interface
uses
{$IFDEF DELPHI16_UP}
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.ComCtrls, Vcl.ToolWin, Vcl.Buttons, Vcl.ExtCtrls,
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.SyncObjs,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ToolWin, Vcl.Buttons, Vcl.ExtCtrls,
{$ELSE}
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs,
ComCtrls, ToolWin, Buttons, ExtCtrls,
Windows, Messages, SysUtils, Variants, Classes, Graphics, SyncObjs,
Controls, Forms, Dialogs, ComCtrls, ToolWin, Buttons, ExtCtrls,
{$ENDIF}
uCEFApplication, uCEFTypes, uCEFConstants;
uCEFApplication, uCEFInterfaces, uCEFTypes, uCEFConstants, uChildForm;
const
CEF_INITIALIZED = WM_APP + $100;
CEF_DESTROYTAB = WM_APP + $101;
CEF_INITIALIZED = WM_APP + $A50;
CEF_DESTROYTAB = WM_APP + $A51;
CEF_CREATENEXTCHILD = WM_APP + $A52;
CEF_CHILDDESTROYED = WM_APP + $A53;
HOMEPAGE_URL = 'https://www.google.com';
DEFAULT_TAB_CAPTION = 'New tab';
@ -73,28 +73,36 @@ type
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormDestroy(Sender: TObject);
protected
// Variables to control when can we destroy the form safely
FChildForm : TChildForm;
FCriticalSection : TCriticalSection;
FCanClose : boolean;
FClosing : boolean;
FClosing : boolean; // Set to True in the CloseQuery event.
FLastTabID : cardinal; // Used by NextTabID to generate unique tab IDs
function GetNextTabID : cardinal;
function GetPopupChildCount : integer;
procedure EnableButtonPnl;
function CloseAllTabs : boolean;
function CloseAllBrowsers : boolean;
procedure CloseTab(aIndex : integer);
procedure CEFInitializedMsg(var aMessage : TMessage); message CEF_INITIALIZED;
procedure DestroyTabMsg(var aMessage : TMessage); message CEF_DESTROYTAB;
procedure CreateNextChildMsg(var aMessage : TMessage); message CEF_CREATENEXTCHILD;
procedure ChildDestroyedMsg(var aMessage : TMessage); message CEF_CHILDDESTROYED;
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
procedure WMEnterMenuLoop(var aMessage: TMessage); message WM_ENTERMENULOOP;
procedure WMExitMenuLoop(var aMessage: TMessage); message WM_EXITMENULOOP;
property NextTabID : cardinal read GetNextTabID;
property PopupChildCount : integer read GetPopupChildCount;
public
function CreateClientHandler(var windowInfo : TCefWindowInfo; var client : ICefClient; const targetFrameName : string; const popupFeatures : TCefPopupFeatures) : boolean;
end;
var
@ -173,6 +181,28 @@ begin
Result := FLastTabID;
end;
function TMainForm.GetPopupChildCount : integer;
var
i : integer;
TempForm : TCustomForm;
begin
Result := 0;
i := pred(screen.CustomFormCount);
while (i >= 0) do
begin
TempForm := screen.CustomForms[i];
// Only count the fully initialized child forms and not the one waiting to be used.
if (TempForm is TChildForm) and
TChildForm(TempForm).ClientInitialized then
inc(Result);
dec(i);
end;
end;
procedure TMainForm.AddTabBtnClick(Sender: TObject);
var
TempNewTab : TBrowserTab;
@ -188,6 +218,9 @@ end;
procedure TMainForm.CEFInitializedMsg(var aMessage : TMessage);
begin
EnableButtonPnl;
if (FChildForm = nil) then
TChildForm.Create(self);
end;
procedure TMainForm.DestroyTabMsg(var aMessage : TMessage);
@ -209,13 +242,39 @@ begin
inc(i);
end;
if FClosing and (BrowserPageCtrl.PageCount = 0) then
if FClosing and (PopupChildCount = 0) and (BrowserPageCtrl.PageCount = 0) then
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
end;
procedure TMainForm.ChildDestroyedMsg(var aMessage : TMessage);
begin
if FClosing and (PopupChildCount = 0) and (BrowserPageCtrl.PageCount = 0) then
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
end;
procedure TMainForm.CreateNextChildMsg(var aMessage : TMessage);
begin
try
FCriticalSection.Acquire;
if (FChildForm <> nil) then
begin
FChildForm.ApplyPopupFeatures;
FChildForm.Show;
end;
FChildForm := TChildForm.Create(self);
finally
FCriticalSection.Release;
end;
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := FCanClose;
@ -225,7 +284,7 @@ begin
FClosing := True;
ButtonPnl.Enabled := False;
if not(CloseAllTabs) then
if not(CloseAllBrowsers) then
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
@ -238,12 +297,24 @@ begin
FCanClose := False;
FClosing := False;
FLastTabID := 0;
FChildForm := nil;
FCriticalSection := TCriticalSection.Create;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(FCriticalSection);
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
if (GlobalCEFApp <> nil) and GlobalCEFApp.GlobalContextInitialized then
begin
EnableButtonPnl;
if (FChildForm = nil) then
FChildForm := TChildForm.Create(self);
end;
end;
procedure TMainForm.RemoveTabBtnClick(Sender: TObject);
@ -251,11 +322,29 @@ begin
CloseTab(BrowserPageCtrl.ActivePageIndex);
end;
function TMainForm.CloseAllTabs : boolean;
function TMainForm.CloseAllBrowsers : boolean;
var
i : integer;
TempForm : TCustomForm;
begin
Result := False;
i := pred(screen.CustomFormCount);
while (i >= 0) do
begin
TempForm := screen.CustomForms[i];
if (TempForm is TChildForm) and
TChildForm(TempForm).ClientInitialized and
not(TChildForm(TempForm).Closing) then
begin
PostMessage(TempForm.Handle, WM_CLOSE, 0, 0);
Result := True;
end;
dec(i);
end;
i := pred(BrowserPageCtrl.PageCount);
while (i >= 0) do
@ -316,4 +405,20 @@ begin
GlobalCEFApp.OsmodalLoop := False;
end;
function TMainForm.CreateClientHandler(var windowInfo : TCefWindowInfo;
var client : ICefClient;
const targetFrameName : string;
const popupFeatures : TCefPopupFeatures) : boolean;
begin
try
FCriticalSection.Acquire;
Result := (FChildForm <> nil) and
FChildForm.CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures) and
PostMessage(Handle, CEF_CREATENEXTCHILD, 0, 0);
finally
FCriticalSection.Release;
end;
end;
end.

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 208,
"InternalVersion" : 209,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "87.1.12.0"
}