1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Update to CEF 3.3626.1891.g52be333

- Added transparency support to TBufferPanel.
- Added TBufferPanel.Transparent property
- Added TBufferPanel.OnPaintParentBkg event
- Added the TRANSPARENT_BROWSER constant in SimpleOSRBrowser to enable transparency
This commit is contained in:
Salvador Díaz Fau
2019-02-20 12:44:07 +01:00
parent 86561f4913
commit b3213a1052
6 changed files with 198 additions and 25 deletions

View File

@@ -55,9 +55,7 @@ uses
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.WindowlessRenderingEnabled := True;
GlobalCEFApp.EnableHighDPISupport := True;
CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
@@ -69,6 +67,5 @@ begin
Application.Run;
end;
GlobalCEFApp.Free;
GlobalCEFApp := nil;
DestroyGlobalCEFApp;
end.

View File

@@ -37,7 +37,7 @@ object Form1: TForm1
object ComboBox1: TComboBox
Left = 5
Top = 5
Width = 909
Width = 907
Height = 21
Align = alClient
ItemIndex = 0
@@ -51,12 +51,14 @@ object Form1: TForm1
'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_selec' +
't_form'
'https://www.briskbard.com'
'https://frames-per-second.appspot.com/')
'https://frames-per-second.appspot.com/'
'file:///transparency.html')
ExplicitWidth = 909
end
object Panel2: TPanel
Left = 914
Left = 912
Top = 5
Width = 69
Width = 71
Height = 20
Margins.Left = 2
Margins.Top = 2
@@ -80,7 +82,7 @@ object Form1: TForm1
OnEnter = GoBtnEnter
end
object SnapshotBtn: TButton
Left = 38
Left = 40
Top = 0
Width = 31
Height = 20
@@ -99,6 +101,7 @@ object Form1: TForm1
TabOrder = 1
OnClick = SnapshotBtnClick
OnEnter = SnapshotBtnEnter
ExplicitLeft = 38
end
end
end
@@ -110,8 +113,11 @@ object Form1: TForm1
OnIMECancelComposition = Panel1IMECancelComposition
OnIMECommitText = Panel1IMECommitText
OnIMESetComposition = Panel1IMESetComposition
OnPaintParentBkg = Panel1PaintParentBkg
Align = alClient
Caption = 'Panel1'
Ctl3D = False
ParentCtl3D = False
BevelOuter = bvNone
TabOrder = 1
TabStop = True
OnClick = Panel1Click
@@ -122,6 +128,7 @@ object Form1: TForm1
OnMouseUp = Panel1MouseUp
OnResize = Panel1Resize
OnMouseLeave = Panel1MouseLeave
ShowCaption = False
end
object chrmosr: TChromium
OnTooltip = chrmosrTooltip

View File

@@ -52,6 +52,11 @@ uses
{$ENDIF}
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uBufferPanel;
const
// Set this constant to True and load "file://transparency.html" to test a
// transparent browser.
TRANSPARENT_BROWSER = False;
type
TForm1 = class(TForm)
NavControlPnl: TPanel;
@@ -107,6 +112,7 @@ type
procedure Timer1Timer(Sender: TObject);
procedure SnapshotBtnEnter(Sender: TObject);
procedure ComboBox1Enter(Sender: TObject);
procedure Panel1PaintParentBkg(Sender: TObject);
protected
FPopUpBitmap : TBitmap;
@@ -149,6 +155,8 @@ type
var
Form1: TForm1;
procedure CreateGlobalCEFApp;
implementation
{$R *.dfm}
@@ -168,6 +176,20 @@ uses
// 3- chrmosr.OnBeforeClose is triggered because the internal browser was destroyed.
// Now we set FCanClose to True and send WM_CLOSE to the form.
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.WindowlessRenderingEnabled := True;
GlobalCEFApp.EnableHighDPISupport := True;
// If you need transparency leave the GlobalCEFApp.BackgroundColor property
// with the default value or set the alpha channel to 0
if TRANSPARENT_BROWSER then
GlobalCEFApp.BackgroundColor := CefColorSetARGB($00, $FF, $FF, $FF)
else
GlobalCEFApp.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
end;
procedure TForm1.AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
var
TempKeyEvent : TCefKeyEvent;
@@ -663,6 +685,8 @@ begin
FResizeCS := TCriticalSection.Create;
FIMECS := TCriticalSection.Create;
Panel1.Transparent := TRANSPARENT_BROWSER;
InitializeLastClick;
end;
@@ -696,8 +720,12 @@ begin
end
else
begin
// opaque white background color
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
// If you need transparency leave the chrmosr.Options.BackgroundColor property
// with the default value or set the alpha channel to 0
if TRANSPARENT_BROWSER then
chrmosr.Options.BackgroundColor := CefColorSetARGB($00, $FF, $FF, $FF)
else
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
// The IME handler needs to be created when Panel1 has a valid handle
// and before the browser creation.
@@ -797,6 +825,21 @@ begin
end;
end;
procedure TForm1.Panel1PaintParentBkg(Sender: TObject);
begin
// This event should only be used if you enabled transparency in the browser
if TRANSPARENT_BROWSER then
begin
// This event should copy the background image into Panel1.Canvas
// The TBufferPanel uses "AlphaBlend" to draw the browser contents over
// this background image.
// For simplicity, we just paint it green.
Panel1.Canvas.Brush.Color := clGreen;
Panel1.Canvas.Brush.Style := bsSolid;
Panel1.Canvas.FillRect(Rect(0, 0, Panel1.Width, Panel1.Height));
end;
end;
procedure TForm1.Panel1Resize(Sender: TObject);
begin
DoResize;