From 3d198d213f67d75398bb5184a8abf5d10b6e9e00 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 13 Nov 2019 10:44:23 +1100 Subject: [PATCH 1/2] fix(windows): focus is incorrect for CEF The focus code paths for Chromium frames (CEF4Delphi) were incorrect. The return value for preventing focus on navigation events was inverted, and then other code was attempting to work around this inversion, wrongly. Fixed the root issue of the inverted test (it would help if the parameter cefSetFocus was known as `Handled` rather than `Result`!) and then the remaining code pathways became far simpler. Fixes #2314. --- .../Keyman.Developer.UI.UframeCEFHost.dfm | 1 - .../Keyman.Developer.UI.UframeCEFHost.pas | 29 ++++--------------- .../developer/TIKE/main/UframeTextEditor.pas | 1 - 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.dfm b/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.dfm index bdbacd30c4..b326cf9e21 100644 --- a/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.dfm +++ b/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.dfm @@ -34,7 +34,6 @@ inherited frameCEFHost: TframeCEFHost Top = 208 end object cef: TChromium - OnWidgetCompMsg = cefWidgetCompMsg OnLoadEnd = cefLoadEnd OnSetFocus = cefSetFocus OnRunContextMenu = cefRunContextMenu diff --git a/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.pas b/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.pas index 818205d189..63d0138cfb 100644 --- a/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.pas +++ b/windows/src/developer/TIKE/main/Keyman.Developer.UI.UframeCEFHost.pas @@ -35,7 +35,6 @@ const CEF_AFTERCREATE = WM_USER + 302; CEF_SHOW = WM_USER + 303; CEF_LOADEND = WM_USER + 304; - CEF_SETFOCUS = WM_USER + 305; CEF_KEYEVENT = WM_USER + 306; CEF_BEFOREBROWSE = WM_USER + 307; CEF_CONSOLEMESSAGE = WM_USER + 308; @@ -106,7 +105,6 @@ type var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; var Result: Boolean); - procedure cefWidgetCompMsg(var aMessage: TMessage; var aHandled: Boolean); procedure cefSetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource; out Result: Boolean); private @@ -134,7 +132,6 @@ type procedure Handle_CEF_AFTERCREATE(var Message: TMessage); procedure Handle_CEF_SHOW(var message: TMessage); procedure Handle_CEF_LOADEND(var message: TMessage); - procedure Handle_CEF_SETFOCUS(var message: TMessage); procedure Handle_CEF_KEYEVENT(var message: TMessage); procedure Handle_CEF_BEFOREBROWSE(var message: TMessage); procedure Handle_CEF_CONSOLEMESSAGE(var message: TMessage); @@ -268,14 +265,6 @@ begin CreateBrowser; end; -procedure TframeCEFHost.cefWidgetCompMsg(var aMessage: TMessage; - var aHandled: Boolean); -begin - AssertCefThread; - if aMessage.Msg = WM_SETFOCUS then - PostMessage(FCallbackWnd, CEF_SETFOCUS, 0, 0); -end; - procedure TframeCEFHost.CreateBrowser; begin AssertVclThread; @@ -308,9 +297,11 @@ end; procedure TframeCEFHost.SetFocus; begin AssertVclThread; - inherited; - if not FIsClosing and cefwp.CanFocus then - cefwp.SetFocus; + if not FIsClosing and cefwp.CanFocus and Assigned(cef) then + begin + GetParentForm(Self).ActiveControl := Self; + cef.SetFocus(True); + end; end; procedure TframeCEFHost.CallbackWndProc(var Message: TMessage); @@ -322,7 +313,6 @@ begin CEF_AFTERCREATE: Handle_CEF_AFTERCREATE(Message); CEF_SHOW: Handle_CEF_SHOW(Message); CEF_LOADEND: Handle_CEF_LOADEND(Message); - CEF_SETFOCUS: Handle_CEF_SETFOCUS(Message); CEF_KEYEVENT: Handle_CEF_KEYEVENT(Message); CEF_BEFOREBROWSE: Handle_CEF_BEFOREBROWSE(Message); CEF_CONSOLEMESSAGE: Handle_CEF_CONSOLEMESSAGE(Message); @@ -534,13 +524,6 @@ begin FOnLoadEnd(Self); end; -procedure TframeCEFHost.Handle_CEF_SETFOCUS(var message: TMessage); -begin - AssertVclThread; - if Assigned(cefwp) and cefwp.Visible and cefwp.CanFocus then - GetParentForm(cefwp).ActiveControl := cefwp; -end; - procedure TframeCEFHost.cefPreKeyEvent(Sender: TObject; const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg; out isKeyboardShortcut, Result: Boolean); @@ -614,7 +597,7 @@ end; procedure TframeCEFHost.cefSetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource; out Result: Boolean); begin - Result := source <> FOCUS_SOURCE_NAVIGATION; + Result := source = FOCUS_SOURCE_NAVIGATION; end; procedure TframeCEFHost.WMEnterMenuLoop(var aMessage: TMessage); diff --git a/windows/src/developer/TIKE/main/UframeTextEditor.pas b/windows/src/developer/TIKE/main/UframeTextEditor.pas index 5b97d4b8f3..fca4d88760 100644 --- a/windows/src/developer/TIKE/main/UframeTextEditor.pas +++ b/windows/src/developer/TIKE/main/UframeTextEditor.pas @@ -656,7 +656,6 @@ end; procedure TframeTextEditor.SetFocus; begin - inherited; cef.SetFocus; end; From bdd2cb90341fac7d83ea0865fca068567e2a2548 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 15 Nov 2019 11:08:00 +1100 Subject: [PATCH 2/2] chore(developer): history.md --- windows/src/developer/history.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/windows/src/developer/history.md b/windows/src/developer/history.md index cfbc63ea89..69c69d909a 100644 --- a/windows/src/developer/history.md +++ b/windows/src/developer/history.md @@ -3,6 +3,9 @@ ## 13.0 alpha * Start version 13.0 +## 2019-11-15 12.0.54 stable +* Bug Fix: Text editor and other controls did not receive focus correctly (#2331) + ## 2019-10-07 12.0.50 stable * Release 12.0