You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-08-04 21:32:54 +02:00
Fixed an issue copying the bitmap in uCEFBrowserThread
Added more checks to uCEFBrowserThread
This commit is contained in:
@ -47,7 +47,9 @@
|
||||
<Unit2>
|
||||
<Filename Value="uWebpageSnapshot.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="WebpageSnapshotFrm"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit2>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
|
@ -4,12 +4,12 @@
|
||||
<PathDelim Value="\"/>
|
||||
<Version Value="11"/>
|
||||
<BuildModes Active="Default"/>
|
||||
<Units Count="6">
|
||||
<Units Count="8">
|
||||
<Unit0>
|
||||
<Filename Value="WebpageSnapshot.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<TopLine Value="45"/>
|
||||
<CursorPos X="37" Y="58"/>
|
||||
<CursorPos Y="73"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
@ -18,9 +18,9 @@
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<TopLine Value="637"/>
|
||||
<CursorPos X="70" Y="657"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<TopLine Value="471"/>
|
||||
<CursorPos X="66" Y="483"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
@ -28,11 +28,14 @@
|
||||
<Unit2>
|
||||
<Filename Value="uWebpageSnapshot.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="WebpageSnapshotFrm"/>
|
||||
<HasResources Value="True"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="139"/>
|
||||
<CursorPos X="74" Y="162"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<TopLine Value="98"/>
|
||||
<CursorPos X="71" Y="163"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
@ -52,112 +55,89 @@
|
||||
<Unit5>
|
||||
<Filename Value="..\..\..\source\uCEFBufferPanel.pas"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="628"/>
|
||||
<CursorPos Y="644"/>
|
||||
<TopLine Value="636"/>
|
||||
<CursorPos Y="652"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit5>
|
||||
<Unit6>
|
||||
<Filename Value="..\ConsoleBrowser2\uCEFBrowserThread.pas"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="31"/>
|
||||
<CursorPos X="17" Y="40"/>
|
||||
<UsageCount Value="10"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
</Unit6>
|
||||
<Unit7>
|
||||
<Filename Value="uCEFBrowserThread_v.pas"/>
|
||||
<UnitName Value="uCEFBrowserThread"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="321"/>
|
||||
<CursorPos Y="338"/>
|
||||
<UsageCount Value="10"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
</Unit7>
|
||||
</Units>
|
||||
<JumpHistory Count="25" HistoryIndex="24">
|
||||
<JumpHistory Count="15" HistoryIndex="14">
|
||||
<Position1>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="381" TopLine="361"/>
|
||||
<Caret Line="348" TopLine="334"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="383" TopLine="361"/>
|
||||
<Caret Line="95" Column="17" TopLine="86"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="384" TopLine="361"/>
|
||||
<Caret Line="326" TopLine="292"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="386" TopLine="363"/>
|
||||
<Caret Line="348" TopLine="334"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="388" TopLine="365"/>
|
||||
<Caret Line="349" TopLine="334"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="390" TopLine="367"/>
|
||||
<Caret Line="351" TopLine="334"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="392" TopLine="369"/>
|
||||
<Caret Line="353" TopLine="334"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="394" TopLine="371"/>
|
||||
<Caret Line="376" TopLine="363"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="396" TopLine="373"/>
|
||||
<Caret Line="378" TopLine="363"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="397" TopLine="374"/>
|
||||
<Caret Line="379" TopLine="363"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="398" TopLine="375"/>
|
||||
<Caret Line="381" TopLine="363"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="397" TopLine="375"/>
|
||||
<Caret Line="382" TopLine="363"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="400" TopLine="377"/>
|
||||
<Caret Line="101" Column="62" TopLine="84"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="401" TopLine="378"/>
|
||||
<Caret Line="515" Column="28" TopLine="397"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="403" TopLine="380"/>
|
||||
<Caret Line="416" Column="50" TopLine="403"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="404" TopLine="381"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="406" TopLine="383"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="595" TopLine="570"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="336" Column="203" TopLine="334"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="98" Column="191" TopLine="98"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="351" Column="65" TopLine="418"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="644" TopLine="630"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="337" TopLine="333"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="651" TopLine="637"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="uCEFBrowserThread.pas"/>
|
||||
<Caret Line="653" TopLine="637"/>
|
||||
</Position25>
|
||||
</JumpHistory>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
|
@ -10,7 +10,7 @@
|
||||
// For more information about CEF4Delphi visit :
|
||||
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
||||
//
|
||||
// Copyright © 2020 Salvador Diaz Fau. All rights reserved.
|
||||
// Copyright � 2020 Salvador Diaz Fau. All rights reserved.
|
||||
//
|
||||
// ************************************************************************
|
||||
// ************ vvvv Original license and comments below vvvv *************
|
||||
@ -35,7 +35,7 @@
|
||||
*
|
||||
*)
|
||||
|
||||
unit uCEFBrowserThread;
|
||||
unit uCEFBrowserThread;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
@ -47,7 +47,7 @@ uses
|
||||
{$IFDEF DELPHI16_UP}
|
||||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics, System.SyncObjs, System.Math,
|
||||
{$ELSE}
|
||||
LCLIntf, LCLType, LMessages, Windows, Messages, SysUtils, Classes, Graphics, SyncObjs, Math,
|
||||
Windows, Messages, SysUtils, Classes, Graphics, SyncObjs, Math,
|
||||
{$ENDIF}
|
||||
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFBufferPanel, uCEFChromiumCore, uCEFMiscFunctions;
|
||||
|
||||
@ -56,7 +56,7 @@ type
|
||||
protected
|
||||
FCustomScale : single;
|
||||
|
||||
function GetScreenScale : single; override;
|
||||
function GetScreenScale : single; override;
|
||||
|
||||
public
|
||||
property CustomScale : single read FCustomScale write FCustomScale;
|
||||
@ -86,12 +86,15 @@ type
|
||||
FErrorText : ustring;
|
||||
FFailedUrl : ustring;
|
||||
FPendingUrl : ustring;
|
||||
FSyncEvents : boolean;
|
||||
|
||||
function GetErrorCode : integer;
|
||||
function GetErrorText : ustring;
|
||||
function GetFailedUrl : ustring;
|
||||
function GetInitialized : boolean;
|
||||
|
||||
procedure SetErrorText(const aValue : ustring);
|
||||
|
||||
procedure Panel_OnResize(Sender: TObject);
|
||||
|
||||
procedure Browser_OnAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||
@ -110,9 +113,11 @@ type
|
||||
procedure DoOnSnapshotAvailable;
|
||||
procedure Resize;
|
||||
function CreateBrowser : boolean;
|
||||
procedure TakeSnapshot;
|
||||
function TakeSnapshot : boolean;
|
||||
procedure CloseBrowser;
|
||||
procedure InitError;
|
||||
procedure WebpagePostProcessing;
|
||||
procedure WebpageError;
|
||||
procedure LoadPendingURL;
|
||||
procedure Execute; override;
|
||||
|
||||
@ -122,12 +127,15 @@ type
|
||||
procedure AfterConstruction; override;
|
||||
function TerminateBrowserThread : boolean;
|
||||
function CopySnapshot(var aSnapshot : TBitmap) : boolean;
|
||||
function SaveSnapshotToFile(const aPath : ustring) : boolean;
|
||||
procedure LoadUrl(const aURL : ustring);
|
||||
|
||||
property ErrorCode : integer read GetErrorCode;
|
||||
property ErrorText : ustring read GetErrorText;
|
||||
property ErrorText : ustring read GetErrorText write SetErrorText;
|
||||
property FailedUrl : ustring read GetFailedUrl;
|
||||
property Initialized : boolean read GetInitialized;
|
||||
property Closing : boolean read FClosing;
|
||||
property SyncEvents : boolean read FSyncEvents write FSyncEvents;
|
||||
|
||||
property OnSnapshotAvailable : TNotifyEvent read FOnSnapshotAvailable write FOnSnapshotAvailable;
|
||||
property OnError : TNotifyEvent read FOnError write FOnError;
|
||||
@ -179,6 +187,7 @@ begin
|
||||
FOnSnapshotAvailable := nil;
|
||||
FOnError := nil;
|
||||
FClosing := False;
|
||||
FSyncEvents := False;
|
||||
end;
|
||||
|
||||
destructor TCEFBrowserThread.Destroy;
|
||||
@ -235,23 +244,41 @@ end;
|
||||
|
||||
function TCEFBrowserThread.GetErrorCode : integer;
|
||||
begin
|
||||
FBrowserInfoCS.Acquire;
|
||||
Result := FErrorCode;
|
||||
FBrowserInfoCS.Release;
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
Result := FErrorCode;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end
|
||||
else
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function TCEFBrowserThread.GetErrorText : ustring;
|
||||
begin
|
||||
FBrowserInfoCS.Acquire;
|
||||
Result := FErrorText;
|
||||
FBrowserInfoCS.Release;
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
Result := FErrorText;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end
|
||||
else
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
function TCEFBrowserThread.GetFailedUrl : ustring;
|
||||
begin
|
||||
FBrowserInfoCS.Acquire;
|
||||
Result := FFailedUrl;
|
||||
FBrowserInfoCS.Release;
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
Result := FFailedUrl;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end
|
||||
else
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
function TCEFBrowserThread.GetInitialized : boolean;
|
||||
@ -267,45 +294,85 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.SetErrorText(const aValue : ustring);
|
||||
begin
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
FErrorText := aValue;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCEFBrowserThread.CopySnapshot(var aSnapshot : TBitmap) : boolean;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
if FClosing or Terminated or (FBrowserInfoCS = nil) then exit;
|
||||
if FClosing or Terminated or not(Initialized) then exit;
|
||||
|
||||
try
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
|
||||
if assigned(FSnapshot) and not(FSnapshot.Empty) then
|
||||
begin
|
||||
if (aSnapshot = nil) then
|
||||
begin
|
||||
aSnapshot := TBitmap.Create;
|
||||
aSnapshot.PixelFormat := pf32bit;
|
||||
aSnapshot.HandleType := bmDIB;
|
||||
aSnapshot.Width := FSnapshot.Width;
|
||||
aSnapshot.Height := FSnapshot.Height;
|
||||
end;
|
||||
if assigned(FSnapshot) and not(FSnapshot.Empty) then
|
||||
begin
|
||||
if (aSnapshot = nil) then
|
||||
begin
|
||||
aSnapshot := TBitmap.Create;
|
||||
aSnapshot.PixelFormat := pf32bit;
|
||||
aSnapshot.HandleType := bmDIB;
|
||||
end;
|
||||
|
||||
aSnapshot.Assign(FSnapshot);
|
||||
Result := True;
|
||||
end;
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('TCEFBrowserThread.CopySnapshot', e) then raise;
|
||||
if (aSnapshot.Width <> FSnapshot.Width) then
|
||||
aSnapshot.Width := FSnapshot.Width;
|
||||
|
||||
if (aSnapshot.Height <> FSnapshot.Height) then
|
||||
aSnapshot.Height := FSnapshot.Height;
|
||||
|
||||
aSnapshot.Canvas.Draw(0, 0, FSnapshot);
|
||||
Result := True;
|
||||
end;
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('TCEFBrowserThread.CopySnapshot', e) then raise;
|
||||
end;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCEFBrowserThread.SaveSnapshotToFile(const aPath : ustring) : boolean;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
if FClosing or Terminated or not(Initialized) then exit;
|
||||
|
||||
if assigned(FBrowserInfoCS) and (length(aPath) > 0) then
|
||||
try
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
|
||||
if assigned(FSnapshot) and not(FSnapshot.Empty) then
|
||||
begin
|
||||
FSnapshot.SaveToFile(aPath);
|
||||
Result := True;
|
||||
end;
|
||||
except
|
||||
on e : exception do
|
||||
if CustomExceptionHandler('TCEFBrowserThread.SaveSnapshotToFile', e) then raise;
|
||||
end;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.LoadUrl(const aURL : ustring);
|
||||
begin
|
||||
if FClosing or Terminated or (FBrowserInfoCS = nil) then
|
||||
exit;
|
||||
if FClosing or Terminated or not(Initialized) then exit;
|
||||
|
||||
if Initialized then
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
FPendingUrl := aURL;
|
||||
@ -328,9 +395,13 @@ end;
|
||||
|
||||
procedure TCEFBrowserThread.Browser_OnAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||
begin
|
||||
FBrowserInfoCS.Acquire;
|
||||
FInitialized := True;
|
||||
FBrowserInfoCS.Release;
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
FInitialized := True;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.Browser_OnPaint(Sender: TObject; const browser: ICefBrowser; kind: TCefPaintElementType; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; const buffer: Pointer; aWidth, aHeight: Integer);
|
||||
@ -344,112 +415,116 @@ var
|
||||
TempBitmap : TBitmap;
|
||||
TempSrcRect : TRect;
|
||||
begin
|
||||
try
|
||||
FResizeCS.Acquire;
|
||||
TempForcedResize := False;
|
||||
if assigned(FResizeCS) and assigned(FPanel) then
|
||||
try
|
||||
FResizeCS.Acquire;
|
||||
TempForcedResize := False;
|
||||
|
||||
if FPanel.BeginBufferDraw then
|
||||
begin
|
||||
if (kind = PET_POPUP) then
|
||||
begin
|
||||
if (FPopUpBitmap = nil) or
|
||||
(aWidth <> FPopUpBitmap.Width) or
|
||||
(aHeight <> FPopUpBitmap.Height) then
|
||||
begin
|
||||
if (FPopUpBitmap <> nil) then FPopUpBitmap.Free;
|
||||
if FPanel.BeginBufferDraw then
|
||||
begin
|
||||
if (kind = PET_POPUP) then
|
||||
begin
|
||||
if (FPopUpBitmap = nil) or
|
||||
(aWidth <> FPopUpBitmap.Width) or
|
||||
(aHeight <> FPopUpBitmap.Height) then
|
||||
begin
|
||||
if (FPopUpBitmap <> nil) then FPopUpBitmap.Free;
|
||||
|
||||
FPopUpBitmap := TBitmap.Create;
|
||||
FPopUpBitmap.PixelFormat := pf32bit;
|
||||
FPopUpBitmap.HandleType := bmDIB;
|
||||
FPopUpBitmap.Width := aWidth;
|
||||
FPopUpBitmap.Height := aHeight;
|
||||
end;
|
||||
FPopUpBitmap := TBitmap.Create;
|
||||
FPopUpBitmap.PixelFormat := pf32bit;
|
||||
FPopUpBitmap.HandleType := bmDIB;
|
||||
FPopUpBitmap.Width := aWidth;
|
||||
FPopUpBitmap.Height := aHeight;
|
||||
end;
|
||||
|
||||
TempBitmap := FPopUpBitmap;
|
||||
TempBitmap.BeginUpdate;
|
||||
TempBitmap := FPopUpBitmap;
|
||||
TempBitmap.BeginUpdate;
|
||||
|
||||
TempWidth := FPopUpBitmap.Width;
|
||||
TempHeight := FPopUpBitmap.Height;
|
||||
end
|
||||
else
|
||||
begin
|
||||
TempForcedResize := FPanel.UpdateBufferDimensions(aWidth, aHeight) or not(FPanel.BufferIsResized(False));
|
||||
TempWidth := FPopUpBitmap.Width;
|
||||
TempHeight := FPopUpBitmap.Height;
|
||||
end
|
||||
else
|
||||
begin
|
||||
TempForcedResize := FPanel.UpdateBufferDimensions(aWidth, aHeight) or not(FPanel.BufferIsResized(False));
|
||||
|
||||
TempBitmap := FPanel.Buffer;
|
||||
TempBitmap.BeginUpdate;
|
||||
TempBitmap := FPanel.Buffer;
|
||||
TempBitmap.BeginUpdate;
|
||||
|
||||
TempWidth := FPanel.BufferWidth;
|
||||
TempHeight := FPanel.BufferHeight;
|
||||
end;
|
||||
TempWidth := FPanel.BufferWidth;
|
||||
TempHeight := FPanel.BufferHeight;
|
||||
end;
|
||||
|
||||
SrcStride := aWidth * SizeOf(TRGBQuad);
|
||||
n := 0;
|
||||
SrcStride := aWidth * SizeOf(TRGBQuad);
|
||||
n := 0;
|
||||
|
||||
while (n < dirtyRectsCount) do
|
||||
begin
|
||||
if (dirtyRects^[n].x >= 0) and (dirtyRects^[n].y >= 0) then
|
||||
begin
|
||||
TempLineSize := min(dirtyRects^[n].width, TempWidth - dirtyRects^[n].x) * SizeOf(TRGBQuad);
|
||||
while (n < dirtyRectsCount) do
|
||||
begin
|
||||
if (dirtyRects^[n].x >= 0) and (dirtyRects^[n].y >= 0) then
|
||||
begin
|
||||
TempLineSize := min(dirtyRects^[n].width, TempWidth - dirtyRects^[n].x) * SizeOf(TRGBQuad);
|
||||
|
||||
if (TempLineSize > 0) then
|
||||
begin
|
||||
TempSrcOffset := ((dirtyRects^[n].y * aWidth) + dirtyRects^[n].x) * SizeOf(TRGBQuad);
|
||||
TempDstOffset := (dirtyRects^[n].x * SizeOf(TRGBQuad));
|
||||
if (TempLineSize > 0) then
|
||||
begin
|
||||
TempSrcOffset := ((dirtyRects^[n].y * aWidth) + dirtyRects^[n].x) * SizeOf(TRGBQuad);
|
||||
TempDstOffset := (dirtyRects^[n].x * SizeOf(TRGBQuad));
|
||||
|
||||
src := @PByte(buffer)[TempSrcOffset];
|
||||
src := @PByte(buffer)[TempSrcOffset];
|
||||
|
||||
i := 0;
|
||||
j := min(dirtyRects^[n].height, TempHeight - dirtyRects^[n].y);
|
||||
i := 0;
|
||||
j := min(dirtyRects^[n].height, TempHeight - dirtyRects^[n].y);
|
||||
|
||||
while (i < j) do
|
||||
begin
|
||||
TempBufferBits := TempBitmap.Scanline[dirtyRects^[n].y + i];
|
||||
dst := @PByte(TempBufferBits)[TempDstOffset];
|
||||
while (i < j) do
|
||||
begin
|
||||
TempBufferBits := TempBitmap.Scanline[dirtyRects^[n].y + i];
|
||||
dst := @PByte(TempBufferBits)[TempDstOffset];
|
||||
|
||||
Move(src^, dst^, TempLineSize);
|
||||
Move(src^, dst^, TempLineSize);
|
||||
|
||||
Inc(src, SrcStride);
|
||||
inc(i);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
Inc(src, SrcStride);
|
||||
inc(i);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
inc(n);
|
||||
end;
|
||||
inc(n);
|
||||
end;
|
||||
|
||||
TempBitmap.EndUpdate;
|
||||
TempBitmap.EndUpdate;
|
||||
|
||||
if FShowPopup and (FPopUpBitmap <> nil) then
|
||||
begin
|
||||
TempSrcRect := Rect(0, 0,
|
||||
min(FPopUpRect.Right - FPopUpRect.Left, FPopUpBitmap.Width),
|
||||
min(FPopUpRect.Bottom - FPopUpRect.Top, FPopUpBitmap.Height));
|
||||
if FShowPopup and (FPopUpBitmap <> nil) then
|
||||
begin
|
||||
TempSrcRect := Rect(0, 0,
|
||||
min(FPopUpRect.Right - FPopUpRect.Left, FPopUpBitmap.Width),
|
||||
min(FPopUpRect.Bottom - FPopUpRect.Top, FPopUpBitmap.Height));
|
||||
|
||||
FPanel.BufferDraw(FPopUpBitmap, TempSrcRect, FPopUpRect);
|
||||
end;
|
||||
FPanel.BufferDraw(FPopUpBitmap, TempSrcRect, FPopUpRect);
|
||||
end;
|
||||
|
||||
FPanel.EndBufferDraw;
|
||||
FPanel.EndBufferDraw;
|
||||
|
||||
if (kind = PET_VIEW) then
|
||||
begin
|
||||
if TempForcedResize or FPendingResize then
|
||||
PostThreadMessage(ThreadID, CEF_PENDINGRESIZE, 0, 0);
|
||||
if (kind = PET_VIEW) then
|
||||
begin
|
||||
if TempForcedResize or FPendingResize then
|
||||
PostThreadMessage(ThreadID, CEF_PENDINGRESIZE, 0, 0);
|
||||
|
||||
FResizing := False;
|
||||
FPendingResize := False;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
FResizeCS.Release;
|
||||
end;
|
||||
FResizing := False;
|
||||
FPendingResize := False;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
FResizeCS.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.Browser_OnGetViewRect(Sender: TObject; const browser: ICefBrowser; var rect: TCefRect);
|
||||
begin
|
||||
rect.x := 0;
|
||||
rect.y := 0;
|
||||
rect.width := DeviceToLogical(FPanel.Width, FScreenScale);
|
||||
rect.height := DeviceToLogical(FPanel.Height, FScreenScale);
|
||||
if assigned(FPanel) then
|
||||
begin
|
||||
rect.x := 0;
|
||||
rect.y := 0;
|
||||
rect.width := DeviceToLogical(FPanel.Width, FScreenScale);
|
||||
rect.height := DeviceToLogical(FPanel.Height, FScreenScale);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.Browser_OnGetScreenPoint(Sender: TObject; const browser: ICefBrowser; viewX, viewY: Integer; var screenX, screenY: Integer; out Result: Boolean);
|
||||
@ -463,19 +538,22 @@ procedure TCEFBrowserThread.Browser_OnGetScreenInfo(Sender: TObject; const brows
|
||||
var
|
||||
TempRect : TCEFRect;
|
||||
begin
|
||||
TempRect.x := 0;
|
||||
TempRect.y := 0;
|
||||
TempRect.width := DeviceToLogical(FPanel.Width, FScreenScale);
|
||||
TempRect.height := DeviceToLogical(FPanel.Height, FScreenScale);
|
||||
if assigned(FPanel) then
|
||||
begin
|
||||
TempRect.x := 0;
|
||||
TempRect.y := 0;
|
||||
TempRect.width := DeviceToLogical(FPanel.Width, FScreenScale);
|
||||
TempRect.height := DeviceToLogical(FPanel.Height, FScreenScale);
|
||||
|
||||
screenInfo.device_scale_factor := FScreenScale;
|
||||
screenInfo.depth := 0;
|
||||
screenInfo.depth_per_component := 0;
|
||||
screenInfo.is_monochrome := Ord(False);
|
||||
screenInfo.rect := TempRect;
|
||||
screenInfo.available_rect := TempRect;
|
||||
screenInfo.device_scale_factor := FScreenScale;
|
||||
screenInfo.depth := 0;
|
||||
screenInfo.depth_per_component := 0;
|
||||
screenInfo.is_monochrome := Ord(False);
|
||||
screenInfo.rect := TempRect;
|
||||
screenInfo.available_rect := TempRect;
|
||||
|
||||
Result := True;
|
||||
Result := True;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.Browser_OnPopupShow(Sender: TObject; const browser: ICefBrowser; show: Boolean);
|
||||
@ -514,7 +592,7 @@ end;
|
||||
|
||||
procedure TCEFBrowserThread.Browser_OnLoadError(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring);
|
||||
begin
|
||||
if not(FClosing) and not(Terminated) and (frame <> nil) and frame.IsValid and frame.IsMain then
|
||||
if not(FClosing) and not(Terminated) and (frame <> nil) and frame.IsValid and frame.IsMain and assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
|
||||
@ -534,37 +612,27 @@ begin
|
||||
PostThreadMessage(ThreadID, CEF_WEBPAGE_LOADED_MSG, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.DoOnError;
|
||||
begin
|
||||
FOnError(self);
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.DoOnSnapshotAvailable;
|
||||
begin
|
||||
FOnSnapshotAvailable(self);
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.Resize;
|
||||
begin
|
||||
if FClosing or Terminated or (FPanel = nil) or (FResizeCS = nil) or (FBrowser = nil) then
|
||||
exit;
|
||||
if FClosing or Terminated or not(Initialized) then exit;
|
||||
|
||||
try
|
||||
FResizeCS.Acquire;
|
||||
if assigned(FResizeCS) and assigned(FPanel) then
|
||||
try
|
||||
FResizeCS.Acquire;
|
||||
|
||||
if FResizing then
|
||||
FPendingResize := True
|
||||
else
|
||||
if FPanel.BufferIsResized then
|
||||
FBrowser.Invalidate(PET_VIEW)
|
||||
if FResizing then
|
||||
FPendingResize := True
|
||||
else
|
||||
begin
|
||||
FResizing := True;
|
||||
FBrowser.WasResized;
|
||||
end;
|
||||
finally
|
||||
FResizeCS.Release;
|
||||
end;
|
||||
if FPanel.BufferIsResized then
|
||||
FBrowser.Invalidate(PET_VIEW)
|
||||
else
|
||||
begin
|
||||
FResizing := True;
|
||||
FBrowser.WasResized;
|
||||
end;
|
||||
finally
|
||||
FResizeCS.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCEFBrowserThread.CreateBrowser : boolean;
|
||||
@ -574,20 +642,20 @@ end;
|
||||
|
||||
procedure TCEFBrowserThread.LoadPendingURL;
|
||||
begin
|
||||
if FClosing or Terminated or (FBrowser = nil) or (FBrowserInfoCS = nil) then
|
||||
exit;
|
||||
if FClosing or Terminated or not(Initialized) then exit;
|
||||
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
if assigned(FBrowserInfoCS) then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
|
||||
if (length(FPendingURL) > 0) then
|
||||
begin
|
||||
FBrowser.LoadURL(FPendingURL);
|
||||
FPendingURL := '';
|
||||
end;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
if (length(FPendingURL) > 0) then
|
||||
begin
|
||||
FBrowser.LoadURL(FPendingURL);
|
||||
FPendingURL := '';
|
||||
end;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.WebpagePostProcessing;
|
||||
@ -598,33 +666,58 @@ begin
|
||||
if (FDelayMs > 0) then
|
||||
sleep(FDelayMs);
|
||||
|
||||
TakeSnapshot;
|
||||
|
||||
if assigned(FOnSnapshotAvailable) then
|
||||
Synchronize(DoOnSnapshotAvailable);
|
||||
if TakeSnapshot and assigned(FOnSnapshotAvailable) then
|
||||
begin
|
||||
if FSyncEvents then
|
||||
Synchronize(DoOnSnapshotAvailable)
|
||||
else
|
||||
DoOnSnapshotAvailable;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.TakeSnapshot;
|
||||
procedure TCEFBrowserThread.WebpageError;
|
||||
begin
|
||||
if (FPanel = nil) or (FPanel.Buffer = nil) or (FBrowserInfoCS = nil) then
|
||||
exit;
|
||||
if not(FClosing) and not(Terminated) and assigned(FOnError) then
|
||||
begin
|
||||
if FSyncEvents then
|
||||
Synchronize(DoOnError)
|
||||
else
|
||||
DoOnError;
|
||||
end;
|
||||
end;
|
||||
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
function TCEFBrowserThread.TakeSnapshot : boolean;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
if (FSnapshot = nil) then
|
||||
begin
|
||||
FSnapshot := TBitmap.Create;
|
||||
FSnapshot.PixelFormat := pf32bit;
|
||||
FSnapshot.HandleType := bmDIB;
|
||||
FSnapshot.Width := FPanel.BufferWidth;
|
||||
FSnapshot.Height := FPanel.BufferHeight;
|
||||
end;
|
||||
if FClosing or Terminated or not(Initialized) then exit;
|
||||
|
||||
FSnapshot.Assign(FPanel.Buffer);
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
end;
|
||||
if assigned(FBrowserInfoCS) and assigned(FPanel) and FPanel.BeginBufferDraw then
|
||||
try
|
||||
FBrowserInfoCS.Acquire;
|
||||
|
||||
if assigned(FPanel.Buffer) and not(FPanel.Buffer.Empty) then
|
||||
begin
|
||||
if (FSnapshot = nil) then
|
||||
begin
|
||||
FSnapshot := TBitmap.Create;
|
||||
FSnapshot.PixelFormat := pf32bit;
|
||||
FSnapshot.HandleType := bmDIB;
|
||||
end;
|
||||
|
||||
if (FSnapshot.Width <> FPanel.BufferWidth) then
|
||||
FSnapshot.Width := FPanel.BufferWidth;
|
||||
|
||||
if (FSnapshot.Height <> FPanel.BufferHeight) then
|
||||
FSnapshot.Height := FPanel.BufferHeight;
|
||||
|
||||
FSnapshot.Canvas.Draw(0, 0, FPanel.Buffer);
|
||||
Result := True;
|
||||
end;
|
||||
finally
|
||||
FBrowserInfoCS.Release;
|
||||
FPanel.EndBufferDraw;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.CloseBrowser;
|
||||
@ -636,6 +729,26 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.DoOnError;
|
||||
begin
|
||||
FOnError(self);
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.DoOnSnapshotAvailable;
|
||||
begin
|
||||
FOnSnapshotAvailable(self);
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.InitError;
|
||||
begin
|
||||
ErrorText := 'There was an error initializing the CEF browser.';
|
||||
|
||||
if FSyncEvents then
|
||||
Synchronize(DoOnError)
|
||||
else
|
||||
DoOnError;
|
||||
end;
|
||||
|
||||
procedure TCEFBrowserThread.Execute;
|
||||
var
|
||||
TempCont : boolean;
|
||||
@ -649,17 +762,19 @@ begin
|
||||
while TempCont and GetMessage(TempMsg, 0, 0, 0) and not(Terminated) do
|
||||
begin
|
||||
case TempMsg.Message of
|
||||
WM_QUIT : TempCont := False;
|
||||
CEF_PENDINGRESIZE : Resize;
|
||||
CEF_CLOSE_BROWSER_MSG : CloseBrowser;
|
||||
CEF_LOAD_PENDING_URL_MSG : LoadPendingURL;
|
||||
CEF_WEBPAGE_LOADED_MSG : WebpagePostProcessing;
|
||||
CEF_WEBPAGE_ERROR_MSG : if assigned(FOnError) then Synchronize(DoOnError);
|
||||
CEF_WEBPAGE_ERROR_MSG : WebpageError;
|
||||
WM_QUIT : TempCont := False;
|
||||
end;
|
||||
|
||||
DispatchMessage(TempMsg);
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
InitError;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -1,24 +1,24 @@
|
||||
object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
Left = 0
|
||||
Height = 486
|
||||
Top = 0
|
||||
Width = 711
|
||||
Caption = 'Web page snapshot'
|
||||
ClientHeight = 486
|
||||
ClientWidth = 711
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'Tahoma'
|
||||
Font.Style = []
|
||||
Position = poScreenCenter
|
||||
OnCloseQuery = FormCloseQuery
|
||||
OnCreate = FormCreate
|
||||
PixelsPerInch = 96
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '2.0.10.0'
|
||||
object Image1: TImage
|
||||
Left = 0
|
||||
Height = 438
|
||||
Top = 25
|
||||
Width = 711
|
||||
Height = 442
|
||||
Align = alClient
|
||||
AutoSize = True
|
||||
Center = True
|
||||
@ -26,10 +26,10 @@ object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
end
|
||||
object StatusBar1: TStatusBar
|
||||
Left = 0
|
||||
Top = 467
|
||||
Height = 23
|
||||
Top = 463
|
||||
Width = 711
|
||||
Height = 19
|
||||
Panels = <
|
||||
Panels = <
|
||||
item
|
||||
Width = 1000
|
||||
end>
|
||||
@ -37,27 +37,29 @@ object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
end
|
||||
object NavigationPnl: TPanel
|
||||
Left = 0
|
||||
Height = 25
|
||||
Top = 0
|
||||
Width = 711
|
||||
Height = 25
|
||||
Align = alTop
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 25
|
||||
ClientWidth = 711
|
||||
TabOrder = 1
|
||||
object GoBtn: TButton
|
||||
Left = 632
|
||||
Left = 636
|
||||
Height = 25
|
||||
Top = 0
|
||||
Width = 75
|
||||
Height = 21
|
||||
Align = alRight
|
||||
Caption = 'Go'
|
||||
TabOrder = 0
|
||||
OnClick = GoBtnClick
|
||||
TabOrder = 0
|
||||
end
|
||||
object AddressEdt: TEdit
|
||||
Left = 0
|
||||
Height = 25
|
||||
Top = 0
|
||||
Width = 632
|
||||
Height = 21
|
||||
Width = 636
|
||||
Align = alClient
|
||||
TabOrder = 1
|
||||
Text = 'https://www.google.com'
|
||||
|
@ -117,6 +117,7 @@ begin
|
||||
FThread := TCEFBrowserThread.Create(AddressEdt.Text, 1024, 768);
|
||||
FThread.OnError := Thread_OnError;
|
||||
FThread.OnSnapshotAvailable := Thread_OnSnapshotAvailable;
|
||||
FThread.SyncEvents := True;
|
||||
FThread.Start;
|
||||
end
|
||||
else
|
||||
|
Reference in New Issue
Block a user