Skip to content

Commit 87667f2

Browse files
committed
Pulling in amaitland:CefSharp feature/focus-handler changes
2 parents 907cca8 + a2debed commit 87667f2

File tree

8 files changed

+64
-8
lines changed

8 files changed

+64
-8
lines changed

CefSharp.Core/Internals/ClientAdapter.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,33 @@ namespace CefSharp
373373
}
374374
}
375375

376+
void ClientAdapter::OnGotFocus(CefRefPtr<CefBrowser> browser)
377+
{
378+
auto winFormsControl = dynamic_cast<IWinFormsWebBrowser^>((IWebBrowserInternal^)_browserControl);
379+
if (winFormsControl != nullptr)
380+
{
381+
winFormsControl->OnGotFocus();
382+
}
383+
}
384+
385+
bool ClientAdapter::OnSetFocus(CefRefPtr<CefBrowser> browser, FocusSource source)
386+
{
387+
auto winFormsControl = dynamic_cast<IWinFormsWebBrowser^>((IWebBrowserInternal^)_browserControl);
388+
if (winFormsControl == nullptr)
389+
{
390+
return false;
391+
}
392+
393+
return winFormsControl->OnSetFocus((CefFocusSource)source);
394+
}
395+
376396
void ClientAdapter::OnTakeFocus(CefRefPtr<CefBrowser> browser, bool next)
377397
{
378-
_browserControl->OnTakeFocus(next);
398+
auto winFormsControl = dynamic_cast<IWinFormsWebBrowser^>((IWebBrowserInternal^)_browserControl);
399+
if (winFormsControl != nullptr)
400+
{
401+
winFormsControl->OnTakeFocus(next);
402+
}
379403
}
380404

381405
bool ClientAdapter::OnJSDialog(CefRefPtr<CefBrowser> browser, const CefString& origin_url, const CefString& accept_lang,

CefSharp.Core/Internals/ClientAdapter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ namespace CefSharp
104104
CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) OVERRIDE;
105105

106106
// CefFocusHandler
107+
virtual DECL void OnGotFocus(CefRefPtr<CefBrowser> browser) OVERRIDE;
108+
virtual DECL bool OnSetFocus(CefRefPtr<CefBrowser> browser, FocusSource source) OVERRIDE;
107109
virtual DECL void OnTakeFocus(CefRefPtr<CefBrowser> browser, bool next) OVERRIDE;
108110

109111
// CefKeyboardHandler

CefSharp.WinForms/ChromiumWebBrowser.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,17 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt
208208
}
209209
}
210210

211-
void IWebBrowserInternal.OnTakeFocus(bool next)
211+
void IWinFormsWebBrowser.OnGotFocus()
212+
{
213+
214+
}
215+
216+
bool IWinFormsWebBrowser.OnSetFocus(CefFocusSource source)
217+
{
218+
return false;
219+
}
220+
221+
void IWinFormsWebBrowser.OnTakeFocus(bool next)
212222
{
213223
SelectNextControl(this, next, true, true, true);
214224
}

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,6 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt
11251125
}
11261126
}
11271127

1128-
void IWebBrowserInternal.OnTakeFocus(bool next)
1129-
{
1130-
throw new NotImplementedException();
1131-
}
1132-
11331128
void IWebBrowserInternal.OnConsoleMessage(string message, string source, int line)
11341129
{
11351130
var handler = ConsoleMessage;

CefSharp/CefFocusSource.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
namespace CefSharp
6+
{
7+
/// <summary>
8+
/// Focus Source
9+
/// </summary>
10+
public enum CefFocusSource
11+
{
12+
///
13+
// The source is explicit navigation via the API (LoadURL(), etc).
14+
///
15+
FocusSourceNavigation = 0,
16+
///
17+
// The source is a system-generated focus event.
18+
///
19+
FocusSourceSystem
20+
}
21+
}

CefSharp/CefSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
<Compile Include="TransitionType.cs" />
115115
<Compile Include="NavStateChangedEventArgs.cs" />
116116
<Compile Include="ICompletionHandler.cs" />
117+
<Compile Include="CefFocusSource.cs" />
117118
<Compile Include="Internals\BitmapInfo.cs" />
118119
<Compile Include="Internals\IBrowserProcess.cs" />
119120
<Compile Include="Internals\JavascriptMethod.cs" />

CefSharp/IWinFormsWebBrowser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ public interface IWinFormsWebBrowser : IWebBrowser
2020
void Paste();
2121
void Delete();
2222
void SelectAll();
23+
24+
void OnGotFocus();
25+
bool OnSetFocus(CefFocusSource source);
26+
void OnTakeFocus(bool next);
2327
}
2428
}

CefSharp/Internals/IWebBrowserInternal.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public interface IWebBrowserInternal : IWebBrowser
1616

1717
void OnFrameLoadStart(string url, bool isMainFrame);
1818
void OnFrameLoadEnd(string url, bool isMainFrame, int httpStatusCode);
19-
void OnTakeFocus(bool next);
2019
void OnConsoleMessage(string message, string source, int line);
2120
void OnStatusMessage(string value);
2221
void OnLoadError(string url, CefErrorCode errorCode, string errorText);

0 commit comments

Comments
 (0)