mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-01-13 10:22:04 +02:00
Extracted base-class for TCefWindow with Chromium
This commit is contained in:
parent
24d5b6b461
commit
ff9d2a39a8
@ -22,7 +22,7 @@
|
||||
<Description Value="CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC."/>
|
||||
<License Value="MPL 1.1"/>
|
||||
<Version Major="88" Minor="2" Release="9"/>
|
||||
<Files Count="197">
|
||||
<Files Count="198">
|
||||
<Item1>
|
||||
<Filename Value="..\source\uCEFAccessibilityHandler.pas"/>
|
||||
<UnitName Value="uCEFAccessibilityHandler"/>
|
||||
@ -827,6 +827,10 @@
|
||||
<Filename Value="..\source\uCEFWorkSchedulerQueueThread.pas"/>
|
||||
<UnitName Value="uCEFWorkSchedulerQueueThread"/>
|
||||
</Item197>
|
||||
<Item198>
|
||||
<Filename Value="uCEFLinkedWinControlBase.pas"/>
|
||||
<UnitName Value="uCEFLinkedWinControlBase"/>
|
||||
</Item198>
|
||||
</Files>
|
||||
<RequiredPkgs Count="4">
|
||||
<Item1>
|
||||
|
@ -65,7 +65,7 @@ uses
|
||||
uCEFMediaSinkDeviceInfoCallback, uCEFJson, uCEFBitmapBitBuffer,
|
||||
uCEFPrintDialogCallback, uCEFPrintHandler, uCEFPrintJobCallback,
|
||||
uCEFLinuxFunctions, uCEFLinuxTypes, uCEFLinuxConstants,
|
||||
uCEFWorkSchedulerQueueThread, LazarusPackageIntf;
|
||||
uCEFWorkSchedulerQueueThread, uCEFLinkedWinControlBase, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
134
packages/uCEFLinkedWinControlBase.pas
Normal file
134
packages/uCEFLinkedWinControlBase.pas
Normal file
@ -0,0 +1,134 @@
|
||||
// ************************************************************************
|
||||
// ***************************** 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 © 2021 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 uCEFLinkedWinControlBase;
|
||||
|
||||
{$I cef.inc}
|
||||
|
||||
{$IFDEF FPC}
|
||||
{$MODE OBJFPC}{$H+}
|
||||
{$IFDEF MACOSX}
|
||||
{$ModeSwitch objectivec1}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
||||
{$MINENUMSIZE 4}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
{$IFDEF DELPHI16_UP}
|
||||
{$IFDEF MSWINDOWS}WinApi.Windows, {$ENDIF} System.Classes, Vcl.Controls, Vcl.Graphics,
|
||||
{$ELSE}
|
||||
{$IFDEF MSWINDOWS}Windows,{$ENDIF} Classes, Controls,
|
||||
{$IFDEF FPC}
|
||||
LCLProc, LCLType, LCLIntf,
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
uCEFTypes, uCEFInterfaces, uCEFWinControl, uCEFChromium;
|
||||
|
||||
type
|
||||
|
||||
{ TCEFLinkedWinControlBase }
|
||||
|
||||
TCEFLinkedWinControlBase = class(TCEFWinControl)
|
||||
protected
|
||||
function GetChromium: TChromium; virtual; abstract;
|
||||
|
||||
{$IFDEF FPC}
|
||||
procedure SetVisible(Value: Boolean); override;
|
||||
{$ENDIF}
|
||||
function GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle; override;
|
||||
|
||||
property Chromium : TChromium read GetChromium;
|
||||
public
|
||||
procedure UpdateSize; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TCEFLinkedWinControlBase }
|
||||
|
||||
{$IFDEF FPC}
|
||||
|
||||
procedure TCEFLinkedWinControlBase.SetVisible(Value: Boolean);
|
||||
{$IFDEF LINUX}
|
||||
var
|
||||
TempChanged : boolean;
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
TempChanged := (Visible <> Value);
|
||||
{$ENDIF}
|
||||
|
||||
inherited SetVisible(Value);
|
||||
|
||||
{$IFDEF LINUX}
|
||||
if not(csDesigning in ComponentState) and
|
||||
TempChanged and
|
||||
(Chromium <> nil) and
|
||||
Chromium.Initialized then
|
||||
Chromium.UpdateXWindowVisibility(Visible);
|
||||
{$ENDIF}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function TCEFLinkedWinControlBase.GetChildWindowHandle: THandle;
|
||||
begin
|
||||
Result := 0;
|
||||
|
||||
if (Chromium <> nil) then Result := Chromium.WindowHandle;
|
||||
|
||||
if (Result = 0) then Result := inherited GetChildWindowHandle;
|
||||
end;
|
||||
|
||||
procedure TCEFLinkedWinControlBase.UpdateSize;
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
if not(csDesigning in ComponentState) and
|
||||
(Chromium <> nil) and
|
||||
Chromium.Initialized then
|
||||
Chromium.UpdateBrowserSize(Left, Top, Width, Height);
|
||||
{$ELSE}
|
||||
inherited UpdateSize;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -59,11 +59,15 @@ uses
|
||||
Messages,
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
uCEFWindowParent, uCEFChromium, uCEFInterfaces, uCEFConstants, uCEFTypes, uCEFWinControl;
|
||||
uCEFWindowParent, uCEFChromium, uCEFInterfaces, uCEFConstants, uCEFTypes,
|
||||
uCEFWinControl, uCEFLinkedWinControlBase;
|
||||
|
||||
type
|
||||
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pidWin32 or pidWin64)]{$ENDIF}{$ENDIF}
|
||||
TChromiumWindow = class(TCEFWinControl)
|
||||
|
||||
{ TChromiumWindow }
|
||||
|
||||
TChromiumWindow = class(TCEFLinkedWinControlBase)
|
||||
protected
|
||||
FChromium : TChromium;
|
||||
FOnClose : TNotifyEvent;
|
||||
@ -71,11 +75,8 @@ type
|
||||
FOnAfterCreated : TNotifyEvent;
|
||||
FUseSetFocus : boolean;
|
||||
|
||||
{$IFDEF FPC}
|
||||
procedure SetVisible(Value: Boolean); override;
|
||||
{$ENDIF}
|
||||
function GetBrowserInitialized : boolean;
|
||||
function GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle; override;
|
||||
function GetChromium: TChromium; override;
|
||||
function GetBrowserInitialized : boolean;
|
||||
{$IFDEF MSWINDOWS}
|
||||
procedure WndProc(var aMessage: TMessage); override;
|
||||
|
||||
@ -101,9 +102,8 @@ type
|
||||
procedure CloseBrowser(aForceClose : boolean);
|
||||
procedure LoadURL(const aURL : ustring);
|
||||
procedure NotifyMoveOrResizeStarted;
|
||||
procedure UpdateSize; override;
|
||||
|
||||
property ChromiumBrowser : TChromium read FChromium;
|
||||
property ChromiumBrowser : TChromium read GetChromium;
|
||||
property Initialized : boolean read GetBrowserInitialized;
|
||||
|
||||
published
|
||||
@ -186,15 +186,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TChromiumWindow.GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle;
|
||||
begin
|
||||
Result := 0;
|
||||
|
||||
if (FChromium <> nil) then Result := FChromium.WindowHandle;
|
||||
|
||||
if (Result = 0) then Result := inherited GetChildWindowHandle;
|
||||
end;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
procedure TChromiumWindow.WndProc(var aMessage: TMessage);
|
||||
var
|
||||
@ -326,39 +317,9 @@ begin
|
||||
if (FChromium <> nil) then FChromium.NotifyMoveOrResizeStarted;
|
||||
end;
|
||||
|
||||
{$IFDEF FPC}
|
||||
procedure TChromiumWindow.SetVisible(Value: Boolean);
|
||||
{$IFDEF LINUX}
|
||||
var
|
||||
TempChanged : boolean;
|
||||
{$ENDIF}
|
||||
function TChromiumWindow.GetChromium: TChromium;
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
TempChanged := (Visible <> Value);
|
||||
{$ENDIF}
|
||||
|
||||
inherited SetVisible(Value);
|
||||
|
||||
{$IFDEF LINUX}
|
||||
if not(csDesigning in ComponentState) and
|
||||
TempChanged and
|
||||
(FChromium <> nil) and
|
||||
FChromium.Initialized then
|
||||
FChromium.UpdateXWindowVisibility(Visible);
|
||||
{$ENDIF}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TChromiumWindow.UpdateSize;
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
if not(csDesigning in ComponentState) and
|
||||
(FChromium <> nil) and
|
||||
FChromium.Initialized then
|
||||
FChromium.UpdateBrowserSize(Left, Top, Width, Height);
|
||||
{$ELSE}
|
||||
inherited UpdateSize;
|
||||
{$ENDIF}
|
||||
result := FChromium;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -60,20 +60,21 @@ uses
|
||||
Messages,
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
uCEFWinControl, uCEFTypes, uCEFInterfaces, uCEFChromium;
|
||||
uCEFWinControl, uCEFTypes, uCEFInterfaces, uCEFChromium,
|
||||
uCEFLinkedWinControlBase;
|
||||
|
||||
type
|
||||
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pidWin32 or pidWin64)]{$ENDIF}{$ENDIF}
|
||||
TCEFLinkedWindowParent = class(TCEFWinControl)
|
||||
|
||||
{ TCEFLinkedWindowParent }
|
||||
|
||||
TCEFLinkedWindowParent = class(TCEFLinkedWinControlBase)
|
||||
protected
|
||||
FChromium : TChromium;
|
||||
|
||||
{$IFDEF FPC}
|
||||
procedure SetVisible(Value: Boolean); override;
|
||||
{$ENDIF}
|
||||
function GetChromium: TChromium; override;
|
||||
procedure SetChromium(aValue : TChromium);
|
||||
|
||||
function GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle; override;
|
||||
{$IFDEF MSWINDOWS}
|
||||
procedure WndProc(var aMessage: TMessage); override;
|
||||
{$ENDIF}
|
||||
@ -81,10 +82,9 @@ type
|
||||
|
||||
public
|
||||
constructor Create(AOwner : TComponent); override;
|
||||
procedure UpdateSize; override;
|
||||
|
||||
published
|
||||
property Chromium : TChromium read FChromium write SetChromium;
|
||||
property Chromium : TChromium read FChromium write SetChromium;
|
||||
end;
|
||||
|
||||
|
||||
@ -105,15 +105,6 @@ begin
|
||||
FChromium := nil;
|
||||
end;
|
||||
|
||||
function TCEFLinkedWindowParent.GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle;
|
||||
begin
|
||||
Result := 0;
|
||||
|
||||
if (FChromium <> nil) then Result := FChromium.WindowHandle;
|
||||
|
||||
if (Result = 0) then Result := inherited GetChildWindowHandle;
|
||||
end;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
procedure TCEFLinkedWindowParent.WndProc(var aMessage: TMessage);
|
||||
var
|
||||
@ -156,39 +147,9 @@ begin
|
||||
if (Operation = opRemove) and (AComponent = FChromium) then FChromium := nil;
|
||||
end;
|
||||
|
||||
{$IFDEF FPC}
|
||||
procedure TCEFLinkedWindowParent.SetVisible(Value: Boolean);
|
||||
{$IFDEF LINUX}
|
||||
var
|
||||
TempChanged : boolean;
|
||||
{$ENDIF}
|
||||
function TCEFLinkedWindowParent.GetChromium: TChromium;
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
TempChanged := (Visible <> Value);
|
||||
{$ENDIF}
|
||||
|
||||
inherited SetVisible(Value);
|
||||
|
||||
{$IFDEF LINUX}
|
||||
if not(csDesigning in ComponentState) and
|
||||
TempChanged and
|
||||
(FChromium <> nil) and
|
||||
FChromium.Initialized then
|
||||
FChromium.UpdateXWindowVisibility(Visible);
|
||||
{$ENDIF}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TCEFLinkedWindowParent.UpdateSize;
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
if not(csDesigning in ComponentState) and
|
||||
(FChromium <> nil) and
|
||||
FChromium.Initialized then
|
||||
FChromium.UpdateBrowserSize(Left, Top, Width, Height);
|
||||
{$ELSE}
|
||||
inherited UpdateSize;
|
||||
{$ENDIF}
|
||||
Result := FChromium;
|
||||
end;
|
||||
|
||||
procedure TCEFLinkedWindowParent.SetChromium(aValue : TChromium);
|
||||
|
Loading…
x
Reference in New Issue
Block a user