1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-01-03 10:15:38 +02:00

Compatibility fixes in SimpleOSRBrowser demo for older Delphi versions

This commit is contained in:
Salvador Díaz Fau 2020-03-18 10:01:28 +01:00
parent a397f68a1a
commit 9962fecc4e
3 changed files with 44 additions and 17 deletions

View File

@ -33,7 +33,7 @@ object Form1: TForm1
Padding.Right = 5 Padding.Right = 5
Padding.Bottom = 5 Padding.Bottom = 5
TabOrder = 0 TabOrder = 0
object ComboBox1: TComboBox object AddressCb: TComboBox
Left = 5 Left = 5
Top = 5 Top = 5
Width = 907 Width = 907
@ -42,7 +42,7 @@ object Form1: TForm1
ItemIndex = 0 ItemIndex = 0
TabOrder = 0 TabOrder = 0
Text = 'https://www.google.com' Text = 'https://www.google.com'
OnEnter = ComboBox1Enter OnEnter = AddressCbEnter
Items.Strings = ( Items.Strings = (
'https://www.google.com' 'https://www.google.com'
'https://html5demos.com/drag' 'https://html5demos.com/drag'

View File

@ -63,7 +63,7 @@ type
NavControlPnl: TPanel; NavControlPnl: TPanel;
chrmosr: TChromium; chrmosr: TChromium;
AppEvents: TApplicationEvents; AppEvents: TApplicationEvents;
ComboBox1: TComboBox; AddressCb: TComboBox;
Panel2: TPanel; Panel2: TPanel;
GoBtn: TButton; GoBtn: TButton;
SnapshotBtn: TButton; SnapshotBtn: TButton;
@ -118,7 +118,7 @@ type
procedure SnapshotBtnEnter(Sender: TObject); procedure SnapshotBtnEnter(Sender: TObject);
procedure Timer1Timer(Sender: TObject); procedure Timer1Timer(Sender: TObject);
procedure ComboBox1Enter(Sender: TObject); procedure AddressCbEnter(Sender: TObject);
protected protected
FPopUpBitmap : TBitmap; FPopUpBitmap : TBitmap;
@ -145,9 +145,11 @@ type
procedure InitializeLastClick; procedure InitializeLastClick;
function CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean; function CancelPreviousClick(x, y : integer; var aCurrentTime : integer) : boolean;
function ArePointerEventsSupported : boolean; function ArePointerEventsSupported : boolean;
{$IFDEF DELPHI14_UP}
function HandlePenEvent(const aID : uint32; aMsg : cardinal) : boolean; function HandlePenEvent(const aID : uint32; aMsg : cardinal) : boolean;
function HandleTouchEvent(const aID : uint32; aMsg : cardinal) : boolean; function HandleTouchEvent(const aID : uint32; aMsg : cardinal) : boolean;
function HandlePointerEvent(var aMessage : TMessage) : boolean; function HandlePointerEvent(var aMessage : TMessage) : boolean;
{$ENDIF}
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;
@ -311,7 +313,7 @@ begin
TempMouseEvent.y := Msg.lParam shr 16; TempMouseEvent.y := Msg.lParam shr 16;
TempMouseEvent.modifiers := GetCefMouseModifiers(Msg.wParam); TempMouseEvent.modifiers := GetCefMouseModifiers(Msg.wParam);
DeviceToLogical(TempMouseEvent, GlobalCEFApp.DeviceScaleFactor); DeviceToLogical(TempMouseEvent, GlobalCEFApp.DeviceScaleFactor);
chrmosr.SendMouseWheelEvent(@TempMouseEvent, 0, int16(Msg.wParam shr 16)); chrmosr.SendMouseWheelEvent(@TempMouseEvent, 0, smallint(Msg.wParam shr 16));
end; end;
end; end;
end; end;
@ -323,7 +325,7 @@ begin
FPendingResize := False; FPendingResize := False;
FResizeCS.Release; FResizeCS.Release;
chrmosr.LoadURL(ComboBox1.Text); chrmosr.LoadURL(AddressCb.Text);
end; end;
procedure TForm1.GoBtnEnter(Sender: TObject); procedure TForm1.GoBtnEnter(Sender: TObject);
@ -580,7 +582,7 @@ begin
Result := True; Result := True;
end; end;
procedure TForm1.ComboBox1Enter(Sender: TObject); procedure TForm1.AddressCbEnter(Sender: TObject);
begin begin
chrmosr.SendFocusEvent(False); chrmosr.SendFocusEvent(False);
end; end;
@ -600,8 +602,8 @@ end;
function TForm1.GetButton(Button: TMouseButton): TCefMouseButtonType; function TForm1.GetButton(Button: TMouseButton): TCefMouseButtonType;
begin begin
case Button of case Button of
TMouseButton.mbRight : Result := MBT_RIGHT; mbRight : Result := MBT_RIGHT;
TMouseButton.mbMiddle : Result := MBT_MIDDLE; mbMiddle : Result := MBT_MIDDLE;
else Result := MBT_LEFT; else Result := MBT_LEFT;
end; end;
end; end;
@ -652,7 +654,6 @@ procedure TForm1.BrowserCreatedMsg(var aMessage : TMessage);
begin begin
Caption := 'Simple OSR Browser'; Caption := 'Simple OSR Browser';
NavControlPnl.Enabled := True; NavControlPnl.Enabled := True;
GoBtn.Click;
end; end;
procedure TForm1.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer); procedure TForm1.FormAfterMonitorDpiChanged(Sender: TObject; OldDPI, NewDPI: Integer);
@ -702,6 +703,8 @@ begin
Panel1.Transparent := TRANSPARENT_BROWSER; Panel1.Transparent := TRANSPARENT_BROWSER;
InitializeLastClick; InitializeLastClick;
chrmosr.DefaultURL := trim(AddressCb.Text);
end; end;
procedure TForm1.FormDestroy(Sender: TObject); procedure TForm1.FormDestroy(Sender: TObject);
@ -746,8 +749,10 @@ begin
// You can skip this if the user doesn't need an "Input Method Editor". // You can skip this if the user doesn't need an "Input Method Editor".
Panel1.CreateIMEHandler; Panel1.CreateIMEHandler;
{$IFDEF DELPHI14_UP}
if not(ArePointerEventsSupported) then if not(ArePointerEventsSupported) then
RegisterTouchWindow(Panel1.Handle, 0); RegisterTouchWindow(Panel1.Handle, 0);
{$ENDIF}
if chrmosr.CreateBrowser(nil, '') then if chrmosr.CreateBrowser(nil, '') then
chrmosr.InitializeDragAndDrop(Panel1) chrmosr.InitializeDragAndDrop(Panel1)
@ -762,6 +767,7 @@ begin
end; end;
procedure TForm1.Panel1CustomTouch(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean); procedure TForm1.Panel1CustomTouch(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
{$IFDEF DELPHI14_UP}
var var
TempTouchEvent : TCefTouchEvent; TempTouchEvent : TCefTouchEvent;
TempHTOUCHINPUT : HTOUCHINPUT; TempHTOUCHINPUT : HTOUCHINPUT;
@ -771,7 +777,9 @@ var
TempPoint : TPoint; TempPoint : TPoint;
TempLParam : LPARAM; TempLParam : LPARAM;
TempResult : LRESULT; TempResult : LRESULT;
{$ENDIF}
begin begin
{$IFDEF DELPHI14_UP}
if not(Panel1.Focused) or (GlobalCEFApp = nil) then exit; if not(Panel1.Focused) or (GlobalCEFApp = nil) then exit;
TempNumPoints := LOWORD(aMessage.wParam); TempNumPoints := LOWORD(aMessage.wParam);
@ -833,6 +841,7 @@ begin
end; end;
SetLength(TempTouchInputs, 0); SetLength(TempTouchInputs, 0);
{$ENDIF}
end; end;
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
@ -840,7 +849,7 @@ var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
TempTime : integer; TempTime : integer;
begin begin
if (GlobalCEFApp <> nil) and (chrmosr <> nil) and not(ssTouch in Shift) then if (GlobalCEFApp <> nil) and (chrmosr <> nil) {$IFDEF DELPHI14_UP}and not(ssTouch in Shift){$ENDIF} then
begin begin
Panel1.SetFocus; Panel1.SetFocus;
@ -890,7 +899,7 @@ var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
TempTime : integer; TempTime : integer;
begin begin
if (GlobalCEFApp <> nil) and (chrmosr <> nil) and not(ssTouch in Shift) then if (GlobalCEFApp <> nil) and (chrmosr <> nil) {$IFDEF DELPHI14_UP}and not(ssTouch in Shift){$ENDIF} then
begin begin
if CancelPreviousClick(x, y, TempTime) then InitializeLastClick; if CancelPreviousClick(x, y, TempTime) then InitializeLastClick;
@ -906,7 +915,7 @@ procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TSh
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
begin begin
if (GlobalCEFApp <> nil) and (chrmosr <> nil) and not(ssTouch in Shift) then if (GlobalCEFApp <> nil) and (chrmosr <> nil) {$IFDEF DELPHI14_UP}and not(ssTouch in Shift){$ENDIF} then
begin begin
TempEvent.x := X; TempEvent.x := X;
TempEvent.y := Y; TempEvent.y := Y;
@ -933,28 +942,41 @@ end;
procedure TForm1.Panel1PointerDown(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean); procedure TForm1.Panel1PointerDown(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
begin begin
{$IFDEF DELPHI14_UP}
aHandled := Panel1.Focused and aHandled := Panel1.Focused and
(GlobalCEFApp <> nil) and (GlobalCEFApp <> nil) and
ArePointerEventsSupported and ArePointerEventsSupported and
HandlePointerEvent(aMessage); HandlePointerEvent(aMessage);
{$ELSE}
aHandled := False;
{$ENDIF}
end; end;
procedure TForm1.Panel1PointerUp(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean); procedure TForm1.Panel1PointerUp(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
begin begin
{$IFDEF DELPHI14_UP}
aHandled := Panel1.Focused and aHandled := Panel1.Focused and
(GlobalCEFApp <> nil) and (GlobalCEFApp <> nil) and
ArePointerEventsSupported and ArePointerEventsSupported and
HandlePointerEvent(aMessage); HandlePointerEvent(aMessage);
{$ELSE}
aHandled := False;
{$ENDIF}
end; end;
procedure TForm1.Panel1PointerUpdate(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean); procedure TForm1.Panel1PointerUpdate(Sender: TObject; var aMessage: TMessage; var aHandled: Boolean);
begin begin
{$IFDEF DELPHI14_UP}
aHandled := Panel1.Focused and aHandled := Panel1.Focused and
(GlobalCEFApp <> nil) and (GlobalCEFApp <> nil) and
ArePointerEventsSupported and ArePointerEventsSupported and
HandlePointerEvent(aMessage); HandlePointerEvent(aMessage);
{$ELSE}
aHandled := False;
{$ENDIF}
end; end;
{$IFDEF DELPHI14_UP}
function TForm1.HandlePointerEvent(var aMessage : TMessage) : boolean; function TForm1.HandlePointerEvent(var aMessage : TMessage) : boolean;
const const
PT_TOUCH = 2; PT_TOUCH = 2;
@ -1078,6 +1100,7 @@ begin
chrmosr.SendTouchEvent(@TempTouchEvent); chrmosr.SendTouchEvent(@TempTouchEvent);
end; end;
{$ENDIF}
procedure TForm1.Panel1Resize(Sender: TObject); procedure TForm1.Panel1Resize(Sender: TObject);
begin begin
@ -1144,10 +1167,14 @@ end;
function TForm1.ArePointerEventsSupported : boolean; function TForm1.ArePointerEventsSupported : boolean;
begin begin
{$IFDEF DELPHI14_UP}
Result := FAtLeastWin8 and Result := FAtLeastWin8 and
(@GetPointerType <> nil) and (@GetPointerType <> nil) and
(@GetPointerTouchInfo <> nil) and (@GetPointerTouchInfo <> nil) and
(@GetPointerPenInfo <> nil); (@GetPointerPenInfo <> nil);
{$ELSE}
Result := False;
{$ENDIF}
end; end;
procedure TForm1.Panel1Enter(Sender: TObject); procedure TForm1.Panel1Enter(Sender: TObject);

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [ "UpdateLazPackages" : [
{ {
"ForceNotify" : true, "ForceNotify" : true,
"InternalVersion" : 107, "InternalVersion" : 108,
"Name" : "cef4delphi_lazarus.lpk", "Name" : "cef4delphi_lazarus.lpk",
"Version" : "80.0.8.0" "Version" : "80.0.8.0"
} }