1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-04-17 06:57:13 +02:00

Extracted base-class for TCefWindow with Chromium / Move WndProc

This commit is contained in:
martin 2021-02-23 17:37:10 +01:00
parent ff9d2a39a8
commit c7fba0eb39
3 changed files with 50 additions and 75 deletions

View File

@ -69,11 +69,15 @@ type
TCEFLinkedWinControlBase = class(TCEFWinControl)
protected
function GetChromium: TChromium; virtual; abstract;
function GetUseSetFocus: Boolean; virtual;
{$IFDEF FPC}
procedure SetVisible(Value: Boolean); override;
{$ENDIF}
function GetChildWindowHandle : {$IFNDEF MSWINDOWS}{$IFDEF FPC}LclType.{$ENDIF}{$ENDIF}THandle; override;
{$IFDEF MSWINDOWS}
procedure WndProc(var aMessage: TMessage); override;
{$ENDIF}
property Chromium : TChromium read GetChromium;
public
@ -86,6 +90,11 @@ implementation
{$IFDEF FPC}
function TCEFLinkedWinControlBase.GetUseSetFocus: Boolean;
begin
Result := True;
end;
procedure TCEFLinkedWinControlBase.SetVisible(Value: Boolean);
{$IFDEF LINUX}
var
@ -117,6 +126,41 @@ begin
if (Result = 0) then Result := inherited GetChildWindowHandle;
end;
{$IFDEF MSWINDOWS}
procedure TCEFLinkedWinControlBase.WndProc(var aMessage: TMessage);
var
TempHandle : THandle;
begin
case aMessage.Msg of
WM_SETFOCUS:
begin
if GetUseSetFocus and (Chromium <> nil) then
Chromium.SetFocus(True)
else
begin
TempHandle := ChildWindowHandle;
if (TempHandle <> 0) then PostMessage(TempHandle, WM_SETFOCUS, aMessage.WParam, 0);
end;
inherited WndProc(aMessage);
end;
WM_ERASEBKGND:
if (ChildWindowHandle = 0) then inherited WndProc(aMessage);
CM_WANTSPECIALKEY:
if not(TWMKey(aMessage).CharCode in [VK_LEFT .. VK_DOWN, VK_RETURN, VK_ESCAPE]) then
aMessage.Result := 1
else
inherited WndProc(aMessage);
WM_GETDLGCODE : aMessage.Result := DLGC_WANTARROWS or DLGC_WANTCHARS;
else inherited WndProc(aMessage);
end;
end;
{$ENDIF}
procedure TCEFLinkedWinControlBase.UpdateSize;
begin
{$IFDEF LINUX}

View File

@ -76,10 +76,9 @@ type
FUseSetFocus : boolean;
function GetChromium: TChromium; override;
function GetUseSetFocus: Boolean; override;
function GetBrowserInitialized : boolean;
{$IFDEF MSWINDOWS}
procedure WndProc(var aMessage: TMessage); override;
procedure OnCloseMsg(var aMessage : TMessage); message CEF_DOONCLOSE;
procedure OnAfterCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
{$ENDIF}
@ -186,41 +185,6 @@ begin
end;
end;
{$IFDEF MSWINDOWS}
procedure TChromiumWindow.WndProc(var aMessage: TMessage);
var
TempHandle : THandle;
begin
case aMessage.Msg of
WM_SETFOCUS:
begin
if FUseSetFocus and (FChromium <> nil) then
FChromium.SetFocus(True)
else
begin
TempHandle := ChildWindowHandle;
if (TempHandle <> 0) then PostMessage(TempHandle, WM_SETFOCUS, aMessage.WParam, 0);
end;
inherited WndProc(aMessage);
end;
WM_ERASEBKGND:
if (ChildWindowHandle = 0) then inherited WndProc(aMessage);
CM_WANTSPECIALKEY:
if not(TWMKey(aMessage).CharCode in [VK_LEFT .. VK_DOWN, VK_RETURN, VK_ESCAPE]) then
aMessage.Result := 1
else
inherited WndProc(aMessage);
WM_GETDLGCODE : aMessage.Result := DLGC_WANTARROWS or DLGC_WANTCHARS;
else inherited WndProc(aMessage);
end;
end;
{$ENDIF}
function TChromiumWindow.GetBrowserInitialized : boolean;
begin
Result := (FChromium <> nil) and FChromium.Initialized;
@ -322,6 +286,11 @@ begin
result := FChromium;
end;
function TChromiumWindow.GetUseSetFocus: Boolean;
begin
Result := FUseSetFocus;
end;
// This is a workaround for the CEF issue #2026
// https://bitbucket.org/chromiumembedded/cef/issues/2026/multiple-major-keyboard-focus-issues-on

View File

@ -75,9 +75,6 @@ type
function GetChromium: TChromium; override;
procedure SetChromium(aValue : TChromium);
{$IFDEF MSWINDOWS}
procedure WndProc(var aMessage: TMessage); override;
{$ENDIF}
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
@ -105,41 +102,6 @@ begin
FChromium := nil;
end;
{$IFDEF MSWINDOWS}
procedure TCEFLinkedWindowParent.WndProc(var aMessage: TMessage);
var
TempHandle : THandle;
begin
case aMessage.Msg of
WM_SETFOCUS:
begin
if (FChromium <> nil) then
FChromium.SetFocus(True)
else
begin
TempHandle := ChildWindowHandle;
if (TempHandle <> 0) then PostMessage(TempHandle, WM_SETFOCUS, aMessage.WParam, 0);
end;
inherited WndProc(aMessage);
end;
WM_ERASEBKGND:
if (ChildWindowHandle = 0) then inherited WndProc(aMessage);
CM_WANTSPECIALKEY:
if not(TWMKey(aMessage).CharCode in [VK_LEFT .. VK_DOWN, VK_RETURN, VK_ESCAPE]) then
aMessage.Result := 1
else
inherited WndProc(aMessage);
WM_GETDLGCODE : aMessage.Result := DLGC_WANTARROWS or DLGC_WANTCHARS;
else inherited WndProc(aMessage);
end;
end;
{$ENDIF}
procedure TCEFLinkedWindowParent.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);