From 05d3f02c8e69f06debd8a117a43de9d90b14d1bf Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 19 Mar 2021 21:24:56 +0100 Subject: [PATCH 1/4] Added NSPrincipalClass for Lazarus 2.1 --- demos/Lazarus_Mac/ExternalPumpBrowser/ExternalPumpBrowser.lpi | 1 + demos/Lazarus_any_OS/BrowserWindow/BrowserWindow.lpi | 1 + demos/Lazarus_any_OS/BrowserWindowDom/BrowserWindowDom.lpi | 1 + demos/Lazarus_any_OS/BrowserWindowEx/BrowserWindowEx.lpi | 1 + demos/Lazarus_any_OS/BrowserWindowOsrDom/BrowserWindowOsrDom.lpi | 1 + demos/Lazarus_any_OS/ExternalPumpBrowser/ExternalPumpBrowser.lpi | 1 + 6 files changed, 6 insertions(+) diff --git a/demos/Lazarus_Mac/ExternalPumpBrowser/ExternalPumpBrowser.lpi b/demos/Lazarus_Mac/ExternalPumpBrowser/ExternalPumpBrowser.lpi index a72ab281..4d0bf509 100644 --- a/demos/Lazarus_Mac/ExternalPumpBrowser/ExternalPumpBrowser.lpi +++ b/demos/Lazarus_Mac/ExternalPumpBrowser/ExternalPumpBrowser.lpi @@ -9,6 +9,7 @@ <Scaled Value="True"/> + <NSPrincipalClass Value="TCrCocoaApplication"/> <ResourceType Value="res"/> <UseXPManifest Value="True"/> <XPManifest> diff --git a/demos/Lazarus_any_OS/BrowserWindow/BrowserWindow.lpi b/demos/Lazarus_any_OS/BrowserWindow/BrowserWindow.lpi index fb1335c4..8d1dc50c 100644 --- a/demos/Lazarus_any_OS/BrowserWindow/BrowserWindow.lpi +++ b/demos/Lazarus_any_OS/BrowserWindow/BrowserWindow.lpi @@ -9,6 +9,7 @@ <SessionStorage Value="InProjectDir"/> <Title Value="BrowserWindow"/> <Scaled Value="True"/> + <NSPrincipalClass Value="TCrCocoaApplication"/> <ResourceType Value="res"/> <UseXPManifest Value="True"/> <XPManifest> diff --git a/demos/Lazarus_any_OS/BrowserWindowDom/BrowserWindowDom.lpi b/demos/Lazarus_any_OS/BrowserWindowDom/BrowserWindowDom.lpi index 3ec9b24d..260179ce 100644 --- a/demos/Lazarus_any_OS/BrowserWindowDom/BrowserWindowDom.lpi +++ b/demos/Lazarus_any_OS/BrowserWindowDom/BrowserWindowDom.lpi @@ -9,6 +9,7 @@ <SessionStorage Value="InProjectDir"/> <Title Value="BrowserWindowDom"/> <Scaled Value="True"/> + <NSPrincipalClass Value="TCrCocoaApplication"/> <ResourceType Value="res"/> <UseXPManifest Value="True"/> <XPManifest> diff --git a/demos/Lazarus_any_OS/BrowserWindowEx/BrowserWindowEx.lpi b/demos/Lazarus_any_OS/BrowserWindowEx/BrowserWindowEx.lpi index cbecfe3f..167cffe2 100644 --- a/demos/Lazarus_any_OS/BrowserWindowEx/BrowserWindowEx.lpi +++ b/demos/Lazarus_any_OS/BrowserWindowEx/BrowserWindowEx.lpi @@ -9,6 +9,7 @@ <SessionStorage Value="InProjectDir"/> <Title Value="BrowserWindowEx"/> <Scaled Value="True"/> + <NSPrincipalClass Value="TCrCocoaApplication"/> <ResourceType Value="res"/> <UseXPManifest Value="True"/> <XPManifest> diff --git a/demos/Lazarus_any_OS/BrowserWindowOsrDom/BrowserWindowOsrDom.lpi b/demos/Lazarus_any_OS/BrowserWindowOsrDom/BrowserWindowOsrDom.lpi index b7441b66..0c35bb14 100644 --- a/demos/Lazarus_any_OS/BrowserWindowOsrDom/BrowserWindowOsrDom.lpi +++ b/demos/Lazarus_any_OS/BrowserWindowOsrDom/BrowserWindowOsrDom.lpi @@ -9,6 +9,7 @@ <SessionStorage Value="InProjectDir"/> <Title Value="BrowserWindowOsrDom"/> <Scaled Value="True"/> + <NSPrincipalClass Value="TCrCocoaApplication"/> <ResourceType Value="res"/> <UseXPManifest Value="True"/> <XPManifest> diff --git a/demos/Lazarus_any_OS/ExternalPumpBrowser/ExternalPumpBrowser.lpi b/demos/Lazarus_any_OS/ExternalPumpBrowser/ExternalPumpBrowser.lpi index 9ab148fa..712efad1 100644 --- a/demos/Lazarus_any_OS/ExternalPumpBrowser/ExternalPumpBrowser.lpi +++ b/demos/Lazarus_any_OS/ExternalPumpBrowser/ExternalPumpBrowser.lpi @@ -10,6 +10,7 @@ <MainUnit Value="0"/> <Title Value="External Pump Browser"/> <Scaled Value="True"/> + <NSPrincipalClass Value="TCrCocoaApplication"/> <ResourceType Value="res"/> <UseXPManifest Value="True"/> <XPManifest> From c45c130b335390d0051a3401b6665a26c9994bbd Mon Sep 17 00:00:00 2001 From: martin <martin@m> Date: Sat, 20 Mar 2021 02:14:13 +0100 Subject: [PATCH 2/4] Expose additional event properties --- packages/cef4delphi_lazarus.lpk | 16 ++-- source/uCEFLazarusOsrBrowserWindow.pas | 100 +++++++++++++++++++++---- source/uceflazarusbrowserwindow.pas | 68 ++++++++++++----- 3 files changed, 146 insertions(+), 38 deletions(-) diff --git a/packages/cef4delphi_lazarus.lpk b/packages/cef4delphi_lazarus.lpk index 5af74a7a..c46187eb 100644 --- a/packages/cef4delphi_lazarus.lpk +++ b/packages/cef4delphi_lazarus.lpk @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <CONFIG> - <Package Version="4"> + <Package Version="5"> <PathDelim Value="\"/> <Name Value="CEF4Delphi_Lazarus"/> <Type Value="RunAndDesignTime"/> @@ -850,19 +850,23 @@ <UnitName Value="uCEFLazarusOsrBrowserWindow"/> </Item202> </Files> - <RequiredPkgs Count="4"> + <CompatibilityMode Value="True"/> + <RequiredPkgs Count="5"> <Item1> - <PackageName Value="dcpcrypt"/> + <PackageName Value="IDEIntf"/> </Item1> <Item2> - <PackageName Value="LCL"/> + <PackageName Value="dcpcrypt"/> </Item2> <Item3> - <PackageName Value="LCLBase"/> + <PackageName Value="LCL"/> </Item3> <Item4> - <PackageName Value="FCL"/> + <PackageName Value="LCLBase"/> </Item4> + <Item5> + <PackageName Value="FCL"/> + </Item5> </RequiredPkgs> <UsageOptions> <UnitPath Value="$(PkgOutDir)"/> diff --git a/source/uCEFLazarusOsrBrowserWindow.pas b/source/uCEFLazarusOsrBrowserWindow.pas index bbe4ffc3..79476f86 100644 --- a/source/uCEFLazarusOsrBrowserWindow.pas +++ b/source/uCEFLazarusOsrBrowserWindow.pas @@ -44,21 +44,33 @@ interface uses {$IFDEF FPC} - LResources, + LResources, PropEdits, {$ENDIF} uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium, uCEFLinkedWinControlBase, uCEFLazApplication, uCEFBufferPanel, uCEFLazarusBrowserWindow, uCEFBitmapBitBuffer, uCEFMiscFunctions, - uCEFConstants, Forms, ExtCtrls, LCLType, Graphics, Controls, syncobjs, - LazLogger, Classes, sysutils, math; + uCEFConstants, uCEFChromiumEvents, Forms, ExtCtrls, LCLType, Graphics, + Controls, syncobjs, LazLogger, Classes, sysutils, math; type TBrowserMouseEvent = procedure(Sender: TObject; Button: TMouseButton; - Shift: TShiftState; X, Y: Integer; - var AHandled: Boolean) of Object; + Shift: TShiftState; X, Y: Integer; + var AHandled: Boolean) of Object; + TBrowserMouseMoveEvent = procedure(Sender: TObject; Shift: TShiftState; + X, Y: Integer; + var AHandled: Boolean) of Object; + TBrowserMouseWheelEvent = procedure(Sender: TObject; Shift: TShiftState; + WheelDelta: Integer; MousePos: TPoint; + var AHandled: Boolean) of Object; + TBrowserKeyEvent = procedure(Sender: TObject; var Key: Word; Shift: TShiftState; var AHandled: Boolean) of Object; + //TBrowserKeyPressEvent = procedure(Sender: TObject; var Key: char; var AHandled: Boolean) of Object; + TBrowserUTF8KeyPressEvent = procedure(Sender: TObject; var UTF8Key: TUTF8Char; var AHandled: Boolean) of Object; + TLazOsrChromium = class(TLazChromium) + end; + { TLazarusOsrBrowserWindow } TLazarusOsrBrowserWindow = class(TBufferPanel) @@ -114,17 +126,22 @@ type AHeight: Integer); private - FChromium : TLazChromium; + FChromium : TLazOsrChromium; FOnBrowserClosed : TNotifyEvent; FOnBrowserCreated : TNotifyEvent; + FOnKeyDown: TBrowserKeyEvent; + FOnKeyUp: TBrowserKeyEvent; FOnMouseDown: TBrowserMouseEvent; + FOnMouseMove: TBrowserMouseMoveEvent; FOnMouseUp: TBrowserMouseEvent; + FOnMouseWheel: TBrowserMouseWheelEvent; + FOnUtf8KeyPress: TBrowserUTF8KeyPressEvent; procedure DoCreateBrowserAfterContext(Sender: TObject); protected - function GetChromium: TLazChromium; + function GetChromium: TLazOsrChromium; function getModifiers(Shift: TShiftState): TCefEventFlags; function getKeyModifiers(Shift: TShiftState): TCefEventFlags; function GetButton(Button: TMouseButton): TCefMouseButtonType; @@ -166,13 +183,18 @@ type procedure LoadURL(aURL: ustring); // published - property Chromium : TLazChromium read GetChromium; + property Chromium : TLazOsrChromium read GetChromium; property OnBrowserCreated : TNotifyEvent read FOnBrowserCreated write FOnBrowserCreated; property OnBrowserClosed : TNotifyEvent read FOnBrowserClosed write FOnBrowserClosed; - property OnMouseDown: TBrowserMouseEvent read FOnMouseDown write FOnMouseDown; - property OnMouseUp: TBrowserMouseEvent read FOnMouseUp write FOnMouseUp; + property OnMouseDown: TBrowserMouseEvent read FOnMouseDown write FOnMouseDown; + property OnMouseUp: TBrowserMouseEvent read FOnMouseUp write FOnMouseUp; + property OnMouseMove: TBrowserMouseMoveEvent read FOnMouseMove write FOnMouseMove; + property OnMouseWheel: TBrowserMouseWheelEvent read FOnMouseWheel write FOnMouseWheel; + property OnKeyDown: TBrowserKeyEvent read FOnKeyDown write FOnKeyDown; + property OnKeyUp: TBrowserKeyEvent read FOnKeyUp write FOnKeyUp; + property OnUtf8KeyPress: TBrowserUTF8KeyPressEvent read FOnUtf8KeyPress write FOnUtf8KeyPress; end; {$IFDEF FPC} @@ -498,7 +520,7 @@ begin end; end; -function TLazarusOsrBrowserWindow.GetChromium: TLazChromium; +function TLazarusOsrBrowserWindow.GetChromium: TLazOsrChromium; begin Result := FChromium; end; @@ -649,8 +671,14 @@ end; procedure TLazarusOsrBrowserWindow.MouseMove(Shift: TShiftState; X, Y: Integer); var TempEvent : TCefMouseEvent; + IsHandled: Boolean; begin inherited MouseMove(Shift, X, Y); + IsHandled := False; + if FOnMouseMove <> nil then + FOnMouseMove(Self, Shift, X, Y, IsHandled); + if IsHandled then + exit; TempEvent.x := x; TempEvent.y := y; @@ -699,8 +727,14 @@ function TLazarusOsrBrowserWindow.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; var TempEvent : TCefMouseEvent; + IsHandled: Boolean; begin Result := inherited DoMouseWheel(Shift, WheelDelta, MousePos); + IsHandled := False; + if FOnMouseWheel <> nil then + FOnMouseWheel(Self, Shift, WheelDelta, MousePos, IsHandled); + if IsHandled then + exit; TempEvent.x := MousePos.x; TempEvent.y := MousePos.y; @@ -717,7 +751,16 @@ end; procedure TLazarusOsrBrowserWindow.KeyDown(var Key: Word; Shift: TShiftState); var TempKeyEvent : TCefKeyEvent; + IsHandled: Boolean; begin + IsHandled := False; + if FOnKeyDown <> nil then + FOnKeyDown(Self, Key, Shift, IsHandled); + if IsHandled then begin + inherited KeyDown(Key, Shift); + exit; + end; + FLastKeyDown := Key; if (Key <> 0) and (Chromium <> nil) then begin @@ -742,7 +785,16 @@ procedure TLazarusOsrBrowserWindow.UTF8KeyPress(var UTF8Key: TUTF8Char); var TempKeyEvent : TCefKeyEvent; TempString : UnicodeString; + IsHandled: Boolean; begin + IsHandled := False; + if FOnUtf8KeyPress <> nil then + FOnUtf8KeyPress(Self, UTF8Key, IsHandled); + if IsHandled then begin + inherited UTF8KeyPress(UTF8Key); + exit; + end; + if Focused then begin TempString := UTF8Decode(UTF8Key); @@ -773,7 +825,16 @@ end; procedure TLazarusOsrBrowserWindow.KeyUp(var Key: Word; Shift: TShiftState); var TempKeyEvent : TCefKeyEvent; + IsHandled: Boolean; begin + IsHandled := False; + if FOnKeyUp <> nil then + FOnKeyUp(Self, Key, Shift, IsHandled); + if IsHandled then begin + inherited KeyUp(Key, Shift); + exit; + end; + if (Key <> 0) and (Chromium <> nil) then begin TempKeyEvent.kind := KEYEVENT_KEYUP; @@ -843,9 +904,9 @@ begin FSelectedRange.from := 0; FSelectedRange.to_ := 0; - FChromium := TLazChromium.Create(Self); - FChromium.OnBrowserClosed := {$IFDEF FPC}@{$ENDIF}DoOnClosed; - FChromium.OnBrowserCreated := {$IFDEF FPC}@{$ENDIF}DoOnCreated; + FChromium := TLazOsrChromium.Create(Self); + FChromium.InternalOnBrowserClosed := {$IFDEF FPC}@{$ENDIF}DoOnClosed; + FChromium.InternalOnBrowserCreated := {$IFDEF FPC}@{$ENDIF}DoOnCreated; FChromium.OnPaint := {$IFDEF FPC}@{$ENDIF}DoChromiumPaint; FChromium.OnGetViewRect := {$IFDEF FPC}@{$ENDIF}DoGetChromiumViewRect; @@ -910,6 +971,17 @@ procedure Register; begin // {$I res/tlazarusosrbrowserwindow.lrs} RegisterComponents('Chromium', [TLazarusOsrBrowserWindow]); + RegisterPropertyEditor(TypeInfo(TOnClose), TLazOsrChromium,'OnClose',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnPaint), TLazOsrChromium,'OnPaint',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnGetViewRect), TLazOsrChromium,'OnGetViewRect',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnCursorChange), TLazOsrChromium,'OnCursorChange',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnGetScreenPoint), TLazOsrChromium,'OnGetScreenPoint',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnGetScreenInfo), TLazOsrChromium,'OnGetScreenInfo',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnPopupShow), TLazOsrChromium,'OnPopupShow',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnPopupSize), TLazOsrChromium,'OnPopupSize',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnTooltip), TLazOsrChromium,'OnTooltip',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnBeforePopup), TLazOsrChromium,'OnBeforePopup',THiddenPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnIMECompositionRangeChanged), TLazOsrChromium,'OnIMECompositionRangeChanged',THiddenPropertyEditor); end; {$ENDIF} diff --git a/source/uceflazarusbrowserwindow.pas b/source/uceflazarusbrowserwindow.pas index fa68d1ac..f697e74f 100644 --- a/source/uceflazarusbrowserwindow.pas +++ b/source/uceflazarusbrowserwindow.pas @@ -44,11 +44,11 @@ interface uses {$IFDEF FPC} - LResources, + LResources, PropEdits, {$ENDIF} uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium, - uCEFLinkedWinControlBase, uCEFLazApplication, uCEFBrowserViewComponent, Forms, - ExtCtrls, Controls, Classes, sysutils; + uCEFLinkedWinControlBase, uCEFLazApplication, uCEFBrowserViewComponent, + uCEFChromiumEvents, Forms, ExtCtrls, Controls, Classes, sysutils; type @@ -63,18 +63,22 @@ type private type TLazChromiumState = (csNoBrowser, csCreatingBrowser, csHasBrowser, csClosingBrowser, csCloseAfterCreate); private - FState : TLazChromiumState; - FOnBrowserClosed : TNotifyEvent; - FOnBrowserCreated : TNotifyEvent; + FInternalOnGotFocus: TOnGotFocus; + FState : TLazChromiumState; + FInternalOnBrowserClosed : TNotifyEvent; + FInternalOnBrowserCreated : TNotifyEvent; FLoadUrl, FFrameName : ustring; function GetIsClosing: Boolean; + procedure SetInternalOnClose(AValue: TOnClose); protected function GetHasBrowser : boolean; reintroduce; procedure doOnBeforeClose(const ABrowser: ICefBrowser); override; procedure doOnAfterCreated(const ABrowser: ICefBrowser); override; + procedure doOnGotFocus(const Abrowser: ICefBrowser); override; + function MustCreateFocusHandler: boolean; override; procedure DoCreated(Data: PtrInt); procedure DoOnClosed(Data: PtrInt); @@ -108,8 +112,9 @@ type - OnBrowserCreated: the parent event may be called when procedure Initialized is still false. - OnBrowserCreated: may not be called, if the CloseBrowser has already been called *) - property OnBrowserCreated : TNotifyEvent read FOnBrowserCreated write FOnBrowserCreated; - property OnBrowserClosed : TNotifyEvent read FOnBrowserClosed write FOnBrowserClosed; + property InternalOnBrowserCreated : TNotifyEvent read FInternalOnBrowserCreated write FInternalOnBrowserCreated; + property InternalOnBrowserClosed : TNotifyEvent read FInternalOnBrowserClosed write FInternalOnBrowserClosed; + property InternalOnGotFocus : TOnGotFocus read FInternalOnGotFocus write FInternalOnGotFocus; end; TLazarusBrowserWindow = class; @@ -148,6 +153,7 @@ type *) procedure WaitForBrowserClosed; + published property Chromium: TLazChromium read FChromium; end; @@ -167,6 +173,7 @@ type procedure DoCreateBrowser(Sender: TObject); procedure DoCreateBrowserAfterContext(Sender: TObject); + function GetLazChromium: TLazChromium; protected function GetChromium: TChromium; override; procedure DestroyHandle; override; @@ -188,7 +195,7 @@ type procedure LoadURL(aURL: ustring); published - property Chromium; // : TChromium read GetChromium; + property Chromium: TLazChromium read GetLazChromium; property OnBrowserCreated : TNotifyEvent read FOnBrowserCreated write FOnBrowserCreated; (* OnBrowserClosed will not be called, if the TLazarusBrowserWindow is @@ -210,6 +217,11 @@ begin Result := FState in [csCloseAfterCreate, csClosingBrowser]; end; +procedure TLazChromium.SetInternalOnClose(AValue: TOnClose); +begin + inherited OnClose := AValue; +end; + function TLazChromium.GetHasBrowser: boolean; begin Result := (FState <> csNoBrowser) or (inherited GetHasBrowser); @@ -233,6 +245,19 @@ begin Application.QueueAsyncCall(@DoCreated, 0); end; +procedure TLazChromium.doOnGotFocus(const Abrowser: ICefBrowser); +begin + inherited doOnGotFocus(Abrowser); + if Assigned(FInternalOnGotFocus) then + FInternalOnGotFocus(Self, Abrowser); +end; + +function TLazChromium.MustCreateFocusHandler: boolean; +begin + Result := assigned(FInternalOnGotFocus) or + inherited MustCreateFocusHandler; +end; + procedure TLazChromium.DoCreated(Data: PtrInt); var u, f: ustring; @@ -247,8 +272,8 @@ begin LoadURL(u, f); end; - if (FOnBrowserCreated <> nil) then - FOnBrowserCreated(Self); + if (FInternalOnBrowserCreated <> nil) then + FInternalOnBrowserCreated(Self); end; csCloseAfterCreate: begin FState := csHasBrowser; @@ -259,8 +284,8 @@ end; procedure TLazChromium.DoOnClosed(Data: PtrInt); begin - if (FOnBrowserClosed <> nil) then - FOnBrowserClosed(Self); + if (FInternalOnBrowserClosed <> nil) then + FInternalOnBrowserClosed(Self); end; constructor TLazChromium.Create(AOwner: TComponent); @@ -400,15 +425,15 @@ begin FBrowserWindow := AOwner; FWrapperState := wsNone; + FChromium := TLazChromium.Create(nil); if not(csDesigning in AOwner.ComponentState) then begin - FChromium := TLazChromium.Create(nil); - FChromium.OnClose := {$IFDEF FPC}@{$ENDIF}BrowserThread_OnClose; - FChromium.OnBrowserClosed := {$IFDEF FPC}@{$ENDIF}DoOnBeforeClose; - FChromium.OnBrowserCreated := {$IFDEF FPC}@{$ENDIF}DoOnAfterCreated; + FChromium.OnClose := {$IFDEF FPC}@{$ENDIF}BrowserThread_OnClose; + FChromium.InternalOnBrowserClosed := {$IFDEF FPC}@{$ENDIF}DoOnBeforeClose; + FChromium.InternalOnBrowserCreated := {$IFDEF FPC}@{$ENDIF}DoOnAfterCreated; {$IFDEF LINUX} // This is a workaround for the CEF issue #2026. Read below for more info. - FChromium.OnGotFocus := {$IFDEF FPC}@{$ENDIF}BrowserThread_OnGotFocus; + FChromium.InternalOnGotFocus := {$IFDEF FPC}@{$ENDIF}BrowserThread_OnGotFocus; {$ENDIF} end; @@ -518,6 +543,11 @@ begin {$ENDIF} end; +function TLazarusBrowserWindow.GetLazChromium: TLazChromium; +begin + Result := FChromiumWrapper.Chromium; +end; + function TLazarusBrowserWindow.GetChromium: TChromium; begin Result := FChromiumWrapper.FChromium; @@ -643,6 +673,8 @@ procedure Register; begin {$I res/tlazarusbrowserwindow.lrs} RegisterComponents('Chromium', [TLazarusBrowserWindow]); + RegisterPropertyEditor(ClassTypeInfo(TLazChromium), nil,'',TClassPropertyEditor); + RegisterPropertyEditor(TypeInfo(TOnClose), TLazChromium, 'OnClose', THiddenPropertyEditor); end; {$ENDIF} From 9346acaaa096aa0c053618fe07418fc945223dc9 Mon Sep 17 00:00:00 2001 From: martin <martin@m> Date: Sat, 20 Mar 2021 05:25:18 +0100 Subject: [PATCH 3/4] MacOS: Get cursor keys to work under OSR --- source/uCEFLazarusOsrBrowserWindow.pas | 7 +++++++ source/uceflazaruscocoa.pas | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source/uCEFLazarusOsrBrowserWindow.pas b/source/uCEFLazarusOsrBrowserWindow.pas index 79476f86..d30dc00b 100644 --- a/source/uCEFLazarusOsrBrowserWindow.pas +++ b/source/uCEFLazarusOsrBrowserWindow.pas @@ -43,6 +43,7 @@ unit uCEFLazarusOsrBrowserWindow; interface uses + uCEFLazarusCocoa, {$IFDEF FPC} LResources, PropEdits, {$ENDIF} @@ -533,6 +534,7 @@ begin if (ssShift in Shift) then Result := Result or EVENTFLAG_SHIFT_DOWN; if (ssAlt in Shift) then Result := Result or EVENTFLAG_ALT_DOWN; if (ssCtrl in Shift) then Result := Result or EVENTFLAG_CONTROL_DOWN; + if (ssMeta in Shift) then Result := Result or EVENTFLAG_COMMAND_DOWN; if (ssLeft in Shift) then Result := Result or EVENTFLAG_LEFT_MOUSE_BUTTON; if (ssRight in Shift) then Result := Result or EVENTFLAG_RIGHT_MOUSE_BUTTON; if (ssMiddle in Shift) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON; @@ -545,6 +547,7 @@ begin if (ssShift in Shift) then Result := Result or EVENTFLAG_SHIFT_DOWN; if (ssAlt in Shift) then Result := Result or EVENTFLAG_ALT_DOWN; if (ssCtrl in Shift) then Result := Result or EVENTFLAG_CONTROL_DOWN; + if (ssMeta in Shift) then Result := Result or EVENTFLAG_COMMAND_DOWN; if (ssNum in Shift) then Result := Result or EVENTFLAG_NUM_LOCK_ON; if (ssCaps in Shift) then Result := Result or EVENTFLAG_CAPS_LOCK_ON; end; @@ -767,7 +770,11 @@ begin TempKeyEvent.kind := KEYEVENT_RAWKEYDOWN; TempKeyEvent.modifiers := getModifiers(Shift); TempKeyEvent.windows_key_code := Key; + {$IFDEF DARWIN} // $IFDEF MACOSX + TempKeyEvent.native_key_code := LastMacOsKeyDownCode; + {$ELSE} TempKeyEvent.native_key_code := 0; + {$ENDIF} TempKeyEvent.is_system_key := ord(False); TempKeyEvent.character := #0; TempKeyEvent.unmodified_character := #0; diff --git a/source/uceflazaruscocoa.pas b/source/uceflazaruscocoa.pas index 8a938d24..a5f88fb2 100644 --- a/source/uceflazaruscocoa.pas +++ b/source/uceflazaruscocoa.pas @@ -31,7 +31,7 @@ uses {$IFDEF DARWIN} // $IFDEF MACOSX CocoaAll, CocoaInt, Cocoa_Extra, {$ENDIF} - Classes, SysUtils; + Classes, SysUtils, ctypes; {$IFDEF DARWIN} // $IFDEF MACOSX type @@ -56,6 +56,7 @@ type procedure AddCrDelegate; +var LastMacOsKeyDownCode: cushort; {$ENDIF} implementation @@ -156,7 +157,12 @@ var begin CurrentHandling:=isHandlingSendEvent; setHandlingSendEvent(true); + if (theEvent.type_ = NSKeyDown) + then begin + LastMacOsKeyDownCode := theEvent.keyCode; + end; inherited; + LastMacOsKeyDownCode:=0; setHandlingSendEvent(CurrentHandling); end; From 9766f0e17560c8901f493a8cbba4e4465074df09 Mon Sep 17 00:00:00 2001 From: martin <martin@m> Date: Sat, 20 Mar 2021 05:44:04 +0100 Subject: [PATCH 4/4] Readme and known restrictions --- .../BrowserWindowOsrDom/README.LIMITATIONS.txt | 1 + demos/Lazarus_any_OS/BrowserWindowOsrDom/README.txt | 4 ++-- source/uCEFLazarusOsrBrowserWindow.pas | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 demos/Lazarus_any_OS/BrowserWindowOsrDom/README.LIMITATIONS.txt diff --git a/demos/Lazarus_any_OS/BrowserWindowOsrDom/README.LIMITATIONS.txt b/demos/Lazarus_any_OS/BrowserWindowOsrDom/README.LIMITATIONS.txt new file mode 100644 index 00000000..53ac90d2 --- /dev/null +++ b/demos/Lazarus_any_OS/BrowserWindowOsrDom/README.LIMITATIONS.txt @@ -0,0 +1 @@ +Keyboard support on MacOS is known to be incomplete. diff --git a/demos/Lazarus_any_OS/BrowserWindowOsrDom/README.txt b/demos/Lazarus_any_OS/BrowserWindowOsrDom/README.txt index 38409acc..c15f3aef 100644 --- a/demos/Lazarus_any_OS/BrowserWindowOsrDom/README.txt +++ b/demos/Lazarus_any_OS/BrowserWindowOsrDom/README.txt @@ -1,9 +1,9 @@ -BrowserWindow +BrowserWindowOSR # ABOUT This example uses - TLazarusBrowserWindow + TLazarusBrowserWindowOSR Examining DOM TCEFWorkScheduler feeds the CEF messageloop by calling DoMessageLoopWork(). On Mac this is currently the only way to run the CEF messageloop. diff --git a/source/uCEFLazarusOsrBrowserWindow.pas b/source/uCEFLazarusOsrBrowserWindow.pas index d30dc00b..bdcf7b9f 100644 --- a/source/uCEFLazarusOsrBrowserWindow.pas +++ b/source/uCEFLazarusOsrBrowserWindow.pas @@ -35,6 +35,15 @@ * *) +(* + + === State of Implementation === + + On MacOS the keyboard support is currently incomplete + + +*) + unit uCEFLazarusOsrBrowserWindow; {$mode objfpc}{$H+}