mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-02-12 10:26:05 +02:00
Buffer panel resize fixes for SimpleOSRBrowser
This commit is contained in:
parent
042c3ac088
commit
47765631e3
@ -48,7 +48,8 @@ object Form1: TForm1
|
|||||||
'https://html5demos.com/drag'
|
'https://html5demos.com/drag'
|
||||||
|
|
||||||
'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_selec' +
|
'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_selec' +
|
||||||
't_form')
|
't_form'
|
||||||
|
'https://www.briskbard.com')
|
||||||
end
|
end
|
||||||
object Panel2: TPanel
|
object Panel2: TPanel
|
||||||
Left = 726
|
Left = 726
|
||||||
@ -111,10 +112,10 @@ object Form1: TForm1
|
|||||||
OnEnter = Panel1Enter
|
OnEnter = Panel1Enter
|
||||||
OnExit = Panel1Exit
|
OnExit = Panel1Exit
|
||||||
OnMouseDown = Panel1MouseDown
|
OnMouseDown = Panel1MouseDown
|
||||||
OnMouseLeave = Panel1MouseLeave
|
|
||||||
OnMouseMove = Panel1MouseMove
|
OnMouseMove = Panel1MouseMove
|
||||||
OnMouseUp = Panel1MouseUp
|
OnMouseUp = Panel1MouseUp
|
||||||
OnResize = Panel1Resize
|
OnResize = Panel1Resize
|
||||||
|
OnMouseLeave = Panel1MouseLeave
|
||||||
end
|
end
|
||||||
object chrmosr: TChromium
|
object chrmosr: TChromium
|
||||||
OnAfterCreated = chrmosrAfterCreated
|
OnAfterCreated = chrmosrAfterCreated
|
||||||
|
@ -103,15 +103,20 @@ type
|
|||||||
FPopUpBitmap : TBitmap;
|
FPopUpBitmap : TBitmap;
|
||||||
FPopUpRect : TRect;
|
FPopUpRect : TRect;
|
||||||
FShowPopUp : boolean;
|
FShowPopUp : boolean;
|
||||||
|
FResizing : boolean;
|
||||||
|
FPendingResize : boolean;
|
||||||
|
FResizeCS : TCriticalSection;
|
||||||
|
|
||||||
function getModifiers(Shift: TShiftState): TCefEventFlags;
|
function getModifiers(Shift: TShiftState): TCefEventFlags;
|
||||||
function GetButton(Button: TMouseButton): TCefMouseButtonType;
|
function GetButton(Button: TMouseButton): TCefMouseButtonType;
|
||||||
|
procedure DoResize;
|
||||||
|
|
||||||
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
|
||||||
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
|
||||||
procedure WMCaptureChanged(var aMessage : TMessage); message WM_CAPTURECHANGED;
|
procedure WMCaptureChanged(var aMessage : TMessage); message WM_CAPTURECHANGED;
|
||||||
procedure WMCancelMode(var aMessage : TMessage); message WM_CANCELMODE;
|
procedure WMCancelMode(var aMessage : TMessage); message WM_CANCELMODE;
|
||||||
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
procedure BrowserCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
||||||
|
procedure PendingResizeMsg(var aMessage : TMessage); message CEF_PENDINGRESIZE;
|
||||||
|
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
@ -132,6 +137,15 @@ uses
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFMiscFunctions, uCEFApplication;
|
uCEFMiscFunctions, uCEFApplication;
|
||||||
|
|
||||||
|
// *********************************
|
||||||
|
// ********* ATTENTION !!! *********
|
||||||
|
// *********************************
|
||||||
|
//
|
||||||
|
// There is a known bug in the destruction of TChromium in OSR mode.
|
||||||
|
// If you destroy the TChromium in OSR mode before the application is closed,
|
||||||
|
// add a timer and wait 1-2 seconds after the TChromium's destruction.
|
||||||
|
// After that you can close the app. Hide the application in the task bar if necessary.
|
||||||
|
|
||||||
procedure TForm1.AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
|
procedure TForm1.AppEventsMessage(var Msg: tagMSG; var Handled: Boolean);
|
||||||
var
|
var
|
||||||
TempKeyEvent : TCefKeyEvent;
|
TempKeyEvent : TCefKeyEvent;
|
||||||
@ -248,6 +262,11 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.GoBtnClick(Sender: TObject);
|
procedure TForm1.GoBtnClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
FResizeCS.Acquire;
|
||||||
|
FResizing := False;
|
||||||
|
FPendingResize := False;
|
||||||
|
FResizeCS.Release;
|
||||||
|
|
||||||
chrmosr.LoadURL(ComboBox1.Text);
|
chrmosr.LoadURL(ComboBox1.Text);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -351,7 +370,12 @@ var
|
|||||||
n : NativeUInt;
|
n : NativeUInt;
|
||||||
TempWidth, TempHeight, TempScanlineSize : integer;
|
TempWidth, TempHeight, TempScanlineSize : integer;
|
||||||
TempBufferBits : Pointer;
|
TempBufferBits : Pointer;
|
||||||
|
TempForcedResize : boolean;
|
||||||
begin
|
begin
|
||||||
|
try
|
||||||
|
FResizeCS.Acquire;
|
||||||
|
TempForcedResize := False;
|
||||||
|
|
||||||
if Panel1.BeginBufferDraw then
|
if Panel1.BeginBufferDraw then
|
||||||
begin
|
begin
|
||||||
if (kind = PET_POPUP) then
|
if (kind = PET_POPUP) then
|
||||||
@ -376,6 +400,7 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
TempForcedResize := Panel1.UpdateBufferDimensions(Width, Height) or not(Panel1.BufferIsResized(False));
|
||||||
TempWidth := Panel1.BufferWidth;
|
TempWidth := Panel1.BufferWidth;
|
||||||
TempHeight := Panel1.BufferHeight;
|
TempHeight := Panel1.BufferHeight;
|
||||||
TempScanlineSize := Panel1.ScanlineSize;
|
TempScanlineSize := Panel1.ScanlineSize;
|
||||||
@ -427,6 +452,17 @@ begin
|
|||||||
|
|
||||||
Panel1.EndBufferDraw;
|
Panel1.EndBufferDraw;
|
||||||
Panel1.InvalidatePanel;
|
Panel1.InvalidatePanel;
|
||||||
|
|
||||||
|
if (kind = PET_VIEW) then
|
||||||
|
begin
|
||||||
|
if TempForcedResize or FPendingResize then PostMessage(Handle, CEF_PENDINGRESIZE, 0, 0);
|
||||||
|
|
||||||
|
FResizing := False;
|
||||||
|
FPendingResize := False;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FResizeCS.Release;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -535,6 +571,9 @@ begin
|
|||||||
FPopUpBitmap := nil;
|
FPopUpBitmap := nil;
|
||||||
FPopUpRect := rect(0, 0, 0, 0);
|
FPopUpRect := rect(0, 0, 0, 0);
|
||||||
FShowPopUp := False;
|
FShowPopUp := False;
|
||||||
|
FResizing := False;
|
||||||
|
FPendingResize := False;
|
||||||
|
FResizeCS := TCriticalSection.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.FormDestroy(Sender: TObject);
|
procedure TForm1.FormDestroy(Sender: TObject);
|
||||||
@ -635,8 +674,33 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.Panel1Resize(Sender: TObject);
|
procedure TForm1.Panel1Resize(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
DoResize;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.PendingResizeMsg(var aMessage : TMessage);
|
||||||
|
begin
|
||||||
|
DoResize;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.DoResize;
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
FResizeCS.Acquire;
|
||||||
|
|
||||||
|
if FResizing then
|
||||||
|
FPendingResize := True
|
||||||
|
else
|
||||||
|
if Panel1.BufferIsResized then
|
||||||
|
chrmosr.Invalidate(PET_VIEW)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
FResizing := True;
|
||||||
chrmosr.WasResized;
|
chrmosr.WasResized;
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
FResizeCS.Release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.Panel1Enter(Sender: TObject);
|
procedure TForm1.Panel1Enter(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
@ -61,10 +61,9 @@ type
|
|||||||
function GetBufferWidth : integer;
|
function GetBufferWidth : integer;
|
||||||
function GetBufferHeight : integer;
|
function GetBufferHeight : integer;
|
||||||
|
|
||||||
procedure CopyBuffer(aDC : HDC; const aRect : TRect);
|
function CopyBuffer(aDC : HDC; const aRect : TRect) : boolean;
|
||||||
function SaveBufferToFile(const aFilename : string) : boolean;
|
function SaveBufferToFile(const aFilename : string) : boolean;
|
||||||
procedure DestroyBuffer;
|
procedure DestroyBuffer;
|
||||||
procedure Resize; override;
|
|
||||||
|
|
||||||
procedure WMPaint(var aMessage: TWMPaint); message WM_PAINT;
|
procedure WMPaint(var aMessage: TWMPaint); message WM_PAINT;
|
||||||
procedure WMEraseBkgnd(var aMessage : TWMEraseBkgnd); message WM_ERASEBKGND;
|
procedure WMEraseBkgnd(var aMessage : TWMEraseBkgnd); message WM_ERASEBKGND;
|
||||||
@ -78,6 +77,8 @@ type
|
|||||||
function BeginBufferDraw : boolean;
|
function BeginBufferDraw : boolean;
|
||||||
procedure EndBufferDraw;
|
procedure EndBufferDraw;
|
||||||
procedure BufferDraw(x, y : integer; const aBitmap : TBitmap);
|
procedure BufferDraw(x, y : integer; const aBitmap : TBitmap);
|
||||||
|
function UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
||||||
|
function BufferIsResized(aUseMutex : boolean = True) : boolean;
|
||||||
|
|
||||||
property Buffer : TBitmap read FBuffer;
|
property Buffer : TBitmap read FBuffer;
|
||||||
property ScanlineSize : integer read FScanlineSize;
|
property ScanlineSize : integer read FScanlineSize;
|
||||||
@ -173,7 +174,7 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
uCEFMiscFunctions;
|
uCEFMiscFunctions, uCEFApplication;
|
||||||
|
|
||||||
constructor TBufferPanel.Create(AOwner: TComponent);
|
constructor TBufferPanel.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
@ -254,11 +255,14 @@ begin
|
|||||||
if (FMutex <> 0) then ReleaseMutex(FMutex);
|
if (FMutex <> 0) then ReleaseMutex(FMutex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBufferPanel.CopyBuffer(aDC : HDC; const aRect : TRect);
|
function TBufferPanel.CopyBuffer(aDC : HDC; const aRect : TRect) : boolean;
|
||||||
begin
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
if BeginBufferDraw then
|
if BeginBufferDraw then
|
||||||
begin
|
begin
|
||||||
if (FBuffer <> nil) and (aDC <> 0) then
|
Result := (FBuffer <> nil) and
|
||||||
|
(aDC <> 0) and
|
||||||
BitBlt(aDC, aRect.Left, aRect.Top, aRect.Right - aRect.Left, aRect.Bottom - aRect.Top,
|
BitBlt(aDC, aRect.Left, aRect.Top, aRect.Right - aRect.Left, aRect.Bottom - aRect.Top,
|
||||||
FBuffer.Canvas.Handle, aRect.Left, aRect.Top,
|
FBuffer.Canvas.Handle, aRect.Left, aRect.Top,
|
||||||
SrcCopy);
|
SrcCopy);
|
||||||
@ -285,38 +289,18 @@ begin
|
|||||||
Canvas.Rectangle(0, 0, Width, Height);
|
Canvas.Rectangle(0, 0, Width, Height);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
CopyBuffer(TempDC, TempPaintStruct.rcPaint);
|
if not(CopyBuffer(TempDC, TempPaintStruct.rcPaint)) then
|
||||||
|
begin
|
||||||
|
Canvas.Brush.Color := Color;
|
||||||
|
Canvas.Brush.Style := bsSolid;
|
||||||
|
Canvas.FillRect(rect(0, 0, Width, Height));
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
EndPaint(Handle, TempPaintStruct);
|
EndPaint(Handle, TempPaintStruct);
|
||||||
aMessage.Result := 1;
|
aMessage.Result := 1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBufferPanel.Resize;
|
|
||||||
begin
|
|
||||||
if BeginBufferDraw then
|
|
||||||
begin
|
|
||||||
if ((FBuffer = nil) or
|
|
||||||
(FBuffer.Width <> Width) or
|
|
||||||
(FBuffer.Height <> Height)) then
|
|
||||||
begin
|
|
||||||
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
|
||||||
|
|
||||||
FBuffer := TBitmap.Create;
|
|
||||||
FBuffer.PixelFormat := pf32bit;
|
|
||||||
FBuffer.HandleType := bmDIB;
|
|
||||||
FBuffer.Width := Width;
|
|
||||||
FBuffer.Height := Height;
|
|
||||||
|
|
||||||
FScanlineSize := FBuffer.Width * SizeOf(TRGBQuad);
|
|
||||||
end;
|
|
||||||
|
|
||||||
EndBufferDraw;
|
|
||||||
end;
|
|
||||||
|
|
||||||
inherited Resize;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TBufferPanel.WMEraseBkgnd(var aMessage : TWMEraseBkgnd);
|
procedure TBufferPanel.WMEraseBkgnd(var aMessage : TWMEraseBkgnd);
|
||||||
begin
|
begin
|
||||||
aMessage.Result := 1;
|
aMessage.Result := 1;
|
||||||
@ -351,4 +335,42 @@ begin
|
|||||||
if (FBuffer <> nil) then FBuffer.Canvas.Draw(x, y, aBitmap);
|
if (FBuffer <> nil) then FBuffer.Canvas.Draw(x, y, aBitmap);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TBufferPanel.UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
||||||
|
begin
|
||||||
|
if ((FBuffer = nil) or
|
||||||
|
(FBuffer.Width <> aWidth) or
|
||||||
|
(FBuffer.Height <> aHeight)) then
|
||||||
|
begin
|
||||||
|
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
||||||
|
|
||||||
|
FBuffer := TBitmap.Create;
|
||||||
|
FBuffer.PixelFormat := pf32bit;
|
||||||
|
FBuffer.HandleType := bmDIB;
|
||||||
|
FBuffer.Width := aWidth;
|
||||||
|
FBuffer.Height := aHeight;
|
||||||
|
FScanlineSize := FBuffer.Width * SizeOf(TRGBQuad);
|
||||||
|
Result := True;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TBufferPanel.BufferIsResized(aUseMutex : boolean) : boolean;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
|
if not(aUseMutex) or BeginBufferDraw then
|
||||||
|
begin
|
||||||
|
// CEF and Chromium use 'floor' to round the float values in Device <-> Logical unit conversions
|
||||||
|
// and Delphi uses MulDiv, which uses the bankers rounding, to resize the components in high DPI mode.
|
||||||
|
// This is the cause of slight differences in size between the buffer and the panel in some occasions.
|
||||||
|
|
||||||
|
Result := (FBuffer <> nil) and
|
||||||
|
(FBuffer.Width = LogicalToDevice(DeviceToLogical(Width, GlobalCEFApp.DeviceScaleFactor), GlobalCEFApp.DeviceScaleFactor)) and
|
||||||
|
(FBuffer.Height = LogicalToDevice(DeviceToLogical(Height, GlobalCEFApp.DeviceScaleFactor), GlobalCEFApp.DeviceScaleFactor));
|
||||||
|
|
||||||
|
if aUseMutex then EndBufferDraw;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -360,6 +360,7 @@ const
|
|||||||
CEF_DOONCLOSE = WM_APP + $A01;
|
CEF_DOONCLOSE = WM_APP + $A01;
|
||||||
CEF_STARTDRAGGING = WM_APP + $A02;
|
CEF_STARTDRAGGING = WM_APP + $A02;
|
||||||
CEF_AFTERCREATED = WM_APP + $A03;
|
CEF_AFTERCREATED = WM_APP + $A03;
|
||||||
|
CEF_PENDINGRESIZE = WM_APP + $A04;
|
||||||
|
|
||||||
CEF_USER_TIMER_MINIMUM = $0000000A;
|
CEF_USER_TIMER_MINIMUM = $0000000A;
|
||||||
CEF_USER_TIMER_MAXIMUM = $7FFFFFFF;
|
CEF_USER_TIMER_MAXIMUM = $7FFFFFFF;
|
||||||
@ -370,3 +371,4 @@ const
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user