From aeaf25cd5f1f5b0355e48b84713f2a5dddd68a3a Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 29 Apr 2014 11:51:56 +1000 Subject: [PATCH 1/4] Add OnGotFocus and OnSetFocus Add CefFocusSource enum for mapping from cef_focus_source_t enum --- CefSharp.Core/Internals/ClientAdapter.cpp | 10 ++++++++++ CefSharp.Core/Internals/ClientAdapter.h | 2 ++ CefSharp.WinForms/ChromiumWebBrowser.cs | 10 ++++++++++ CefSharp.Wpf/ChromiumWebBrowser.cs | 12 +++++++++++- CefSharp/CefFocusSource.cs | 17 +++++++++++++++++ CefSharp/CefSharp.csproj | 1 + CefSharp/Internals/IWebBrowserInternal.cs | 2 ++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 CefSharp/CefFocusSource.cs diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index ecb393e94f..b7889c6167 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -373,6 +373,16 @@ namespace CefSharp } } + void ClientAdapter::OnGotFocus(CefRefPtr browser) + { + _browserControl->OnGotFocus(); + } + + bool ClientAdapter::OnSetFocus(CefRefPtr browser, FocusSource source) + { + return _browserControl->OnSetFocus((CefFocusSource)source); + } + void ClientAdapter::OnTakeFocus(CefRefPtr browser, bool next) { _browserControl->OnTakeFocus(next); diff --git a/CefSharp.Core/Internals/ClientAdapter.h b/CefSharp.Core/Internals/ClientAdapter.h index 37ecaebb2d..09332578d5 100644 --- a/CefSharp.Core/Internals/ClientAdapter.h +++ b/CefSharp.Core/Internals/ClientAdapter.h @@ -104,6 +104,8 @@ namespace CefSharp CefRefPtr params, CefRefPtr model) OVERRIDE; // CefFocusHandler + virtual DECL void OnGotFocus(CefRefPtr browser) OVERRIDE; + virtual DECL bool OnSetFocus(CefRefPtr browser, FocusSource source) OVERRIDE; virtual DECL void OnTakeFocus(CefRefPtr browser, bool next) OVERRIDE; // CefKeyboardHandler diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index cfe5b9d7cb..4204fc135b 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -208,6 +208,16 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt } } + void IWebBrowserInternal. OnGotFocus() + { + + } + + void IWebBrowserInternal. OnSetFocus(CefFocusSource source) + { + return false; + } + void IWebBrowserInternal.OnTakeFocus(bool next) { SelectNextControl(this, next, true, true, true); diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index e786430d66..952f356ce8 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1125,9 +1125,19 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt } } + void IWebBrowserInternal.OnGotFocus() + { + + } + + bool IWebBrowserInternal.OnSetFocus(CefFocusSource source) + { + return false; + } + void IWebBrowserInternal.OnTakeFocus(bool next) { - throw new NotImplementedException(); + } void IWebBrowserInternal.OnConsoleMessage(string message, string source, int line) diff --git a/CefSharp/CefFocusSource.cs b/CefSharp/CefFocusSource.cs new file mode 100644 index 0000000000..41f09ca5f3 --- /dev/null +++ b/CefSharp/CefFocusSource.cs @@ -0,0 +1,17 @@ +namespace CefSharp +{ + /// + /// Focus Source + /// + public enum CefFocusSource + { + /// + // The source is explicit navigation via the API (LoadURL(), etc). + /// + FocusSourceNavigation = 0, + /// + // The source is a system-generated focus event. + /// + FocusSourceSystem + } +} diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 82c6541505..e1e6a90e4b 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -114,6 +114,7 @@ + diff --git a/CefSharp/Internals/IWebBrowserInternal.cs b/CefSharp/Internals/IWebBrowserInternal.cs index 403189119e..13844938c7 100644 --- a/CefSharp/Internals/IWebBrowserInternal.cs +++ b/CefSharp/Internals/IWebBrowserInternal.cs @@ -16,6 +16,8 @@ public interface IWebBrowserInternal : IWebBrowser void OnFrameLoadStart(string url, bool isMainFrame); void OnFrameLoadEnd(string url, bool isMainFrame, int httpStatusCode); + void OnGotFocus(); + bool OnSetFocus(CefFocusSource source); void OnTakeFocus(bool next); void OnConsoleMessage(string message, string source, int line); void OnStatusMessage(string value); From ad55fdf9ac836e88dd04626147c4d65dbcfd49a1 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 9 Jul 2014 11:23:06 +1000 Subject: [PATCH 2/4] Add license disclaimer --- CefSharp/CefFocusSource.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CefSharp/CefFocusSource.cs b/CefSharp/CefFocusSource.cs index 41f09ca5f3..9855c4348d 100644 --- a/CefSharp/CefFocusSource.cs +++ b/CefSharp/CefFocusSource.cs @@ -1,4 +1,8 @@ -namespace CefSharp +// Copyright © 2010-2014 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +namespace CefSharp { /// /// Focus Source From 75cf2e69329fa1d6ea1683d3e07e2c247dac0666 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 9 Jul 2014 11:30:20 +1000 Subject: [PATCH 3/4] Fix return type and minor formatting --- CefSharp.WinForms/ChromiumWebBrowser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 4204fc135b..1770b5e898 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -208,12 +208,12 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt } } - void IWebBrowserInternal. OnGotFocus() + void IWebBrowserInternal.OnGotFocus() { } - void IWebBrowserInternal. OnSetFocus(CefFocusSource source) + bool IWebBrowserInternal.OnSetFocus(CefFocusSource source) { return false; } From 5b56436a1a1ddc58aa087c339e6a96a639eba97c Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 9 Jul 2014 11:37:10 +1000 Subject: [PATCH 4/4] Move Focus methods from IWebBrowserInternal to IWinFormsWebBrowser and only call them in the context of the WinForms ChromiumWebBrowser --- CefSharp.Core/Internals/ClientAdapter.cpp | 20 +++++++++++++++++--- CefSharp.WinForms/ChromiumWebBrowser.cs | 6 +++--- CefSharp.Wpf/ChromiumWebBrowser.cs | 15 --------------- CefSharp/IWinFormsWebBrowser.cs | 4 ++++ CefSharp/Internals/IWebBrowserInternal.cs | 3 --- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index b7889c6167..70ac832082 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -375,17 +375,31 @@ namespace CefSharp void ClientAdapter::OnGotFocus(CefRefPtr browser) { - _browserControl->OnGotFocus(); + auto winFormsControl = dynamic_cast((IWebBrowserInternal^)_browserControl); + if (winFormsControl != nullptr) + { + winFormsControl->OnGotFocus(); + } } bool ClientAdapter::OnSetFocus(CefRefPtr browser, FocusSource source) { - return _browserControl->OnSetFocus((CefFocusSource)source); + auto winFormsControl = dynamic_cast((IWebBrowserInternal^)_browserControl); + if (winFormsControl == nullptr) + { + return false; + } + + return winFormsControl->OnSetFocus((CefFocusSource)source); } void ClientAdapter::OnTakeFocus(CefRefPtr browser, bool next) { - _browserControl->OnTakeFocus(next); + auto winFormsControl = dynamic_cast((IWebBrowserInternal^)_browserControl); + if (winFormsControl != nullptr) + { + winFormsControl->OnTakeFocus(next); + } } bool ClientAdapter::OnJSDialog(CefRefPtr browser, const CefString& origin_url, const CefString& accept_lang, diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 1770b5e898..f45e7c5c3b 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -208,17 +208,17 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt } } - void IWebBrowserInternal.OnGotFocus() + void IWinFormsWebBrowser.OnGotFocus() { } - bool IWebBrowserInternal.OnSetFocus(CefFocusSource source) + bool IWinFormsWebBrowser.OnSetFocus(CefFocusSource source) { return false; } - void IWebBrowserInternal.OnTakeFocus(bool next) + void IWinFormsWebBrowser.OnTakeFocus(bool next) { SelectNextControl(this, next, true, true, true); } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 952f356ce8..08464e79fe 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -1125,21 +1125,6 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt } } - void IWebBrowserInternal.OnGotFocus() - { - - } - - bool IWebBrowserInternal.OnSetFocus(CefFocusSource source) - { - return false; - } - - void IWebBrowserInternal.OnTakeFocus(bool next) - { - - } - void IWebBrowserInternal.OnConsoleMessage(string message, string source, int line) { var handler = ConsoleMessage; diff --git a/CefSharp/IWinFormsWebBrowser.cs b/CefSharp/IWinFormsWebBrowser.cs index 322efb48ce..f579bd6206 100644 --- a/CefSharp/IWinFormsWebBrowser.cs +++ b/CefSharp/IWinFormsWebBrowser.cs @@ -20,5 +20,9 @@ public interface IWinFormsWebBrowser : IWebBrowser void Paste(); void Delete(); void SelectAll(); + + void OnGotFocus(); + bool OnSetFocus(CefFocusSource source); + void OnTakeFocus(bool next); } } diff --git a/CefSharp/Internals/IWebBrowserInternal.cs b/CefSharp/Internals/IWebBrowserInternal.cs index 13844938c7..c65220306c 100644 --- a/CefSharp/Internals/IWebBrowserInternal.cs +++ b/CefSharp/Internals/IWebBrowserInternal.cs @@ -16,9 +16,6 @@ public interface IWebBrowserInternal : IWebBrowser void OnFrameLoadStart(string url, bool isMainFrame); void OnFrameLoadEnd(string url, bool isMainFrame, int httpStatusCode); - void OnGotFocus(); - bool OnSetFocus(CefFocusSource source); - void OnTakeFocus(bool next); void OnConsoleMessage(string message, string source, int line); void OnStatusMessage(string value); void OnLoadError(string url, CefErrorCode errorCode, string errorText);