Skip to content
Merged
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: 26 additions & 0 deletions CefSharp.WinForms/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,32 @@ public Task<string> GetTextAsync()
return taskStringVisitor.Task;
}

/// <summary>
/// Manually implement Focused because cef does not implement it.
/// </summary>
/// <remarks>
/// This is also how the Microsoft's WebBrowserControl implements the Focused property.
/// </remarks>
public override bool Focused
{
get
{
if (base.Focused)
{
return true;
}

if (!IsHandleCreated)
{
return false;
}

// Ask Windows which control has the focus and then check if it's one of our children
IntPtr focus = User32.GetFocus();
return focus != IntPtr.Zero && User32.IsChild(Handle, focus);
}
}

protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Expand Down
1 change: 1 addition & 0 deletions CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CefFileDialogMode.cs" />
<Compile Include="Internals\User32.cs" />
<Compile Include="IsBrowserInitializedChangedEventArgs.cs" />
<Compile Include="CefTerminationStatus.cs" />
<Compile Include="IDialogHandler.cs" />
Expand Down
18 changes: 18 additions & 0 deletions CefSharp/Internals/User32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

using System;
using System.Runtime.InteropServices;

namespace CefSharp.Internals
{
public static class User32
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this class into CefSharp.WinForms? it's unlikely to be used in any of the other projects.

{
[DllImport("User32.dll")]
public extern static IntPtr GetFocus();

[DllImport("user32.dll")]
public extern static bool IsChild(IntPtr parent, IntPtr child);
}
}