From 584baa21708b96dca52452a4be37e15cf65e503f Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 30 Dec 2014 16:23:36 +1000 Subject: [PATCH] Remove User32.cs and implement Focused methods in NativeMethodWrapper --- CefSharp.Core/NativeMethodWrapper.cpp | 15 +++++++++++---- CefSharp.Core/NativeMethodWrapper.h | 11 ++++++----- CefSharp.WinForms/CefSharp.WinForms.csproj | 1 - CefSharp.WinForms/ChromiumWebBrowser.cs | 4 +--- CefSharp.WinForms/Internals/User32.cs | 18 ------------------ 5 files changed, 18 insertions(+), 31 deletions(-) delete mode 100644 CefSharp.WinForms/Internals/User32.cs diff --git a/CefSharp.Core/NativeMethodWrapper.cpp b/CefSharp.Core/NativeMethodWrapper.cpp index bd82975d2..04c00538e 100644 --- a/CefSharp.Core/NativeMethodWrapper.cpp +++ b/CefSharp.Core/NativeMethodWrapper.cpp @@ -11,8 +11,15 @@ using namespace System; namespace CefSharp { - void NativeMethodWrapper::CopyMemoryUsingHandle(IntPtr^ dest, IntPtr^ src, int numberOfBytes) - { - CopyMemory(dest->ToPointer(), src->ToPointer(), numberOfBytes); - } + void NativeMethodWrapper::CopyMemoryUsingHandle(IntPtr^ dest, IntPtr^ src, int numberOfBytes) + { + CopyMemory(dest->ToPointer(), src->ToPointer(), numberOfBytes); + } + + bool NativeMethodWrapper::IsFocused(IntPtr handle) + { + // Ask Windows which control has the focus and then check if it's one of our children + auto focusControl = GetFocus(); + return focusControl != 0 && (IsChild((HWND)handle.ToPointer(), focusControl) == 1); + } } diff --git a/CefSharp.Core/NativeMethodWrapper.h b/CefSharp.Core/NativeMethodWrapper.h index ea6abbd44..660fc4c8d 100644 --- a/CefSharp.Core/NativeMethodWrapper.h +++ b/CefSharp.Core/NativeMethodWrapper.h @@ -10,9 +10,10 @@ using namespace System; namespace CefSharp { - public ref class NativeMethodWrapper sealed - { - public: - static void CopyMemoryUsingHandle(IntPtr^ dest, IntPtr^ src, int numberOfBytes); - }; + public ref class NativeMethodWrapper sealed + { + public: + static void CopyMemoryUsingHandle(IntPtr^ dest, IntPtr^ src, int numberOfBytes); + static bool IsFocused(IntPtr handle); + }; } \ No newline at end of file diff --git a/CefSharp.WinForms/CefSharp.WinForms.csproj b/CefSharp.WinForms/CefSharp.WinForms.csproj index d945875db..708d642ed 100644 --- a/CefSharp.WinForms/CefSharp.WinForms.csproj +++ b/CefSharp.WinForms/CefSharp.WinForms.csproj @@ -52,7 +52,6 @@ - Component diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 40ec8d6fe..ea2fdc618 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -384,9 +384,7 @@ namespace CefSharp.WinForms return false; } - // Ask Windows which control has the focus and then check if it's one of our children - var focus = User32.GetFocus(); - return focus != IntPtr.Zero && User32.IsChild(Handle, focus); + return NativeMethodWrapper.IsFocused(Handle); } } diff --git a/CefSharp.WinForms/Internals/User32.cs b/CefSharp.WinForms/Internals/User32.cs deleted file mode 100644 index 8aadba285..000000000 --- a/CefSharp.WinForms/Internals/User32.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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.WinForms.Internals -{ - public static class User32 - { - [DllImport("User32.dll")] - public extern static IntPtr GetFocus(); - - [DllImport("user32.dll")] - public extern static bool IsChild(IntPtr parent, IntPtr child); - } -} \ No newline at end of file