1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-06-12 22:07:39 +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

@ -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;