Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OnGotFocus and OnSetFocus #341

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion CefSharp.Core/Internals/ClientAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,33 @@ namespace CefSharp
}
}

void ClientAdapter::OnGotFocus(CefRefPtr<CefBrowser> browser)
{
auto winFormsControl = dynamic_cast<IWinFormsWebBrowser^>((IWebBrowserInternal^)_browserControl);
if (winFormsControl != nullptr)
{
winFormsControl->OnGotFocus();
}
}

bool ClientAdapter::OnSetFocus(CefRefPtr<CefBrowser> browser, FocusSource source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space here after browser parameter.

{
auto winFormsControl = dynamic_cast<IWinFormsWebBrowser^>((IWebBrowserInternal^)_browserControl);
if (winFormsControl == nullptr)
{
return false;
}

return winFormsControl->OnSetFocus((CefFocusSource)source);
}

void ClientAdapter::OnTakeFocus(CefRefPtr<CefBrowser> browser, bool next)
{
_browserControl->OnTakeFocus(next);
auto winFormsControl = dynamic_cast<IWinFormsWebBrowser^>((IWebBrowserInternal^)_browserControl);
if (winFormsControl != nullptr)
{
winFormsControl->OnTakeFocus(next);
}
}

bool ClientAdapter::OnJSDialog(CefRefPtr<CefBrowser> browser, const CefString& origin_url, const CefString& accept_lang,
Expand Down
2 changes: 2 additions & 0 deletions CefSharp.Core/Internals/ClientAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ namespace CefSharp
CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) OVERRIDE;

// CefFocusHandler
virtual DECL void OnGotFocus(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual DECL bool OnSetFocus(CefRefPtr<CefBrowser> browser, FocusSource source) OVERRIDE;
virtual DECL void OnTakeFocus(CefRefPtr<CefBrowser> browser, bool next) OVERRIDE;

// CefKeyboardHandler
Expand Down
12 changes: 11 additions & 1 deletion CefSharp.WinForms/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,17 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt
}
}

void IWebBrowserInternal.OnTakeFocus(bool next)
void IWinFormsWebBrowser.OnGotFocus()
{

}

bool IWinFormsWebBrowser.OnSetFocus(CefFocusSource source)
{
return false;
}

void IWinFormsWebBrowser.OnTakeFocus(bool next)
{
SelectNextControl(this, next, true, true, true);
}
Expand Down
5 changes: 0 additions & 5 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,6 @@ void IWebBrowserInternal.OnFrameLoadEnd(string url, bool isMainFrame, int httpSt
}
}

void IWebBrowserInternal.OnTakeFocus(bool next)
{
throw new NotImplementedException();
}

void IWebBrowserInternal.OnConsoleMessage(string message, string source, int line)
{
var handler = ConsoleMessage;
Expand Down
21 changes: 21 additions & 0 deletions CefSharp/CefFocusSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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
{
/// <summary>
/// Focus Source
/// </summary>
public enum CefFocusSource
{
///
// The source is explicit navigation via the API (LoadURL(), etc).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best as <summary> tags for the XML docs.

///
FocusSourceNavigation = 0,
///
// The source is a system-generated focus event.
///
FocusSourceSystem
}
}
1 change: 1 addition & 0 deletions CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="TransitionType.cs" />
<Compile Include="NavStateChangedEventArgs.cs" />
<Compile Include="ICompletionHandler.cs" />
<Compile Include="CefFocusSource.cs" />
<Compile Include="Internals\BitmapInfo.cs" />
<Compile Include="Internals\IBrowserProcess.cs" />
<Compile Include="Internals\JavascriptMethod.cs" />
Expand Down
4 changes: 4 additions & 0 deletions CefSharp/IWinFormsWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ public interface IWinFormsWebBrowser : IWebBrowser
void Paste();
void Delete();
void SelectAll();

void OnGotFocus();
bool OnSetFocus(CefFocusSource source);
void OnTakeFocus(bool next);
}
}
1 change: 0 additions & 1 deletion CefSharp/Internals/IWebBrowserInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public interface IWebBrowserInternal : IWebBrowser

void OnFrameLoadStart(string url, bool isMainFrame);
void OnFrameLoadEnd(string url, bool isMainFrame, int httpStatusCode);
void OnTakeFocus(bool next);
void OnConsoleMessage(string message, string source, int line);
void OnStatusMessage(string value);
void OnLoadError(string url, CefErrorCode errorCode, string errorText);
Expand Down